![]() | ![]() |
![]() |
| Project | Ver 1.1 | Ver 1.2 | JDO | JPA | Guides | Tools |
| 1.1 | Preparation | O/R Mapping | Runtime | Extensions | Developer |
![]() JPOX utilises connections to the datastore differently depending on the transaction type. For pessimistic (or datastore) transactions when begin() is called on the transaction, a connection will be obtained to the datastore. This datastore connection will be held for the duration of the transaction until such time as either commit() or rollback() are called. For optimistic transactions things are a little more complicated. The call to begin() has no effect with respect to datastore connections. The datastore connection is only obtained when a datastore operation is required. The connection is typically released after performing that operation. So datastore connections, in general, are held for much smaller periods of time. This is complicated slightly by use of the PMF property java.jdo.IgnoreCache. When this is set to false, the connection, once obtained, is not released until the call to commit() or rollback(). When the operation is outside of a transaction, where nontransactionalRead is enabled, the Connection is allocated when the operation starts, and closed when it ends for the particular PersistenceManager. This can result in "ConnectionInUse" problems where another operation on another thread comes in and tries to perform something while that first operation is still in use. This happens because the JDO spec requires an implementation to use a single datastore connection at any one time. When this situation crops up the user ought to use multiple PersistenceManagers. Another important aspect is use of queries for Optimistic transactions, or for non-transactional contexts. In these situations it isn't possible to keep the datastore connection open indefinitely and so when the Query is executed the ResultSet is then read into core making the queried objects available thereafter. Occasionally systems may need access to the datastore directly. JDO2 provides an accessor for obtaining a connection to the datastore. You obtain a connection as follows
// Obtain the connection from the JDO implementation
JDOConnection conn = pm.getDataStoreConnection();
try
{
java.sql.Connection sqlConn = (java.sql.Connection)conn;
... use the "sqlConn" connection to perform some operations.
}
finally
{
// Hand the connection back to the JDO implementation
conn.close();
}
The "JDOConnection"
![]() JPOX also allows specification of the transaction isolation level. This is specified via the PersistenceManagerFactory property org.jpox.transactionIsolation. It accepts the standard JDBC values of READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE. The default is READ_COMMITTED. If the RDBMS doesn't support a particular isolation level then it will silently be changed to one that is supported. As an alternative you can also specify it on a per-transaction basis as follows ((org.jpox.store.rdbms.RDBMSTransaction)pm.currentTransaction).setTransactionIsolation(isolation); |