2 * The former (German) documentation of this classe
3 * stated that this class is an abstract one. There is,
4 * however, not a single abstract method in this class.
13 import freemarker.template.*;
16 import mir.storage.store.*;
21 * Container class for lists of Entities.
22 * Now implements freemarker.template.TemplateListModel
23 * and @see mir.storage.store.StorableObject.
26 * first version 27.6.1999
28 * @version 1.0 (freemarker compliant & and storable in ObjectStore)
30 public class EntityList implements TemplateListModel, StorableObject {
32 private static Logfile theLog;
33 private ArrayList theEntityArrayList = new ArrayList();
34 private String whereClause, orderClause;
35 private Class theEntityClass;
36 private int count, offset, limit;
37 private int offsetnext = -1, offsetprev = -1;
38 private int freemarkerListPointer=-1;
42 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
48 public EntityList(){ }
50 /* get/set EntityClass of Objects stored in EntityList */
51 public void setEntityClass(Class theEntityClass) { this.theEntityClass=theEntityClass; }
52 public Class getEntityClass() { return theEntityClass; }
54 public void setLimit(int limit) { this.limit = limit; }
57 * Sets the WHERE clause that fetched the Entities of this EntityList from the database.
58 * @param wc The string that contains the WHERE clause
60 public void setWhere(String wc) {
61 this.whereClause = wc;
65 * Returns the WHERE clause that returned this EntityList from the database
66 * @return whereClause The WHERE clause
68 public String getWhere() {
74 * Sets the sorting criterium of this EntityList
77 public void setOrder(String oc) {
78 this.orderClause = oc;
82 * Returns the sorting criterium.
83 * @return orderClause The sort order
85 public String getOrder() {
90 * Sets the number of rows that match the WHERE clause
91 * @param i The number of rows that match the WHERE clause
93 public void setCount(int i) {
98 * Returns the number of rows that match the WHERE clause
99 * @return The number of rows ...
101 public int getCount() {
107 * @param i The offset
109 public void setOffset(int i) {
117 public int getOffset() {
122 * Sets the offset of the next batch of Entities.
123 * @param i The next offset
125 public void setNextBatch(int i) {
130 * Returns the offset of the next batch of Entities.
131 * @return offset of the next batch
133 public int getNextBatch() {
138 * Returns whether there is a next batch within the WHERE clause
139 * @return true if yes, false if no.
141 public boolean hasNextBatch() {
142 return (offsetnext >= 0);
146 * Sets the offset of the previous batch.
147 * @param i the previous offset
149 public void setPrevBatch(int i) {
154 * Returns the offset of the previous batch.
155 * @return offset of the previous batch
157 public int getPrevBatch() {
162 * Returns whether there is a previous batch.
163 * @return true if yes, false if no
165 public boolean hasPrevBatch() {
166 return (offsetprev >= 0);
170 * Returns the start index of the batch.
173 public int getFrom() {
178 * Returns the end index of the batch.
189 * Inserts an Entity into the EntityList.
190 * @param anEntity The entity to be inserted.
193 public void add (Entity anEntity) {
195 theEntityArrayList.add(anEntity);
197 theLog.printWarning("EntityList: add called with empty Entity");
202 * @return The number of Entities in the EntityList.
206 return theEntityArrayList.size();
211 * Returns the element at position i in the EntityList as Entity
212 * @param i the position of the element in question
213 * @return The element at position i.
216 public Entity elementAt(int i) {
217 /** @todo check if i is in list.size() */
218 return (Entity)theEntityArrayList.get(i);
222 // The following methods have to be implemented
223 // for this class to be an implementation of the
224 // TemplateListModel of the Freemarker packages
226 public TemplateModel get(int i) { return elementAt(i); }
227 public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
228 public void rewind() { freemarkerListPointer=-1; }
230 public TemplateModel next() {
232 freemarkerListPointer++;return get(freemarkerListPointer); }
238 * Returns whether there is a next element
239 * @return true if there is a next element, else false
242 public boolean hasNext() {
243 return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
248 * Returns whether EntityList is empty or not
249 * @return true in case of empty list, false otherwise
252 public boolean isEmpty() {
253 if (theEntityArrayList!=null)
254 return theEntityArrayList.size()<1 ;
259 // Methods to implement StorableObject
261 public Set getNotifyOnReleaseSet() { return null; }
263 public StoreIdentifier getStoreIdentifier() {
264 if ( theEntityClass!=null ) {
266 new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,
267 StoreUtil.getEntityListUniqueIdentifierFor( whereClause, orderClause, offset, limit ));
269 theLog.printWarning("EntityList could not return StoreIdentifier");