Search in sources :

Example 1 with Transaction

use of com.persistit.Transaction in project titan by thinkaurelius.

the class PersistitTransaction method commit.

@Override
public void commit() throws StorageException {
    synchronized (this) {
        if (null == sessionId) {
            // Already closed
            log.warn("Can't commit {}: already closed, trace to redundant commit follows", this, new IllegalStateException("redundant commit"));
            return;
        }
        super.commit();
        assign();
        Transaction tx = db.getTransaction();
        int retries = 3;
        try {
            if (tx.isActive() && !tx.isRollbackPending()) {
                int i = 0;
                while (true) {
                    try {
                        tx.commit(Transaction.CommitPolicy.HARD);
                        tx.end();
                        break;
                    } catch (RollbackException ex) {
                        if (i++ >= retries) {
                            throw ex;
                        }
                    }
                }
                close();
            }
        } catch (PersistitException ex) {
            throw new PermanentStorageException(ex);
        }
    }
}
Also used : AbstractStoreTransaction(com.thinkaurelius.titan.diskstorage.common.AbstractStoreTransaction) Transaction(com.persistit.Transaction) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) PersistitException(com.persistit.exception.PersistitException) RollbackException(com.persistit.exception.RollbackException)

Example 2 with Transaction

use of com.persistit.Transaction in project titan by thinkaurelius.

the class PersistitTransaction method rollback.

@Override
public void rollback() throws StorageException {
    super.rollback();
    synchronized (this) {
        assign();
        Transaction tx = db.getTransaction();
        if (tx.isActive() && !tx.isCommitted()) {
            tx.rollback();
        }
        tx.end();
        close();
    }
}
Also used : AbstractStoreTransaction(com.thinkaurelius.titan.diskstorage.common.AbstractStoreTransaction) Transaction(com.persistit.Transaction)

Aggregations

Transaction (com.persistit.Transaction)2 AbstractStoreTransaction (com.thinkaurelius.titan.diskstorage.common.AbstractStoreTransaction)2 PersistitException (com.persistit.exception.PersistitException)1 RollbackException (com.persistit.exception.RollbackException)1 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)1