Class DataIterator<E>

java.lang.Object
com.jalios.jcms.search.DataIterator<E>
Type Parameters:
E - the type being iterated
All Implemented Interfaces:
Iterator<E>

public class DataIterator<E> extends Object implements 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

    Constructors
    Constructor
    Description
    Creates 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 Type
    Method
    Description
    void
    addCollection(Collection<? extends E> coll)
    Add the specified Collection to the element to iterate.
    void
    addDBClass(Class<?> clazz)
    Add the specified DB Class to the element to iterate.
    void
    addScrollableResults(org.hibernate.ScrollableResults sr, int dbcount)
    Add the specified ScrollableResults to the element to iterate.
    boolean
    Returns true if the iteration has more elements.
    Returns the next element in the iteration.
    void
    Unsupported Operation
    int
    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, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining
  • Constructor Details

    • DataIterator

      public DataIterator()
      Creates a new empty DataIterator.
    • DataIterator

      public DataIterator(Collection<? extends E> coll)
      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

      public DataIterator(Collection<? extends E> coll, org.hibernate.ScrollableResults sr, int dbcount)
      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

      public void addCollection(Collection<? extends E> coll)
      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

      public void addDBClass(Class<?> clazz)
      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()
      Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
      Specified by:
      hasNext in interface Iterator<E>
      Returns:
      true if the iterator has more elements.
    • next

      public E next()
      Returns the next element in the iteration. Calling this method repeatedly until the hasNext() method returns false will return each element in the underlying collection exactly once.
      Specified by:
      next in interface Iterator<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:
      remove in interface Iterator<E>
      Throws:
      UnsupportedOperationException