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