public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { connection.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (SQLException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }
public BitronixXAException(String message, int errorCode, Throwable t) { super(message); this.errorCode = errorCode; initCause(t); }
private boolean delistResource(XAResourceHolderState resourceHolderState, int flag) throws BitronixSystemException { try { return resourceManager.delist(resourceHolderState, flag); } catch (XAException ex) { // if the resource could not be delisted, the transaction must not commit -> mark it as rollback only if (status != Status.STATUS_MARKED_ROLLBACK) setStatus(Status.STATUS_MARKED_ROLLBACK); String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // The resource unilaterally rolled back here. We have to throw an exception to indicate this but // The signature of this method is inherited from javax.transaction.Transaction. Thereof, we have choice // between creating a sub-exception of SystemException or using a RuntimeException. Is that the best way // forward as this 'hidden' exception can be left throw out at unexpected locations where SystemException // should be rethrown but the exception thrown here should be catched & handled... ? throw new BitronixRollbackSystemException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot delist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } }
private boolean delistResource(XAResourceHolderState resourceHolderState, int flag) throws BitronixSystemException { try { return resourceManager.delist(resourceHolderState, flag); } catch (XAException ex) { // if the resource could not be delisted, the transaction must not commit -> mark it as rollback only if (status != Status.STATUS_MARKED_ROLLBACK) setStatus(Status.STATUS_MARKED_ROLLBACK); String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // The resource unilaterally rolled back here. We have to throw an exception to indicate this but // The signature of this method is inherited from javax.transaction.Transaction. Thereof, we have choice // between creating a sub-exception of SystemException or using a RuntimeException. Is that the best way // forward as this 'hidden' exception can be left throw out at unexpected locations where SystemException // should be rethrown but the exception thrown here should be catched & handled... ? throw new BitronixRollbackSystemException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot delist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } }
public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { connection.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (SQLException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }
private boolean delistResource(XAResourceHolderState resourceHolderState, int flag) throws BitronixSystemException { try { return resourceManager.delist(resourceHolderState, flag); } catch (XAException ex) { // if the resource could not be delisted, the transaction must not commit -> mark it as rollback only if (status != Status.STATUS_MARKED_ROLLBACK) setStatus(Status.STATUS_MARKED_ROLLBACK); String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // The resource unilaterally rolled back here. We have to throw an exception to indicate this but // The signature of this method is inherited from javax.transaction.Transaction. Thereof, we have choice // between creating a sub-exception of SystemException or using a RuntimeException. Is that the best way // forward as this 'hidden' exception can be left throw out at unexpected locations where SystemException // should be rethrown but the exception thrown here should be catched & handled... ? throw new BitronixRollbackSystemException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot delist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } }
public BitronixXAException(String message, int errorCode, Throwable t) { super(message); this.errorCode = errorCode; initCause(t); }
@Override public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) { log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { connection.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (SQLException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }
private boolean delistResource(XAResourceHolderState resourceHolderState, int flag) throws BitronixSystemException { try { return resourceManager.delist(resourceHolderState, flag); } catch (XAException ex) { // if the resource could not be delisted, the transaction must not commit -> mark it as rollback only if (status != Status.STATUS_MARKED_ROLLBACK) setStatus(Status.STATUS_MARKED_ROLLBACK); String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // The resource unilaterally rolled back here. We have to throw an exception to indicate this but // The signature of this method is inherited from javax.transaction.Transaction. Thereof, we have choice // between creating a sub-exception of SystemException or using a RuntimeException. Is that the best way // forward as this 'hidden' exception can be left throw out at unexpected locations where SystemException // should be rethrown but the exception thrown here should be catched & handled... ? throw new BitronixRollbackSystemException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot delist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } }
public BitronixXAException(String message, int errorCode, Throwable t) { super(message); this.errorCode = errorCode; initCause(t); }
@Override public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) { log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { connection.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (SQLException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }
@Override public boolean enlistResource(XAResource xaResource) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction started or finished 2PC, cannot enlist any more resource"); XAResourceHolder resourceHolder = ResourceRegistrar.findXAResourceHolder(xaResource); if (resourceHolder == null) throw new BitronixSystemException("unknown XAResource " + xaResource + ", it does not belong to a registered resource"); XAResourceHolderState resourceHolderState = new XAResourceHolderState(resourceHolder, resourceHolder.getResourceBean()); // resource timeout must be set here so manually enlisted resources can receive it resourceHolderState.setTransactionTimeoutDate(timeoutDate); try { resourceManager.enlist(resourceHolderState); } catch (XAException ex) { String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // if the resource unilaterally rolled back, the transaction will never be able to commit -> mark it as rollback only setStatus(Status.STATUS_MARKED_ROLLBACK); throw new BitronixRollbackException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot enlist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } resourceHolder.putXAResourceHolderState(resourceHolderState.getXid(), resourceHolderState); return true; }
public BitronixXAException(String message, int errorCode, Throwable t) { super(message); this.errorCode = errorCode; initCause(t); }
public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { session.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (JMSException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }
public boolean enlistResource(XAResource xaResource) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction started or finished 2PC, cannot enlist any more resource"); XAResourceHolder resourceHolder = ResourceRegistrar.findXAResourceHolder(xaResource); if (resourceHolder == null) throw new BitronixSystemException("unknown XAResource " + xaResource + ", it does not belong to a registered resource"); XAResourceHolderState resourceHolderState = new XAResourceHolderState(resourceHolder, resourceHolder.getResourceBean()); // resource timeout must be set here so manually enlisted resources can receive it resourceHolderState.setTransactionTimeoutDate(timeoutDate); try { resourceManager.enlist(resourceHolderState); } catch (XAException ex) { String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // if the resource unilaterally rolled back, the transaction will never be able to commit -> mark it as rollback only setStatus(Status.STATUS_MARKED_ROLLBACK); throw new BitronixRollbackException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot enlist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } resourceHolder.putXAResourceHolderState(resourceHolderState.getXid(), resourceHolderState); return true; }
public void rollback(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) log.debug("OK to rollback, old state=" + xlatedState() + ", XID=" + xid); } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot roll it back on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { this.state = NO_TX; throw new BitronixXAException("resource committed during prepare on XID " + this.xid, XAException.XA_HEURCOM); } try { session.rollback(); } catch (JMSException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } finally { this.state = NO_TX; this.xid = null; } }
public boolean enlistResource(XAResource xaResource) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction started or finished 2PC, cannot enlist any more resource"); XAResourceHolder resourceHolder = ResourceRegistrar.findXAResourceHolder(xaResource); if (resourceHolder == null) throw new BitronixSystemException("unknown XAResource " + xaResource + ", it does not belong to a registered resource"); XAResourceHolderState resourceHolderState = new XAResourceHolderState(resourceHolder, resourceHolder.getResourceBean()); // resource timeout must be set here so manually enlisted resources can receive it resourceHolderState.setTransactionTimeoutDate(timeoutDate); try { resourceManager.enlist(resourceHolderState); } catch (XAException ex) { String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // if the resource unilaterally rolled back, the transaction will never be able to commit -> mark it as rollback only setStatus(Status.STATUS_MARKED_ROLLBACK); throw new BitronixRollbackException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot enlist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } resourceHolder.putXAResourceHolderState(resourceHolderState.getXid(), resourceHolderState); return true; }
@Override public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) { log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { session.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (JMSException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }
@Override public boolean enlistResource(XAResource xaResource) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction started or finished 2PC, cannot enlist any more resource"); XAResourceHolder resourceHolder = ResourceRegistrar.findXAResourceHolder(xaResource); if (resourceHolder == null) throw new BitronixSystemException("unknown XAResource " + xaResource + ", it does not belong to a registered resource"); XAResourceHolderState resourceHolderState = new XAResourceHolderState(resourceHolder, resourceHolder.getResourceBean()); // resource timeout must be set here so manually enlisted resources can receive it resourceHolderState.setTransactionTimeoutDate(timeoutDate); try { resourceManager.enlist(resourceHolderState); } catch (XAException ex) { String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex); if (BitronixXAException.isUnilateralRollback(ex)) { // if the resource unilaterally rolled back, the transaction will never be able to commit -> mark it as rollback only setStatus(Status.STATUS_MARKED_ROLLBACK); throw new BitronixRollbackException("resource " + resourceHolderState + " unilaterally rolled back, error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } throw new BitronixSystemException("cannot enlist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex); } resourceHolder.putXAResourceHolderState(resourceHolderState.getXid(), resourceHolderState); return true; }
public int prepare(Xid xid) throws XAException { if (xid == null) throw new BitronixXAException("XID cannot be null", XAException.XAER_INVAL); if (state == NO_TX) { throw new BitronixXAException("resource never started on XID " + xid, XAException.XAER_PROTO); } else if (state == STARTED) { throw new BitronixXAException("resource never ended on XID " + xid, XAException.XAER_PROTO); } else if (state == ENDED) { if (this.xid.equals(xid)) { if (log.isDebugEnabled()) log.debug("OK to prepare, old state=" + xlatedState() + ", XID=" + xid); } else throw new BitronixXAException("resource already started on XID " + this.xid + " - cannot prepare it on another XID " + xid, XAException.XAER_PROTO); } else if (state == PREPARED) { throw new BitronixXAException("resource already prepared on XID " + this.xid, XAException.XAER_PROTO); } try { session.commit(); this.state = PREPARED; return XAResource.XA_OK; } catch (JMSException ex) { throw new BitronixXAException("error preparing non-XA resource", XAException.XAER_RMERR, ex); } }