Browse Source

Polishing

pull/1884/head
Juergen Hoeller 8 years ago
parent
commit
1ab9e2ceda
  1. 3
      spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java
  2. 9
      spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ConnectionHolder.java
  3. 6
      spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java
  4. 4
      spring-jms/src/main/java/org/springframework/jms/listener/LocallyExposedJmsResourceHolder.java
  5. 2
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java
  6. 8
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java
  7. 8
      spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionHolder.java
  8. 11
      spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java
  9. 8
      spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerHolder.java
  10. 6
      spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java
  11. 22
      spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java
  12. 11
      spring-tx/src/main/java/org/springframework/jca/cci/connection/ConnectionHolder.java

3
spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -41,6 +41,7 @@ public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDisc @@ -41,6 +41,7 @@ public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDisc
private static final boolean kotlinPresent =
ClassUtils.isPresent("kotlin.Unit", DefaultParameterNameDiscoverer.class.getClassLoader());
public DefaultParameterNameDiscoverer() {
if (kotlinPresent) {
addDiscoverer(new KotlinReflectionParameterNameDiscoverer());

9
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ConnectionHolder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -25,9 +25,9 @@ import org.springframework.transaction.support.ResourceHolderSupport; @@ -25,9 +25,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert;
/**
* Connection holder, wrapping a JDBC Connection.
* Resource holder wrapping a JDBC {@link Connection}.
* {@link DataSourceTransactionManager} binds instances of this class
* to the thread, for a specific DataSource.
* to the thread, for a specific {@link javax.sql.DataSource}.
*
* <p>Inherits rollback-only support for nested JDBC transactions
* and reference count functionality from the base class.
@ -41,6 +41,9 @@ import org.springframework.util.Assert; @@ -41,6 +41,9 @@ import org.springframework.util.Assert;
*/
public class ConnectionHolder extends ResourceHolderSupport {
/**
* Prefix for savepoint names.
*/
public static final String SAVEPOINT_NAME_PREFIX = "SAVEPOINT_";

6
spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java

@ -38,9 +38,9 @@ import org.springframework.util.CollectionUtils; @@ -38,9 +38,9 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
/**
* JMS resource holder, wrapping a JMS Connection and a JMS Session.
* JmsTransactionManager binds instances of this class to the thread,
* for a given JMS ConnectionFactory.
* Resource holder wrapping a JMS {@link Connection} and a JMS {@link Session}.
* {@link JmsTransactionManager} binds instances of this class to the thread,
* for a given JMS {@link ConnectionFactory}.
*
* <p>Note: This is an SPI class, not intended to be used by applications.
*

4
spring-jms/src/main/java/org/springframework/jms/listener/LocallyExposedJmsResourceHolder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2018 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.
@ -21,7 +21,7 @@ import javax.jms.Session; @@ -21,7 +21,7 @@ import javax.jms.Session;
import org.springframework.jms.connection.JmsResourceHolder;
/**
* JmsResourceHolder marker subclass that indicates local exposure,
* {@link JmsResourceHolder} marker subclass that indicates local exposure,
* i.e. that does not indicate an externally managed transaction.
*
* @author Juergen Hoeller

2
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java

@ -69,7 +69,7 @@ import org.springframework.util.ReflectionUtils; @@ -69,7 +69,7 @@ import org.springframework.util.ReflectionUtils;
*
* <p><b>NOTE: Hibernate access code can also be coded against the native Hibernate
* {@link Session}. Hence, for newly started projects, consider adopting the standard
* Hibernate style of coding against {@link SessionFactory#getCurrentSession()}.</b>
* Hibernate style of coding against {@link SessionFactory#getCurrentSession()}.
* Alternatively, use {@link #execute(HibernateCallback)} with Java 8 lambda code blocks
* against the callback-provided {@code Session} which results in elegant code as well,
* decoupled from the Hibernate Session lifecycle. The remaining operations on this

8
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -203,7 +203,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana @@ -203,7 +203,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
* @see org.springframework.jdbc.core.JdbcTemplate
*/
public void setDataSource(@Nullable DataSource dataSource) {
if (dataSource != null && dataSource instanceof TransactionAwareDataSourceProxy) {
if (dataSource instanceof TransactionAwareDataSourceProxy) {
// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
// for its underlying target DataSource, else data access code won't see
// properly exposed transactions (i.e. transactions for the target DataSource).
@ -336,7 +336,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana @@ -336,7 +336,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
@Nullable
public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException {
if (this.entityInterceptor instanceof Interceptor) {
return (Interceptor) entityInterceptor;
return (Interceptor) this.entityInterceptor;
}
else if (this.entityInterceptor instanceof String) {
if (this.beanFactory == null) {
@ -777,7 +777,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana @@ -777,7 +777,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
* from the {@code org.springframework.dao} hierarchy.
* <p>Will automatically apply a specified SQLExceptionTranslator to a
* Hibernate JDBCException, else rely on Hibernate's default translation.
* @param ex HibernateException that occurred
* @param ex the HibernateException that occurred
* @return a corresponding DataAccessException
* @see SessionFactoryUtils#convertHibernateAccessException
*/

8
spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionHolder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -25,9 +25,9 @@ import org.springframework.transaction.support.ResourceHolderSupport; @@ -25,9 +25,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert;
/**
* Session holder, wrapping a Hibernate Session and a Hibernate Transaction.
* HibernateTransactionManager binds instances of this class to the thread,
* for a given SessionFactory.
* Resource holder wrapping a Hibernate {@link Session} (plus an optional {@link Transaction}).
* {@link HibernateTransactionManager} binds instances of this class to the thread,
* for a given {@link org.hibernate.SessionFactory}.
*
* <p>Note: This is an SPI class, not intended to be used by applications.
*

11
spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -32,9 +32,9 @@ import org.springframework.lang.Nullable; @@ -32,9 +32,9 @@ import org.springframework.lang.Nullable;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
* Implementation of Hibernate 3.1's CurrentSessionContext interface
* that delegates to Spring's SessionFactoryUtils for providing a
* Spring-managed current Session.
* Implementation of Hibernate 3.1's {@link CurrentSessionContext} interface
* that delegates to Spring's {@link SessionFactoryUtils} for providing a
* Spring-managed current {@link Session}.
*
* <p>This CurrentSessionContext implementation can also be specified in custom
* SessionFactory setup through the "hibernate.current_session_context_class"
@ -110,7 +110,8 @@ public class SpringSessionContext implements CurrentSessionContext { @@ -110,7 +110,8 @@ public class SpringSessionContext implements CurrentSessionContext {
if (this.transactionManager.getStatus() == Status.STATUS_ACTIVE) {
Session session = this.jtaSessionContext.currentSession();
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(new SpringFlushSynchronization(session));
TransactionSynchronizationManager.registerSynchronization(
new SpringFlushSynchronization(session));
}
return session;
}

8
spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerHolder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -24,9 +24,9 @@ import org.springframework.transaction.support.ResourceHolderSupport; @@ -24,9 +24,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert;
/**
* Holder wrapping a JPA EntityManager.
* JpaTransactionManager binds instances of this class to the thread,
* for a given EntityManagerFactory.
* Resource holder wrapping a JPA {@link EntityManager}.
* {@link JpaTransactionManager} binds instances of this class to the thread,
* for a given {@link javax.persistence.EntityManagerFactory}.
*
* <p>Note: This is an SPI class, not intended to be used by applications.
*

6
spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -138,7 +138,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager @@ -138,7 +138,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
/**
* Create a new JpaTransactionManager instance.
* @param emf EntityManagerFactory to manage transactions for
* @param emf the EntityManagerFactory to manage transactions for
*/
public JpaTransactionManager(EntityManagerFactory emf) {
this();
@ -255,7 +255,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager @@ -255,7 +255,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
* @see org.springframework.jdbc.core.JdbcTemplate
*/
public void setDataSource(@Nullable DataSource dataSource) {
if (dataSource != null && dataSource instanceof TransactionAwareDataSourceProxy) {
if (dataSource instanceof TransactionAwareDataSourceProxy) {
// If we got a TransactionAwareDataSourceProxy, we need to perform transactions
// for its underlying target DataSource, else data access code won't see
// properly exposed transactions (i.e. transactions for the target DataSource).

22
spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@ -39,7 +39,8 @@ import static org.junit.Assert.*; @@ -39,7 +39,8 @@ import static org.junit.Assert.*;
* @author Rod Johnson
* @author Juergen Hoeller
*/
public abstract class AbstractContainerEntityManagerFactoryIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
extends AbstractEntityManagerFactoryIntegrationTests {
@Test
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
@ -78,7 +79,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte @@ -78,7 +79,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
}
@Test
@SuppressWarnings({ "unused", "unchecked" })
@SuppressWarnings("unchecked")
public void testEntityManagerProxyIsProxy() {
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
Query q = sharedEntityManager.createQuery("select p from Person as p");
@ -107,9 +108,8 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte @@ -107,9 +108,8 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
try {
Person notThere = sharedEntityManager.getReference(Person.class, 666);
// We may get here (as with Hibernate).
// Either behaviour is valid: throw exception on first access
// or on getReference itself.
// We may get here (as with Hibernate). Either behaviour is valid:
// throw exception on first access or on getReference itself.
notThere.getFirstName();
fail("Should have thrown an EntityNotFoundException");
}
@ -209,6 +209,8 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte @@ -209,6 +209,8 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersonsNotTransactional() {
endTransaction();
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
@ -223,12 +225,12 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte @@ -223,12 +225,12 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
}
@Test
@SuppressWarnings({ "unused", "unchecked" })
@SuppressWarnings("unchecked")
public void testQueryNoPersonsShared() {
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
Query q = em.createQuery("select p from Person as p");
Query q = this.sharedEntityManager.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList();
assertEquals(0, people.size());
try {
assertNull(q.getSingleResult());
fail("Should have thrown NoResultException");
@ -243,7 +245,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte @@ -243,7 +245,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
public void testQueryNoPersonsSharedNotTransactional() {
endTransaction();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
EntityManager em = this.sharedEntityManager;
Query q = em.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList();

11
spring-tx/src/main/java/org/springframework/jca/cci/connection/ConnectionHolder.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@ -21,10 +21,9 @@ import javax.resource.cci.Connection; @@ -21,10 +21,9 @@ import javax.resource.cci.Connection;
import org.springframework.transaction.support.ResourceHolderSupport;
/**
* Connection holder, wrapping a CCI Connection.
*
* <p>CciLocalTransactionManager binds instances of this class
* to the thread, for a given ConnectionFactory.
* Resource holder wrapping a CCI {@link Connection}.
* {@link CciLocalTransactionManager} binds instances of this class to the thread,
* for a given {@link javax.resource.cci.ConnectionFactory}.
*
* <p>Note: This is an SPI class, not intended to be used by applications.
*
@ -38,10 +37,12 @@ public class ConnectionHolder extends ResourceHolderSupport { @@ -38,10 +37,12 @@ public class ConnectionHolder extends ResourceHolderSupport {
private final Connection connection;
public ConnectionHolder(Connection connection) {
this.connection = connection;
}
public Connection getConnection() {
return this.connection;
}

Loading…
Cancel
Save