package org.onetwo.plugins.batch;

import org.springframework.batch.item.database.HibernatePagingItemReader;
import org.springframework.util.Assert;

public class HibernateQueryPagingItemReader<E> extends HibernatePagingItemReader<E> {
	
	private boolean hql;
	private String sqlQueryString;
	private Class<E> entityClass; 

	private boolean resultTransformer = false;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		if(!isHql()){
			Assert.hasText(sqlQueryString, "queryString must be set!");
			Assert.notNull(entityClass, "entityClass must be set!");
			
			HibernateNativeQueryProvider<E> queryProvider = new HibernateNativeQueryProvider<E>();
			queryProvider.setSqlQuery(sqlQueryString);
			queryProvider.setResultClass(entityClass, resultTransformer);
			setQueryProvider(queryProvider);
		}
		super.afterPropertiesSet();
	}

	public boolean isHql() {
		return hql;
	}

	public void setHql(boolean hql) {
		this.hql = hql;
	}

	public void setQueryString(String queryString) {
		super.setQueryString(queryString);
		this.sqlQueryString = queryString;
	}

	public void setEntityClass(Class<E> entityClass) {
		this.entityClass = entityClass;
	}

	public void setResultTransformer(boolean resultTransformer) {
		this.resultTransformer = resultTransformer;
	}
	
	
}

@@ -377,16 +377,88 @@
 se;%0D%0A%09%0D%0A
+%09public HibernateQueryPagingItemReader()%7B%0D%0A%09%09setPageSize(1000);%0D%0A%09%7D%0D%0A%09%0D%0A
 %09@Overri

add pagesize