Backport further refinements from the nullability efforts
Issue: SPR-15656
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,14 +40,14 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
*
|
||||
* <p>Application code is required to retrieve the CCI Connection via
|
||||
* {@link ConnectionFactoryUtils#getConnection(ConnectionFactory)} instead of a standard
|
||||
* J2EE-style {@link ConnectionFactory#getConnection()} call. Spring classes such as
|
||||
* Java EE-style {@link ConnectionFactory#getConnection()} call. Spring classes such as
|
||||
* {@link org.springframework.jca.cci.core.CciTemplate} use this strategy implicitly.
|
||||
* If not used in combination with this transaction manager, the
|
||||
* {@link ConnectionFactoryUtils} lookup strategy behaves exactly like the native
|
||||
* DataSource lookup; it can thus be used in a portable fashion.
|
||||
*
|
||||
* <p>Alternatively, you can allow application code to work with the standard
|
||||
* J2EE lookup pattern {@link ConnectionFactory#getConnection()}, for example
|
||||
* Java EE lookup pattern {@link ConnectionFactory#getConnection()}, for example
|
||||
* for legacy code that is not aware of Spring at all. In that case, define a
|
||||
* {@link TransactionAwareConnectionFactoryProxy} for your target ConnectionFactory,
|
||||
* which will automatically participate in Spring-managed transactions.
|
||||
@@ -135,7 +135,7 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
|
||||
protected boolean isExistingTransaction(Object transaction) {
|
||||
CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
|
||||
// Consider a pre-bound connection as transaction.
|
||||
return (txObject.getConnectionHolder() != null);
|
||||
return txObject.hasConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,6 +269,10 @@ public class CciLocalTransactionManager extends AbstractPlatformTransactionManag
|
||||
public ConnectionHolder getConnectionHolder() {
|
||||
return this.connectionHolder;
|
||||
}
|
||||
|
||||
public boolean hasConnectionHolder() {
|
||||
return (this.connectionHolder != null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,11 @@ package org.springframework.jca.cci.connection;
|
||||
|
||||
import javax.resource.ResourceException;
|
||||
import javax.resource.cci.Connection;
|
||||
import javax.resource.cci.ConnectionFactory;
|
||||
import javax.resource.cci.ConnectionSpec;
|
||||
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* An adapter for a target CCI {@link javax.resource.cci.ConnectionFactory},
|
||||
@@ -129,15 +131,9 @@ public class ConnectionSpecConnectionFactoryAdapter extends DelegatingConnection
|
||||
* @see javax.resource.cci.ConnectionFactory#getConnection()
|
||||
*/
|
||||
protected Connection doGetConnection(ConnectionSpec spec) throws ResourceException {
|
||||
if (getTargetConnectionFactory() == null) {
|
||||
throw new IllegalStateException("targetConnectionFactory is required");
|
||||
}
|
||||
if (spec != null) {
|
||||
return getTargetConnectionFactory().getConnection(spec);
|
||||
}
|
||||
else {
|
||||
return getTargetConnectionFactory().getConnection();
|
||||
}
|
||||
ConnectionFactory connectionFactory = getTargetConnectionFactory();
|
||||
Assert.state(connectionFactory != null, "No 'targetConnectionFactory' set");
|
||||
return (spec != null ? connectionFactory.getConnection(spec) : connectionFactory.getConnection());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -197,7 +197,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||
* @see NameMatchTransactionAttributeSource
|
||||
* @see org.springframework.transaction.annotation.AnnotationTransactionAttributeSource
|
||||
*/
|
||||
public void setTransactionAttributeSources(TransactionAttributeSource[] transactionAttributeSources) {
|
||||
public void setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources) {
|
||||
this.transactionAttributeSource = new CompositeTransactionAttributeSource(transactionAttributeSources);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,7 +34,7 @@ abstract class TransactionAttributeSourcePointcut extends StaticMethodMatcherPoi
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class<?> targetClass) {
|
||||
if (TransactionalProxy.class.isAssignableFrom(targetClass)) {
|
||||
if (targetClass != null && TransactionalProxy.class.isAssignableFrom(targetClass)) {
|
||||
return false;
|
||||
}
|
||||
TransactionAttributeSource tas = getTransactionAttributeSource();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,11 +38,11 @@ public class TransactionSupportTests {
|
||||
PlatformTransactionManager tm = new TestTransactionManager(false, true);
|
||||
DefaultTransactionStatus status1 = (DefaultTransactionStatus)
|
||||
tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
|
||||
assertTrue("Must not have transaction", status1.getTransaction() == null);
|
||||
assertFalse("Must not have transaction", status1.hasTransaction());
|
||||
|
||||
DefaultTransactionStatus status2 = (DefaultTransactionStatus)
|
||||
tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
|
||||
assertTrue("Must have transaction", status2.getTransaction() != null);
|
||||
assertTrue("Must have transaction", status2.hasTransaction());
|
||||
assertTrue("Must be new transaction", status2.isNewTransaction());
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user