Search in sources :

Example 26 with RollbackException

use of javax.transaction.RollbackException in project neo4j-mobile-android by neo4j-contrib.

the class ReadOnlyTransactionImpl method enlistResource.

public synchronized boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException {
    if (xaRes == null) {
        throw new IllegalArgumentException("Null xa resource");
    }
    if (status == Status.STATUS_ACTIVE || status == Status.STATUS_PREPARING) {
        try {
            if (resourceList.size() == 0) {
                //
                byte[] branchId = txManager.getBranchId(xaRes);
                Xid xid = new XidImpl(globalId, branchId);
                resourceList.add(new ResourceElement(xid, xaRes));
                xaRes.start(xid, XAResource.TMNOFLAGS);
                return true;
            }
            Xid sameRmXid = null;
            Iterator<ResourceElement> itr = resourceList.iterator();
            while (itr.hasNext()) {
                ResourceElement re = itr.next();
                if (sameRmXid == null && re.getResource().isSameRM(xaRes)) {
                    sameRmXid = re.getXid();
                }
                if (xaRes == re.getResource()) {
                    if (re.getStatus() == RS_SUSPENDED) {
                        xaRes.start(re.getXid(), XAResource.TMRESUME);
                    } else {
                        // either enlisted or delisted
                        // is TMJOIN correct then?
                        xaRes.start(re.getXid(), XAResource.TMJOIN);
                    }
                    re.setStatus(RS_ENLISTED);
                    return true;
                }
            }
            if (// should we join?
            sameRmXid != null) {
                resourceList.add(new ResourceElement(sameRmXid, xaRes));
                xaRes.start(sameRmXid, XAResource.TMJOIN);
            } else // new branch
            {
                // ResourceElement re = resourceList.getFirst();
                byte[] branchId = txManager.getBranchId(xaRes);
                Xid xid = new XidImpl(globalId, branchId);
                resourceList.add(new ResourceElement(xid, xaRes));
                xaRes.start(xid, XAResource.TMNOFLAGS);
            }
            return true;
        } catch (XAException e) {
            log.log(Level.SEVERE, "Unable to enlist resource[" + xaRes + "]", e);
            status = Status.STATUS_MARKED_ROLLBACK;
            return false;
        }
    } else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_MARKED_ROLLBACK) {
        throw new RollbackException("Tx status is: " + txManager.getTxStatusAsString(status));
    }
    throw new IllegalStateException("Tx status is: " + txManager.getTxStatusAsString(status));
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) RollbackException(javax.transaction.RollbackException)

Example 27 with RollbackException

use of javax.transaction.RollbackException in project graphdb by neo4j-attic.

the class ReadOnlyTransactionImpl method enlistResource.

public synchronized boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException {
    if (xaRes == null) {
        throw new IllegalArgumentException("Null xa resource");
    }
    if (status == Status.STATUS_ACTIVE || status == Status.STATUS_PREPARING) {
        try {
            if (resourceList.size() == 0) {
                // 
                byte[] branchId = txManager.getBranchId(xaRes);
                Xid xid = new XidImpl(globalId, branchId);
                resourceList.add(new ResourceElement(xid, xaRes));
                xaRes.start(xid, XAResource.TMNOFLAGS);
                return true;
            }
            Xid sameRmXid = null;
            Iterator<ResourceElement> itr = resourceList.iterator();
            while (itr.hasNext()) {
                ResourceElement re = itr.next();
                if (sameRmXid == null && re.getResource().isSameRM(xaRes)) {
                    sameRmXid = re.getXid();
                }
                if (xaRes == re.getResource()) {
                    if (re.getStatus() == RS_SUSPENDED) {
                        xaRes.start(re.getXid(), XAResource.TMRESUME);
                    } else {
                        // either enlisted or delisted
                        // is TMJOIN correct then?
                        xaRes.start(re.getXid(), XAResource.TMJOIN);
                    }
                    re.setStatus(RS_ENLISTED);
                    return true;
                }
            }
            if (// should we join?
            sameRmXid != null) {
                resourceList.add(new ResourceElement(sameRmXid, xaRes));
                xaRes.start(sameRmXid, XAResource.TMJOIN);
            } else // new branch
            {
                // ResourceElement re = resourceList.getFirst();
                byte[] branchId = txManager.getBranchId(xaRes);
                Xid xid = new XidImpl(globalId, branchId);
                resourceList.add(new ResourceElement(xid, xaRes));
                xaRes.start(xid, XAResource.TMNOFLAGS);
            }
            return true;
        } catch (XAException e) {
            e.printStackTrace();
            log.severe("Unable to enlist resource[" + xaRes + "]");
            status = Status.STATUS_MARKED_ROLLBACK;
            return false;
        }
    } else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_MARKED_ROLLBACK) {
        throw new RollbackException("Tx status is: " + txManager.getTxStatusAsString(status));
    }
    throw new IllegalStateException("Tx status is: " + txManager.getTxStatusAsString(status));
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) RollbackException(javax.transaction.RollbackException)

Example 28 with RollbackException

use of javax.transaction.RollbackException in project graphdb by neo4j-attic.

the class ReadOnlyTxManager method rollbackCommit.

private void rollbackCommit(Thread thread, ReadOnlyTransactionImpl tx) throws HeuristicMixedException, RollbackException {
    try {
        tx.doRollback();
    } catch (XAException e) {
        e.printStackTrace();
        log.severe("Unable to rollback marked transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
        throw new HeuristicMixedException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode);
    }
    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
    throw new RollbackException("Failed to commit, transaction rolledback");
}
Also used : XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException) RollbackException(javax.transaction.RollbackException)

Example 29 with RollbackException

use of javax.transaction.RollbackException in project graphdb by neo4j-attic.

the class TransactionImpl method enlistResource.

public synchronized boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException, SystemException {
    if (xaRes == null) {
        throw new IllegalArgumentException("Null xa resource");
    }
    if (status == Status.STATUS_ACTIVE || status == Status.STATUS_PREPARING) {
        try {
            if (resourceList.size() == 0) {
                if (!globalStartRecordWritten) {
                    txManager.writeStartRecord(globalId);
                    globalStartRecordWritten = true;
                }
                // 
                byte[] branchId = txManager.getBranchId(xaRes);
                Xid xid = new XidImpl(globalId, branchId);
                resourceList.add(new ResourceElement(xid, xaRes));
                xaRes.start(xid, XAResource.TMNOFLAGS);
                try {
                    txManager.getTxLog().addBranch(globalId, branchId);
                } catch (IOException e) {
                    e.printStackTrace();
                    log.severe("Error writing transaction log");
                    txManager.setTmNotOk();
                    throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
                }
                return true;
            }
            Xid sameRmXid = null;
            Iterator<ResourceElement> itr = resourceList.iterator();
            while (itr.hasNext()) {
                ResourceElement re = itr.next();
                if (sameRmXid == null && re.getResource().isSameRM(xaRes)) {
                    sameRmXid = re.getXid();
                }
                if (xaRes == re.getResource()) {
                    if (re.getStatus() == RS_SUSPENDED) {
                        xaRes.start(re.getXid(), XAResource.TMRESUME);
                    } else {
                        // either enlisted or delisted
                        // is TMJOIN correct then?
                        xaRes.start(re.getXid(), XAResource.TMJOIN);
                    }
                    re.setStatus(RS_ENLISTED);
                    return true;
                }
            }
            if (// should we join?
            sameRmXid != null) {
                resourceList.add(new ResourceElement(sameRmXid, xaRes));
                xaRes.start(sameRmXid, XAResource.TMJOIN);
            } else // new branch
            {
                // ResourceElement re = resourceList.getFirst();
                byte[] branchId = txManager.getBranchId(xaRes);
                Xid xid = new XidImpl(globalId, branchId);
                resourceList.add(new ResourceElement(xid, xaRes));
                xaRes.start(xid, XAResource.TMNOFLAGS);
                try {
                    txManager.getTxLog().addBranch(globalId, branchId);
                } catch (IOException e) {
                    e.printStackTrace();
                    log.severe("Error writing transaction log");
                    txManager.setTmNotOk();
                    throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
                }
            }
            return true;
        } catch (XAException e) {
            e.printStackTrace();
            log.severe("Unable to enlist resource[" + xaRes + "]");
            status = Status.STATUS_MARKED_ROLLBACK;
            return false;
        }
    } else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_MARKED_ROLLBACK) {
        throw new RollbackException("Tx status is: " + txManager.getTxStatusAsString(status));
    }
    throw new IllegalStateException("Tx status is: " + txManager.getTxStatusAsString(status));
}
Also used : Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) IOException(java.io.IOException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException)

Example 30 with RollbackException

use of javax.transaction.RollbackException in project graphdb by neo4j-attic.

the class TxManager method rollbackCommit.

private void rollbackCommit(Thread thread, TransactionImpl tx) throws HeuristicMixedException, RollbackException, SystemException {
    try {
        tx.doRollback();
    } catch (XAException e) {
        e.printStackTrace();
        log.severe("Unable to rollback marked transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
        setTmNotOk();
        throw new HeuristicMixedException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode);
    }
    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    try {
        if (tx.isGlobalStartRecordWritten()) {
            getTxLog().txDone(tx.getGlobalId());
        }
    } catch (IOException e) {
        e.printStackTrace();
        log.severe("Error writing transaction log");
        setTmNotOk();
        throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
    throw new RollbackException("Failed to commit, transaction rolledback");
}
Also used : XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException)

Aggregations

RollbackException (javax.transaction.RollbackException)57 SystemException (javax.transaction.SystemException)25 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)15 Transaction (javax.transaction.Transaction)14 UserTransaction (javax.transaction.UserTransaction)14 HeuristicMixedException (javax.transaction.HeuristicMixedException)12 Test (org.junit.Test)11 Connection (java.sql.Connection)8 XAException (javax.transaction.xa.XAException)8 PreparedStatement (java.sql.PreparedStatement)7 NotSupportedException (javax.transaction.NotSupportedException)7 IOException (java.io.IOException)6 EJBException (javax.ejb.EJBException)6 Account (org.apache.openejb.test.object.Account)6 RemoteException (java.rmi.RemoteException)5 CreateException (javax.ejb.CreateException)5 DataSource (javax.sql.DataSource)5 SQLException (java.sql.SQLException)4 Synchronization (javax.transaction.Synchronization)4 XAResource (javax.transaction.xa.XAResource)4