# Class DataSourceXAConnectionFactory

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

All Implemented Interfaces:
  `ConnectionFactory`, `XAConnectionFactory`

public class DataSourceXAConnectionFactory extends Object implements XAConnectionFactory
An implementation of XAConnectionFactory which uses a real XADataSource to obtain connections and XAResources.

Since:
  2.0

## Constructor Summary

Constructors
Constructor
Description
`DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource)`
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource to create database connections.
`DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, String userName, char[] userPassword)`
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource to create database connections.
`DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, String userName, char[] userPassword, TransactionSynchronizationRegistry transactionSynchronizationRegistry)`
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource to create database connections.
`DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, String userName, String userPassword)`
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource to create database connections.
`DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, TransactionSynchronizationRegistry transactionSynchronizationRegistry)`
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource to create database connections.

## Method Summary

Modifier and Type
Method
Description
`Connection`
`createConnection()`
Creates a new `Connection` in an implementation specific fashion.
`TransactionRegistry`
`getTransactionRegistry()`
Gets the TransactionRegistry for this connection factory which contains the XAResource for every connection created by this factory.
`String`
`getUsername()`
Deprecated.
Use `getUserName()`.
`String`
`getUserName()`
Gets the user name used to authenticate new connections.
`char[]`
`getUserPassword()`
Gets the user password.
`XADataSource`
`getXaDataSource()`
Gets the XA data source.
`void`
`setPassword(char[] userPassword)`
Sets the password used to authenticate new connections.
`void`
`setPassword(String userPassword)`
Sets the password used to authenticate new connections.
`void`
`setUsername(String userName)`
Sets the user name used to authenticate new connections.

### Methods inherited from class java.lang.Object

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

## Constructor Details

### DataSourceXAConnectionFactory

public DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource)
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource 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
  `xaDataSource` - the data source from which connections will be retrieved
Since:
  2.6.0

### DataSourceXAConnectionFactory

public DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, String userName, char[] userPassword)
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource 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
  `xaDataSource` - the data source from which connections will be retrieved
  `userName` - the user name used for authenticating new connections or null for unauthenticated
  `userPassword` - the password used for authenticating new connections

### DataSourceXAConnectionFactory

public DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, String userName, char[] userPassword, TransactionSynchronizationRegistry transactionSynchronizationRegistry)
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource 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
  `xaDataSource` - the data source from which connections will be retrieved
  `userName` - the user name used for authenticating new connections or null for unauthenticated
  `userPassword` - the password used for authenticating new connections
  `transactionSynchronizationRegistry` - register with this TransactionSynchronizationRegistry
Since:
  2.6.0

### DataSourceXAConnectionFactory

public DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, String userName, String userPassword)
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource 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
  `xaDataSource` - the data source from which connections will be retrieved
  `userName` - the user name used for authenticating new connections or null for unauthenticated
  `userPassword` - the password used for authenticating new connections

### DataSourceXAConnectionFactory

public DataSourceXAConnectionFactory(TransactionManager transactionManager, XADataSource xaDataSource, TransactionSynchronizationRegistry transactionSynchronizationRegistry)
Creates an DataSourceXAConnectionFactory which uses the specified XADataSource 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
  `xaDataSource` - the data source from which connections will be retrieved
  `transactionSynchronizationRegistry` - register with this TransactionSynchronizationRegistry

## 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

### getTransactionRegistry

public TransactionRegistry getTransactionRegistry()
Description copied from interface: `XAConnectionFactory`
Gets the TransactionRegistry for this connection factory which contains the XAResource for every connection created by this factory.

Specified by:
  `getTransactionRegistry` in interface `XAConnectionFactory`
Returns:
  the transaction registry for this connection factory

### getUsername

@Deprecated public String getUsername()
Deprecated.
Use `getUserName()`.
Gets the user name used to authenticate new connections.

Returns:
  the user name or null if unauthenticated connections are used

### getUserName

public String getUserName()
Gets the user name used to authenticate new connections.

Returns:
  the user name or null if unauthenticated connections are used
Since:
  2.6.0

### getUserPassword

public char[] getUserPassword()
Gets the user password.

Returns:
  the user password.

### getXaDataSource

public XADataSource getXaDataSource()
Gets the XA data source.

Returns:
  the XA data source.

### setPassword

public void setPassword(char[] userPassword)
Sets the password used to authenticate new connections.

Parameters:
  `userPassword` - the password used for authenticating the connection or null for unauthenticated.
Since:
  2.4.0

### setPassword

public void setPassword(String userPassword)
Sets the password used to authenticate new connections.

Parameters:
  `userPassword` - the password used for authenticating the connection or null for unauthenticated

### setUsername

public void setUsername(String userName)
Sets the user name used to authenticate new connections.

Parameters:
  `userName` - the user name used for authenticating the connection or null for unauthenticated