List of usage examples for javax.transaction.xa XAException initCause
public synchronized Throwable initCause(Throwable cause)
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); }/*ww w . j ava2 s .co m*/ // 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.XATransaction.java
private void storeCommit(final TransactionId txid, final boolean wasPrepared) throws XAException, IOException { try {/*from w w w. j a va 2s . c o m*/ 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 doPrePrepare() throws XAException, IOException { try {/*from w ww. j a v a 2 s .co m*/ this.prePrepare(); } catch (final XAException e) { throw e; } catch (final Throwable e) { LOG.warn("PRE-PREPARE FAILED: ", e); this.rollback(); final XAException xae = new XAException("PRE-PREPARE FAILED: Transaction rolled back."); xae.errorCode = XAException.XA_RBOTHER; xae.initCause(e); throw xae; } }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
/** * XA//from w w w . ja va 2s . co m * * @param e * @return */ XAException toXAException(final Exception e) { if (e.getCause() != null && e.getCause() instanceof XAException) { final XAException original = (XAException) e.getCause(); final XAException xae = new XAException(original.getMessage()); xae.errorCode = original.errorCode; xae.initCause(original); return xae; } if (e instanceof XAException) { // ((XAException) e).errorCode = XAException.XAER_RMFAIL; return (XAException) e; } final XAException xae = new XAException(e.getMessage()); xae.errorCode = XAException.XAER_RMFAIL; xae.initCause(e); return xae; }
From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java
public void commit(final Xid xid, final boolean onePhase) throws XAException { LOG.trace("commit [" + xid.toString() + "] " + (onePhase ? "one phase" : "two phase")); TransactionState state = xidToTransactionState.remove(xid); if (state == null) { throw new XAException(XAException.XAER_NOTA); }/* w w w .j a v a 2 s . c o m*/ try { if (onePhase) { transactionManager.tryCommit(state); } else { transactionManager.doCommit(state); } } catch (CommitUnsuccessfulException e) { throw new XAException(XAException.XA_RBROLLBACK); } catch (UnsuccessfulDDLException e) { throw new XAException(XAException.XA_RBROLLBACK); } catch (IOException e) { XAException xae = new XAException(XAException.XAER_RMERR); xae.initCause(e); throw xae; } finally { threadLocalTransactionState.remove(); } }
From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java
public void forget(final Xid xid) throws XAException { LOG.trace("forget [" + xid.toString() + "] "); threadLocalTransactionState.remove(); TransactionState state = xidToTransactionState.remove(xid); if (state != null) { try {//from w w w . ja v a 2 s. com transactionManager.abort(state); } catch (Exception e) { XAException xae = new XAException(XAException.XAER_RMERR); xae.initCause(e); throw xae; } } }
From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java
public int prepare(final Xid xid) throws XAException { LOG.trace("prepare [" + xid.toString() + "] "); TransactionState state = xidToTransactionState.get(xid); int status;/*from w w w . ja va 2s. co m*/ try { status = this.transactionManager.prepareCommit(state); } catch (CommitUnsuccessfulException e) { XAException xae = new XAException(XAException.XA_HEURRB); xae.initCause(e); throw xae; } catch (IOException e) { XAException xae = new XAException(XAException.XAER_RMERR); xae.initCause(e); throw xae; } switch (status) { case TransactionalReturn.COMMIT_OK: return XAResource.XA_OK; case TransactionalReturn.COMMIT_OK_READ_ONLY: return XAResource.XA_RDONLY; default: throw new XAException(XAException.XA_RBPROTO); } }
From source file:org.efaps.db.store.VFSStoreResource.java
/** * The method is called from the transaction manager if the complete * transaction is completed.<br/>//from w ww .j av a 2 s.co m * A file in the virtual file system is committed with the algorithms: * <ol> * <li>any existing backup fill will be moved to an older backup file. The * maximum number of backups can be defined by setting the property * {@link #PROPERTY_NUMBER_BACKUP}. Default is one. To disable the * property must be set to 0.</li> * <li>the current file is moved to the backup file (or deleted if property * {@link #PROPERTY_NUMBER_BACKUP} is 0)</li> * <li>the new file is moved to the original name</li> * </ol> * * @param _xid global transaction identifier (not used, because each * file with the file id gets a new VFS store resource * instance) * @param _onePhase <i>true</i> if it is a one phase commitment transaction * (not used) * @throws XAException if any exception occurs (catch on * {@link java.lang.Throwable}) */ @Override public void commit(final Xid _xid, final boolean _onePhase) throws XAException { if (VFSStoreResource.LOG.isDebugEnabled()) { VFSStoreResource.LOG.debug("transaction commit"); } if (getStoreEvent() == VFSStoreResource.StoreEvent.WRITE) { try { final FileObject tmpFile = this.manager.resolveFile(this.manager.getBaseFile(), this.storeFileName + VFSStoreResource.EXTENSION_TEMP); final FileObject currentFile = this.manager.resolveFile(this.manager.getBaseFile(), this.storeFileName + VFSStoreResource.EXTENSION_NORMAL); final FileObject bakFile = this.manager.resolveFile(this.manager.getBaseFile(), this.storeFileName + VFSStoreResource.EXTENSION_BACKUP); if (bakFile.exists() && (this.numberBackup > 0)) { backup(bakFile, 0); } if (currentFile.exists()) { if (this.numberBackup > 0) { currentFile.moveTo(bakFile); } else { currentFile.delete(); } } tmpFile.moveTo(currentFile); tmpFile.close(); currentFile.close(); bakFile.close(); } catch (final FileSystemException e) { VFSStoreResource.LOG .error("transaction commit fails for " + _xid + " (one phase = " + _onePhase + ")", e); final XAException xa = new XAException(XAException.XA_RBCOMMFAIL); xa.initCause(e); throw xa; } } else if (getStoreEvent() == VFSStoreResource.StoreEvent.DELETE) { try { final FileObject curFile = this.manager.resolveFile(this.manager.getBaseFile(), this.storeFileName + VFSStoreResource.EXTENSION_NORMAL); final FileObject bakFile = this.manager.resolveFile(this.manager.getBaseFile(), this.storeFileName + VFSStoreResource.EXTENSION_BACKUP); if (bakFile.exists()) { bakFile.delete(); } if (curFile.exists()) { curFile.moveTo(bakFile); } bakFile.close(); curFile.close(); } catch (final FileSystemException e) { VFSStoreResource.LOG .error("transaction commit fails for " + _xid + " (one phase = " + _onePhase + ")", e); final XAException xa = new XAException(XAException.XA_RBCOMMFAIL); xa.initCause(e); throw xa; } } }
From source file:org.efaps.db.store.VFSStoreResource.java
/** * If the file written in the virtual file system must be rolled back, only * the created temporary file (created from method {@link #write}) is * deleted.//from w w w . jav a2 s . c o m * * @param _xid global transaction identifier (not used, because each * file with the file id gets a new VFS store resource * instance) * @throws XAException if any exception occurs (catch on * {@link java.lang.Throwable}) */ @Override public void rollback(final Xid _xid) throws XAException { if (VFSStoreResource.LOG.isDebugEnabled()) { VFSStoreResource.LOG.debug("rollback (xid = " + _xid + ")"); } try { final FileObject tmpFile = this.manager.resolveFile(this.manager.getBaseFile(), this.storeFileName + VFSStoreResource.EXTENSION_TEMP); if (tmpFile.exists()) { tmpFile.delete(); } } catch (final FileSystemException e) { VFSStoreResource.LOG.error("transaction rollback fails for " + _xid, e); final XAException xa = new XAException(XAException.XA_RBCOMMFAIL); xa.initCause(e); throw xa; } }
From source file:org.nuxeo.ecm.core.blob.storage.impl.XASession.java
public void commit(Xid xid, boolean onePhase) throws XAException { TransactionContext tx = (TransactionContext) transactions.get(xid); if (tx == null) { throw new XAException(XAException.XAER_NOTA); }//from w w w . j a va 2s. com try { if (onePhase) { tx.prepare(); } tx.commit(); } catch (ResourceException e) { XAException ee = new XAException(XAException.XAER_RMERR); ee.initCause(e); throw ee; } transactions.remove(xid); }