@@ -108,6 +108,7 @@ public static void setTransactionTemplate(TransactionTemplate transactionTemplat
108
108
*/
109
109
@ Override
110
110
public Object prepareFence (String xid , Long branchId , String actionName , Callback <Object > targetCallback ) {
111
+ executeWithHandling (() -> beforePrepareFence (xid , branchId , actionName ), xid , branchId , "beforePrepareFence" );
111
112
return transactionTemplate .execute (status -> {
112
113
try {
113
114
Connection conn = DataSourceUtils .getConnection (dataSource );
@@ -129,10 +130,27 @@ public Object prepareFence(String xid, Long branchId, String actionName, Callbac
129
130
} catch (Throwable t ) {
130
131
status .setRollbackOnly ();
131
132
throw new SkipCallbackWrapperException (t );
133
+ } finally {
134
+ executeWithHandling (() -> afterPrepareFence (xid , branchId , actionName ), xid , branchId ,"afterPrepareFence" );
132
135
}
133
136
});
134
137
}
135
138
139
+ /**
140
+ * This method executes a Runnable with transaction context and logs any exceptions that occur without allowing them to propagate.
141
+ * @param runnable the runnable
142
+ * @param xid the global transaction id
143
+ * @param branchId the branch transaction id
144
+ * @param methodName the runnable name
145
+ */
146
+ private void executeWithHandling (Runnable runnable , String xid , Long branchId , String methodName ) {
147
+ try {
148
+ runnable .run ();
149
+ } catch (Exception e ) {
150
+ LOGGER .warn ("Tcc fence Exception in {}, xid: {}, branchId: {}" , methodName , xid , branchId , e );
151
+ }
152
+ }
153
+
136
154
/**
137
155
* common commit method enhanced
138
156
*
@@ -146,6 +164,7 @@ public Object prepareFence(String xid, Long branchId, String actionName, Callbac
146
164
@ Override
147
165
public boolean commitFence (Method commitMethod , Object targetTCCBean ,
148
166
String xid , Long branchId , Object [] args ) {
167
+ executeWithHandling (() -> beforeCommitFence (xid , branchId ), xid , branchId , "beforeCommitFence" );
149
168
return transactionTemplate .execute (status -> {
150
169
try {
151
170
Connection conn = DataSourceUtils .getConnection (dataSource );
@@ -170,6 +189,8 @@ public boolean commitFence(Method commitMethod, Object targetTCCBean,
170
189
} catch (Throwable t ) {
171
190
status .setRollbackOnly ();
172
191
throw new SkipCallbackWrapperException (t );
192
+ } finally {
193
+ executeWithHandling (() -> afterCommitFence (xid , branchId ), xid , branchId , "afterCommitFence" );
173
194
}
174
195
});
175
196
}
@@ -188,6 +209,7 @@ public boolean commitFence(Method commitMethod, Object targetTCCBean,
188
209
@ Override
189
210
public boolean rollbackFence (Method rollbackMethod , Object targetTCCBean ,
190
211
String xid , Long branchId , Object [] args , String actionName ) {
212
+ executeWithHandling (() -> beforeRollbackFence (xid , branchId , actionName ), xid , branchId ,"beforeRollbackFence" );
191
213
return transactionTemplate .execute (status -> {
192
214
try {
193
215
Connection conn = DataSourceUtils .getConnection (dataSource );
@@ -219,6 +241,8 @@ public boolean rollbackFence(Method rollbackMethod, Object targetTCCBean,
219
241
} catch (Throwable t ) {
220
242
status .setRollbackOnly ();
221
243
throw new SkipCallbackWrapperException (t );
244
+ } finally {
245
+ executeWithHandling (() -> afterRollbackFence (xid , branchId , actionName ), xid , branchId , "afterRollbackFence" );
222
246
}
223
247
});
224
248
}
0 commit comments