View Javadoc

1   /**
2    * Copyright 2005 Steve Molloy
3    * 
4    * This file is part of OV4J.
5    * 
6    * OV4J is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
7    * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
8    * 
9    * OV4J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
10   * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11   * 
12   * You should have received a copy of the GNU General Public License along with OV4J; if not, write to the Free Software
13   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14   * 
15   */
16  package org.ov4j;
17  
18  import java.io.IOException;
19  import java.io.Serializable;
20  
21  import org.ov4j.data.Item;
22  
23  /**
24   * Interface to implement to serve as data storage for controler.
25   * 
26   * @author smolloy
27   * 
28   */
29  public interface IContainer<T extends Comparable<? super T> & Cloneable & Serializable, C extends Comparable<? super C>> {
30  	/**
31  	 * Delete an array of items all at once, items which are not found will simply be ignored.
32  	 * 
33  	 * @param <T>
34  	 *            Type of object in the items, must extend VersionableObject.
35  	 * @param items
36  	 *            Items to be deleted.
37  	 * @param keepTrack
38  	 *            Whether or not the ID should be kept in history.
39  	 * @throws IOException
40  	 */
41  	public void batchDelete(Item<T, C>[] items, boolean keepTrack) throws IOException;
42  
43  	/**
44  	 * Merge an array of items all at once, items which are not found will simply be ignored.
45  	 * 
46  	 * @param ids
47  	 *            IDs to be merged.
48  	 * @throws IOException
49  	 */
50  	public void batchMerge(C[] ids) throws IOException;
51  
52  	/**
53  	 * Save array of items all at once. If abortOnDuplicate is set to true, data will not be saved if 1 or more item ids
54  	 * are in use.
55  	 * 
56  	 * @param <T>
57  	 *            Type of object in the items, must extend VersionableObject.
58  	 * @param items
59  	 *            Array of items to be saved.
60  	 * @param abortOnDuplicate
61  	 *            Whether or not saving should abort when an item has an ID already in use.
62  	 * @throws IOException
63  	 */
64  	public void batchSave(Item<T, C>[] items, boolean abortOnDuplicate) throws IOException;
65  
66  	/**
67  	 * Clear all data in the container.
68  	 * 
69  	 */
70  	public void clear();
71  
72  	/**
73  	 * Close the container.
74  	 * 
75  	 * @throws IOException
76  	 * 
77  	 */
78  	public void close() throws IOException;
79  
80  	/**
81  	 * Commit all changes.
82  	 * 
83  	 */
84  	public void commit();
85  
86  	/**
87  	 * Delete the item.
88  	 * 
89  	 * @param <T>
90  	 *            Type of object in the item, must extend VersionableObject.
91  	 * @param it
92  	 *            Item to be deleted.
93  	 * @param keepTrack
94  	 *            Whether or not the ID should be kept in history.
95  	 * @throws IOException
96  	 */
97  	public void delete(Item<T, C> it, boolean keepTrack) throws IOException;
98  
99  	/**
100 	 * Retrieve list of IDs that have been deleted.
101 	 * 
102 	 * @return All IDs deleted.
103 	 * @throws IOException
104 	 */
105 	public C[] deletedIds() throws IOException;
106 
107 	/**
108 	 * Retrieve a list of IDs that have been deleted since the given timestamp.
109 	 * 
110 	 * @param timestamp
111 	 *            Timestamp to use.
112 	 * @return All IDS deleted since the given timestamp.
113 	 * @throws IOException
114 	 */
115 	public C[] deletedIdsSince(long timestamp) throws IOException;
116 
117 	/**
118 	 * Converts the given IContainer into an hessian implementation.
119 	 * 
120 	 * @param cont
121 	 *            IContainer to convert.
122 	 * @throws IOException
123 	 */
124 	public void duplicate(IContainer<T, C> cont) throws IOException;
125 
126 	/**
127 	 * Determine if the given id is in use.
128 	 * 
129 	 * @param id
130 	 *            ID to check.
131 	 * @return True if the ID is already used in the system.
132 	 * @throws IOException
133 	 */
134 	public boolean inUse(C id) throws IOException;
135 
136 	/**
137 	 * Determine if the container has already been closed.
138 	 * 
139 	 * @return True if the container has been closed.
140 	 */
141 	public boolean isClosed();
142 
143 	/**
144 	 * List all items modified since the given timestamp.
145 	 * 
146 	 * @param timestamp
147 	 *            Timestamp to use.
148 	 * @return An array of IDs for items modified since specified timestamp.
149 	 * @throws IOException
150 	 */
151 	public C[] listModifiedSince(long timestamp) throws IOException;
152 
153 	/**
154 	 * Load an item using its id.
155 	 * 
156 	 * @param id
157 	 *            ID to look for.
158 	 * @param allVersions
159 	 *            Whether or not all versions should be loaded.
160 	 * @return The item with specified ID.
161 	 * @throws IOException
162 	 */
163 	public Item<T, C> load(C id, boolean allVersions) throws IOException;
164 
165 	/**
166 	 * Load multiple items at once, using the specified ids.
167 	 * 
168 	 * @param ids
169 	 *            Array of IDs to look for.
170 	 * @param allVersions
171 	 *            Whether or not all versions should be loaded.
172 	 * @return An array of items with specified IDs, not necessarily in the same order.
173 	 * @throws IOException
174 	 */
175 	public Item<T, C>[] load(C[] ids, boolean allVersions) throws IOException;
176 
177 	/**
178 	 * Load all items modified since the given timestamp.
179 	 * 
180 	 * @param timestamp
181 	 *            Timestamp to use.
182 	 * @param allVersions
183 	 *            Whether or not all versions should be loaded.
184 	 * @return An array of items modified since specified timestamp.
185 	 * @throws IOException
186 	 */
187 	public Item<T, C>[] modifiedSince(long timestamp, boolean allVersions) throws IOException;
188 
189 	/**
190 	 * Release the object so it can be garbage collected immediately.
191 	 * 
192 	 * @param obj
193 	 *            Object to release.
194 	 */
195 	public void release(Object obj);
196 
197 	/**
198 	 * Rollback and discard all changes since last commit.
199 	 * 
200 	 */
201 	public void rollback();
202 
203 	/**
204 	 * Save the item.
205 	 * 
206 	 * @param <T>
207 	 *            Type of object in the item, must extend VersionableObject.
208 	 * @param it
209 	 *            Item to be saved.
210 	 * @throws IOException
211 	 */
212 	public void save(Item<T, C> it) throws IOException;
213 
214 	/**
215 	 * Wait for all saves and deletes pending tasks to finish.
216 	 * 
217 	 */
218 	public void waitForPendingSaves();
219 
220 	/**
221 	 * Wait for all tasks pending tasks to finish.
222 	 * 
223 	 */
224 	public void waitForPendingTasks();
225 }