Package com.jalios.jcms.search
Class DataIterator<E>
java.lang.Object
com.jalios.jcms.search.DataIterator<E>
- Type Parameters:
E- the type being iterated
- All Implemented Interfaces:
Iterator<E>
DataIterator allowing efficient iteration over hybrid sources
of Data (JStore and/or JcmsDB) with size retrieval.
Warning : elements will not be sorted accross sources, JStore objects are iterated first, then JcmsDB object are iterated !
This iterator does not support remove operation.
Example to iterate all Publication object :
DataIterator<Publication> iterator = new DataIterator<Publication>();
// JStore
TreeSet<Publication> jStorePubSet = new TreeSet<Publication>(channel.getDataSet(Publication.class));
iterator.addCollection(jStorePubSet);
// JcmsDB
for(Class<? extends Publication> clazz : channel.getDBPublicationClassList()) {
ScrollableResults sr = HibernateUtil.getSession().createCriteria(clazz).scroll();
int dbcount = HibernateUtil.queryCountExact(clazz, null);
iterator.addScrollableResults(sr, dbcount);
}
- Since:
- jcms-6.0.1
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty DataIterator.DataIterator(Collection<? extends E> coll) Creates a new DataIterator to iterate the specified Collection of objects.DataIterator(Collection<? extends E> coll, org.hibernate.ScrollableResults sr, int dbcount) Creates a new DataIterator to iterate both the specified Collection the JcmsDB results.DataIterator(org.hibernate.ScrollableResults sr, int dbcount) Creates a new DataIterator to iterate the specified JcmsDB results. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCollection(Collection<? extends E> coll) Add the specified Collection to the element to iterate.voidaddDBClass(Class<?> clazz) Add the specified DB Class to the element to iterate.voidaddScrollableResults(org.hibernate.ScrollableResults sr, int dbcount) Add the specified ScrollableResults to the element to iterate.booleanhasNext()Returnstrueif the iteration has more elements.next()Returns the next element in the iteration.voidremove()Unsupported Operationintsize()Return the total number of object available in the iteration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
DataIterator
public DataIterator()Creates a new empty DataIterator. -
DataIterator
Creates a new DataIterator to iterate the specified Collection of objects.- Parameters:
coll- a collection to iterate
-
DataIterator
public DataIterator(org.hibernate.ScrollableResults sr, int dbcount) Creates a new DataIterator to iterate the specified JcmsDB results.- Parameters:
sr- the JcmsDB ScrollableResults.dbcount- the number or result returned in the ScrollableResults.
-
DataIterator
Creates a new DataIterator to iterate both the specified Collection the JcmsDB results.- Parameters:
coll- the collection to iterate (can be null, in which case iterate on collection is skipped).sr- the JcmsDB ScrollableResults.dbcount- the number or result returned in the ScrollableResults.
-
-
Method Details
-
addCollection
Add the specified Collection to the element to iterate.- Parameters:
coll- the Collection to iterate (can be null, in which case iterate on collection is skipped).- Throws:
IllegalStateException- if the iteration has already begun
-
addScrollableResults
public void addScrollableResults(org.hibernate.ScrollableResults sr, int dbcount) Add the specified ScrollableResults to the element to iterate.- Parameters:
sr- the JcmsDB ScrollableResults.dbcount- the number or result returned in the ScrollableResults.- Throws:
IllegalStateException- if the iteration has already begun
-
addDBClass
Add the specified DB Class to the element to iterate.- Parameters:
clazz- a class of data inside the database- Throws:
IllegalStateException- if the iteration has already begun- Since:
- jcms-7.0.0
-
hasNext
public boolean hasNext()Returnstrueif the iteration has more elements. (In other words, returnstrueifnextwould return an element rather than throwing an exception.) -
next
Returns the next element in the iteration. Calling this method repeatedly until thehasNext()method returns false will return each element in the underlying collection exactly once.- Specified by:
nextin interfaceIterator<E>- Returns:
- the next element in the iteration.
- Throws:
NoSuchElementException- iteration has no more elements.
-
size
public int size()Return the total number of object available in the iteration.Warning : When used with JcmsDB results, the correctness of this number depends on the parameters specified at construction time !
- Returns:
- the number of object being iterated
-
remove
public void remove()Unsupported Operation- Specified by:
removein interfaceIterator<E>- Throws:
UnsupportedOperationException
-