Java Reference
In-Depth Information
Transaction-completion methods have the same semantics as
javax.transaction.UserTransaction and are valid only in the nonmanaged, nondistributed
transaction environment. Do not be surprised if you are told that the most useful methods in the
javax.jdo.Transaction interface are as follows:
 
void begin()
 
void commit()
 
void rollback()
You may use these APIs as follows:
… …
PersistentManager pm = pmf.getPersistentManager(); // get a PM instance
Transaction txn = pm.currentTransaction(); // get current
transaction context
pm.deletePersistent(pm.getObjectById(oid), false); // delete a persisted
object
txn.commit(); // commit the
transaction
pm.close();
… …
For operation in the distributed environment, Transaction is declared to implement
javax.transaction.Synchronization . This allows for flushing the cache to the data store during
externally managed transaction completion.
A Test Client Example
The most commonly used APIs are discussed in the preceding sections. To illustrate the use of these
APIs, a test client for the persistence-capable class Yacht is developed as shown in Listing 23-2 . You
can see from this example that the coding for JDO applications is very simple and straightforward.
Listing 23-2: A test client for the persistent class Yacht
package java_database.jdo;
import java.util.*;
import javax.jdo.*;
import com.prismt.j2ee.connector.jdbc.ManagedConnectionFactoryImpl;
public class TestClient {
private final static int SIZE = 4;
private PersistenceManagerFactory pmf = null;
private PersistenceManager pm = null;
private Transaction transaction = null;
private Yacht[] yachts; // Array of yachts for persistence
test
private Vector id = new Vector(SIZE); // Vector of object identifiers
Search WWH ::




Custom Search