Apply "instanceof pattern matching" in spring-tx
Closes gh-30019
This commit is contained in:
parent
00c2c1d2a1
commit
375114defa
|
|
@ -77,11 +77,11 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF
|
|||
* @see #setTransactionTimeout
|
||||
*/
|
||||
public void setTransactionManager(Object transactionManager) {
|
||||
if (transactionManager instanceof TransactionFactory) {
|
||||
this.transactionFactory = (TransactionFactory) transactionManager;
|
||||
if (transactionManager instanceof TransactionFactory factory) {
|
||||
this.transactionFactory = factory;
|
||||
}
|
||||
else if (transactionManager instanceof TransactionManager) {
|
||||
this.transactionFactory = new SimpleTransactionFactory((TransactionManager) transactionManager);
|
||||
else if (transactionManager instanceof TransactionManager manager) {
|
||||
this.transactionFactory = new SimpleTransactionFactory(manager);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Transaction manager [" + transactionManager +
|
||||
|
|
|
|||
|
|
@ -429,8 +429,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
catch (Throwable ex) {
|
||||
if (txAttr.rollbackOn(ex)) {
|
||||
// A RuntimeException: will lead to a rollback.
|
||||
if (ex instanceof RuntimeException) {
|
||||
throw (RuntimeException) ex;
|
||||
if (ex instanceof RuntimeException rex) {
|
||||
throw rex;
|
||||
}
|
||||
else {
|
||||
throw new ThrowableHolderException(ex);
|
||||
|
|
@ -538,8 +538,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
|
||||
String methodIdentification = methodIdentification(method, targetClass);
|
||||
if (methodIdentification == null) {
|
||||
if (txAttr instanceof DefaultTransactionAttribute) {
|
||||
methodIdentification = ((DefaultTransactionAttribute) txAttr).getDescriptor();
|
||||
if (txAttr instanceof DefaultTransactionAttribute dta) {
|
||||
methodIdentification = dta.getDescriptor();
|
||||
}
|
||||
if (methodIdentification == null) {
|
||||
methodIdentification = ClassUtils.getQualifiedMethodName(method, targetClass);
|
||||
|
|
@ -1047,8 +1047,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
if (txInfo.transactionAttribute != null && txInfo.transactionAttribute.rollbackOn(ex)) {
|
||||
return txInfo.getTransactionManager().rollback(txInfo.getReactiveTransaction()).onErrorMap(ex2 -> {
|
||||
logger.error("Application exception overridden by rollback exception", ex);
|
||||
if (ex2 instanceof TransactionSystemException) {
|
||||
((TransactionSystemException) ex2).initApplicationException(ex);
|
||||
if (ex2 instanceof TransactionSystemException systemException) {
|
||||
systemException.initApplicationException(ex);
|
||||
}
|
||||
return ex2;
|
||||
}
|
||||
|
|
@ -1059,8 +1059,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
// Will still roll back if TransactionStatus.isRollbackOnly() is true.
|
||||
return txInfo.getTransactionManager().commit(txInfo.getReactiveTransaction()).onErrorMap(ex2 -> {
|
||||
logger.error("Application exception overridden by commit exception", ex);
|
||||
if (ex2 instanceof TransactionSystemException) {
|
||||
((TransactionSystemException) ex2).initApplicationException(ex);
|
||||
if (ex2 instanceof TransactionSystemException systemException) {
|
||||
systemException.initApplicationException(ex);
|
||||
}
|
||||
return ex2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -547,8 +547,8 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
|||
* @return a corresponding UserTransaction handle
|
||||
*/
|
||||
protected UserTransaction buildUserTransaction(TransactionManager transactionManager) {
|
||||
if (transactionManager instanceof UserTransaction) {
|
||||
return (UserTransaction) transactionManager;
|
||||
if (transactionManager instanceof UserTransaction userTransaction) {
|
||||
return userTransaction;
|
||||
}
|
||||
else {
|
||||
return new UserTransactionAdapter(transactionManager);
|
||||
|
|
@ -702,11 +702,11 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
|||
*/
|
||||
@Nullable
|
||||
protected TransactionManager findTransactionManager(@Nullable UserTransaction ut) {
|
||||
if (ut instanceof TransactionManager) {
|
||||
if (ut instanceof TransactionManager transactionManager) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("JTA UserTransaction object [" + ut + "] implements TransactionManager");
|
||||
}
|
||||
return (TransactionManager) ut;
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
// Check fallback JNDI locations.
|
||||
|
|
@ -762,11 +762,11 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager
|
|||
}
|
||||
}
|
||||
// Check whether the UserTransaction or TransactionManager implements it...
|
||||
if (ut instanceof TransactionSynchronizationRegistry) {
|
||||
return (TransactionSynchronizationRegistry) ut;
|
||||
if (ut instanceof TransactionSynchronizationRegistry tsr) {
|
||||
return tsr;
|
||||
}
|
||||
if (tm instanceof TransactionSynchronizationRegistry) {
|
||||
return (TransactionSynchronizationRegistry) tm;
|
||||
if (tm instanceof TransactionSynchronizationRegistry tsr) {
|
||||
return tsr;
|
||||
}
|
||||
// OK, so no JTA 1.1 TransactionSynchronizationRegistry is available...
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ abstract class TransactionSynchronizationUtils {
|
|||
Assert.notNull(resource, "Resource must not be null");
|
||||
Object resourceRef = resource;
|
||||
// unwrap infrastructure proxy
|
||||
if (resourceRef instanceof InfrastructureProxy) {
|
||||
resourceRef = ((InfrastructureProxy) resourceRef).getWrappedObject();
|
||||
if (resourceRef instanceof InfrastructureProxy infraProxy) {
|
||||
resourceRef = infraProxy.getWrappedObject();
|
||||
}
|
||||
if (aopAvailable) {
|
||||
// now unwrap scoped proxy
|
||||
|
|
@ -125,8 +125,8 @@ abstract class TransactionSynchronizationUtils {
|
|||
private static class ScopedProxyUnwrapper {
|
||||
|
||||
public static Object unwrapIfNecessary(Object resource) {
|
||||
if (resource instanceof ScopedObject) {
|
||||
return ((ScopedObject) resource).getTargetObject();
|
||||
if (resource instanceof ScopedObject so) {
|
||||
return so.getTargetObject();
|
||||
}
|
||||
else {
|
||||
return resource;
|
||||
|
|
|
|||
|
|
@ -118,8 +118,8 @@ final class TransactionalOperatorImpl implements TransactionalOperator {
|
|||
logger.debug("Initiating transaction rollback on application exception", ex);
|
||||
return this.transactionManager.rollback(status).onErrorMap(ex2 -> {
|
||||
logger.error("Application exception overridden by rollback exception", ex);
|
||||
if (ex2 instanceof TransactionSystemException) {
|
||||
((TransactionSystemException) ex2).initApplicationException(ex);
|
||||
if (ex2 instanceof TransactionSystemException tse) {
|
||||
tse.initApplicationException(ex);
|
||||
}
|
||||
return ex2;
|
||||
}
|
||||
|
|
@ -129,8 +129,8 @@ final class TransactionalOperatorImpl implements TransactionalOperator {
|
|||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (super.equals(other) && (!(other instanceof TransactionalOperatorImpl) ||
|
||||
getTransactionManager() == ((TransactionalOperatorImpl) other).getTransactionManager())));
|
||||
return (this == other || (super.equals(other) && (!(other instanceof TransactionalOperatorImpl toi) ||
|
||||
getTransactionManager() == toi.getTransactionManager())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -174,11 +174,11 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
|
|||
@Override
|
||||
protected SavepointManager getSavepointManager() {
|
||||
Object transaction = this.transaction;
|
||||
if (!(transaction instanceof SavepointManager)) {
|
||||
if (!(transaction instanceof SavepointManager manager)) {
|
||||
throw new NestedTransactionNotSupportedException(
|
||||
"Transaction object [" + this.transaction + "] does not support savepoints");
|
||||
}
|
||||
return (SavepointManager) transaction;
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,8 +198,8 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
|
|||
*/
|
||||
@Override
|
||||
public void flush() {
|
||||
if (this.transaction instanceof SmartTransactionObject) {
|
||||
((SmartTransactionObject) this.transaction).flush();
|
||||
if (this.transaction instanceof SmartTransactionObject transactionObject) {
|
||||
transactionObject.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ public abstract class TransactionSynchronizationUtils {
|
|||
Assert.notNull(resource, "Resource must not be null");
|
||||
Object resourceRef = resource;
|
||||
// unwrap infrastructure proxy
|
||||
if (resourceRef instanceof InfrastructureProxy) {
|
||||
resourceRef = ((InfrastructureProxy) resourceRef).getWrappedObject();
|
||||
if (resourceRef instanceof InfrastructureProxy infrasProxy) {
|
||||
resourceRef = infrasProxy.getWrappedObject();
|
||||
}
|
||||
if (aopAvailable) {
|
||||
// now unwrap scoped proxy
|
||||
|
|
@ -185,8 +185,8 @@ public abstract class TransactionSynchronizationUtils {
|
|||
private static class ScopedProxyUnwrapper {
|
||||
|
||||
public static Object unwrapIfNecessary(Object resource) {
|
||||
if (resource instanceof ScopedObject) {
|
||||
return ((ScopedObject) resource).getTargetObject();
|
||||
if (resource instanceof ScopedObject scopedObject) {
|
||||
return scopedObject.getTargetObject();
|
||||
}
|
||||
else {
|
||||
return resource;
|
||||
|
|
|
|||
|
|
@ -181,8 +181,8 @@ public class TransactionTemplate extends DefaultTransactionDefinition
|
|||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (super.equals(other) && (!(other instanceof TransactionTemplate) ||
|
||||
getTransactionManager() == ((TransactionTemplate) other).getTransactionManager())));
|
||||
return (this == other || (super.equals(other) && (!(other instanceof TransactionTemplate template) ||
|
||||
getTransactionManager() == template.getTransactionManager())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue