Class 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 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 interface ConnectionManager
      • disableConnectionCaching

        public void disableConnectionCaching()
        Disable binding objects to ExecutionContext references, so automatically disables the connection caching.
        Specified by:
        disableConnectionCaching in interface ConnectionManager
      • 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 interface ConnectionManager
        Parameters:
        ec - execution context
        options - 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 interface ConnectionManager
        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 interface ConnectionManager
        Parameters:
        primary - Whether to take use the "primary" connection factory, otherwise takes the "secondary"
        ec - ExecutionContext
        txn - The Transaction
        Returns:
        The ManagedConnection
      • removeManagedConnection

        protected void removeManagedConnection​(boolean primary,
                                               ExecutionContext ec)
        Method to remove the ManagedConnection from the cache.
        Parameters:
        primary - Whether to use the primary ConnectionFactory
        ec - ExecutionContext
      • getManagedConnection

        protected ManagedConnection getManagedConnection​(boolean primary,
                                                         ExecutionContext ec)
        Get a ManagedConnection from the cache.
        Parameters:
        primary - Whether to use the primary ConnectionFactory
        ec - 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 ConnectionFactory
        ec - ExecutionContext
        mconn - The ManagedConnection