@Override protected void doCommit(DefaultTransactionStatus status) { String prefix=""; if(logger.isDebugEnabled()) { prefix += "[" + TransactionId.get().getCurrentId() + "]"; try { Connection connection = ((JdbcTransactionObjectSupport)status.getTransaction()).getConnectionHolder().getConnection(); prefix += "[" + (null != connection ? connection : "") + "]"; } catch (Exception e) {} } logger.debug(prefix+"DataSource doCommit"); //将status持久化到jvm内存 if(null!=TransactionContextFactory.getInstance()&& TransactionSupport.isProxy()){ logger.debug(prefix+"DataSource doCommit before store"); Transaction transaction=TransactionContextFactory.getInstance().persistent(status); if(transaction instanceof DBTransaction){ logger.debug(prefix+"DataSource doCommit in store"); DBTransaction dbT=(DBTransaction)transaction; dbT.setDataSource(getDataSource()); dbT.setIsNewConnectionHolder(checkNewConnectionHolder(status.getTransaction())); } }else{//如果事务容器工厂类初始化失败,执行默认逻辑 logger.debug(prefix+"DataSource doCommit don't store"); super.doCommit(status); super.doCleanupAfterCompletion(status.getTransaction()); } }
public boolean prepare(){ try { if (status.getTransaction() instanceof JdbcTransactionObjectSupport) { JdbcTransactionObjectSupport support = (JdbcTransactionObjectSupport) status.getTransaction(); ConnectionHolder holder = support.getConnectionHolder(); Connection con = holder.getConnection(); return !con.isClosed() && !con.isReadOnly(); } }catch (Exception e){ } return false; }
@Override public boolean commit() throws SQLException { logger.debug("[realDbCommit]"+getTransactionId().getCurrentId()); if(status.getTransaction() instanceof JdbcTransactionObjectSupport){ JdbcTransactionObjectSupport support=(JdbcTransactionObjectSupport)status.getTransaction(); ConnectionHolder holder=support.getConnectionHolder(); Connection con = holder.getConnection(); con.commit(); logger.debug("[realDbCommit]["+getTransactionId().getCurrentId()+"]"+con); } clearConnection(); return true; }
@Override public boolean rollback() throws SQLException { if(status.getTransaction() instanceof JdbcTransactionObjectSupport) { JdbcTransactionObjectSupport support = (JdbcTransactionObjectSupport) status.getTransaction(); ConnectionHolder holder = support.getConnectionHolder(); Connection con = holder.getConnection(); con.rollback(); } clearConnection(); return true; }
@Override public Object getTransactionOpaqueIdentity() { JdbcTransactionObjectSupport txImplementation = (JdbcTransactionObjectSupport) ((DefaultTransactionStatus) getCurrentTransactionStatus()) .getTransaction(); return txImplementation.getConnectionHolder().getConnectionHandle(); }
public Object getTransactionOpaqueIdentity() { JdbcTransactionObjectSupport txImplementation = (JdbcTransactionObjectSupport) ((DefaultTransactionStatus) getCurrentTransactionStatus()) .getTransaction(); return txImplementation.getConnectionHolder().getConnectionHandle(); }