use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class TransactionContext method prepare.
/**
* Prepare the transaction identified by this context. Prepares changes on
* all resources. If some resource reports an error on prepare,
* automatically rollback changes on all other resources. Throw exception
* at the end if errors were found.
*
* @throws XAException if an error occurs
*/
public synchronized void prepare() throws XAException {
bindCurrentXid();
status = STATUS_PREPARING;
beforeOperation();
TransactionException txe = null;
for (int i = 0; i < resources.length; i++) {
try {
resources[i].prepare(this);
} catch (TransactionException e) {
txe = e;
break;
} catch (Exception e) {
txe = new TransactionException("Error while preparing resource " + resources, e);
break;
}
}
afterOperation();
status = STATUS_PREPARED;
if (txe != null) {
// force immediate rollback on error.
try {
rollback();
} catch (XAException e) {
/* ignore */
}
XAException e = new XAException(XAException.XA_RBOTHER);
e.initCause(txe);
throw e;
}
}
use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class TransactionContext method commit.
/**
* Commit the transaction identified by this context. Commits changes on
* all resources. If some resource reports an error on commit,
* automatically rollback changes on all other resources. Throw
* exception at the end if some commit failed.
*
* @throws XAException if an error occurs
*/
public synchronized void commit() throws XAException {
if (status == STATUS_ROLLED_BACK) {
throw new XAException(XAException.XA_HEURRB);
}
boolean heuristicCommit = false;
bindCurrentXid();
status = STATUS_COMMITTING;
beforeOperation();
TransactionException txe = null;
for (int i = 0; i < resources.length; i++) {
InternalXAResource resource = resources[i];
if (txe != null) {
try {
resource.rollback(this);
} catch (Exception e) {
log.warn("Unable to rollback changes on " + resource, e);
}
} else {
try {
resource.commit(this);
heuristicCommit = true;
} catch (TransactionException e) {
txe = e;
} catch (Exception e) {
txe = new TransactionException("Error while committing resource " + resource, e);
}
}
}
afterOperation();
status = STATUS_COMMITTED;
cleanCurrentXid();
if (txe != null) {
XAException e = null;
if (heuristicCommit) {
e = new XAException(XAException.XA_HEURMIX);
} else {
e = new XAException(XAException.XA_HEURRB);
}
e.initCause(txe);
throw e;
}
}
use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class UserTransactionImpl method begin.
/**
* @see javax.transaction.UserTransaction#begin
*/
public void begin() throws NotSupportedException, SystemException {
if (status != Status.STATUS_NO_TRANSACTION) {
throw new IllegalStateException("Transaction already active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.start(xid, XAResource.TMNOFLAGS);
}
status = Status.STATUS_ACTIVE;
} catch (XAException e) {
throw new SystemException("Unable to begin transaction: " + "XA_ERR=" + e.errorCode);
}
}
Aggregations