Package org.datanucleus.store.connection
Interface ConnectionManager
-
- All Known Implementing Classes:
ConnectionManagerImpl
public interface ConnectionManager
Manager of connections for a StoreManager, allowing ManagedConnection pooling, 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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default 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.default ManagedConnection
getConnection(ExecutionContext ec)
Accessor for a connection for the specified ExecutionContext.ManagedConnection
getConnection(ExecutionContext ec, Map options)
Accessor for a connection for the specified ExecutionContext.
-
-
-
Method Detail
-
close
void close()
Method to close the connection manager. This will close all open connections.
-
disableConnectionCaching
void disableConnectionCaching()
Disable binding objects to "ExecutionContext" references, so automatically disables the connection caching.
-
getConnection
default ManagedConnection getConnection(ExecutionContext ec)
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).- Parameters:
ec
- execution context- Returns:
- The ManagedConnection
- Throws:
NucleusException
- Thrown if an error occurs getting the connection
-
getConnection
ManagedConnection getConnection(ExecutionContext ec, Map options)
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).- Parameters:
ec
- execution contextoptions
- connection options- Returns:
- The ManagedConnection
- Throws:
NucleusException
- Thrown if an error occurs getting the connection
-
getConnection
ManagedConnection getConnection(int isolationLevel)
Accessor for a connection for the specified transaction isolation level. This is used for schema and sequence access operations.- Parameters:
isolationLevel
- Isolation level (-1 implies use the default for the datastore).- Returns:
- The ManagedConnection
- Throws:
NucleusException
- Thrown if an error occurs getting the connection
-
getConnection
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.- Parameters:
primary
- Whether to take use the "primary" connection factory, otherwise takes the "secondary"ec
- ExecutionContexttxn
- The Transaction- Returns:
- The ManagedConnection
-
closeAllConnections
void closeAllConnections(ExecutionContext ec)
Method to close all pooled connections for the specified ExecutionContext.- Parameters:
ec
- The ExecutionContext
-
-