View Javadoc

1   /***
2    * @(#)JDOService.java
3    * 
4    * JFoxSOAF, Service-Oriented Application Framework
5    * 
6    * Copyright(c) JFoxSOAF Team
7    * 
8    * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
9    * you may not use this file except in compliance with the License. 
10   * You may obtain a copy of the License at  
11   * 
12   * http://www.gnu.org/copyleft/lesser.html
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, 
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17   * See the License for the specific language governing permissions and 
18   * limitations under the License. 
19   * 
20   * For more information, please visit:
21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22   * http://www.huihoo.org/jfox/jfoxsoaf
23   */
24  
25  package org.huihoo.jfox.soaf.services.persistence;
26  
27  import java.util.Collection;
28  import java.util.Map;
29  
30  import javax.jdo.JDOException;
31  import javax.jdo.PersistenceManagerFactory;
32  
33  import org.huihoo.jfox.soaf.exception.DAOException;
34  
35  /***
36   * <p>
37   * JDO persistence service wrapper.
38   * </p>
39   * 
40   * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
41   * @version $Revision: 1.1 $ $Date: 2006/02/15 08:45:45 $
42   * @version Revision: 1.0
43   */
44  
45  public interface JdoService {
46  
47  	/***
48  	 * Set SessionFactory
49  	 * 
50  	 * @param sessionFactory
51  	 */
52  	void setPersistenceManagerFactory(PersistenceManagerFactory pmFactory);
53  
54  	/***
55  	 * Begin a transaction.
56  	 * 
57  	 * @throws JDOException
58  	 */
59  	void beginTransaction() throws JDOException;
60  
61  	/***
62  	 * Commit the current transaction.
63  	 * 
64  	 * @throws JDOException
65  	 */
66  	void commit() throws JDOException;
67  
68  	/***
69  	 * Roll back the current transaction.
70  	 * 
71  	 * @throws JDOException
72  	 */
73  	void rollback() throws JDOException;
74  
75  	/***
76  	 * Close this PersistenceManager so that no further requests may be made on
77  	 * it.
78  	 */
79  	void close() throws JDOException;
80  
81  	/***
82  	 * The ObjectId returned by this method represents the JDO identity of the
83  	 * instance.
84  	 * 
85  	 * @param object -
86  	 *            the PersistenceCapable instance
87  	 * @return - the ObjectId of the instance
88  	 * @throws DAOException
89  	 */
90  	Object getObjectById(Object oid) throws JDOException, DAOException;
91  
92  	/***
93  	 * Looks up the instance of the given type with the given key.
94  	 * 
95  	 * @param clazz
96  	 * @param oid
97  	 * @return the corresponding persistent instance
98  	 * @throws DAOException
99  	 */
100 	Object getObjectById(Class clazz, Object oid) throws JDOException,
101 			DAOException;
102 
103 	/***
104 	 * This method locates a persistent instance in the cache of instances
105 	 * managed by this PersistenceManager.
106 	 * 
107 	 * @param object
108 	 * @param validate
109 	 * @return the PersistenceCapable instance with the specified ObjectId
110 	 * @throws JDOException
111 	 * @throws DAOException
112 	 */
113 	Object getObjectById(Object oid, boolean validate) throws JDOException,
114 			DAOException;
115 
116 	/***
117 	 * The ObjectId returned by this method represents the JDO identity of the
118 	 * instance. The ObjectId is a copy (clone) of the internal state of the
119 	 * instance, and changing it does not affect the JDO identity of the
120 	 * instance.
121 	 * 
122 	 * @param object
123 	 * @return the ObjectId of the instance
124 	 * @throws JDOException
125 	 * @throws DAOException
126 	 */
127 	Object getObjectId(Object pc) throws JDOException, DAOException;
128 
129 	/***
130 	 * Return the Class that implements the JDO Identity for the specified
131 	 * PersistenceCapable class.
132 	 * 
133 	 * @param clazz -
134 	 *            cls - the PersistenceCapable Class
135 	 * @return the Class of the ObjectId of the parameter
136 	 * @throws JDOException
137 	 * @throws DAOException
138 	 */
139 	Class getObjectIdClass(Class clazz) throws JDOException, DAOException;
140 
141 	/***
142 	 * Return the objects with the given oids.
143 	 * 
144 	 * @param oids
145 	 * @return the objects that were looked up, in the same order as the oids
146 	 *         parameter.
147 	 * @throws JDOException
148 	 * @throws DAOException
149 	 */
150 	Collection getObjectsById(Collection oids) throws JDOException,
151 			DAOException;
152 
153 	/***
154 	 * Return the objects with the given oids.
155 	 * 
156 	 * @param oids
157 	 * @param validate
158 	 *            validate - if true, the existance of the objects in the
159 	 *            datastore will be validated.
160 	 * @return the objects that were looked up, in the same order as the oids
161 	 *         parameter.
162 	 * @throws JDOException
163 	 * @throws DAOException
164 	 */
165 	Collection getObjectsById(Collection oids, boolean validate)
166 			throws JDOException, DAOException;
167 
168 	/***
169 	 * Return the objects with the given oids. This method is equivalent to
170 	 * calling getObjectsById(Object[],boolean) with the validate flag true.
171 	 * 
172 	 * @param oids -
173 	 *            the oids of the objects to return
174 	 * @return the objects that were looked up, in the same order as the oids
175 	 *         parameter.
176 	 */
177 	Object[] getObjectsById(Object[] oids) throws JDOException, DAOException;
178 
179 	/***
180 	 * Return the objects with the given oids.
181 	 * 
182 	 * @param oids -
183 	 *            the oids of the objects to return
184 	 * @param validate -
185 	 *            validate - if true, the existance of the objects in the
186 	 *            datastore will be validated.
187 	 * @return the objects that were looked up, in the same order as the oids
188 	 *         parameter.
189 	 */
190 	Object[] getObjectsById(Object[] oids, boolean validate)
191 			throws JDOException, DAOException;
192 
193 	/***
194 	 * @param clazz
195 	 * @return
196 	 * @throws JDOException
197 	 * @throws DAOException
198 	 */
199 	Collection query(Class clazz) throws JDOException, DAOException;
200 
201 	/***
202 	 * Query with the Class of the candidate instances and filter
203 	 * 
204 	 * @param clazz
205 	 * @return the filtered Collection
206 	 * @throws JDOException
207 	 * @throws DAOException
208 	 */
209 	Collection query(Class clazz, String filter) throws JDOException,
210 			DAOException;
211 
212 	/***
213 	 * Query with the Class of the candidate instances and filter
214 	 * 
215 	 * @param clazz
216 	 * @return the filtered Collection
217 	 * @throws JDOException
218 	 * @throws DAOException
219 	 */
220 	Collection query(Class clazz, String filter, String ordering)
221 			throws JDOException, DAOException;
222 
223 	/***
224 	 * Query with the Class of the candidate instances and filter
225 	 * 
226 	 * @param clazz
227 	 * @return the filtered Collection
228 	 * @throws JDOException
229 	 * @throws DAOException
230 	 */
231 	Collection queryWithMap(Class clazz, String filter, String parameters,
232 			Map values) throws JDOException, DAOException;
233 
234 	/***
235 	 * Query with the Class of the candidate instances and filter
236 	 * 
237 	 * @param clazz
238 	 * @return the filtered Collection
239 	 * @throws JDOException
240 	 * @throws DAOException
241 	 */
242 	Collection queryWithMap(Class clazz, String filter, String ordering,
243 			String parameters, Map values) throws JDOException, DAOException;
244 
245 	/***
246 	 * Query with the Class of the candidate instances and filter
247 	 * 
248 	 * @param clazz
249 	 * @return the filtered Collection
250 	 * @throws JDOException
251 	 * @throws DAOException
252 	 */
253 	Collection queryWithMap(Class clazz, String filter, String parameters,
254 			Object[] values) throws JDOException, DAOException;
255 
256 	/***
257 	 * Query with the Class of the candidate instances and filter
258 	 * 
259 	 * @param clazz
260 	 * @return the filtered Collection
261 	 * @throws JDOException
262 	 * @throws DAOException
263 	 */
264 	Collection queryWithMap(Class clazz, String filter, String ordering,
265 			String parameters, Object[] values) throws JDOException,
266 			DAOException;
267 
268 	/***
269 	 * Query with the Class of the candidate instances, candidate Collection.
270 	 * 
271 	 * @param clazz
272 	 * @return the filtered Collection.
273 	 * @throws JDOException
274 	 * @throws DAOException
275 	 */
276 	Collection query(Class clazz, Collection coll) throws JDOException,
277 			DAOException;
278 
279 	/***
280 	 * Query with the Class of the candidate instances, candidate Collection,
281 	 * and filter.
282 	 * 
283 	 * @param clazz
284 	 * @return the filtered Collection.
285 	 * @throws JDOException
286 	 * @throws DAOException
287 	 */
288 	Collection query(Class clazz, Collection coll, String filter)
289 			throws JDOException, DAOException;
290 
291 	/***
292 	 * Query using elements from another Query.
293 	 * 
294 	 * @param clazz
295 	 * @return the filtered Collection.
296 	 * @throws JDOException
297 	 * @throws DAOException
298 	 */
299 	Collection query(Object object) throws JDOException, DAOException;
300 
301 	/***
302 	 * Query instance using the specified String as the single-string
303 	 * representation of the query.
304 	 * 
305 	 * @param clazz
306 	 * @return the filtered Collection.
307 	 * @throws JDOException
308 	 * @throws DAOException
309 	 */
310 	Collection query(String queryStr) throws JDOException, DAOException;
311 
312 	/***
313 	 * Mark an instance as no longer needed in the cache
314 	 * 
315 	 * @param pc -
316 	 *            the instance to evict from the cache.
317 	 */
318 	void evict(Object object) throws JDOException, DAOException;
319 
320 	/***
321 	 * Mark all persistent-nontransactional instances as no longer needed in the
322 	 * cache.
323 	 * 
324 	 * @throws JDOException
325 	 * @throws DAOException
326 	 */
327 	void evictAll() throws JDOException, DAOException;
328 
329 	/***
330 	 * Mark a Collection of instances as no longer needed in the cache.
331 	 * 
332 	 * @param pcs
333 	 * @throws JDOException
334 	 * @throws DAOException
335 	 */
336 	void evictAll(Collection coll) throws JDOException, DAOException;
337 
338 	/***
339 	 * Mark an array of instances as no longer needed in the cache.
340 	 * 
341 	 * @param pcs
342 	 * @throws JDOException
343 	 * @throws DAOException
344 	 */
345 	void evictAll(Object[] objects) throws JDOException, DAOException;
346 
347 	/***
348 	 * Flushes all dirty, new, and deleted instances to the data store. It has
349 	 * no effect if a transaction is not active.
350 	 * 
351 	 * @throws JDOException
352 	 * @throws DAOException
353 	 */
354 	void flush() throws JDOException, DAOException;
355 
356 	/***
357 	 * Make the transient instance persistent in this PersistenceManager.
358 	 * 
359 	 * @param object -
360 	 *            a transient instance of a Class that implements
361 	 *            PersistenceCapable
362 	 * @throws JDOException
363 	 * @throws DAOException
364 	 */
365 	void makePersistent(Object object) throws JDOException, DAOException;
366 
367 	/***
368 	 * Make a Collection of instances persistent.
369 	 * 
370 	 * @param coll -
371 	 *            a Collection of transient instances
372 	 */
373 	void makePersistentAll(Collection coll) throws JDOException, DAOException;
374 
375 	/***
376 	 * Make an array of instances persistent.
377 	 * 
378 	 * @param pcs
379 	 */
380 	void makePersistentAll(Object[] objects) throws JDOException, DAOException;
381 
382 	/***
383 	 * Delete the persistent instance from the data store.
384 	 * 
385 	 * @param pc
386 	 * @throws JDOException
387 	 * @throws DAOException
388 	 */
389 	void deletePersistent(Object object) throws JDOException, DAOException;
390 
391 	/***
392 	 * Delete a Collection of instances from the data store.
393 	 * 
394 	 * @param pcs
395 	 * @throws JDOException
396 	 * @throws DAOException
397 	 */
398 	void deletePersistentAll(Collection coll) throws JDOException, DAOException;
399 
400 	/***
401 	 * Delete an array of instances from the data store.
402 	 * 
403 	 * @param pcs
404 	 */
405 	void deletePersistentAll(Object[] objects) throws JDOException,
406 			DAOException;
407 
408 }