OPEN - issue BATCH-1422: HibernateCursorItemReader causes OutOfMemoryError when skipping large sets of data
Javadocs.
This commit is contained in:
@@ -35,8 +35,10 @@ import org.springframework.util.ClassUtils;
|
||||
* executes the HQL query when initialized iterates over the result set as
|
||||
* {@link #read()} method is called, returning an object corresponding to
|
||||
* current row. The query can be set directly using
|
||||
* {@link #setQueryString(String)} or a named query can be used by
|
||||
* {@link #setQueryName(String)}.
|
||||
* {@link #setQueryString(String)}, a named query can be used by
|
||||
* {@link #setQueryName(String)}, or a query provider strategy can be supplied
|
||||
* via {@link #setQueryProvider(HibernateQueryProvider)}.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* The reader can be configured to use either {@link StatelessSession}
|
||||
@@ -165,7 +167,7 @@ public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStream
|
||||
cursor = helper.getForwardOnlyCursor();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the context and clear the session if stateful.
|
||||
*
|
||||
|
||||
@@ -26,16 +26,18 @@ import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.item.database.support.AbstractHibernateQueryProvider;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Internal shared state helper for hibernate readers.
|
||||
* Internal shared state helper for hibernate readers managing sessions and
|
||||
* queries.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
class HibernateItemReaderHelper<T> {
|
||||
class HibernateItemReaderHelper<T> implements InitializingBean {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@@ -170,7 +172,7 @@ class HibernateItemReaderHelper<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// if queryProvider is set use it to create a query
|
||||
// If queryProvider is set use it to create a query
|
||||
return queryProvider.createQuery();
|
||||
|
||||
}
|
||||
@@ -203,8 +205,11 @@ class HibernateItemReaderHelper<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param page the page to read
|
||||
* @param pageSize the size of the page
|
||||
* Read a page of data, clearing the existing session (if necessary) first,
|
||||
* and creating a new session before executing the query.
|
||||
*
|
||||
* @param page the page to read (starting at 0)
|
||||
* @param pageSize the size of the page or maximum number of items to read
|
||||
* @return a collection of items
|
||||
*/
|
||||
public Collection<? extends T> readPage(int page, int pageSize) {
|
||||
@@ -225,7 +230,7 @@ class HibernateItemReaderHelper<T> {
|
||||
* Clear the session if stateful.
|
||||
*/
|
||||
public void clear() {
|
||||
if (statefulSession!=null) {
|
||||
if (statefulSession != null) {
|
||||
statefulSession.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,13 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link ItemReader} for reading database records built on top of Hibernate. It
|
||||
* executes the HQL query when initialized iterates over the result set as
|
||||
* {@link #read()} method is called, returning an object corresponding to
|
||||
* current row. The query can be set directly using
|
||||
* {@link #setQueryString(String)} or a named query can be used by
|
||||
* {@link #setQueryName(String)}.
|
||||
* {@link ItemReader} for reading database records built on top of Hibernate and
|
||||
* reading only up to a fixed number of items at a time. It executes an HQL
|
||||
* query when initialized is paged as the {@link #read()} method is called. The
|
||||
* query can be set directly using {@link #setQueryString(String)}, a named
|
||||
* query can be used by {@link #setQueryName(String)}, or a query provider
|
||||
* strategy can be supplied via
|
||||
* {@link #setQueryProvider(HibernateQueryProvider)}.
|
||||
*
|
||||
* <p>
|
||||
* The reader can be configured to use either {@link StatelessSession}
|
||||
@@ -63,11 +64,6 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
|
||||
setName(ClassUtils.getShortName(HibernatePagingItemReader.class));
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.afterPropertiesSet();
|
||||
helper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* The parameter values to apply to a query (map of name:value).
|
||||
*
|
||||
@@ -131,6 +127,11 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
|
||||
helper.setUseStatelessSession(useStatelessSession);
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.afterPropertiesSet();
|
||||
helper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOpen() throws Exception {
|
||||
super.doOpen();
|
||||
@@ -145,7 +146,7 @@ public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> im
|
||||
else {
|
||||
results.clear();
|
||||
}
|
||||
|
||||
|
||||
results.addAll(helper.readPage(getPage(), getPageSize()));
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user