Class BasicManagedDataSource

  • All Implemented Interfaces:
    AutoCloseable, Wrapper, MBeanRegistration, CommonDataSource, DataSource, BasicDataSourceMXBean, DataSourceMXBean

    public class BasicManagedDataSource
    extends BasicDataSource

    BasicManagedDataSource is an extension of BasicDataSource which creates ManagedConnections. This data source can create either full two-phase-commit XA connections or one-phase-commit local connections. Both types of connections are committed or rolled back as part of the global transaction (a.k.a. XA transaction or JTA Transaction), but only XA connections can be recovered in the case of a system crash.

    BasicManagedDataSource adds the TransactionManager and XADataSource properties. The TransactionManager property is required and is used to enlist connections in global transactions. The XADataSource is optional and if set is the class name of the XADataSource class for a two-phase-commit JDBC driver. If the XADataSource property is set, the driverClassName is ignored and a DataSourceXAConnectionFactory is created. Otherwise, a standard DriverConnectionFactory is created and wrapped with a LocalXAConnectionFactory.

    See Also:
    BasicDataSource, ManagedConnection
    • Constructor Detail

      • BasicManagedDataSource

        public BasicManagedDataSource()
    • Method Detail

      • createConnectionFactory

        protected ConnectionFactory createConnectionFactory()
                                                     throws SQLException
        Description copied from class: BasicDataSource
        Creates a JDBC connection factory for this data source. The JDBC driver is loaded using the following algorithm:
        1. If a Driver instance has been specified via BasicDataSource.setDriver(Driver) use it
        2. If no Driver instance was specified and {code driverClassName} is specified that class is loaded using the ClassLoader of this class or, if {code driverClassLoader} is set, {code driverClassName} is loaded with the specified ClassLoader.
        3. If {code driverClassName} is specified and the previous attempt fails, the class is loaded using the context class loader of the current thread.
        4. If a driver still isn't loaded one is loaded via the DriverManager using the specified {code url}.

        This method exists so subclasses can replace the implementation class.

        createConnectionFactory in class BasicDataSource
        A new connection factory.
        SQLException - If the connection factory cannot be created
      • getTransactionManager

        public TransactionManager getTransactionManager()
        Gets the required transaction manager property.
        the transaction manager used to enlist connections
      • getTransactionRegistry

        protected TransactionRegistry getTransactionRegistry()
        Gets the transaction registry.
        the transaction registry associating XAResources with managed connections
      • getTransactionSynchronizationRegistry

        public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
        Gets the optional TransactionSynchronizationRegistry.
        the TSR that can be used to register synchronizations.
      • getXADataSource

        public String getXADataSource()
        Gets the optional XADataSource class name.
        the optional XADataSource class name
      • getXaDataSourceInstance

        public XADataSource getXaDataSourceInstance()
        Gets the XADataSource instance used by the XAConnectionFactory.
        the XADataSource
      • setTransactionManager

        public void setTransactionManager​(TransactionManager transactionManager)
        Sets the required transaction manager property.
        transactionManager - the transaction manager used to enlist connections
      • setTransactionSynchronizationRegistry

        public void setTransactionSynchronizationRegistry​(TransactionSynchronizationRegistry transactionSynchronizationRegistry)
        Sets the optional TransactionSynchronizationRegistry property.
        transactionSynchronizationRegistry - the TSR used to register synchronizations
      • setXADataSource

        public void setXADataSource​(String xaDataSource)
        Sets the optional XADataSource class name.
        xaDataSource - the optional XADataSource class name
      • setXaDataSourceInstance

        public void setXaDataSourceInstance​(XADataSource xaDataSourceInstance)

        Sets the XADataSource instance used by the XAConnectionFactory.

        Note: this method currently has no effect once the pool has been initialized. The pool is initialized the first time one of the following methods is invoked: getConnection, setLogwriter, setLoginTimeout, getLoginTimeout, getLogWriter.

        xaDataSourceInstance - XADataSource instance