2929import io .r2dbc .spi .R2dbcTransientException ;
3030import io .r2dbc .spi .R2dbcTransientResourceException ;
3131import io .r2dbc .spi .Wrapped ;
32- import org .apache .commons .logging .Log ;
33- import org .apache .commons .logging .LogFactory ;
3432import reactor .core .publisher .Mono ;
3533
3634import org .springframework .core .Ordered ;
@@ -69,11 +67,6 @@ public abstract class ConnectionFactoryUtils {
6967 */
7068 public static final int CONNECTION_SYNCHRONIZATION_ORDER = 1000 ;
7169
72- private static final Log logger = LogFactory .getLog (ConnectionFactoryUtils .class );
73-
74-
75- private ConnectionFactoryUtils () {}
76-
7770
7871 /**
7972 * Obtain a {@link Connection} from the given {@link ConnectionFactory}.
@@ -112,48 +105,34 @@ public static Mono<Connection> doGetConnection(ConnectionFactory connectionFacto
112105 if (conHolder != null && (conHolder .hasConnection () || conHolder .isSynchronizedWithTransaction ())) {
113106 conHolder .requested ();
114107 if (!conHolder .hasConnection ()) {
115-
116- if (logger .isDebugEnabled ()) {
117- logger .debug ("Fetching resumed R2DBC Connection from ConnectionFactory" );
118- }
119108 return fetchConnection (connectionFactory ).doOnNext (conHolder ::setConnection );
120109 }
121110 return Mono .just (conHolder .getConnection ());
122111 }
123112 // Else we either got no holder or an empty thread-bound holder here.
124113
125- if (logger .isDebugEnabled ()) {
126- logger .debug ("Fetching R2DBC Connection from ConnectionFactory" );
127- }
128-
129114 Mono <Connection > con = fetchConnection (connectionFactory );
130-
131115 if (synchronizationManager .isSynchronizationActive ()) {
132-
133- return con .flatMap (connection -> {
134- return Mono .just (connection ).doOnNext (conn -> {
135-
136- // Use same Connection for further R2DBC actions within the transaction.
137- // Thread-bound object will get removed by synchronization at transaction completion.
138- ConnectionHolder holderToUse = conHolder ;
139- if (holderToUse == null ) {
140- holderToUse = new ConnectionHolder (conn );
141- }
142- else {
143- holderToUse .setConnection (conn );
144- }
145- holderToUse .requested ();
146- synchronizationManager
147- .registerSynchronization (new ConnectionSynchronization (holderToUse , connectionFactory ));
148- holderToUse .setSynchronizedWithTransaction (true );
149- if (holderToUse != conHolder ) {
150- synchronizationManager .bindResource (connectionFactory , holderToUse );
151- }
152- }) // Unexpected exception from external delegation call -> close Connection and rethrow.
153- .onErrorResume (e -> releaseConnection (connection , connectionFactory ).then (Mono .error (e )));
154- });
116+ return con .flatMap (connection -> Mono .just (connection ).doOnNext (conn -> {
117+ // Use same Connection for further R2DBC actions within the transaction.
118+ // Thread-bound object will get removed by synchronization at transaction completion.
119+ ConnectionHolder holderToUse = conHolder ;
120+ if (holderToUse == null ) {
121+ holderToUse = new ConnectionHolder (conn );
122+ }
123+ else {
124+ holderToUse .setConnection (conn );
125+ }
126+ holderToUse .requested ();
127+ synchronizationManager
128+ .registerSynchronization (new ConnectionSynchronization (holderToUse , connectionFactory ));
129+ holderToUse .setSynchronizedWithTransaction (true );
130+ if (holderToUse != conHolder ) {
131+ synchronizationManager .bindResource (connectionFactory , holderToUse );
132+ }
133+ }) // Unexpected exception from external delegation call -> close Connection and rethrow.
134+ .onErrorResume (e -> releaseConnection (connection , connectionFactory ).then (Mono .error (e ))));
155135 }
156-
157136 return con ;
158137 }).onErrorResume (NoTransactionException .class , e -> Mono .from (connectionFactory .create ()));
159138 }
@@ -356,9 +335,7 @@ public int getOrder() {
356335 @ Override
357336 public Mono <Void > suspend () {
358337 if (this .holderActive ) {
359- return TransactionSynchronizationManager .forCurrentTransaction ()
360- .flatMap (synchronizationManager -> {
361-
338+ return TransactionSynchronizationManager .forCurrentTransaction ().flatMap (synchronizationManager -> {
362339 synchronizationManager .unbindResource (this .connectionFactory );
363340 if (this .connectionHolder .hasConnection () && !this .connectionHolder .isOpen ()) {
364341 // Release Connection on suspend if the application doesn't keep
@@ -371,7 +348,6 @@ public Mono<Void> suspend() {
371348 return Mono .empty ();
372349 });
373350 }
374-
375351 return Mono .empty ();
376352 }
377353
@@ -388,11 +364,10 @@ public Mono<Void> resume() {
388364
389365 @ Override
390366 public Mono <Void > beforeCompletion () {
391- // Release Connection early if the holder is not open anymore
392- // (that is, not used by another resource
393- // that has its own cleanup via transaction synchronization),
394- // to avoid issues with strict transaction implementations that expect
395- // the close call before transaction completion.
367+ // Release Connection early if the holder is not open anymore (that is,
368+ // not used by another resource that has its own cleanup via transaction
369+ // synchronization), to avoid issues with strict transaction implementations
370+ // that expect the close call before transaction completion.
396371 if (!this .connectionHolder .isOpen ()) {
397372 return TransactionSynchronizationManager .forCurrentTransaction ().flatMap (synchronizationManager -> {
398373 synchronizationManager .unbindResource (this .connectionFactory );
@@ -414,8 +389,7 @@ public Mono<Void> afterCompletion(int status) {
414389 if (this .holderActive ) {
415390 // The bound ConnectionHolder might not be available anymore,
416391 // since afterCompletion might get called from a different thread.
417- return TransactionSynchronizationManager .forCurrentTransaction ()
418- .flatMap (synchronizationManager -> {
392+ return TransactionSynchronizationManager .forCurrentTransaction ().flatMap (synchronizationManager -> {
419393 synchronizationManager .unbindResourceIfPossible (this .connectionFactory );
420394 this .holderActive = false ;
421395 if (this .connectionHolder .hasConnection ()) {
@@ -426,7 +400,6 @@ public Mono<Void> afterCompletion(int status) {
426400 return Mono .empty ();
427401 });
428402 }
429-
430403 this .connectionHolder .reset ();
431404 return Mono .empty ();
432405 }
0 commit comments