Class DataIterator<E>

  • Type Parameters:
    E - the type being iterated
    All Implemented Interfaces:
    java.util.Iterator<E>

    public class DataIterator<E>
    extends java.lang.Object
    implements java.util.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
      DataIterator()
      Creates a new empty DataIterator.
      DataIterator​(java.util.Collection<? extends E> coll)
      Creates a new DataIterator to iterate the specified Collection of objects.
      DataIterator​(java.util.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCollection​(java.util.Collection<? extends E> coll)
      Add the specified Collection to the element to iterate.
      void addDBClass​(java.lang.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 hasNext()
      Returns true if the iteration has more elements.
      E next()
      Returns the next element in the iteration.
      void remove()
      Unsupported Operation
      int size()
      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 Detail

      • DataIterator

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

        public DataIterator​(java.util.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​(java.util.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 Detail

      • addCollection

        public void addCollection​(java.util.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:
        java.lang.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:
        java.lang.IllegalStateException - if the iteration has already begun
      • addDBClass

        public void addDBClass​(java.lang.Class<?> clazz)
        Add the specified DB Class to the element to iterate.
        Parameters:
        clazz - a class of data inside the database
        Throws:
        java.lang.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 java.util.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 java.util.Iterator<E>
        Returns:
        the next element in the iteration.
        Throws:
        java.util.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 java.util.Iterator<E>
        Throws:
        java.lang.UnsupportedOperationException