public static boolean checkConnectionAlreadyUse(Connection conn) throws SQLException { boolean isUsed = false; if (connections.containsValue(new ConnectionMapper(conn))) { isUsed = true; log.debug(" Connection toString : " + conn.toString()); } return isUsed; }
private void endTransaction(NHttpServerConnection conn) { try { Long serverWorkerThreadId = (Long) conn.getContext().getAttribute( PassThroughConstants.SERVER_WORKER_THREAD_ID); if (serverWorkerThreadId != null) { TranscationManger.endTransaction(false, serverWorkerThreadId); } } catch (Exception ex) { log.warn("Transaction rollback error after Connection closed " + ex.getMessage() + conn); } }
private void beginNewTransaction(MessageContext synCtx) { try { TranscationManger.beginTransaction(); org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext(); axis2MsgCtx.setProperty(NhttpConstants.DISTRIBUTED_TRANSACTION, TranscationManger.getTransaction()); axis2MsgCtx.setProperty(NhttpConstants.DISTRIBUTED_TRANSACTION_MANAGER, TranscationManger.getTransactionManager()); } catch (Exception e) { handleException("Unable to begin a new transaction", e, synCtx); } }
try { TranscationManger.lookUp(txContext); } catch (Exception e) { handleException("Cloud not get the context name " + USER_TX_LOOKUP_STR, e, synCtx); TranscationManger.endTransaction(true, key); } catch (Exception e) { handleException("Unable to commit transaction", e, synCtx); TranscationManger.rollbackTransaction(true, key); } catch (Exception e) { handleException("Unable to rollback transaction", e, synCtx); try { status = TranscationManger.getStatus(); } catch (Exception e) { handleException("Unable to query transaction status", e, synCtx); status = TranscationManger.getStatus(); } catch (Exception e) { handleException("Unable to query transaction status", e, synCtx); status = TranscationManger.getStatus(); } catch (Exception e) { handleException("Unable to query transaction status", e, synCtx);
public static void bindConnection(final Connection conn) throws Exception { long key = Thread.currentThread().getId(); try { if (conn instanceof XAConnection) { Transaction tx = transactions.get().get(key); XAResource xaRes = ((XAConnection) conn).getXAResource(); if (!isXAResourceEnlisted(xaRes)) { tx.enlistResource(xaRes); addToEnlistedXADataSources(xaRes, key); log.debug(" DS enlisted in thread " + key + " XA Resource : "+ xaRes.hashCode()); } } } catch (Exception ex) { StringBuilder logMsg = new StringBuilder(); Connection actual = ((javax.sql.PooledConnection)conn).getConnection(); logMsg .append(" Thread Id : "+key) .append(" BIND ERROR , Transaction Manager status : " + txManagers.get().get(key).getStatus()) .append("\n") .append(" BIND ERROR , Transaction status : " + transactions.get().get(key).getStatus()) .append("\n") .append(" JDBC Connection status : " + actual.isClosed()) .append("\n") .append(" BIND ERROR : " + ex); log.error(logMsg.toString()); rollbackTransaction(true,key); throw ex; } }
private void rollbackTransaction(NHttpServerConnection conn) { try { Long serverWorkerThreadId = (Long) conn.getContext().getAttribute( PassThroughConstants.SERVER_WORKER_THREAD_ID); if (serverWorkerThreadId != null) { TranscationManger.rollbackTransaction(false, serverWorkerThreadId); } } catch (Exception ex) { log.warn("Transaction rollback error after Connection closed " + ex.getMessage() + conn); } }
initContext(synCtx); try { TranscationManger.lookUp(txContext); } catch (Exception e) { handleException("Cloud not get the context name " + USER_TX_LOOKUP_STR, e, synCtx); TranscationManger.beginTransaction(); axis2MsgCtx.setProperty(NhttpConstants.DISTRIBUTED_TRANSACTION, TranscationManger.getTransaction()); axis2MsgCtx.setProperty(NhttpConstants.DISTRIBUTED_TRANSACTION_MANAGER,TranscationManger.getTransactionManager()); } catch (Exception e) { handleException("Error starting transaction",synCtx);
public static Connection addConnection(final DataSource ds) throws Exception{ long key = Thread.currentThread().getId(); Connection conn = getConnection(); if(conn != null){ log.debug(" Connection can get from map : "+ key); continue; if(!TranscationManger.checkConnectionAlreadyUse(conn) && !actual.isClosed()){ if(!connections.containsKey(key)){ connections.putIfAbsent(key, new ConnectionMapper(conn)); log.debug(" Connection added to map in attempt : "+ count + " Thread : "+key);
boolean threadInTx = false; try { if(TranscationManger.isThreadHasEnlistment() || useTransaction){ threadInTx = true; try { con = TranscationManger.addConnection(this.getDataSource()); if(useTransaction){ TranscationManger.bindConnection(con);
public static void delistResource(int flag, long key) throws Exception { Map<Long,XAResource> enlistedResources = enlistedXADataSources.get(); XAResource resource = null; try { if (enlistedResources != null && !enlistedResources.isEmpty()) { Transaction tx = transactions.get().get(key); resource = enlistedResources.get(key); if (tx != null && resource != null) { tx.delistResource(resource, flag); } } } catch (Exception ex) { throw new Exception("Error occurred while delisting datasource " + "connection: " + ex.getMessage(), ex); }finally{ removeConnectionUsed(key); removeTransaction(key); enlistedResources.remove(key); } }
boolean threadInTx = false; try { if(TranscationManger.isThreadHasEnlistment()){ threadInTx = true; try { con = TranscationManger.addConnection(this.getDataSource()); }catch (Exception e)
public static void endTransaction(boolean insideSynapse, long key) throws Exception { int xaResourceStatus = XAResource.TMNOFLAGS; try { if(insideSynapse && transactions.get() == null){ log.warn(" END Thread Local null "); return; } if(insideSynapse && transactions.get().get(key) == null){ log.warn(" END Some How TX null "); return; } if (transactions.get().get(key) != null && javax.transaction.Status.STATUS_ACTIVE == transactions .get().get(key).getStatus()) { txManagers.get().get(key).commit(); xaResourceStatus = XAResource.TMSUCCESS; } } catch (Exception ex) { xaResourceStatus = XAResource.TMFAIL; log.error(" END ERROR : " + txManagers.get().get(key).getStatus()); throw ex; }finally{ // delist delistResource(xaResourceStatus, key); } }
public static void rollbackTransaction(boolean insideSynapse, long key) throws Exception { int xaResourceStatus = XAResource.TMFAIL; try { if (log.isDebugEnabled()) { log.debug("rollbackTransaction()"); } if (insideSynapse && transactions.get() == null) { log.warn(" ROLLBACK Thread Local null "); return; } if (insideSynapse && transactions.get().get(key) == null) { log.warn(" ROLLBACK Some How TX null "); return; } if (transactions.get().get(key) != null && javax.transaction.Status.STATUS_ACTIVE == transactions .get().get(key).getStatus()) { txManagers.get().get(key).rollback(); xaResourceStatus = XAResource.TMFAIL; } } catch (Exception ex) { log.error(" ROLLBACK ERROR : " + txManagers.get().get(key).getStatus()); throw ex; }finally{ // delist delistResource(xaResourceStatus,key); } }