use of org.apache.jackrabbit.data.core.TransactionContext 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 org.apache.jackrabbit.data.core.TransactionContext 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 org.apache.jackrabbit.data.core.TransactionContext in project jackrabbit by apache.
the class XASessionImpl method createTransaction.
/**
* Create a new transaction context.
* @param xid xid of global transaction.
* @return transaction context
*/
private TransactionContext createTransaction(Xid xid) {
TransactionContext tx = new TransactionContext(xid, txResources);
txGlobal.put(xid, tx);
return tx;
}
use of org.apache.jackrabbit.data.core.TransactionContext in project jackrabbit by apache.
the class XASessionImpl method prepare.
/**
* {@inheritDoc}
*/
public int prepare(Xid xid) throws XAException {
TransactionContext tx = txGlobal.get(xid);
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
tx.prepare();
return XA_OK;
}
Aggregations