rebuilding head
[mir.git] / source / mir / entity / EntityList.java
index f792413..e9c839a 100755 (executable)
-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with  any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two.  You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries.  If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package  mir.entity;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Set;\r
-\r
-import mir.config.MirPropertiesConfiguration;\r
-import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.StorageObject;\r
-import mir.storage.store.StorableObject;\r
-import mir.storage.store.StoreContainerType;\r
-import mir.storage.store.StoreIdentifier;\r
-import mir.storage.store.StoreUtil;\r
-\r
-/**\r
- *\r
- * Container class for lists of Entities.\r
- * Now implements @see mir.storage.store.StorableObject.\r
- *\r
- * @author <RK>\r
- * first version       27.6.1999\r
- *\r
- * @version 1.1 (cleaned up)\r
- */\r
-public class EntityList implements StorableObject {\r
-  protected static MirPropertiesConfiguration configuration;\r
-  protected LoggerWrapper logger;\r
-  private ArrayList           theEntityArrayList = new ArrayList();\r
-  private String              whereClause, orderClause;\r
-  private StorageObject       theStorage;\r
-  private int                 count, offset, limit;\r
-  private int                 offsetnext = -1, offsetprev = -1;\r
-\r
-  static {\r
-    try {\r
-      configuration = MirPropertiesConfiguration.instance();\r
-    }\r
-    catch (PropertiesConfigExc e) {\r
-      throw new RuntimeException("Unable to get configuration: " + e.getMessage());\r
-    }\r
-  }\r
-\r
-  /**\r
-   * Constructor.\r
-   */\r
-  public EntityList(){\r
-    logger = new LoggerWrapper("Entity.List");\r
-  }\r
-\r
-/* get/set EntityClass of Objects stored in EntityList */\r
-  public void setStorage(StorageObject storage) { this.theStorage=storage; }\r
-  public StorageObject getStorage() { return theStorage; }\r
-\r
-  public void setLimit(int limit) { this.limit = limit; }\r
-\r
-  /**\r
-   * Sets the WHERE clause that fetched the Entities of this EntityList from the database.\r
-   * @param wc The string that contains the WHERE clause\r
-   */\r
-  public void setWhere(String wc) {\r
-    this.whereClause = wc;\r
-  }\r
-\r
-  /**\r
-   * Returns the WHERE clause that returned this EntityList from the database\r
-   * @return whereClause The WHERE clause\r
-   */\r
-  public String getWhere() {\r
-    return whereClause;\r
-  }\r
-\r
-\r
-  /**\r
-   * Sets the sorting criterium of this EntityList\r
-   * @param oc\r
-   */\r
-  public void setOrder(String oc) {\r
-    this.orderClause = oc;\r
-  }\r
-\r
-  /**\r
-   * Returns the sorting criterium.\r
-   * @return orderClause The sort order\r
-   */\r
-  public String getOrder() {\r
-    return orderClause;\r
-  }\r
-\r
-  /**\r
-   * Sets the number of rows that match the WHERE clause\r
-   * @param i The number of rows that match the WHERE clause\r
-   */\r
-  public void setCount(int i) {\r
-    this.count = i;\r
-  }\r
-\r
-  /**\r
-   * Returns the number of rows that match the WHERE clause\r
-   * @return The number of rows ...\r
-   */\r
-  public int getCount() {\r
-    return count;\r
-  }\r
-\r
-  /**\r
-   * Sets the offset\r
-   * @param i The offset\r
-   */\r
-  public void setOffset(int i) {\r
-    offset = i;\r
-  }\r
-\r
-  /**\r
-   * Returns the offset\r
-   * @return offset\r
-   */\r
-  public int getOffset() {\r
-    return offset;\r
-  }\r
-\r
-  /**\r
-   * Sets the offset of the next batch of Entities.\r
-   * @param i The next offset\r
-   */\r
-  public void setNextBatch(int i) {\r
-    offsetnext = i;\r
-  }\r
-\r
-  /**\r
-   * Returns the offset of the next batch of Entities.\r
-   * @return offset of the next batch\r
-   */\r
-  public int getNextBatch() {\r
-    return offsetnext;\r
-  }\r
-\r
-  /**\r
-   * Returns whether there is a next batch within the WHERE clause\r
-   * @return true if yes, false if no.\r
-   */\r
-  public boolean hasNextBatch() {\r
-    return (offsetnext >= 0);\r
-  }\r
-\r
-  /**\r
-   * Sets the offset of the previous batch.\r
-   * @param i the previous offset\r
-   */\r
-  public void setPrevBatch(int i) {\r
-    offsetprev = i;\r
-  }\r
-\r
-  /**\r
-   * Returns the offset of the previous batch.\r
-   * @return offset of the previous batch\r
-   */\r
-  public int getPrevBatch() {\r
-    return offsetprev;\r
-  }\r
-\r
-  /**\r
-   * Returns whether there is a previous batch.\r
-   * @return true if yes, false if no\r
-   */\r
-  public boolean hasPrevBatch() {\r
-    return (offsetprev >= 0);\r
-  }\r
-\r
-  /**\r
-   * Returns the start index of the batch.\r
-   * @return\r
-   */\r
-  public int getFrom() {\r
-    return offset+1;\r
-  }\r
-\r
-  /**\r
-   * Returns the end index of the batch.\r
-   * @return\r
-   */\r
-  public int getTo() {\r
-    if (hasNextBatch())\r
-      return offsetnext;\r
-    else\r
-      return count;\r
-  }\r
-\r
-  /**\r
-   * Inserts an Entity into the EntityList.\r
-   * @param anEntity The entity to be inserted.\r
-   */\r
-\r
-  public void add (Entity anEntity) {\r
-    if (anEntity!=null)\r
-      theEntityArrayList.add(anEntity);\r
-    else\r
-      logger.warn("EntityList: add called with empty Entity");\r
-  }\r
-\r
-\r
-  /**\r
-   * @return The number of Entities in the EntityList.\r
-   */\r
-\r
-  public int size() {\r
-    return theEntityArrayList.size();\r
-  }\r
-\r
-\r
-  /**\r
-   * Returns the element at position i in the EntityList as Entity\r
-   * @param i the position of the element in question\r
-   * @return The element at position i.\r
-   */\r
-\r
-  public Entity elementAt(int i) {\r
-    /** @todo check if i is in list.size() */\r
-    return (Entity)theEntityArrayList.get(i);\r
-  }\r
-\r
-\r
-\r
-// Methods to implement StorableObject\r
-\r
-  public Set getNotifyOnReleaseSet() { return null; }\r
-\r
-  public StoreIdentifier getStoreIdentifier() {\r
-    if ( theStorage!=null ) {\r
-      return\r
-      new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,\r
-      StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(),\r
-      whereClause, orderClause, offset, limit ));\r
-    }\r
-    logger.warn("EntityList could not return StoreIdentifier");\r
-    return null;\r
-  }\r
-\r
-}\r
+/*
+ * 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;
+
+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 @see mir.storage.store.StorableObject.
+ *
+ * @author <RK>
+ * first version       27.6.1999
+ *
+ * @version 1.1 (cleaned up)
+ */
+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 int                 count, offset, limit;
+  private int                 offsetnext = -1, offsetprev = -1;
+
+  public EntityList(){
+    logger = new LoggerWrapper("Entity.List");
+  }
+
+/* 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;
+  }
+
+  /**
+   * 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 ( theStorage!=null ) {
+      return
+      new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,
+      StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(),
+      whereClause, orderClause, offset, limit ));
+    }
+    logger.warn("EntityList could not return StoreIdentifier");
+    return null;
+  }
+
+}