List of usage examples for javax.transaction.xa XAException XAER_RMERR
int XAER_RMERR
To view the source code for javax.transaction.xa XAException XAER_RMERR.
Click Source Link
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 ww w . j a v a 2s . co m }
From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java
private void throwRMFailException(final BooleanCommand resp) throws XAException { final XAException xaException = new XAException(resp.getErrorMsg()); xaException.errorCode = XAException.XAER_RMERR; throw xaException; }
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); }//from ww w. j a v a2 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 www. j av a2 s . c o m 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;/* ww w . ja va2 s .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.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;//w w w .j av a2s .c o 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.jdbc.RecoveredResource.java
public Xid[] recover(int flags) throws XAException { List<Xid> xidList = new ArrayList<Xid>(); Connection conn = null;/*from w w w. j ava2s . c o m*/ PreparedStatement stmt = null; ResultSet rs = null; try { conn = this.dataSource.getConnection(); stmt = conn.prepareStatement("select gxid, bxid from bytejta"); rs = stmt.executeQuery(); while (rs.next()) { String gxid = rs.getString(1); String bxid = rs.getString(2); byte[] globalTransactionId = ByteUtils.stringToByteArray(gxid); byte[] branchQualifier = ByteUtils.stringToByteArray(bxid); TransactionXid xid = null; if (StringUtils.equals(gxid, bxid)) { xid = new TransactionXid(XidFactory.JTA_FORMAT_ID, globalTransactionId); } else { xid = new TransactionXid(XidFactory.JTA_FORMAT_ID, globalTransactionId, branchQualifier); } xidList.add(xid); } } catch (Exception ex) { boolean tableExists = false; try { tableExists = this.isTableExists(conn); } catch (Exception sqlEx) { logger.warn("Error occurred while recovering local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } if (tableExists) { throw new XAException(XAException.XAER_RMERR); } } finally { this.closeQuietly(rs); this.closeQuietly(stmt); this.closeQuietly(conn); } Xid[] xidArray = new Xid[xidList.size()]; xidList.toArray(xidArray); return xidArray; }
From source file:org.bytesoft.bytejta.supports.jdbc.RecoveredResource.java
public synchronized void forget(Xid[] xids) throws XAException { if (xids == null || xids.length == 0) { return;/*from ww w .j ava2 s.c om*/ } String[] xidArray = new String[xids.length]; for (int i = 0; i < xids.length; i++) { Xid xid = xids[i]; byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); xidArray[i] = this.getIdentifier(globalTransactionId, branchQualifier); } Connection conn = null; PreparedStatement stmt = null; Boolean autoCommit = null; try { conn = this.dataSource.getConnection(); autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); stmt = conn.prepareStatement("delete from bytejta where xid = ?"); for (int i = 0; i < xids.length; i++) { stmt.setString(1, xidArray[i]); stmt.addBatch(); } stmt.executeBatch(); conn.commit(); } catch (Exception ex) { logger.error("Error occurred while forgetting resources."); try { conn.rollback(); } catch (Exception sqlEx) { logger.error("Error occurred while rolling back local resources.", sqlEx); } boolean tableExists = false; try { tableExists = this.isTableExists(conn); } catch (Exception sqlEx) { logger.warn("Error occurred while forgeting local resources.", ex); throw new XAException(XAException.XAER_RMFAIL); } if (tableExists) { throw new XAException(XAException.XAER_RMERR); } } finally { if (autoCommit != null) { try { conn.setAutoCommit(autoCommit); } catch (SQLException sqlEx) { logger.error("Error occurred while configuring attribute 'autoCommit'.", sqlEx); } } this.closeQuietly(stmt); this.closeQuietly(conn); } }
From source file:org.bytesoft.bytejta.supports.jdbc.RecoveredResource.java
public synchronized void forget(Xid xid) throws XAException { if (xid == null) { logger.warn("Error occurred while forgeting local-xa-resource: invalid xid."); return;//w w w. jav a2 s.c om } byte[] globalTransactionId = xid.getGlobalTransactionId(); byte[] branchQualifier = xid.getBranchQualifier(); String identifier = this.getIdentifier(globalTransactionId, branchQualifier); Connection conn = null; PreparedStatement stmt = null; try { conn = this.dataSource.getConnection(); stmt = conn.prepareStatement("delete from bytejta where xid = ?"); stmt.setString(1, identifier); stmt.executeUpdate(); } catch (Exception ex) { boolean tableExists = false; try { tableExists = this.isTableExists(conn); } catch (Exception sqlEx) { logger.warn("Error occurred while forgeting local-xa-resource.", ex); throw new XAException(XAException.XAER_RMFAIL); } if (tableExists) { throw new XAException(XAException.XAER_RMERR); } } finally { this.closeQuietly(stmt); this.closeQuietly(conn); } }
From source file:org.bytesoft.bytejta.supports.springcloud.SpringCloudCoordinator.java
public Object invokePostCoordinator(Object proxy, Method method, Object[] args) throws Throwable { Class<?> returnType = method.getReturnType(); try {/*from w w w . ja v a 2 s .c o m*/ RestTemplate transactionRestTemplate = SpringCloudBeanRegistry.getInstance().getRestTemplate(); RestTemplate restTemplate = transactionRestTemplate == null ? new RestTemplate() : transactionRestTemplate; StringBuilder ber = new StringBuilder(); int firstIndex = this.identifier.indexOf(":"); int lastIndex = this.identifier.lastIndexOf(":"); String prefix = firstIndex <= 0 ? null : this.identifier.substring(0, firstIndex); String suffix = lastIndex <= 0 ? null : this.identifier.substring(lastIndex + 1); ber.append("http://"); ber.append(prefix == null || suffix == null ? null : prefix + ":" + suffix); ber.append("/org/bytesoft/bytejta/"); ber.append(method.getName()); for (int i = 0; i < args.length; i++) { Serializable arg = (Serializable) args[i]; ber.append("/").append(this.serialize(arg)); } ResponseEntity<?> response = restTemplate.postForEntity(ber.toString(), null, returnType, new Object[0]); return response.getBody(); } catch (HttpClientErrorException ex) { throw new XAException(XAException.XAER_RMFAIL); } catch (HttpServerErrorException ex) { // int statusCode = ex.getRawStatusCode(); HttpHeaders headers = ex.getResponseHeaders(); String failureText = StringUtils.trimToNull(headers.getFirst("failure")); String errorText = StringUtils.trimToNull(headers.getFirst("XA_XAER")); Boolean failure = failureText == null ? null : Boolean.parseBoolean(failureText); Integer errorCode = null; try { errorCode = errorText == null ? null : Integer.parseInt(errorText); } catch (Exception ignore) { logger.debug(ignore.getMessage()); } if (failure != null && errorCode != null) { throw new XAException(errorCode); } else { throw new XAException(XAException.XAER_RMERR); } } catch (Exception ex) { throw new XAException(XAException.XAER_RMERR); } }