KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > jdo > JdoCallback


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.jdo;
18
19 import javax.jdo.JDOException;
20 import javax.jdo.PersistenceManager;
21
22 /**
23  * Callback interface for JDO code. To be used with {@link JdoTemplate}'s
24  * execution methods, often as anonymous classes within a method implementation.
25  * A typical implementation will call PersistenceManager CRUD to perform
26  * some operations on persistent objects.
27  *
28  * <p>Note that JDO works on bytecode-modified Java objects, to be able to
29  * perform dirty detection on each modification of a persistent instance field.
30  * In contrast to Hibernate, using returned objects outside of an active
31  * PersistenceManager poses a problem: To be able to read and modify fields
32  * e.g. in a web GUI, one has to explicitly make the instances "transient".
33  * Reassociation with a new PersistenceManager, e.g. for updates when coming
34  * back from the GUI, isn't possible, as the JDO instances have lost their
35  * identity when turned transient. This means that either value objects have
36  * to be used as parameters, or the contents of the outside-modified instance
37  * have to be copied to a freshly loaded active instance on reassociation.
38  *
39  * @author Juergen Hoeller
40  * @since 03.06.2003
41  * @see JdoTemplate
42  * @see JdoTransactionManager
43  */

44 public interface JdoCallback {
45
46     /**
47      * Gets called by <code>JdoTemplate.execute</code> with an active JDO
48      * <code>PersistenceManager</code>. Does not need to care about activating
49      * or closing the <code>PersistenceManager</code>, or handling transactions.
50      *
51      * <p>Note that JDO callback code will not flush any modifications to the
52      * database if not executed within a transaction. Thus, you need to make
53      * sure that JdoTransactionManager has initiated a JDO transaction when
54      * the callback gets called, at least if you want to write to the database.
55      *
56      * <p>Allows for returning a result object created within the callback,
57      * i.e. a domain object or a collection of domain objects.
58      * A thrown custom RuntimeException is treated as an application exception:
59      * It gets propagated to the caller of the template.
60      *
61      * @param pm active PersistenceManager
62      * @return a result object, or <code>null</code> if none
63      * @throws JDOException if thrown by the JDO API
64      * @see JdoTemplate#execute
65      * @see JdoTemplate#executeFind
66      */

67     Object JavaDoc doInJdo(PersistenceManager pm) throws JDOException;
68
69 }
70
Popular Tags