public JtaDaoTransaction(UserTransaction utx, DataSource ds) {
// Check parameters
userTransaction = utx;
dataSource = ds;
if (userTransaction == null) {
throw new DaoException("JtaTransaction initialization failed. UserTransaction was null.");
}
if (dataSource == null) {
throw new DaoException("JtaTransaction initialization failed. DataSource was null.");
}
// Start JTA Transaction
try {
newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION;
if (newTransaction) {
userTransaction.begin();
}
} catch (Exception e) {
throw new DaoException("JtaTransaction could not start transaction. Cause: ", e);
}
try {
// Open JDBC Connection
connection = dataSource.getConnection();
if (connection == null) {
throw new DaoException("Could not start transaction. Cause: The DataSource returned a null connection.");
}
if (connection.getAutoCommit()) {
connection.setAutoCommit(false);
}
if (connectionLog.isDebugEnabled()) {
connection = ConnectionLogProxy.newInstance(connection);
}
} catch (SQLException e) {
throw new DaoException("Error opening JDBC connection. Cause: " + e, e);
}
}