use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class ClientXASession method getXAException.
private XAException getXAException(RemoteException e) {
XAException exception = new XAException("Remote operation failed");
exception.initCause(e);
return exception;
}
use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class XASessionImpl method start.
/**
* {@inheritDoc}
* <p>
* If <code>TMNOFLAGS</code> is specified, we create a new transaction
* context and associate it with this resource.
* If <code>TMJOIN</code> is specified, this resource should use the
* same transaction context as another, already known transaction.
* If <code>TMRESUME</code> is specified, we should resume work on
* a transaction context that was suspended earlier.
* All other flags generate an <code>XAException</code> of type
* <code>XAER_INVAL</code>
*/
public void start(Xid xid, int flags) throws XAException {
if (isAssociated()) {
log.error("Resource already associated with a transaction.");
throw new XAException(XAException.XAER_PROTO);
}
TransactionContext tx = txGlobal.get(xid);
if (flags == TMNOFLAGS) {
if (tx != null) {
throw new XAException(XAException.XAER_DUPID);
}
tx = createTransaction(xid);
} else if (flags == TMJOIN) {
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
} else if (flags == TMRESUME) {
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
if (!tx.isSuspended()) {
log.error("Unable to resume: transaction not suspended.");
throw new XAException(XAException.XAER_PROTO);
}
tx.setSuspended(false);
} else {
throw new XAException(XAException.XAER_INVAL);
}
associate(tx);
}
use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class XASessionImpl method end.
/**
* {@inheritDoc}
* <p>
* If <code>TMSUCCESS</code> is specified, we disassociate this session
* from the transaction specified.
* If <code>TMFAIL</code> is specified, we disassociate this session from
* the transaction specified and mark the transaction rollback only.
* If <code>TMSUSPEND</code> is specified, we disassociate this session
* from the transaction specified.
* All other flags generate an <code>XAException</code> of type
* <code>XAER_INVAL</code>
* <p>
* It is legal for a transaction association to be suspended and then
* ended (either with <code>TMSUCCESS</code> or <code>TMFAIL</code>)
* without having been resumed again.
*/
public void end(Xid xid, int flags) throws XAException {
TransactionContext tx = txGlobal.get(xid);
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
if (flags == TMSUSPEND) {
if (!isAssociated()) {
log.error("Resource not associated with a transaction.");
throw new XAException(XAException.XAER_PROTO);
}
associate(null);
tx.setSuspended(true);
} else if (flags == TMFAIL || flags == TMSUCCESS) {
if (!tx.isSuspended()) {
if (!isAssociated()) {
log.error("Resource not associated with a transaction.");
throw new XAException(XAException.XAER_PROTO);
}
associate(null);
} else {
tx.setSuspended(false);
}
} else {
throw new XAException(XAException.XAER_INVAL);
}
}
use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class UserTransactionImpl method rollback.
/**
* @see javax.transaction.UserTransaction#rollback
*/
public void rollback() throws IllegalStateException, SecurityException, SystemException {
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException("Transaction not active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.end(xid, XAResource.TMFAIL);
}
status = Status.STATUS_ROLLING_BACK;
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.rollback(xid);
}
status = Status.STATUS_ROLLEDBACK;
} catch (XAException e) {
SystemException se = new SystemException("Unable to rollback transaction: XA_ERR=" + e.errorCode);
se.initCause(e.getCause());
throw se;
}
}
use of javax.transaction.xa.XAException in project jackrabbit by apache.
the class UserTransactionImpl method commit.
/**
* @see javax.transaction.UserTransaction#commit
*/
public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
if (status != Status.STATUS_ACTIVE) {
throw new IllegalStateException("Transaction not active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.end(xid, XAResource.TMSUCCESS);
}
status = Status.STATUS_PREPARING;
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.prepare(xid);
}
status = Status.STATUS_PREPARED;
status = Status.STATUS_COMMITTING;
if (distributedThreadAccess) {
Thread distributedThread = new Thread() {
public void run() {
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.commit(xid, false);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
};
distributedThread.start();
distributedThread.join(1000);
if (distributedThread.isAlive()) {
throw new SystemException("Commit from different thread but same XID must not block");
}
} else {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.commit(xid, false);
}
}
status = Status.STATUS_COMMITTED;
} catch (XAException e) {
if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) {
RollbackException re = new RollbackException("Transaction rolled back: XA_ERR=" + e.errorCode);
re.initCause(e.getCause());
throw re;
} else {
SystemException se = new SystemException("Unable to commit transaction: XA_ERR=" + e.errorCode);
se.initCause(e.getCause());
throw se;
}
} catch (InterruptedException e) {
throw new SystemException("Thread.join() interrupted");
}
}
Aggregations