"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java" between
spring-framework-5.3.7.tar.gz and spring-framework-5.3.8.tar.gz

About: Spring Framework is an application framework for the Java platform and .NET Framework. Community edition.

R2dbcTransactionManager.java  (spring-framework-5.3.7):R2dbcTransactionManager.java  (spring-framework-5.3.8)
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skipping to change at line 42 skipping to change at line 42
import org.springframework.transaction.TransactionException; import org.springframework.transaction.TransactionException;
import org.springframework.transaction.reactive.AbstractReactiveTransactionManag er; import org.springframework.transaction.reactive.AbstractReactiveTransactionManag er;
import org.springframework.transaction.reactive.GenericReactiveTransaction; import org.springframework.transaction.reactive.GenericReactiveTransaction;
import org.springframework.transaction.reactive.TransactionSynchronizationManage r; import org.springframework.transaction.reactive.TransactionSynchronizationManage r;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* {@link org.springframework.transaction.ReactiveTransactionManager} * {@link org.springframework.transaction.ReactiveTransactionManager}
* implementation for a single R2DBC {@link ConnectionFactory}. This class is * implementation for a single R2DBC {@link ConnectionFactory}. This class is
* capable of working in any environment with any R2DBC driver, as long as the * capable of working in any environment with any R2DBC driver, as long as the
* setup uses a {@link ConnectionFactory} as its {@link Connection} factory * setup uses a {@code ConnectionFactory} as its {@link Connection} factory
* mechanism. Binds a R2DBC {@link Connection} from the specified * mechanism. Binds a R2DBC {@code Connection} from the specified
* {@link ConnectionFactory} to the current subscriber context, potentially * {@code ConnectionFactory} to the current subscriber context, potentially
* allowing for one context-bound {@link Connection} per {@link ConnectionFactor * allowing for one context-bound {@code Connection} per {@code ConnectionFactor
y}. y}.
* *
* <p><b>Note: The {@link ConnectionFactory} that this transaction manager * <p><b>Note: The {@code ConnectionFactory} that this transaction manager
* operates on needs to return independent {@link Connection}s.</b> * operates on needs to return independent {@code Connection}s.</b>
* The {@link Connection}s may come from a pool (the typical case), but the * The {@code Connection}s may come from a pool (the typical case), but the
* {@link ConnectionFactory} must not return scoped scoped {@link Connection}s * {@code ConnectionFactory} must not return scoped scoped {@code Connection}s
* or the like. This transaction manager will associate {@link Connection} * or the like. This transaction manager will associate {@code Connection}
* with context-bound transactions itself, according to the specified propagatio n * with context-bound transactions itself, according to the specified propagatio n
* behavior. It assumes that a separate, independent {@link Connection} can * behavior. It assumes that a separate, independent {@code Connection} can
* be obtained even during an ongoing transaction. * be obtained even during an ongoing transaction.
* *
* <p>Application code is required to retrieve the R2DBC Connection via * <p>Application code is required to retrieve the R2DBC Connection via
* {@link ConnectionFactoryUtils#getConnection(ConnectionFactory)} * {@link ConnectionFactoryUtils#getConnection(ConnectionFactory)}
* instead of a standard R2DBC-style {@link ConnectionFactory#create()} call. * instead of a standard R2DBC-style {@link ConnectionFactory#create()} call.
* Spring classes such as {@code DatabaseClient} use this strategy implicitly. * Spring classes such as {@code DatabaseClient} use this strategy implicitly.
* If not used in combination with this transaction manager, the * If not used in combination with this transaction manager, the
* {@link ConnectionFactoryUtils} lookup strategy behaves exactly like the * {@link ConnectionFactoryUtils} lookup strategy behaves exactly like the
* native {@link ConnectionFactory} lookup; it can thus be used in a portable fa shion. * native {@code ConnectionFactory} lookup; it can thus be used in a portable fa shion.
* *
* <p>Alternatively, you can allow application code to work with the standard * <p>Alternatively, you can allow application code to work with the standard
* R2DBC lookup pattern {@link ConnectionFactory#create()}, for example for code * R2DBC lookup pattern {@link ConnectionFactory#create()}, for example for code
* that is not aware of Spring at all. In that case, define a * that is not aware of Spring at all. In that case, define a
* {@link TransactionAwareConnectionFactoryProxy} for your target {@link Connect * {@link TransactionAwareConnectionFactoryProxy} for your target {@code Connect
ionFactory}, ionFactory},
* and pass that proxy {@link ConnectionFactory} to your DAOs, which will automa * and pass that proxy {@code ConnectionFactory} to your DAOs, which will automa
tically tically
* participate in Spring-managed transactions when accessing it. * participate in Spring-managed transactions when accessing it.
* *
* <p>This transaction manager triggers flush callbacks on registered transactio n * <p>This transaction manager triggers flush callbacks on registered transactio n
* synchronizations (if synchronization is generally active), assuming resources * synchronizations (if synchronization is generally active), assuming resources
* operating on the underlying R2DBC {@link Connection}. * operating on the underlying R2DBC {@code Connection}.
* *
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
* @see ConnectionFactoryUtils#getConnection(ConnectionFactory) * @see ConnectionFactoryUtils#getConnection(ConnectionFactory)
* @see ConnectionFactoryUtils#releaseConnection * @see ConnectionFactoryUtils#releaseConnection
* @see TransactionAwareConnectionFactoryProxy * @see TransactionAwareConnectionFactoryProxy
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class R2dbcTransactionManager extends AbstractReactiveTransactionManager implements InitializingBean { public class R2dbcTransactionManager extends AbstractReactiveTransactionManager implements InitializingBean {
@Nullable @Nullable
private ConnectionFactory connectionFactory; private ConnectionFactory connectionFactory;
private boolean enforceReadOnly = false; private boolean enforceReadOnly = false;
/** /**
* Create a new @link ConnectionFactoryTransactionManager} instance. * Create a new {@code R2dbcTransactionManager} instance.
* A ConnectionFactory has to be set to be able to use it. * A ConnectionFactory has to be set to be able to use it.
* @see #setConnectionFactory * @see #setConnectionFactory
*/ */
public R2dbcTransactionManager() {} public R2dbcTransactionManager() {}
/** /**
* Create a new {@link R2dbcTransactionManager} instance. * Create a new {@code R2dbcTransactionManager} instance.
* @param connectionFactory the R2DBC ConnectionFactory to manage transac tions for * @param connectionFactory the R2DBC ConnectionFactory to manage transac tions for
*/ */
public R2dbcTransactionManager(ConnectionFactory connectionFactory) { public R2dbcTransactionManager(ConnectionFactory connectionFactory) {
this(); this();
setConnectionFactory(connectionFactory); setConnectionFactory(connectionFactory);
afterPropertiesSet(); afterPropertiesSet();
} }
/** /**
* Set the R2DBC {@link ConnectionFactory} that this instance should mana ge transactions for. * Set the R2DBC {@link ConnectionFactory} that this instance should mana ge transactions for.
* <p>This will typically be a locally defined {@link ConnectionFactory}, * <p>This will typically be a locally defined {@code ConnectionFactory},
for example an connection pool. for example an connection pool.
* <p><b>The {@link ConnectionFactory} passed in here needs to return ind * <p><b>The {@code ConnectionFactory} passed in here needs to return ind
ependent {@link Connection}s.</b> ependent {@link Connection}s.</b>
* The {@link Connection}s may come from a pool (the typical case), but t * The {@code Connection}s may come from a pool (the typical case), but t
he {@link ConnectionFactory} he {@code ConnectionFactory}
* must not return scoped {@link Connection}s or the like. * must not return scoped {@code Connection}s or the like.
* @see TransactionAwareConnectionFactoryProxy * @see TransactionAwareConnectionFactoryProxy
*/ */
public void setConnectionFactory(@Nullable ConnectionFactory connectionFa ctory) { public void setConnectionFactory(@Nullable ConnectionFactory connectionFa ctory) {
this.connectionFactory = connectionFactory; this.connectionFactory = connectionFactory;
} }
/** /**
* Return the R2DBC {@link ConnectionFactory} that this instance manages transactions for. * Return the R2DBC {@link ConnectionFactory} that this instance manages transactions for.
*/ */
@Nullable @Nullable
public ConnectionFactory getConnectionFactory() { public ConnectionFactory getConnectionFactory() {
return this.connectionFactory; return this.connectionFactory;
} }
/** /**
* Obtain the {@link ConnectionFactory} for actual use. * Obtain the {@link ConnectionFactory} for actual use.
* @return the {@link ConnectionFactory} (never {@code null}) * @return the {@code ConnectionFactory} (never {@code null})
* @throws IllegalStateException in case of no ConnectionFactory set * @throws IllegalStateException in case of no ConnectionFactory set
*/ */
protected ConnectionFactory obtainConnectionFactory() { protected ConnectionFactory obtainConnectionFactory() {
ConnectionFactory connectionFactory = getConnectionFactory(); ConnectionFactory connectionFactory = getConnectionFactory();
Assert.state(connectionFactory != null, "No ConnectionFactory set "); Assert.state(connectionFactory != null, "No ConnectionFactory set ");
return connectionFactory; return connectionFactory;
} }
/** /**
* Specify whether to enforce the read-only nature of a transaction (as i ndicated by * Specify whether to enforce the read-only nature of a transaction (as i ndicated by
skipping to change at line 406 skipping to change at line 406
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Switching R2DBC Connection [" + con + "] to manual commit"); logger.debug("Switching R2DBC Connection [" + con + "] to manual commit");
} }
prepare = prepare.then(Mono.from(con.setAutoCommit(false) )); prepare = prepare.then(Mono.from(con.setAutoCommit(false) ));
} }
return prepare; return prepare;
} }
/** /**
* Resolve the {@link TransactionDefinition#getIsolationLevel() isolation level constant} to a R2DBC * Resolve the {@linkplain TransactionDefinition#getIsolationLevel() isol ation level constant} to a R2DBC
* {@link IsolationLevel}. If you'd like to extend isolation level transl ation for vendor-specific * {@link IsolationLevel}. If you'd like to extend isolation level transl ation for vendor-specific
* {@link IsolationLevel}s, override this method accordingly. * {@code IsolationLevel}s, override this method accordingly.
* @param isolationLevel the isolation level to translate. * @param isolationLevel the isolation level to translate.
* @return the resolved isolation level. Can be {@code null} if not resol vable or the isolation level * @return the resolved isolation level. Can be {@code null} if not resol vable or the isolation level
* should remain {@link TransactionDefinition#ISOLATION_DEFAULT default}. * should remain {@link TransactionDefinition#ISOLATION_DEFAULT default}.
* @see TransactionDefinition#getIsolationLevel() * @see TransactionDefinition#getIsolationLevel()
*/ */
@Nullable @Nullable
protected IsolationLevel resolveIsolationLevel(int isolationLevel) { protected IsolationLevel resolveIsolationLevel(int isolationLevel) {
switch (isolationLevel) { switch (isolationLevel) {
case TransactionDefinition.ISOLATION_READ_COMMITTED: case TransactionDefinition.ISOLATION_READ_COMMITTED:
return IsolationLevel.READ_COMMITTED; return IsolationLevel.READ_COMMITTED;
 End of changes. 13 change blocks. 
30 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)