X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2FEntityList.java;h=a2e6cce6be74ebfd7b5bff8fcd0f2783aa61de28;hb=63e0ee1fb8038eb6d8f0190cf38c3b3ab2727216;hp=98883c82fffc1e16f1c190d5940ec0f7158e9b37;hpb=5bf2a1fa11c1529a731ab6b4521b8254c1fa100f;p=mir.git diff --git a/source/mir/entity/EntityList.java b/source/mir/entity/EntityList.java index 98883c82..a2e6cce6 100755 --- a/source/mir/entity/EntityList.java +++ b/source/mir/entity/EntityList.java @@ -1,199 +1,283 @@ /* - * put your module comment here + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * 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 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; +import java.util.ArrayList; +import java.util.Set; -package mir.entity; - -import java.lang.*; -import java.util.*; -import mir.misc.*; - +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; /** * - * abstrakte Containerklasse für Listen von Entities. + * Container class for lists of Entities. + * Now implements @see mir.storage.store.StorableObject. * * @author - * @version 27.6.1999 + * first version 27.6.1999 + * + * @version 1.1 (cleaned up) */ -public class EntityList { - private static Logfile theLog; - private ArrayList theEntityArrayList; - private String whereClause; - private String orderClause; - private int count; - private int offset; - private int offsetnext = -1; - private int offsetprev = -1; - - /** - * Konstruktor für leere Liste von Entities - */ - public EntityList(){ - this.theEntityArrayList = new ArrayList(); - if (theLog == null) - this.theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Entity.Logfile")); - } - - /** - * Setzt die WhereClause, mit der die Entitis dieser Liste geholt wurden. - * @param wc - */ - public void setWhere(String wc) { - this.whereClause = wc; - } - - /** - * Liefert die WhereClause zurueck, mit der die Entities geholt wurden. - * @return whereClause - */ - public String getWhere() { - return whereClause; - } - - /** - * Setzt das Sortierkriterium fest, mit der die Entities in die Liste - * gestellt wurden. - * - * @param oc - */ - public void setOrder(String oc) { - this.orderClause = oc; - } - - /** - * Liefert das Sortierkriterium der Liste zurueck. - * @return orderClause - */ - public String getOrder() { - return orderClause; - } - - /** - * Setzt die Anzahl der Datensätze fest, die WhereClause erfüllen. - * @param i - */ - public void setCount(int i) { - this.count = i; - } - - /** - * Liefert Anzahle der Datensätze, die WhereClause erfüllen. - * @return - */ - public int getCount() { - return count; - } - - /** - * Setzt den Offset fest. - * @param i - */ - public void setOffset(int i) { - offset = i; - } - - /** - * Liefert den Offset zurueck - * @return offset - */ - public int getOffset() { - return offset; - } - - /** - * Setzt den offset für das naechste Batch von Entities fest. - * @param i - */ - public void setNextBatch(int i) { - offsetnext = i; - } - - /** - * Liefert den offset für das naechste Batch von Entities - * @return offset für naechstes Batch - */ - public int getNextBatch() { - return offsetnext; - } - - /** - * Fragt ab, ob es noch nachfolgendes Batch innerhalb der WhereClause gibt - * @return - */ - public boolean hasNextBatch() { - return (offsetnext >= 0); - } - - /** - * Setzt offset des vorhergehenden Batches fest. - * @param i - */ - public void setPrevBatch(int i) { - offsetprev = i; - } - - /** - * Liefert offset des vorhergehenden Batches zurueck. - * @return offset des vorhergehenden Batches. - */ - public int getPrevBatch() { - return offsetprev; - } - - /** - * Fragt ab, ob es ein vorhergehendes Batch gibt - * @return true wenn ja, sont false - */ - public boolean hasPrevBatch() { - return (offsetprev >= 0); - } - - /** - * Liefert den Startindex des Batches zurueck. - * @return - */ - public int getFrom() { - return offset+1; - } - - /** - * Liefert den Endindex des Batches zurueck. - * @return - */ - public int getTo() { - if (hasNextBatch()) - return offsetnext; - else - return count; - } - - /** - * Fügt eine Entity in die Liste ein - * @param anEntity - */ - public void add (Entity anEntity) { - if (anEntity!=null) - theEntityArrayList.add(anEntity); - else - theLog.printWarning("add (EntityList) mit leerer Entity"); - } - - /** - * @return Anzahl der Entities in der Liste - */ - public int size() { - return theEntityArrayList.size(); - } - - - - - - - public Entity elementAt(int i) { - return (Entity)theEntityArrayList.get(i); - } +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 storage; + private int count, offset, limit; + private int nextOffset = -1; + private int previousOffset = -1; + + public EntityList(){ + logger = new LoggerWrapper("Entity.List"); + } + +/* get/set EntityClass of Objects stored in EntityList */ + public void setStorage(StorageObject aStorage) { + storage=aStorage; + } + + public StorageObject getStorage() { + return storage; + } + + public void setLimit(int aLimit) { + limit = aLimit; + } + + /** + * 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) { + 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) { + nextOffset = i; + } + + /** + * Returns the offset of the next batch of Entities. + * + * @return offset of the next batch + */ + public int getNextBatch() { + return nextOffset; + } + + /** + * 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 void add (Entity anEntity) { + if (anEntity!=null) + theEntityArrayList.add(anEntity); + else + logger.warn("EntityList: add called with empty Entity"); + } + + + /** + * @return The number of Entities in the EntityList. + */ + + public int size() { + return theEntityArrayList.size(); + } + + + /** + * 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 Entity elementAt(int i) { + /** todo check if i is in list.size() */ + return (Entity) theEntityArrayList.get(i); + } + + + +// Methods to implement StorableObject + + public Set getNotifyOnReleaseSet() { return null; } + + public StoreIdentifier getStoreIdentifier() { + if ( storage!=null ) { + return + 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; + } + } }