# Class LocalXAConnectionFactory

java.lang.Object
org.apache.tomcat.dbcp.dbcp2.managed.LocalXAConnectionFactory

All Implemented Interfaces:
  `ConnectionFactory, XAConnectionFactory`

public class LocalXAConnectionFactory extends Object implements XAConnectionFactory
An implementation of XAConnectionFactory which manages non-XA connections in XA transactions. A non-XA connection commits and rolls back as part of the XA transaction, but is not recoverable since the connection does not implement the 2-phase protocol.

Since:
  2.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static class`
  `LocalXAConnectionFactory.LocalXAResource`
  LocalXAResource is a fake XAResource for non-XA connections.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LocalXAConnectionFactory(TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry, ConnectionFactory connectionFactory)`
  Creates an LocalXAConnectionFactory which uses the specified connection factory to create database connections.
  `LocalXAConnectionFactory(TransactionManager transactionManager, ConnectionFactory connectionFactory)`
  Creates an LocalXAConnectionFactory which uses the specified connection factory to create database connections.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Connection`
  `createConnection()`
  Creates a new `Connection` in an implementation specific fashion.
  `ConnectionFactory`
  `getConnectionFactory()`
  Gets the connection factory.
  `TransactionRegistry`
  `getTransactionRegistry()`
  Gets the transaction registry.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### LocalXAConnectionFactory

    public LocalXAConnectionFactory(TransactionManager transactionManager, ConnectionFactory connectionFactory)
    Creates an LocalXAConnectionFactory which uses the specified connection factory to create database connections. The connections are enlisted into transactions using the specified transaction manager.
    Parameters:
      `transactionManager` - the transaction manager in which connections will be enlisted
      `connectionFactory` - the connection factory from which connections will be retrieved

  - ### LocalXAConnectionFactory

    public LocalXAConnectionFactory(TransactionManager transactionManager, TransactionSynchronizationRegistry transactionSynchronizationRegistry, ConnectionFactory connectionFactory)
    Creates an LocalXAConnectionFactory which uses the specified connection factory to create database connections. The connections are enlisted into transactions using the specified transaction manager.
    Parameters:
      `transactionManager` - the transaction manager in which connections will be enlisted
      `transactionSynchronizationRegistry` - the optional TSR to register synchronizations with
      `connectionFactory` - the connection factory from which connections will be retrieved
    Since:
      2.8.0

- ## Method Details

  - ### createConnection

    public Connection createConnection() throws SQLException
    Description copied from interface: `XAConnectionFactory`
    Creates a new `Connection` in an implementation specific fashion.

    An implementation can assume that the caller of this will wrap the connection in a proxy that protects access to the setAutoCommit, commit and rollback when enrolled in a XA transaction.

    Specified by:
      `createConnection` in interface `ConnectionFactory`
    Specified by:
      `createConnection` in interface `XAConnectionFactory`
    Returns:
      a new `Connection`
    Throws:
      `SQLException` - if a database error occurs creating the connection

  - ### getConnectionFactory

    public ConnectionFactory getConnectionFactory()
    Gets the connection factory.
    Returns:
      The connection factory.
    Since:
      2.6.0

  - ### getTransactionRegistry

    public TransactionRegistry getTransactionRegistry()
    Gets the transaction registry.
    Specified by:
      `getTransactionRegistry` in interface `XAConnectionFactory`
    Returns:
      The transaction registry.