View Javadoc

1   /**
2    * 2010, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
3    * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
4    */
5   
6   package pt.digitalis.dif.model.hibernate;
7   
8   import java.util.Iterator;
9   
10  import org.hibernate.Criteria;
11  import org.hibernate.ScrollableResults;
12  
13  import pt.digitalis.utils.common.IBeanAttributes;
14  
15  /**
16   * An {@link Iterator} for an Hibernate {@link ScrollableResults} result.<br>
17   * Will allow forward navigation with cache disabled, and entity cache cleanup at regular intervals to present Hibernate
18   * entity memory overflow in large result sets.
19   * 
20   * @author Pedro Viegas <a href="mailto:pviegas@digitalis.pt">pviegas@digitalis.pt</a><br/>
21   * @param <T>
22   *            the data type of the results
23   * @created 2010/10/01
24   */
25  public class HibernateScrollableResultsIterator<T extends IBeanAttributes> implements Iterator<T> {
26  
27      // TODO: Review if this is necessary after implementation of this feature
28      // /** Iterator counter for hibernate memory flush */
29      // private long recordsServer = 0;
30  
31      /** The result to iterate */
32      private ScrollableResults results;
33  
34      /**
35       * Executes the given {@link Criteria} setting all necessary tweaks for simple non-cached forward navigation in the
36       * Result Set.
37       * 
38       * @param criteria
39       */
40      public HibernateScrollableResultsIterator(Criteria criteria)
41      {
42          // TODO: Must Implement this
43          // this.results = results;
44      }
45  
46      /**
47       * Wraps a {@link ScrollableResults} in an iterator implementation
48       * 
49       * @param results
50       */
51      public HibernateScrollableResultsIterator(ScrollableResults results)
52      {
53          this.results = results;
54      }
55  
56      /**
57       * @see java.util.Iterator#hasNext()
58       */
59      public boolean hasNext()
60      {
61  
62          return results.next();
63      }
64  
65      /**
66       * @see java.util.Iterator#next()
67       */
68      @SuppressWarnings("unchecked")
69      public T next()
70      {
71          return (T) results.get(0);
72      }
73  
74      /**
75       * @see java.util.Iterator#remove()
76       */
77      public void remove()
78      {
79          throw new UnsupportedOperationException("remove() not supported");
80      }
81  }