use of org.datanucleus.store.NucleusConnection in project datanucleus-rdbms by datanucleus.
the class RDBMSStoreManager method getNucleusConnection.
/**
* Method to return a NucleusConnection for the ExecutionContext.
* @param ec execution context
* @return The NucleusConnection
*/
public NucleusConnection getNucleusConnection(final ExecutionContext ec) {
ManagedConnection mc = connectionMgr.getConnection(ec.getTransaction().isActive(), ec, ec.getTransaction());
// Lock the connection now that it is in use by the user
mc.lock();
Runnable closeRunnable = new Runnable() {
public void run() {
// Unlock the connection now that the user has finished with it
mc.unlock();
if (!ec.getTransaction().isActive()) {
// Close the (unenlisted) connection (committing its statements)
try {
((Connection) mc.getConnection()).close();
} catch (SQLException sqle) {
throw new NucleusDataStoreException(sqle.getMessage());
}
}
}
};
return new NucleusConnectionImpl(mc.getConnection(), closeRunnable);
}
Aggregations