-
- // clean IDs
- this.xid = null;
- userDirectory.clearEditingTransactionXid();
-
- try {
- // FIXME Make it less bitronix dependant
- EhCacheXAResourceProducer.unregisterXAResource(cacheName, this);
- } catch (Exception e) {
- log.error("Cannot unregister resource from Bitronix", e);
- }
- }
-
- @Override
- public int prepare(Xid xid) throws XAException {
- checkXid(xid);
- if (noModifications())
- return XA_RDONLY;
- try {
- userDirectory.prepare(this);
- } catch (Exception e) {
- log.error("Cannot prepare " + xid, e);
- throw new XAException(XAException.XA_RBOTHER);
- }
- return XA_OK;
- }
-
- @Override
- public void commit(Xid xid, boolean onePhase) throws XAException {
- try {
- checkXid(xid);
- if (noModifications())
- return;
- if (onePhase)
- userDirectory.prepare(this);
- userDirectory.commit(this);
- } catch (Exception e) {
- log.error("Cannot commit " + xid, e);
- throw new XAException(XAException.XA_RBOTHER);
- } finally {
- cleanUp();
- }
- }
-
- @Override
- public void rollback(Xid xid) throws XAException {
- try {
- checkXid(xid);
- userDirectory.rollback(this);
- } catch (Exception e) {
- log.error("Cannot rollback " + xid, e);
- throw new XAException(XAException.XA_HEURMIX);
- } finally {
- cleanUp();
- }
- }
-
- @Override
- public void forget(Xid xid) throws XAException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isSameRM(XAResource xares) throws XAException {
- return xares == this;
- }
-
- @Override
- public Xid[] recover(int flag) throws XAException {
- return new Xid[0];
- }
-
- @Override
- public int getTransactionTimeout() throws XAException {
- return transactionTimeout;
- }
-
- @Override
- public boolean setTransactionTimeout(int seconds) throws XAException {
- transactionTimeout = seconds;
- return true;
- }
-
- Xid getXid() {
- return xid;
- }
-
- private void checkXid(Xid xid) throws XAException {
- if (this.xid == null)
- throw new XAException(XAException.XAER_OUTSIDE);
- if (!this.xid.equals(xid))
- throw new XAException(XAException.XAER_NOTA);