2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with any library licensed under the Apache Software License,
\r
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
\r
23 * (or with modified versions of the above that use the same license as the above),
\r
24 * and distribute linked combinations including the two. You must obey the
\r
25 * GNU General Public License in all respects for all of the code used other than
\r
26 * the above mentioned libraries. If you modify this file, you may extend this
\r
27 * exception to your version of the file, but you are not obligated to do so.
\r
28 * If you do not wish to do so, delete this exception statement from your version.
\r
32 import java.util.ArrayList;
\r
33 import java.util.Set;
\r
35 import mir.config.MirPropertiesConfiguration;
\r
36 import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
\r
37 import mir.log.LoggerWrapper;
\r
38 import mir.storage.StorageObject;
\r
39 import mir.storage.store.StorableObject;
\r
40 import mir.storage.store.StoreContainerType;
\r
41 import mir.storage.store.StoreIdentifier;
\r
42 import mir.storage.store.StoreUtil;
\r
46 * Container class for lists of Entities.
\r
47 * Now implements @see mir.storage.store.StorableObject.
\r
50 * first version 27.6.1999
\r
52 * @version 1.1 (cleaned up)
\r
54 public class EntityList implements StorableObject {
\r
55 protected static MirPropertiesConfiguration configuration;
\r
56 protected LoggerWrapper logger;
\r
57 private ArrayList theEntityArrayList = new ArrayList();
\r
58 private String whereClause, orderClause;
\r
59 private StorageObject theStorage;
\r
60 private int count, offset, limit;
\r
61 private int offsetnext = -1, offsetprev = -1;
\r
65 configuration = MirPropertiesConfiguration.instance();
\r
67 catch (PropertiesConfigExc e) {
\r
68 throw new RuntimeException("Unable to get configuration: " + e.getMessage());
\r
75 public EntityList(){
\r
76 logger = new LoggerWrapper("Entity.List");
\r
79 /* get/set EntityClass of Objects stored in EntityList */
\r
80 public void setStorage(StorageObject storage) { this.theStorage=storage; }
\r
81 public StorageObject getStorage() { return theStorage; }
\r
83 public void setLimit(int limit) { this.limit = limit; }
\r
86 * Sets the WHERE clause that fetched the Entities of this EntityList from the database.
\r
87 * @param wc The string that contains the WHERE clause
\r
89 public void setWhere(String wc) {
\r
90 this.whereClause = wc;
\r
94 * Returns the WHERE clause that returned this EntityList from the database
\r
95 * @return whereClause The WHERE clause
\r
97 public String getWhere() {
\r
103 * Sets the sorting criterium of this EntityList
\r
106 public void setOrder(String oc) {
\r
107 this.orderClause = oc;
\r
111 * Returns the sorting criterium.
\r
112 * @return orderClause The sort order
\r
114 public String getOrder() {
\r
115 return orderClause;
\r
119 * Sets the number of rows that match the WHERE clause
\r
120 * @param i The number of rows that match the WHERE clause
\r
122 public void setCount(int i) {
\r
127 * Returns the number of rows that match the WHERE clause
\r
128 * @return The number of rows ...
\r
130 public int getCount() {
\r
136 * @param i The offset
\r
138 public void setOffset(int i) {
\r
143 * Returns the offset
\r
146 public int getOffset() {
\r
151 * Sets the offset of the next batch of Entities.
\r
152 * @param i The next offset
\r
154 public void setNextBatch(int i) {
\r
159 * Returns the offset of the next batch of Entities.
\r
160 * @return offset of the next batch
\r
162 public int getNextBatch() {
\r
167 * Returns whether there is a next batch within the WHERE clause
\r
168 * @return true if yes, false if no.
\r
170 public boolean hasNextBatch() {
\r
171 return (offsetnext >= 0);
\r
175 * Sets the offset of the previous batch.
\r
176 * @param i the previous offset
\r
178 public void setPrevBatch(int i) {
\r
183 * Returns the offset of the previous batch.
\r
184 * @return offset of the previous batch
\r
186 public int getPrevBatch() {
\r
191 * Returns whether there is a previous batch.
\r
192 * @return true if yes, false if no
\r
194 public boolean hasPrevBatch() {
\r
195 return (offsetprev >= 0);
\r
199 * Returns the start index of the batch.
\r
202 public int getFrom() {
\r
207 * Returns the end index of the batch.
\r
210 public int getTo() {
\r
211 if (hasNextBatch())
\r
218 * Inserts an Entity into the EntityList.
\r
219 * @param anEntity The entity to be inserted.
\r
222 public void add (Entity anEntity) {
\r
223 if (anEntity!=null)
\r
224 theEntityArrayList.add(anEntity);
\r
226 logger.warn("EntityList: add called with empty Entity");
\r
231 * @return The number of Entities in the EntityList.
\r
234 public int size() {
\r
235 return theEntityArrayList.size();
\r
240 * Returns the element at position i in the EntityList as Entity
\r
241 * @param i the position of the element in question
\r
242 * @return The element at position i.
\r
245 public Entity elementAt(int i) {
\r
246 /** @todo check if i is in list.size() */
\r
247 return (Entity)theEntityArrayList.get(i);
\r
252 // Methods to implement StorableObject
\r
254 public Set getNotifyOnReleaseSet() { return null; }
\r
256 public StoreIdentifier getStoreIdentifier() {
\r
257 if ( theStorage!=null ) {
\r
259 new StoreIdentifier( this, StoreContainerType.STOC_TYPE_ENTITYLIST,
\r
260 StoreUtil.getEntityListUniqueIdentifierFor( theStorage.getTableName(),
\r
261 whereClause, orderClause, offset, limit ));
\r
263 logger.warn("EntityList could not return StoreIdentifier");
\r