List of usage examples for javax.transaction.xa XAException XAER_NOTA
int XAER_NOTA
To view the source code for javax.transaction.xa XAException XAER_NOTA.
Click Source Link
From source file:org.apache.slide.store.txfile.TxXMLFileDescriptorsStore.java
public synchronized void start(Xid xid, int flags) throws XAException { Object txId = wrap(xid);//from w w w .ja v a 2s.c o m Thread currentThread = Thread.currentThread(); getLogger().log("Thread " + currentThread + (flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" : " resumes") + " work on behalf of transaction branch " + txId, LOG_CHANNEL, DEBUG_LEVEL); switch (flags) { // a new transaction case TMNOFLAGS: if (getActiveTxId() != null) { throw new XAException(XAException.XAER_INVAL); } try { rm.startTransaction(txId); TxContext txContext = new TxContext(txId); activeTransactionBranch.set(txContext); activeContexts.put(txId, txContext); } catch (ResourceManagerException e) { throw createXAException(e); } break; case TMJOIN: if (getActiveTxId() != null) { throw new XAException(XAException.XAER_INVAL); } try { if (rm.getTransactionState(txId) == STATUS_NO_TRANSACTION) { throw new XAException(XAException.XAER_INVAL); } } catch (ResourceManagerException e) { throw createXAException(e); } TxContext txContext = new TxContext(txId); activeTransactionBranch.set(txContext); activeContexts.put(txId, txContext); break; case TMRESUME: if (getActiveTxId() != null) { throw new XAException(XAException.XAER_INVAL); } txContext = (TxContext) suspendedContexts.remove(txId); if (txContext == null) { throw new XAException(XAException.XAER_NOTA); } activeTransactionBranch.set(txContext); break; } }
From source file:org.bytesoft.bytejta.supports.dubbo.spi.TransactionServiceFilter.java
public Result providerInvokeForJTA(Invoker<?> invoker, Invocation invocation) throws RpcException { TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance(); TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory(); XidFactory xidFactory = beanFactory.getXidFactory(); TransactionRepository transactionRepository = beanFactory.getTransactionRepository(); RemoteCoordinator transactionCoordinator = beanFactory.getTransactionCoordinator(); Class<?>[] parameterTypeArray = invocation.getParameterTypes(); Class<?> parameterType = (parameterTypeArray == null || parameterTypeArray.length == 0) ? null : parameterTypeArray[0];/*www . j av a 2s . c o m*/ if (parameterTypeArray == null || parameterTypeArray.length == 0) { return this.wrapResultForProvider(invoker, invocation, false); } else if (Xid.class.equals(parameterType) == false) { return this.wrapResultForProvider(invoker, invocation, false); } RpcResult result = new RpcResult(); Object[] arguments = invocation.getArguments(); Xid xid = (Xid) arguments[0]; TransactionXid globalXid = xidFactory.createGlobalXid(xid.getGlobalTransactionId()); Transaction transaction = transactionRepository.getTransaction(globalXid); if (transaction == null) { InvocationResult wrapped = new InvocationResult(); wrapped.setError(new XAException(XAException.XAER_NOTA)); wrapped.setVariable(TransactionCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); } else { TransactionContext transactionContext = transaction.getTransactionContext(); String propagatedBy = String.valueOf(transactionContext.getPropagatedBy()); String remoteAddr = invocation.getAttachment(TransactionCoordinator.class.getName()); if (StringUtils.equals(propagatedBy, remoteAddr)) { return this.wrapResultForProvider(invoker, invocation, false); } InvocationResult wrapped = new InvocationResult(); wrapped.setError(new XAException(XAException.XAER_PROTO)); wrapped.setVariable(TransactionCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); logger.warn("{}| branch should be invoked by its own coordinator.", globalXid); } return result; }
From source file:org.bytesoft.bytejta.supports.jdbc.RecoveredResource.java
public void recoverable(Xid xid) throws XAException { byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); String identifier = this.getIdentifier(globalTransactionId, branchQualifier); Connection conn = null;//from w w w . j a v a 2 s . co m PreparedStatement stmt = null; ResultSet rs = null; try { conn = this.dataSource.getConnection(); stmt = conn.prepareStatement("select gxid, bxid from bytejta where xid = ?"); stmt.setString(1, identifier); rs = stmt.executeQuery(); if (rs.next() == false) { throw new XAException(XAException.XAER_NOTA); } } catch (SQLException ex) { try { this.isTableExists(conn); } catch (SQLException sqlEx) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } catch (RuntimeException rex) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } throw new XAException(XAException.XAER_RMERR); } catch (RuntimeException ex) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMERR); } finally { this.closeQuietly(rs); this.closeQuietly(stmt); this.closeQuietly(conn); } }
From source file:org.bytesoft.bytejta.supports.resource.LocalXAResourceDescriptor.java
public boolean isTransactionCommitted(Xid xid) throws IllegalStateException { try {/*from w ww . j a va 2s . c o m*/ if (RecoveredResource.class.isInstance(this.delegate)) { ((RecoveredResource) this.delegate).recoverable(xid); } else { ((LocalXAResource) this.delegate).recoverable(xid); } return true; } catch (XAException ex) { switch (ex.errorCode) { case XAException.XAER_NOTA: return false; default: throw new IllegalStateException(ex); } } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
private synchronized void fireRemoteParticipantConfirm() throws HeuristicMixedException, HeuristicRollbackException, SystemException { boolean commitExists = false; boolean rollbackExists = false; boolean errorExists = false; for (int i = 0; i < this.resourceList.size(); i++) { XAResourceArchive current = this.resourceList.get(i); if (current.isCommitted()) { commitExists = true;//from www. j a v a 2s. c om continue; } CompensableLogger transactionLogger = this.beanFactory.getCompensableLogger(); XidFactory xidFactory = this.beanFactory.getCompensableXidFactory(); TransactionXid branchXid = (TransactionXid) current.getXid(); TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId()); try { current.commit(globalXid, true); commitExists = true; current.setCommitted(true); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.info("{}| confirm remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); } catch (XAException ex) { switch (ex.errorCode) { case XAException.XAER_NOTA: logger.warn("{}| error occurred while confirming remote branch: {}, transaction is not exists!", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); break; case XAException.XA_HEURCOM: commitExists = true; current.setCommitted(true); current.setHeuristic(false); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.info("{}| confirm remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); break; case XAException.XA_HEURRB: rollbackExists = true; current.setRolledback(true); current.setHeuristic(false); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, ex); break; case XAException.XA_HEURMIX: // should never happen commitExists = true; rollbackExists = true; current.setHeuristic(true); // current.setCommitted(true); // current.setRolledback(true); // current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, ex); break; default: errorExists = false; logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, ex); } } catch (RuntimeException rex) { errorExists = false; logger.error("{}| error occurred while confirming branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, rex); } } if (commitExists && rollbackExists) { throw new HeuristicMixedException(); } else if (rollbackExists) { throw new HeuristicRollbackException(); } else if (errorExists) { throw new SystemException(); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
private synchronized void fireRemoteParticipantCancel() throws SystemException { boolean errorExists = false; for (int i = 0; i < this.resourceList.size(); i++) { XAResourceArchive current = this.resourceList.get(i); if (current.isRolledback()) { continue; }//from w w w . ja va2s. c o m CompensableLogger transactionLogger = this.beanFactory.getCompensableLogger(); XidFactory xidFactory = this.beanFactory.getCompensableXidFactory(); TransactionXid branchXid = (TransactionXid) current.getXid(); TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId()); try { current.rollback(globalXid); current.setRolledback(true); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.info("{}| cancel remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); } catch (XAException ex) { switch (ex.errorCode) { case XAException.XAER_NOTA: logger.warn("{}| error occurred while cancelling remote branch: {}, transaction is not exists!", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); break; default: errorExists = true; logger.error("{}| error occurred while cancelling remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex); } } catch (RuntimeException rex) { errorExists = true; logger.error("{}| error occurred while cancelling remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, rex); } } if (errorExists) { throw new SystemException(); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
private synchronized void fireNativeParticipantRecoveryConfirmForRecoveredTransaction() throws SystemException { boolean errorExists = false; ContainerContext container = this.beanFactory.getContainerContext(); XAResourceDeserializer resourceDeserializer = this.beanFactory.getResourceDeserializer(); CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger(); boolean previouConfirmed = false; for (int i = this.archiveList.size() - 1; i >= 0; i--) { CompensableArchive current = this.archiveList.get(i); boolean currentConfirmed = current.isConfirmed(); if (currentConfirmed) { continue; }//from www. j ava2 s .c o m TransactionXid compensableXid = (TransactionXid) current.getCompensableXid(); try { this.positive = true; this.archive = current; String identifier = current.getCompensableResourceKey(); if (StringUtils.isBlank(identifier)) { if (previouConfirmed) { logger.warn( "There is no valid resource participated in the current branch transaction, the status of the current branch transaction is unknown!"); } else { logger.debug("There is no valid resource participated in the current branch transaction!"); } } else { XAResource xares = resourceDeserializer.deserialize(identifier); if (RecoveredResource.class.isInstance(xares)) { RecoveredResource resource = (RecoveredResource) xares; try { resource.recoverable(compensableXid); current.setConfirmed(true); compensableLogger.updateCompensable(current); continue; } catch (XAException xaex) { switch (xaex.errorCode) { case XAException.XAER_NOTA: break; case XAException.XAER_RMERR: logger.warn( "The database table 'bytejta' cannot found, the status of the current branch transaction is unknown!"); break; case XAException.XAER_RMFAIL: errorExists = true; logger.error( "{}| error occurred while recovering the branch transaction service: {}", ByteUtils.byteArrayToString( this.transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString( current.getIdentifier().getGlobalTransactionId()), xaex); break; default: logger.error( "Illegal state, the status of the current branch transaction is unknown!"); } } } else { logger.error("Illegal resources, the status of the current branch transaction is unknown!"); } } CompensableInvocation invocation = current.getCompensable(); if (invocation == null) { errorExists = true; logger.error( "{}| error occurred while confirming service: {}, please check whether the params of method(compensable-service) supports serialization.", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(current.getIdentifier().getGlobalTransactionId())); } else if (StringUtils.isNotBlank(invocation.getConfirmableKey())) { container.confirm(invocation); } else { current.setConfirmed(true); logger.info("{}| confirm: identifier= {}, resourceKey= {}, resourceXid= {}.", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(current.getIdentifier().getGlobalTransactionId()), current.getCompensableResourceKey(), current.getCompensableXid()); } } catch (RuntimeException rex) { errorExists = true; TransactionXid transactionXid = this.transactionContext.getXid(); logger.error("{}| error occurred while confirming service: {}", ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()), this.archive, rex); } finally { this.archive = null; this.positive = null; previouConfirmed = currentConfirmed; } } if (errorExists) { throw new SystemException(); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
private synchronized void fireRemoteParticipantRecoveryConfirm() throws HeuristicMixedException, HeuristicRollbackException, SystemException { boolean commitExists = false; boolean rollbackExists = false; boolean errorExists = false; for (int i = 0; i < this.resourceList.size(); i++) { XAResourceArchive current = this.resourceList.get(i); if (current.isCommitted()) { commitExists = true;//from ww w. j av a 2 s . co m continue; } CompensableLogger transactionLogger = this.beanFactory.getCompensableLogger(); XidFactory xidFactory = this.beanFactory.getCompensableXidFactory(); TransactionXid branchXid = (TransactionXid) current.getXid(); TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId()); try { current.recoveryCommit(globalXid); commitExists = true; current.setCommitted(true); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.info("{}| recovery-confirm remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); } catch (XAException ex) { switch (ex.errorCode) { case XAException.XAER_NOTA: logger.warn("{}| error occurred while confirming remote branch: {}, transaction is not exists!", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); break; case XAException.XA_HEURCOM: current.setCommitted(true); current.setHeuristic(false); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.info("{}| recovery-confirm remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); break; case XAException.XA_HEURRB: rollbackExists = true; current.setRolledback(true); current.setHeuristic(false); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex); break; case XAException.XA_HEURMIX: commitExists = true; rollbackExists = true; current.setHeuristic(true); // current.setCommitted(true); // current.setRolledback(true); // current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex); break; default: errorExists = false; logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex); } } catch (RuntimeException rex) { errorExists = false; logger.error("{}| error occurred while confirming remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, rex); } } if (commitExists && rollbackExists) { throw new HeuristicMixedException(); } else if (rollbackExists) { throw new HeuristicRollbackException(); } else if (errorExists) { throw new SystemException(); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
private synchronized void fireNativeParticipantRecoveryCancelForRecoveredTransaction() throws SystemException { boolean errorExists = false; ContainerContext container = this.beanFactory.getContainerContext(); XAResourceDeserializer resourceDeserializer = this.beanFactory.getResourceDeserializer(); CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger(); boolean previouCancelled = false; for (int i = this.archiveList.size() - 1; i >= 0; i--) { CompensableArchive current = this.archiveList.get(i); boolean currentCancelled = current.isCancelled(); if (currentCancelled) { continue; }// w w w. ja va 2s . c o m if (current.isTried() == false) /* this.transactionContext.isCoordinator() == false && */ { String identifier = current.getTransactionResourceKey(); if (StringUtils.isBlank(identifier)) { logger.warn( "There is no valid resource participated in the trying branch transaction, the status of the branch transaction is unknown!"); } else { XAResource xares = resourceDeserializer.deserialize(identifier); if (RecoveredResource.class.isInstance(xares)) { RecoveredResource resource = (RecoveredResource) xares; try { resource.recoverable(current.getTransactionXid()); current.setTried(true); compensableLogger.updateCompensable(current); } catch (XAException xaex) { switch (xaex.errorCode) { case XAException.XAER_NOTA: current.setTried(false); continue; case XAException.XAER_RMERR: logger.warn( "The database table 'bytejta' cannot found, the status of the trying branch transaction is unknown!"); break; case XAException.XAER_RMFAIL: errorExists = true; Xid xid = current.getTransactionXid(); logger.error("Error occurred while recovering the branch transaction service: {}", ByteUtils.byteArrayToString(xid.getGlobalTransactionId()), xaex); break; default: logger.error( "Illegal state, the status of the trying branch transaction is unknown!"); } } } else { logger.error("Illegal resources, the status of the trying branch transaction is unknown!"); } } } TransactionXid compensableXid = (TransactionXid) current.getCompensableXid(); try { this.positive = false; this.archive = current; String identifier = current.getCompensableResourceKey(); if (StringUtils.isBlank(identifier)) { if (previouCancelled) { logger.warn( "There is no valid resource participated in the current branch transaction, the status of the current branch transaction is unknown!"); } else { logger.debug("There is no valid resource participated in the current branch transaction!"); } } else { XAResource xares = resourceDeserializer.deserialize(identifier); if (RecoveredResource.class.isInstance(xares)) { RecoveredResource resource = (RecoveredResource) xares; try { resource.recoverable(compensableXid); current.setCancelled(true); compensableLogger.updateCompensable(current); continue; } catch (XAException xaex) { switch (xaex.errorCode) { case XAException.XAER_NOTA: break; case XAException.XAER_RMERR: logger.warn( "The database table 'bytejta' cannot found, the status of the current branch transaction is unknown!"); break; case XAException.XAER_RMFAIL: errorExists = true; logger.error( "{}| error occurred while recovering the branch transaction service: {}", ByteUtils.byteArrayToString( this.transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString( current.getIdentifier().getGlobalTransactionId()), xaex); break; default: logger.error( "Illegal state, the status of the current branch transaction is unknown!"); } } } else { logger.error("Illegal resources, the status of the current branch transaction is unknown!"); } } CompensableInvocation invocation = current.getCompensable(); if (current.isTried() == false) { logger.info( "{}| the operation in try phase is rolled back, so the cancel operation is ignored, compensable service: {}.", ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(current.getIdentifier().getGlobalTransactionId())); } else if (invocation == null) { errorExists = true; logger.error( "{}| error occurred while cancelling service: {}, please check whether the params of method(compensable-service) supports serialization.", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(current.getIdentifier().getGlobalTransactionId())); } else if (StringUtils.isNotBlank(invocation.getCancellableKey())) { container.cancel(invocation); } else { this.archive.setCancelled(true); logger.info("{}| cancel: identifier= {}, resourceKey= {}, resourceXid= {}.", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ByteUtils.byteArrayToString(current.getIdentifier().getGlobalTransactionId()), current.getCompensableResourceKey(), current.getCompensableXid()); } } catch (RuntimeException rex) { errorExists = true; logger.error("{}| error occurred while cancelling service: {}", ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), this.archive, rex); } finally { this.archive = null; this.positive = null; previouCancelled = currentCancelled; } } if (errorExists) { throw new SystemException(); } }
From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java
private synchronized void fireRemoteParticipantRecoveryCancel() throws SystemException { boolean errorExists = false; for (int i = 0; i < this.resourceList.size(); i++) { XAResourceArchive current = this.resourceList.get(i); if (current.isRolledback()) { continue; }// w ww. j av a 2 s . com CompensableLogger transactionLogger = this.beanFactory.getCompensableLogger(); XidFactory xidFactory = this.beanFactory.getCompensableXidFactory(); TransactionXid branchXid = (TransactionXid) current.getXid(); TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId()); try { current.recoveryRollback(globalXid); current.setRolledback(true); current.setCompleted(true); transactionLogger.updateCoordinator(current); logger.info("{}| recovery-cancel remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); } catch (XAException ex) { switch (ex.errorCode) { case XAException.XAER_NOTA: logger.warn( "{}| error occurred while recovery-cancelling remote branch: {}, transaction is not exists!", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current.getDescriptor().getIdentifier()); break; default: errorExists = true; logger.error("{}| error occurred while recovery-cancelling remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex); } } catch (RuntimeException rex) { errorExists = true; logger.error("{}| error occurred while recovery-cancelling remote branch: {}", ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, rex); } } if (errorExists) { throw new SystemException(); } }