List of usage examples for javax.transaction.xa XAException XAException
public XAException(int errcode)
From source file:com.taobao.metamorphosis.server.transaction.LocalTransaction.java
@Override public void commit(final boolean onePhase) throws XAException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("commit: " + this.xid); }/* w w w .j av a2 s.com*/ // Get ready for commit. try { this.prePrepare(); } catch (final XAException e) { throw e; } catch (final Throwable e) { LOG.warn("COMMIT FAILED: ", e); this.rollback(); // Let them know we rolled back. final XAException xae = new XAException("COMMIT FAILED: Transaction rolled back."); xae.errorCode = XAException.XA_RBOTHER; xae.initCause(e); throw xae; } this.setState(Transaction.FINISHED_STATE); this.context.getTransactions().remove(this.xid); try { this.transactionStore.commit(this.getTransactionId(), false); } catch (final Throwable t) { LOG.warn("Store COMMIT FAILED: ", t); this.rollback(); final XAException xae = new XAException("STORE COMMIT FAILED: Transaction rolled back."); xae.errorCode = XAException.XA_RBOTHER; xae.initCause(t); throw xae; } }
From source file:com.taobao.metamorphosis.server.transaction.Transaction.java
public void prePrepare() throws Exception { // Is it ok to call prepare now given the state of the // transaction? switch (this.state) { case START_STATE: case IN_USE_STATE: break;//from ww w. j av a2 s . co m default: final XAException xae = new XAException("Prepare cannot be called now."); xae.errorCode = XAException.XAER_PROTO; throw xae; } }
From source file:com.taobao.metamorphosis.server.transaction.LocalTransaction.java
@Override public int prepare() throws XAException { final XAException xae = new XAException("Prepare not implemented on Local Transactions."); xae.errorCode = XAException.XAER_RMERR; throw xae;/*from w w w . j a va 2 s .c o m*/ }
From source file:com.clican.pluto.transaction.resources.memory.XAFileResourceMemoryImpl.java
public void commit(Xid xid, boolean onePhase) throws XAException { byte[] data = modifiedDataMapping.get(xid); OutputStream os = null;/*from ww w . j av a 2 s. c o m*/ try { if (data == null) { file.deleteOnExit(); } else { os = new FileOutputStream(file); os.write(data); } } catch (Exception e) { rollback(xid); throw new XAException(XAException.XA_HEURRB); } finally { lockedXid = null; if (os != null) { try { os.close(); } catch (Exception e) { log.error("", e); } } } }
From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java
public void delete(File file) throws XAException { if (lockedXid != null && lockedXid != xidThreadLocal.get()) { throw new XAException( "This directory [" + directory + "] has been locked by anthoer thread, you can't write it"); }//from w w w . jav a2s.c o m lockedXid = xidThreadLocal.get(); modifiedDataMapping.get(xidThreadLocal.get()).put(file, null); }
From source file:com.taobao.metamorphosis.server.transaction.XATransaction.java
private void storeCommit(final TransactionId txid, final boolean wasPrepared) throws XAException, IOException { try {/*from www . j av a 2s.c om*/ this.transactionStore.commit(this.getTransactionId(), wasPrepared); } catch (final Throwable t) { LOG.warn("Store COMMIT FAILED: ", t); this.rollback(); final XAException xae = new XAException("STORE COMMIT FAILED: Transaction rolled back."); xae.errorCode = XAException.XA_RBOTHER; xae.initCause(t); throw xae; } }
From source file:com.taobao.metamorphosis.server.transaction.XATransaction.java
private void illegalStateTransition(final String callName) throws XAException { final XAException xae = new XAException("Cannot call " + callName + " now."); xae.errorCode = XAException.XAER_PROTO; throw xae;//from w ww . ja v a2s . co m }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
@Override public void commit(final Xid xid, final boolean onePhase) throws XAException { if (LOG.isDebugEnabled()) { LOG.debug("Commit: " + xid); }/*w w w. j av a2s .c o m*/ XATransactionId x; if (xid == null || this.equals(this.associatedXid, xid)) { throw new XAException(XAException.XAER_PROTO); } else { x = new XATransactionId(xid); } MetaStatLog.addStat(null, StatConstants.TX_COMMIT); this.checkConnectionConnected(); try { // Notify the server that the tx was committed back final TransactionInfo info = new TransactionInfo(x, this.sessionId, onePhase ? TransactionInfo.TransactionType.COMMIT_ONE_PHASE : TransactionInfo.TransactionType.COMMIT_TWO_PHASE); this.syncSendXATxCommand(info); } finally { this.associatedSession.removeContext(this); this.logTxTime(); } }
From source file:com.taobao.metamorphosis.server.transaction.XATransaction.java
private void checkForPreparedState(final boolean onePhase) throws XAException { if (!onePhase) { final XAException xae = new XAException( "Cannot do 2 phase commit if the transaction has not been prepared."); xae.errorCode = XAException.XAER_PROTO; throw xae; }//from ww w . j a v a2s.c om }
From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java
public void commit(Xid xid, boolean onePhase) throws XAException { for (File file : modifiedDataMapping.get(xid).keySet()) { OutputStream os = null;// ww w . j av a 2s . c o m try { byte[] data = modifiedDataMapping.get(xid).get(file); if (data == null) { file.deleteOnExit(); } else { os = new FileOutputStream(file); os.write(modifiedDataMapping.get(xid).get(file)); } } catch (Exception e) { rollback(xid); throw new XAException(XAException.XA_HEURRB); } finally { lockedXid = null; modifiedDataMapping.remove(xid); oldDataMapping.remove(xid); if (os != null) { try { os.close(); } catch (Exception e) { log.error("", e); } } } } }