Search in sources :

Example 1 with NucleusConnection

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);
}
Also used : NucleusDataStoreException(org.datanucleus.exceptions.NucleusDataStoreException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) NucleusConnection(org.datanucleus.store.NucleusConnection) ManagedConnection(org.datanucleus.store.connection.ManagedConnection) NucleusConnectionImpl(org.datanucleus.store.NucleusConnectionImpl) ManagedConnection(org.datanucleus.store.connection.ManagedConnection)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)1 NucleusConnection (org.datanucleus.store.NucleusConnection)1 NucleusConnectionImpl (org.datanucleus.store.NucleusConnectionImpl)1 ManagedConnection (org.datanucleus.store.connection.ManagedConnection)1