@@ -40,58 +40,54 @@ boolean hasActions() {
4040 void afterTransactionCompletion (boolean success ) {
4141 AfterCompletionCallback process ;
4242 while ( (process = processes .poll ()) != null ) {
43- try {
44- process .doAfterTransactionCompletion ( success , session );
45- }
46- catch (CacheException ce ) {
47- CORE_LOGGER .unableToReleaseCacheLock ( ce );
48- // continue loop
49- }
50- catch (Exception e ) {
51- throw new HibernateException (
52- "Unable to perform afterTransactionCompletion callback: " + e .getMessage (), e );
53- }
43+ callAfterCompletion ( success , process );
5444 }
45+ invalidateCaches ();
46+ }
5547
56- final var factory = session .getFactory ();
57- if ( factory .getSessionFactoryOptions ().isQueryCacheEnabled () ) {
58- factory .getCache ().getTimestampsCache ()
59- .invalidate ( querySpacesToInvalidate .toArray ( EMPTY_STRING_ARRAY ), session );
48+ void executePendingBulkOperationCleanUpActions () {
49+ if ( performBulkOperationCallbacks () ) {
50+ invalidateCaches ();
6051 }
61- querySpacesToInvalidate .clear ();
6252 }
6353
64- void executePendingBulkOperationCleanUpActions () {
54+ private boolean performBulkOperationCallbacks () {
6555 boolean hasPendingBulkOperationCleanUpActions = false ;
6656 var iterator = processes .iterator ();
6757 while ( iterator .hasNext () ) {
6858 var process = iterator .next ();
6959 if ( process instanceof BulkOperationCleanUpAfterTransactionCompletionProcess ) {
70- try {
71- hasPendingBulkOperationCleanUpActions = true ;
72- process .doAfterTransactionCompletion ( true , session );
60+ hasPendingBulkOperationCleanUpActions = true ;
61+ if ( callAfterCompletion ( true , process ) ) {
7362 iterator .remove ();
7463 }
75- catch (CacheException ce ) {
76- CORE_LOGGER .unableToReleaseCacheLock ( ce );
77- // continue loop
78- }
79- catch (Exception e ) {
80- throw new HibernateException (
81- "Unable to perform afterTransactionCompletion callback: " + e .getMessage (),
82- e
83- );
84- }
8564 }
8665 }
66+ return hasPendingBulkOperationCleanUpActions ;
67+ }
8768
88- if ( hasPendingBulkOperationCleanUpActions ) {
89- final var factory = session .getFactory ();
90- if ( factory .getSessionFactoryOptions ().isQueryCacheEnabled () ) {
91- factory .getCache ().getTimestampsCache ().
92- invalidate ( querySpacesToInvalidate .toArray ( EMPTY_STRING_ARRAY ), session );
93- }
94- querySpacesToInvalidate .clear ();
69+ private boolean callAfterCompletion (boolean success , AfterCompletionCallback process ) {
70+ try {
71+ process .doAfterTransactionCompletion ( success , session );
72+ return true ;
73+ }
74+ catch (CacheException ce ) {
75+ CORE_LOGGER .unableToReleaseCacheLock ( ce );
76+ // continue loop
77+ return false ;
78+ }
79+ catch (Exception e ) {
80+ throw new HibernateException (
81+ "Unable to perform afterTransactionCompletion callback: " + e .getMessage (), e );
82+ }
83+ }
84+
85+ private void invalidateCaches () {
86+ final var factory = session .getFactory ();
87+ if ( factory .getSessionFactoryOptions ().isQueryCacheEnabled () ) {
88+ factory .getCache ().getTimestampsCache ().
89+ invalidate ( querySpacesToInvalidate .toArray ( EMPTY_STRING_ARRAY ), session );
9590 }
91+ querySpacesToInvalidate .clear ();
9692 }
9793}
0 commit comments