List of usage examples for javax.transaction.xa XAException XAException
public XAException(int errcode)
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 .j av a2 s .co m*/ } 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 invoke(Object proxy, Method method, Object[] args) throws Throwable { Class<?> clazz = method.getDeclaringClass(); String methodName = method.getName(); if (Object.class.equals(clazz)) { return method.invoke(this, args); } else if (RemoteCoordinator.class.equals(clazz)) { if ("getIdentifier".equals(methodName)) { return this.identifier; } else if ("getApplication".equals(methodName)) { int firstIndex = this.identifier.indexOf(":"); int lastIndex = this.identifier.lastIndexOf(":"); return firstIndex <= 0 || lastIndex <= 0 || firstIndex > lastIndex // ? null//from w ww . j a v a2 s .c o m : this.identifier.subSequence(firstIndex + 1, lastIndex); } else { throw new XAException(XAException.XAER_RMFAIL); } } else if (XAResource.class.equals(clazz)) { if ("prepare".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("commit".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("rollback".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("recover".equals(methodName)) { return this.invokeGetCoordinator(proxy, method, args); } else if ("forget".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else { throw new XAException(XAException.XAER_RMFAIL); } } else { throw new IllegalAccessException(); } }
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 {/* www . 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); } }
From source file:org.bytesoft.bytejta.supports.springcloud.SpringCloudCoordinator.java
public Object invokeGetCoordinator(Object proxy, Method method, Object[] args) throws Throwable { Class<?> returnType = method.getReturnType(); try {//w ww .j a va2s.c om 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.getForEntity(ber.toString(), 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); } }
From source file:org.bytesoft.bytetcc.supports.springcloud.SpringCloudCoordinator.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Class<?> clazz = method.getDeclaringClass(); String methodName = method.getName(); if (Object.class.equals(clazz)) { return method.invoke(this, args); } else if (RemoteCoordinator.class.equals(clazz)) { if ("getIdentifier".equals(methodName)) { return this.identifier; } else if ("recoveryCommit".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("recoveryRollback".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("recoveryForget".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else {/*from w ww . ja va 2 s . c o m*/ throw new XAException(XAException.XAER_RMFAIL); } } else if (XAResource.class.equals(clazz)) { if ("prepare".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("commit".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("rollback".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else if ("recover".equals(methodName)) { return this.invokeGetCoordinator(proxy, method, args); } else if ("forget".equals(methodName)) { return this.invokePostCoordinator(proxy, method, args); } else { throw new XAException(XAException.XAER_RMFAIL); } } else { throw new IllegalAccessException(); } }
From source file:org.bytesoft.bytetcc.supports.springcloud.SpringCloudCoordinator.java
public Object invokePostCoordinator(Object proxy, Method method, Object[] args) throws Throwable { Class<?> returnType = method.getReturnType(); try {/*from www. j av a 2s .c o m*/ 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); String instanceId = prefix == null || suffix == null ? null : prefix + ":" + suffix; StringBuilder ber = new StringBuilder(); ber.append("http://"); ber.append(instanceId); ber.append("/org/bytesoft/bytetcc/"); 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 = new 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 = errorText == null || errorText.matches("\\d+") == false ? null : Integer.parseInt(errorText); 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); } }
From source file:org.bytesoft.bytetcc.supports.springcloud.SpringCloudCoordinator.java
public Object invokeGetCoordinator(Object proxy, Method method, Object[] args) throws Throwable { Class<?> returnType = method.getReturnType(); try {/*from w w w . j a v a 2 s . c o m*/ StringBuilder ber = new StringBuilder(); ber.append("http://"); ber.append(this.identifier); ber.append("/org/bytesoft/bytetcc/"); 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 = new RestTemplate().getForEntity(ber.toString(), returnType, new Object[0]); return response.getBody(); } catch (HttpClientErrorException ex) { throw new XAException(XAException.XAER_RMFAIL); } catch (HttpServerErrorException ex) { 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 = errorText == null || errorText.matches("\\d+") == false ? null : Integer.parseInt(errorText); 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); } }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.JDBCMapper.java
@Override public void start(Xid xid, int flags) throws XAException { try {/*from w w w. j av a 2s .co m*/ checkConnectionValid(); xaresource.start(xid, flags); if (log.isDebugEnabled()) { log.debug("XA start on " + xid.getFormatId()); } } catch (StorageException e) { throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } catch (XAException e) { checkConnectionReset(e); log.error("XA start error on " + xid.getFormatId(), e); throw e; } }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.JDBCMapper.java
@Override public void end(Xid xid, int flags) throws XAException { try {// w ww . jav a 2 s.c o m xaresource.end(xid, flags); if (log.isDebugEnabled()) { log.debug("XA end on " + xid.getFormatId()); } } catch (NullPointerException e) { // H2 when no active transaction log.error("XA end error on " + xid, e); throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } catch (XAException e) { log.error("XA end error on " + xid, e); throw e; } }
From source file:org.eclipse.ecr.core.storage.sql.SessionImpl.java
@Override public void start(Xid xid, int flags) throws XAException { if (flags == TMNOFLAGS) { try {// www. ja va2 s .c o m processReceivedInvalidations(); } catch (Exception e) { log.error("Could not start transaction", e); throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e); } } mapper.start(xid, flags); inTransaction = true; checkThreadStart(); }