Package org.datanucleus.store.connection
Class ConnectionManagerImpl
- java.lang.Object
-
- org.datanucleus.store.connection.ConnectionManagerImpl
-
- All Implemented Interfaces:
ConnectionManager
public class ConnectionManagerImpl extends Object implements ConnectionManager
Manager of connections for a datastore, allowing caching of ManagedConnections, enlistment in transaction. Manages a "primary" and (optionally) a "secondary" ConnectionFactory. When caching is enabled it maintains caches of the allocated ManagedConnection per ExecutionContext (an EC can have a single ManagedConnection per ConnectionFactory at any time).The "allocateConnection" method can create connections and enlist them (like most normal persistence operations need) or create a connection and return it without enlisting it into a transaction, for example on a read-only operation, or when running non-transactional, or to get schema information.
Connections can be locked per ExecutionContext basis. Locking of connections is used to handle the connection over to the user application. A locked connection denies any further access to the datastore, until the user application unlock it.
-
-
Constructor Summary
Constructors Constructor Description ConnectionManagerImpl(StoreManager storeMgr)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Method to close the connection manager.void
closeAllConnections(ExecutionContext ec)
Method to close all pooled connections for the specified ExecutionContext.void
disableConnectionCaching()
Disable binding objects to ExecutionContext references, so automatically disables the connection caching.ManagedConnection
getConnection(boolean primary, ExecutionContext ec, Transaction txn)
Accessor for a connection from the specified factory, for the specified ExecutionContext dependent on whether the connection will be enlisted.ManagedConnection
getConnection(int isolationLevel)
Accessor for a connection for the specified transaction isolation level.ManagedConnection
getConnection(ExecutionContext ec, Map options)
Accessor for a connection for the specified ExecutionContext.protected ManagedConnection
getManagedConnection(boolean primary, ExecutionContext ec)
Get a ManagedConnection from the cache.protected void
putManagedConnection(boolean primary, ExecutionContext ec, ManagedConnection mconn)
Put a ManagedConnection into the cache.protected void
removeManagedConnection(boolean primary, ExecutionContext ec)
Method to remove the ManagedConnection from the cache.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.datanucleus.store.connection.ConnectionManager
getConnection
-
-
-
-
Constructor Detail
-
ConnectionManagerImpl
public ConnectionManagerImpl(StoreManager storeMgr)
Constructor. This will register the "primary" and "secondary" ConnectionFactory objects.- Parameters:
storeMgr
- Store manager for whom we are managing connections
-
-
Method Detail
-
close
public void close()
Description copied from interface:ConnectionManager
Method to close the connection manager. This will close all open connections.- Specified by:
close
in interfaceConnectionManager
-
disableConnectionCaching
public void disableConnectionCaching()
Disable binding objects to ExecutionContext references, so automatically disables the connection caching.- Specified by:
disableConnectionCaching
in interfaceConnectionManager
-
getConnection
public ManagedConnection getConnection(ExecutionContext ec, Map options)
Description copied from interface:ConnectionManager
Accessor for a connection for the specified ExecutionContext. If there is an active transaction, a connection from the primary connection factory will be returned. If there is no active transaction, a connection from the secondary connection factory will be returned (unless the user has specified to just use the primary).- Specified by:
getConnection
in interfaceConnectionManager
- Parameters:
ec
- execution contextoptions
- connection options- Returns:
- The ManagedConnection
-
getConnection
public ManagedConnection getConnection(int isolationLevel)
Description copied from interface:ConnectionManager
Accessor for a connection for the specified transaction isolation level. This is used for schema and sequence access operations.- Specified by:
getConnection
in interfaceConnectionManager
- Parameters:
isolationLevel
- Isolation level (-1 implies use the default for the datastore).- Returns:
- The ManagedConnection
-
getConnection
public ManagedConnection getConnection(boolean primary, ExecutionContext ec, Transaction txn)
Description copied from interface:ConnectionManager
Accessor for a connection from the specified factory, for the specified ExecutionContext dependent on whether the connection will be enlisted.- Specified by:
getConnection
in interfaceConnectionManager
- Parameters:
primary
- Whether to take use the "primary" connection factory, otherwise takes the "secondary"ec
- ExecutionContexttxn
- The Transaction- Returns:
- The ManagedConnection
-
closeAllConnections
public void closeAllConnections(ExecutionContext ec)
Description copied from interface:ConnectionManager
Method to close all pooled connections for the specified ExecutionContext.- Specified by:
closeAllConnections
in interfaceConnectionManager
- Parameters:
ec
- The ExecutionContext
-
removeManagedConnection
protected void removeManagedConnection(boolean primary, ExecutionContext ec)
Method to remove the ManagedConnection from the cache.- Parameters:
primary
- Whether to use the primary ConnectionFactoryec
- ExecutionContext
-
getManagedConnection
protected ManagedConnection getManagedConnection(boolean primary, ExecutionContext ec)
Get a ManagedConnection from the cache.- Parameters:
primary
- Whether to use the primary ConnectionFactoryec
- ExecutionContext- Returns:
- The managed connection
-
putManagedConnection
protected void putManagedConnection(boolean primary, ExecutionContext ec, ManagedConnection mconn)
Put a ManagedConnection into the cache.- Parameters:
primary
- Whether to use the primary ConnectionFactoryec
- ExecutionContextmconn
- The ManagedConnection
-
-