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.*;
17 import mir.storage.store.*;
23 * Container class for lists of Entities.
24 * Now implements freemarker.template.TemplateListModel
25 * and @see mir.storage.store.StorableObject.
28 * first version 27.6.1999
30 * @version 1.0 (freemarker compliant & and storable in ObjectStore)
32 public class EntityList implements TemplateListModel, StorableObject {
34 private static Logfile theLog;
35 private ArrayList theEntityArrayList = new ArrayList();
36 private String whereClause, orderClause;
37 private StorageObject theStorage;
38 private int count, offset, limit;
39 private int offsetnext = -1, offsetprev = -1;
40 private int freemarkerListPointer=-1;
44 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
50 public EntityList(){ }
52 /* get/set EntityClass of Objects stored in EntityList */
53 public void setStorage(StorageObject storage) { this.theStorage=storage; }
54 public StorageObject getStorage() { return theStorage; }
56 public void setLimit(int limit) { this.limit = limit; }
59 * Sets the WHERE clause that fetched the Entities of this EntityList from the database.
60 * @param wc The string that contains the WHERE clause
62 public void setWhere(String wc) {
63 this.whereClause = wc;
67 * Returns the WHERE clause that returned this EntityList from the database
68 * @return whereClause The WHERE clause
70 public String getWhere() {
76 * Sets the sorting criterium of this EntityList
79 public void setOrder(String oc) {
80 this.orderClause = oc;
84 * Returns the sorting criterium.
85 * @return orderClause The sort order
87 public String getOrder() {
92 * Sets the number of rows that match the WHERE clause
93 * @param i The number of rows that match the WHERE clause
95 public void setCount(int i) {
100 * Returns the number of rows that match the WHERE clause
101 * @return The number of rows ...
103 public int getCount() {
109 * @param i The offset
111 public void setOffset(int i) {
119 public int getOffset() {
124 * Sets the offset of the next batch of Entities.
125 * @param i The next offset
127 public void setNextBatch(int i) {
132 * Returns the offset of the next batch of Entities.
133 * @return offset of the next batch
135 public int getNextBatch() {
140 * Returns whether there is a next batch within the WHERE clause
141 * @return true if yes, false if no.
143 public boolean hasNextBatch() {
144 return (offsetnext >= 0);
148 * Sets the offset of the previous batch.
149 * @param i the previous offset
151 public void setPrevBatch(int i) {
156 * Returns the offset of the previous batch.
157 * @return offset of the previous batch
159 public int getPrevBatch() {
164 * Returns whether there is a previous batch.
165 * @return true if yes, false if no
167 public boolean hasPrevBatch() {
168 return (offsetprev >= 0);
172 * Returns the start index of the batch.
175 public int getFrom() {
180 * Returns the end index of the batch.
191 * Inserts an Entity into the EntityList.
192 * @param anEntity The entity to be inserted.
195 public void add (Entity anEntity) {
197 theEntityArrayList.add(anEntity);
199 theLog.printWarning("EntityList: add called with empty Entity");
204 * @return The number of Entities in the EntityList.
208 return theEntityArrayList.size();
213 * Returns the element at position i in the EntityList as Entity
214 * @param i the position of the element in question
215 * @return The element at position i.
218 public Entity elementAt(int i) {
219 /** @todo check if i is in list.size() */
220 return (Entity)theEntityArrayList.get(i);
224 // The following methods have to be implemented
225 // for this class to be an implementation of the
226 // TemplateListModel of the Freemarker packages
228 public TemplateModel get(int i) { return elementAt(i); }
229 public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
230 public void rewind() { freemarkerListPointer=-1; }
232 public TemplateModel next() {
234 freemarkerListPointer++;return get(freemarkerListPointer); }
240 * Returns whether there is a next element
241 * @return true if there is a next element, else false
244 public boolean hasNext() {
245 return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
250 * Returns whether EntityList is empty or not
251 * @return true in case of empty list, false otherwise
254 public boolean isEmpty() {
255 if (theEntityArrayList!=null)
256 return theEntityArrayList.size()<1 ;
261 // Methods to implement StorableObject
263 public Set getNotifyOnReleaseSet() { return null; }
265 public StoreIdentifier getStoreIdentifier() {
266 if ( theStorage!=null ) {
268 new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,
269 StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(),
270 whereClause, orderClause, offset, limit ));
272 theLog.printWarning("EntityList could not return StoreIdentifier");