List of usage examples for javax.transaction.xa XAException XAException
public XAException(int errcode)
From source file:org.eclipse.ecr.core.storage.sql.SessionImpl.java
@Override public void end(Xid xid, int flags) throws XAException { boolean failed = true; try {//from ww w .j a v a 2s . co m if (flags != TMFAIL) { try { flush(); } catch (Exception e) { String msg = "Could not end transaction"; if (e instanceof ConcurrentModificationException) { log.debug(msg, e); } else { log.error(msg, e); } throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } } failed = false; mapper.end(xid, flags); } finally { if (failed) { try { mapper.end(xid, TMFAIL); } finally { rollback(xid); } } } }
From source file:org.eclipse.ecr.core.storage.sql.SessionImpl.java
@Override public void commit(Xid xid, boolean onePhase) throws XAException { try {/*from w ww . j av a 2 s . c o m*/ mapper.commit(xid, onePhase); } finally { inTransaction = false; try { try { sendInvalidationsToOthers(); } finally { checkThreadEnd(); } } catch (Exception e) { log.error("Could not commit transaction", e); throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } } }
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 w w. j a v a 2s .c om * 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.// w w w . ja v a 2s. c om * * @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.enhydra.jdbc.standard.StandardXADataSource.java
/** * Checks the start of the free list to see if the connection * previously associated with the supplied Xid has timed out. * <P>//ww w. ja v a 2 s . c o m * Note that this can be an expensive operation as it has to * scan all free connections. so it should only be called in * the event of an error. */ synchronized private void checkTimeouts(Xid xid) throws XAException { log.debug("StandardXADataSource:checkTimeouts"); for (int i = 0; i < freeConnections.size(); i++) { // check each free connection Object o = freeConnections.elementAt(i); // get next connection StandardXAStatefulConnection cur = (StandardXAStatefulConnection) o; // cast to something more convenient if (!cur.timedOut) { // if it hasn't timed out continue; // skip it } log.debug("StandardXADataSource:checkTimeouts (" + i + "/" + freeConnections.size() + ") xid = " + xid); log.debug("StandardXADataSource:checkTimeouts cur.xid = " + cur.xid); if (xid.equals(cur.xid)) { // if we've found our xid cur.timedOut = false; // cancel time out throw new XAException(XAException.XA_RBTIMEOUT); } } }
From source file:org.enhydra.jdbc.standard.StandardXADataSource.java
/** * Returns the connection associated with a given XID. * is reached, the Xid is found or an exception is thrown. */// w w w . jav a2 s . c o m synchronized StandardXAStatefulConnection getConnection(Xid xid, boolean mustFind) throws XAException { log.debug("StandardXADataSource:getConnection (xid=" + xid + ", mustFind=" + mustFind + ")"); Object o = xidConnections.get(xid); // lookup the connection by XID log.debug("XID: " + o); StandardXAStatefulConnection cur = (StandardXAStatefulConnection) o; // cast to something more convenient if (mustFind) { // if we expected to find the connection if (cur == null) { // and we didn't log.debug("StandardXADataSource:getConnection (StatefulConnection is null)"); checkTimeouts(xid); // see if it's been freed during a timeout throw new XAException(XAException.XAER_NOTA); // not a valid XID } } else { // didn't expect to find the connection if (cur != null) { // but we found it anyway throw new XAException(XAException.XAER_DUPID); // duplicate XID } } log.debug("StandardXADataSource:getConnection return connection associated with a given XID"); return cur; }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * Acts like the {@link org.apache.commons.transaction.file.FileResourceManager#prepareTransaction(Object)} * method does.// ww w. j a v a 2s . c o m * * @param xid the global transaction id * @throws XAException * if a <code>ResourceManagerException</code> is thrown */ public int prepare(Xid xid) throws XAException { // flush data on disk here System.out.println("XAFileResourceManager.prepare(Xid=" + xid + ")"); try { return freMngr.prepareTransaction(curTxId); } catch (ResourceManagerException rme) { throw new XAException(rme.getMessage()); } }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * Method to commit the global transaction with the given <code>xid</code>. * <p/>/*from w w w . jav a 2 s. co m*/ * It also acts like the {@link org.apache.commons.transaction.file.FileResourceManager#commitTransaction(Object)} * does. * * @param xid a global Transaction id * @param onePhase If true, the resource manager should use a one-phase * commit protocol to commit the work done on behalf of xid * @throws XAException * if a <code>ResourceManagerException</code> is thrown */ public void commit(Xid xid, boolean onePhase) throws XAException { System.out.println("XAFileResourceManager.commit(Xid=" + xid + ", onePhase=" + onePhase + ")"); if (!xid.equals(currentXid)) { System.out.println("XAFileResourceManager.commit - wrong Xid!"); } try { if (!recovers) { freMngr.commitTransaction(curTxId); } else { // the initFREM() method will take care of incomplete txs } } catch (ResourceManagerException rme) { throw new XAException(rme.getMessage()); } currentXid = null; }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * Obtain the current transaction timeout value set for this * <code>XAFileResourceManager</code> instance. If * <code>XAFileResourceManager.setTransactionTimeout</code> was not used prior to * invoking this method, the return value is the default timeout set for * the resource manager; otherwise, the value used in the previous * <code>setTransactionTimeout</code> call is returned. * * @return the transaction timeout value in seconds *///from w w w . j a v a 2s .c om public int getTransactionTimeout() throws XAException { try { int timeout = (int) freMngr.getTransactionTimeout(curTxId) / 1000; // ms -> secs System.out.println("XAFileResourceManager.getTransactionTimeout() [returning " + timeout + "]"); return timeout; } catch (ResourceManagerException rme) { throw new XAException(rme.getMessage()); } }
From source file:org.jboss.jbossts.fileio.xalib.txdirs.dir.XAFileResourceManager.java
/** * Rollback any updates attempted to be written to the directory. * <p/>//w w w .ja v a 2 s. c om * The method acts like the * {@link org.apache.commons.transaction.file.FileResourceManager#rollbackTransaction(Object)} * does. * @param xid a global Transaction id * @throws XAException * if a <code>ResourceManagerException</code> is thrown */ public void rollback(Xid xid) throws XAException { System.out.println("XAFileResourceManager.rollback(Xid=" + xid + ")"); try { freMngr.rollbackTransaction(curTxId); } catch (ResourceManagerException rme) { throw new XAException(rme.getMessage()); } currentXid = null; }