/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001, 2002 The Mir-coders group
*
* This file is part of Mir.
*
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with the com.oreilly.servlet library, any library
- * licensed under the Apache Software License, The Sun (tm) Java Advanced
- * Imaging library (JAI), The Sun JIMI library (or with modified versions of
- * the above that use the same license as the above), and distribute linked
- * combinations including the two. You must obey the GNU General Public
- * License in all respects for all of the code used other than the above
- * mentioned libraries. If you modify this file, you may extend this exception
- * to your version of the file, but you are not obligated to do so. If you do
- * not wish to do so, delete this exception statement from your version.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
*/
+package mir.entity;
-package mir.entity;
+import java.util.ArrayList;
+import java.util.Set;
-import java.lang.*;
-import java.util.*;
-
-import freemarker.template.*;
-
-import mir.misc.*;
-import mir.storage.*;
-import mir.storage.store.*;
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+import mir.log.LoggerWrapper;
+import mir.storage.StorageObject;
+import mir.storage.store.StorableObject;
+import mir.storage.store.StoreContainerType;
+import mir.storage.store.StoreIdentifier;
+import mir.storage.store.StoreUtil;
/**
*
* Container class for lists of Entities.
- * Now implements freemarker.template.TemplateListModel
- * and @see mir.storage.store.StorableObject.
+ * Now implements @see mir.storage.store.StorableObject.
*
* @author <RK>
* first version 27.6.1999
*
- * @version 1.0 (freemarker compliant & and storable in ObjectStore)
+ * @version 1.1 (cleaned up)
*/
-public class EntityList implements TemplateListModel, StorableObject {
-
- private static Logfile theLog;
+public class EntityList implements StorableObject {
+ protected static MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
+ protected LoggerWrapper logger;
private ArrayList theEntityArrayList = new ArrayList();
private String whereClause, orderClause;
- private StorageObject theStorage;
+ private StorageObject storage;
private int count, offset, limit;
- private int offsetnext = -1, offsetprev = -1;
- private int freemarkerListPointer=-1;
+ private int nextOffset = -1;
+ private int previousOffset = -1;
+ public EntityList(){
+ logger = new LoggerWrapper("Entity.List");
+ }
- static {
- theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
+/* get/set EntityClass of Objects stored in EntityList */
+ public void setStorage(StorageObject aStorage) {
+ storage=aStorage;
}
- /**
- * Constructor.
- */
- public EntityList(){ }
-
- /* get/set EntityClass of Objects stored in EntityList */
- public void setStorage(StorageObject storage) { this.theStorage=storage; }
- public StorageObject getStorage() { return theStorage; }
-
- public void setLimit(int limit) { this.limit = limit; }
-
- /**
- * Sets the WHERE clause that fetched the Entities of this EntityList from the database.
- * @param wc The string that contains the WHERE clause
- */
- public void setWhere(String wc) {
- this.whereClause = wc;
- }
-
- /**
- * Returns the WHERE clause that returned this EntityList from the database
- * @return whereClause The WHERE clause
- */
- public String getWhere() {
- return whereClause;
- }
-
-
- /**
- * Sets the sorting criterium of this EntityList
- * @param oc
- */
- public void setOrder(String oc) {
- this.orderClause = oc;
- }
-
- /**
- * Returns the sorting criterium.
- * @return orderClause The sort order
- */
- public String getOrder() {
- return orderClause;
- }
-
- /**
- * Sets the number of rows that match the WHERE clause
- * @param i The number of rows that match the WHERE clause
- */
- public void setCount(int i) {
- this.count = i;
- }
-
- /**
- * Returns the number of rows that match the WHERE clause
- * @return The number of rows ...
- */
- public int getCount() {
- return count;
- }
-
- /**
- * Sets the offset
- * @param i The offset
- */
- public void setOffset(int i) {
- offset = i;
- }
-
- /**
- * Returns the offset
- * @return offset
- */
- public int getOffset() {
- return offset;
- }
-
- /**
- * Sets the offset of the next batch of Entities.
- * @param i The next offset
- */
- public void setNextBatch(int i) {
- offsetnext = i;
- }
-
- /**
- * Returns the offset of the next batch of Entities.
- * @return offset of the next batch
- */
- public int getNextBatch() {
- return offsetnext;
- }
-
- /**
- * Returns whether there is a next batch within the WHERE clause
- * @return true if yes, false if no.
- */
- public boolean hasNextBatch() {
- return (offsetnext >= 0);
- }
-
- /**
- * Sets the offset of the previous batch.
- * @param i the previous offset
- */
- public void setPrevBatch(int i) {
- offsetprev = i;
- }
-
- /**
- * Returns the offset of the previous batch.
- * @return offset of the previous batch
- */
- public int getPrevBatch() {
- return offsetprev;
- }
-
- /**
- * Returns whether there is a previous batch.
- * @return true if yes, false if no
- */
- public boolean hasPrevBatch() {
- return (offsetprev >= 0);
- }
-
- /**
- * Returns the start index of the batch.
- * @return
- */
- public int getFrom() {
- return offset+1;
- }
-
- /**
- * Returns the end index of the batch.
- * @return
- */
- public int getTo() {
- if (hasNextBatch())
- return offsetnext;
- else
- return count;
- }
+ public StorageObject getStorage() {
+ return storage;
+ }
+
+ public void setLimit(int aLimit) {
+ limit = aLimit;
+ }
/**
- * Inserts an Entity into the EntityList.
- * @param anEntity The entity to be inserted.
+ * Sets the WHERE clause that fetched the Entities of this EntityList from the database.
+ *
+ * @param wc The string that contains the WHERE clause
*/
+ public void setWhere(String wc) {
+ this.whereClause = wc;
+ }
- public void add (Entity anEntity) {
- if (anEntity!=null)
- theEntityArrayList.add(anEntity);
- else
- theLog.printWarning("EntityList: add called with empty Entity");
+ /**
+ * Returns the WHERE clause that returned this EntityList from the database
+ *
+ * @return whereClause The WHERE clause
+ */
+ public String getWhere() {
+ return whereClause;
}
+ /**
+ * Sets the sorting criterium of this EntityList
+ *
+ * @param oc
+ */
+ public void setOrder(String oc) {
+ this.orderClause = oc;
+ }
/**
- * @return The number of Entities in the EntityList.
+ * Returns the sorting criterium.
+ *
+ * @return orderClause The sort order
*/
+ public String getOrder() {
+ return orderClause;
+ }
- public int size() {
- return theEntityArrayList.size();
+ /**
+ * Sets the number of rows that match the WHERE clause
+ *
+ * @param i The number of rows that match the WHERE clause
+ */
+ public void setCount(int i) {
+ count = i;
}
+ /**
+ * Returns the number of rows that match the WHERE clause
+ *
+ * @return The number of rows ...
+ */
+ public int getCount() {
+ return count;
+ }
/**
- * Returns the element at position i in the EntityList as Entity
- * @param i the position of the element in question
- * @return The element at position i.
+ * Sets the offset
+ *
+ * @param i The offset
*/
+ public void setOffset(int i) {
+ offset = i;
+ }
- public Entity elementAt(int i) {
- /** @todo check if i is in list.size() */
- return (Entity)theEntityArrayList.get(i);
+ /**
+ * Returns the offset
+ *
+ * @return offset
+ */
+ public int getOffset() {
+ return offset;
}
+ /**
+ * Sets the offset of the next batch of Entities.
+ *
+ * @param i The next offset
+ */
+ public void setNextBatch(int i) {
+ nextOffset = i;
+ }
- // The following methods have to be implemented
- // for this class to be an implementation of the
- // TemplateListModel of the Freemarker packages
+ /**
+ * Returns the offset of the next batch of Entities.
+ *
+ * @return offset of the next batch
+ */
+ public int getNextBatch() {
+ return nextOffset;
+ }
- public TemplateModel get(int i) { return elementAt(i); }
- public boolean isRewound() { return (freemarkerListPointer==-1) ? true : false; }
- public void rewind() { freemarkerListPointer=-1; }
+ /**
+ * Returns whether there is a next batch within the WHERE clause
+ *
+ * @return true if yes, false if no.
+ */
+ public boolean hasNextBatch() {
+ return (nextOffset >= 0);
+ }
+
+ /**
+ * Sets the offset of the previous batch.
+ *
+ * @param i the previous offset
+ */
+ public void setPrevBatch(int i) {
+ previousOffset = i;
+ }
+
+ /**
+ * Returns the offset of the previous batch.
+ *
+ * @return offset of the previous batch
+ */
+ public int getPrevBatch() {
+ return previousOffset;
+ }
+
+ /**
+ * Returns whether there is a previous batch.
+ *
+ * @return true if yes, false if no
+ */
+ public boolean hasPrevBatch() {
+ return (previousOffset >= 0);
+ }
+
+ /**
+ * Returns the start index of the batch.
+ *
+ * @return
+ */
+ public int getFrom() {
+ return offset+1;
+ }
+
+ /**
+ * Returns the end index of the batch.
+ *
+ * @return
+ */
+ public int getTo() {
+ if (hasNextBatch())
+ return nextOffset;
+ else
+ return count;
+ }
+
+ /**
+ * Inserts an Entity into the EntityList.
+ *
+ * @param anEntity The entity to be inserted.
+ */
- public TemplateModel next() {
- if (hasNext()) {
- freemarkerListPointer++;return get(freemarkerListPointer); }
- else return null;
+ public void add (Entity anEntity) {
+ if (anEntity!=null)
+ theEntityArrayList.add(anEntity);
+ else
+ logger.warn("EntityList: add called with empty Entity");
}
/**
- * Returns whether there is a next element
- * @return true if there is a next element, else false
+ * @return The number of Entities in the EntityList.
*/
- public boolean hasNext() {
- return theEntityArrayList.size()>0 && freemarkerListPointer+2<=theEntityArrayList.size();
+ public int size() {
+ return theEntityArrayList.size();
}
/**
- * Returns whether EntityList is empty or not
- * @return true in case of empty list, false otherwise
+ * Returns the element at position i in the EntityList as Entity
+ * @param i the position of the element in question
+ * @return The element at position i.
*/
- public boolean isEmpty() {
- if (theEntityArrayList!=null)
- return theEntityArrayList.size()<1 ;
- else return false;
+ public Entity elementAt(int i) {
+ /** todo check if i is in list.size() */
+ return (Entity) theEntityArrayList.get(i);
}
- // Methods to implement StorableObject
+
+// Methods to implement StorableObject
public Set getNotifyOnReleaseSet() { return null; }
public StoreIdentifier getStoreIdentifier() {
- if ( theStorage!=null ) {
+ if ( storage!=null ) {
return
- new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,
- StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(),
- whereClause, orderClause, offset, limit ));
+ new StoreIdentifier(
+ this, StoreContainerType.STOC_TYPE_ENTITYLIST,
+ StoreUtil.getEntityListUniqueIdentifierFor( storage.getTableName(),
+ whereClause, orderClause, offset, limit ));
+ }
+ else {
+ logger.warn("EntityList could not return StoreIdentifier");
+
+ return null;
}
- theLog.printWarning("EntityList could not return StoreIdentifier");
- return null;
}
}