Search in sources :

Example 1 with FBManagedConnection

use of org.firebirdsql.jaybird.xca.FBManagedConnection in project jaybird by FirebirdSQL.

the class InternalTransactionCoordinator method setTransactionCoordinator.

/**
 * Sets the transaction coordinator.
 * <p>
 * In most cases {@link #switchTransactionCoordinator(boolean)} should be called.
 * </p>
 *
 * @param managedConnection
 *         Whether this is a managed connection
 * @param autoCommit
 *         Value for auto commit
 * @throws SQLException
 *         If {@code autoCommit} is {@code true}, and {@code managedConnection} is {@code false} and
 *         the connection is currently enlisted in a distributed transaction
 */
void setTransactionCoordinator(boolean managedConnection, boolean autoCommit) throws SQLException {
    FBManagedConnection mc = connection.getManagedConnection();
    InternalTransactionCoordinator.AbstractTransactionCoordinator coordinator;
    if (managedConnection && mc.inDistributedTransaction()) {
        coordinator = new ManagedTransactionCoordinator(connection);
    } else if (autoCommit) {
        if (mc.inDistributedTransaction()) {
            throw new SQLException("Connection enlisted in distributed transaction", SQLStateConstants.SQL_STATE_INVALID_TX_STATE);
        }
        if (connection.isUseFirebirdAutoCommit()) {
            coordinator = new FirebirdAutoCommitCoordinator(connection, connection.getLocalTransaction());
        } else {
            coordinator = new AutoCommitCoordinator(connection, connection.getLocalTransaction());
        }
    } else {
        coordinator = new LocalTransactionCoordinator(connection, connection.getLocalTransaction());
    }
    setCoordinator(coordinator);
}
Also used : SQLException(java.sql.SQLException) FBManagedConnection(org.firebirdsql.jaybird.xca.FBManagedConnection)

Aggregations

SQLException (java.sql.SQLException)1 FBManagedConnection (org.firebirdsql.jaybird.xca.FBManagedConnection)1