33import com .codingapi .tx .client .bean .DTXLocal ;
44import com .codingapi .tx .client .bean .TxTransactionInfo ;
55import com .codingapi .tx .client .spi .transaction .txc .resource .def .TxcService ;
6+ import com .codingapi .tx .client .support .message .TxMangerReporter ;
67import com .codingapi .tx .client .support .separate .TXLCNTransactionControl ;
78import com .codingapi .tx .client .support .common .template .TransactionCleanTemplate ;
89import com .codingapi .tx .client .support .common .template .TransactionControlTemplate ;
910import com .codingapi .tx .client .spi .transaction .txc .resource .def .bean .RollbackInfo ;
1011import com .codingapi .tx .commons .exception .TransactionClearException ;
1112import com .codingapi .tx .commons .exception .TxClientException ;
1213import com .codingapi .tx .commons .exception .TxcLogicException ;
14+ import com .codingapi .tx .logger .TxLogger ;
1315import lombok .extern .slf4j .Slf4j ;
1416import org .springframework .beans .factory .annotation .Autowired ;
1517import org .springframework .stereotype .Component ;
@@ -30,6 +32,11 @@ public class TxcRunningTransaction implements TXLCNTransactionControl {
3032
3133 private final TransactionControlTemplate transactionControlTemplate ;
3234
35+ @ Autowired
36+ private TxMangerReporter txMangerReporter ;
37+
38+ @ Autowired
39+ private TxLogger txLogger ;
3340
3441 @ Autowired
3542 public TxcRunningTransaction (TxcService txcService ,
@@ -71,7 +78,15 @@ public void onBusinessCodeSuccess(TxTransactionInfo info, Object result) throws
7178 txcService .writeUndoLog (
7279 info .getGroupId (), info .getUnitId (), (RollbackInfo ) DTXLocal .cur ().getAttachment ());
7380 } catch (TxcLogicException e ) {
74- throw new TxClientException (e );
81+ //执行回滚处理。(启用备用连接池的方式)
82+ try {
83+ RollbackInfo rollbackInfo = (RollbackInfo ) DTXLocal .cur ().getAttachment ();
84+ txLogger .trace (info .getGroupId (), info .getUnitId (), "txc" , "exception rollbackInfo sql " + rollbackInfo .toString ());
85+ txcService .undoRollbackInfo (rollbackInfo );
86+ } catch (TxcLogicException e1 ) {
87+ txMangerReporter .reportTxcRollbackException (info .getGroupId (), info .getUnitId ());
88+ }
89+ throw new TxClientException ("txc rollback fail." );
7590 }
7691 // 加入事务组
7792 transactionControlTemplate .joinGroup (info .getGroupId (), info .getUnitId (), info .getTransactionType (),
0 commit comments