Search in sources :

Example 6 with TransactionException

use of io.requery.TransactionException in project requery by requery.

the class ManagedTransaction method begin.

@Override
public Transaction begin() {
    if (active()) {
        throw new IllegalStateException("transaction already active");
    }
    transactionListener.beforeBegin(null);
    int status = getSynchronizationRegistry().getTransactionStatus();
    if (status == Status.STATUS_NO_TRANSACTION) {
        try {
            getUserTransaction().begin();
            initiatedTransaction = true;
        } catch (NotSupportedException | SystemException e) {
            throw new TransactionException(e);
        }
    }
    getSynchronizationRegistry().registerInterposedSynchronization(this);
    try {
        connection = connectionProvider.getConnection();
    } catch (SQLException e) {
        throw new TransactionException(e);
    }
    uncloseableConnection = new UncloseableConnection(connection);
    committed = false;
    rolledBack = false;
    entities.clear();
    transactionListener.afterBegin(null);
    return this;
}
Also used : TransactionException(io.requery.TransactionException) SystemException(javax.transaction.SystemException) SQLException(java.sql.SQLException) NotSupportedException(javax.transaction.NotSupportedException)

Example 7 with TransactionException

use of io.requery.TransactionException in project requery by requery.

the class ConnectionTransaction method commit.

@Override
public void commit() {
    try {
        transactionListener.beforeCommit(entities.types());
        if (supportsTransaction) {
            connection.commit();
            committed = true;
        }
        transactionListener.afterCommit(entities.types());
        entities.clear();
    } catch (SQLException e) {
        throw new TransactionException(e);
    } finally {
        resetConnection();
        close();
    }
}
Also used : TransactionException(io.requery.TransactionException) SQLException(java.sql.SQLException)

Aggregations

TransactionException (io.requery.TransactionException)7 SQLException (java.sql.SQLException)5 SystemException (javax.transaction.SystemException)3 PersistenceException (io.requery.PersistenceException)1 ReadOnlyException (io.requery.ReadOnlyException)1 RollbackException (io.requery.RollbackException)1 Transaction (io.requery.Transaction)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 NotSupportedException (javax.transaction.NotSupportedException)1 RollbackException (javax.transaction.RollbackException)1