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 @@
/* /*
* 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"); * 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.
@ -41,6 +41,7 @@ public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDisc
private static final boolean kotlinPresent = private static final boolean kotlinPresent =
ClassUtils.isPresent("kotlin.Unit", DefaultParameterNameDiscoverer.class.getClassLoader()); ClassUtils.isPresent("kotlin.Unit", DefaultParameterNameDiscoverer.class.getClassLoader());
public DefaultParameterNameDiscoverer() { public DefaultParameterNameDiscoverer() {
if (kotlinPresent) { if (kotlinPresent) {
addDiscoverer(new KotlinReflectionParameterNameDiscoverer()); addDiscoverer(new KotlinReflectionParameterNameDiscoverer());

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

@ -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"); * 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.
@ -25,9 +25,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert; 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 * {@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 * <p>Inherits rollback-only support for nested JDBC transactions
* and reference count functionality from the base class. * and reference count functionality from the base class.
@ -41,6 +41,9 @@ import org.springframework.util.Assert;
*/ */
public class ConnectionHolder extends ResourceHolderSupport { public class ConnectionHolder extends ResourceHolderSupport {
/**
* Prefix for savepoint names.
*/
public static final String SAVEPOINT_NAME_PREFIX = "SAVEPOINT_"; 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;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
/** /**
* JMS resource holder, wrapping a JMS Connection and a JMS Session. * Resource holder wrapping a JMS {@link Connection} and a JMS {@link Session}.
* JmsTransactionManager binds instances of this class to the thread, * {@link JmsTransactionManager} binds instances of this class to the thread,
* for a given JMS ConnectionFactory. * for a given JMS {@link ConnectionFactory}.
* *
* <p>Note: This is an SPI class, not intended to be used by applications. * <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 @@
/* /*
* 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"); * 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.
@ -21,7 +21,7 @@ import javax.jms.Session;
import org.springframework.jms.connection.JmsResourceHolder; 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. * i.e. that does not indicate an externally managed transaction.
* *
* @author Juergen Hoeller * @author Juergen Hoeller

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

@ -69,7 +69,7 @@ import org.springframework.util.ReflectionUtils;
* *
* <p><b>NOTE: Hibernate access code can also be coded against the native Hibernate * <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 * {@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 * Alternatively, use {@link #execute(HibernateCallback)} with Java 8 lambda code blocks
* against the callback-provided {@code Session} which results in elegant code as well, * against the callback-provided {@code Session} which results in elegant code as well,
* decoupled from the Hibernate Session lifecycle. The remaining operations on this * 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 @@
/* /*
* 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"); * 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.
@ -203,7 +203,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
* @see org.springframework.jdbc.core.JdbcTemplate * @see org.springframework.jdbc.core.JdbcTemplate
*/ */
public void setDataSource(@Nullable DataSource dataSource) { 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 // If we got a TransactionAwareDataSourceProxy, we need to perform transactions
// for its underlying target DataSource, else data access code won't see // for its underlying target DataSource, else data access code won't see
// properly exposed transactions (i.e. transactions for the target DataSource). // properly exposed transactions (i.e. transactions for the target DataSource).
@ -336,7 +336,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
@Nullable @Nullable
public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException { public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException {
if (this.entityInterceptor instanceof Interceptor) { if (this.entityInterceptor instanceof Interceptor) {
return (Interceptor) entityInterceptor; return (Interceptor) this.entityInterceptor;
} }
else if (this.entityInterceptor instanceof String) { else if (this.entityInterceptor instanceof String) {
if (this.beanFactory == null) { if (this.beanFactory == null) {
@ -777,7 +777,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
* from the {@code org.springframework.dao} hierarchy. * from the {@code org.springframework.dao} hierarchy.
* <p>Will automatically apply a specified SQLExceptionTranslator to a * <p>Will automatically apply a specified SQLExceptionTranslator to a
* Hibernate JDBCException, else rely on Hibernate's default translation. * Hibernate JDBCException, else rely on Hibernate's default translation.
* @param ex HibernateException that occurred * @param ex the HibernateException that occurred
* @return a corresponding DataAccessException * @return a corresponding DataAccessException
* @see SessionFactoryUtils#convertHibernateAccessException * @see SessionFactoryUtils#convertHibernateAccessException
*/ */

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

@ -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"); * 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.
@ -25,9 +25,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Session holder, wrapping a Hibernate Session and a Hibernate Transaction. * Resource holder wrapping a Hibernate {@link Session} (plus an optional {@link Transaction}).
* HibernateTransactionManager binds instances of this class to the thread, * {@link HibernateTransactionManager} binds instances of this class to the thread,
* for a given SessionFactory. * for a given {@link org.hibernate.SessionFactory}.
* *
* <p>Note: This is an SPI class, not intended to be used by applications. * <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 @@
/* /*
* 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"); * 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.
@ -32,9 +32,9 @@ import org.springframework.lang.Nullable;
import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.support.TransactionSynchronizationManager;
/** /**
* Implementation of Hibernate 3.1's CurrentSessionContext interface * Implementation of Hibernate 3.1's {@link CurrentSessionContext} interface
* that delegates to Spring's SessionFactoryUtils for providing a * that delegates to Spring's {@link SessionFactoryUtils} for providing a
* Spring-managed current Session. * Spring-managed current {@link Session}.
* *
* <p>This CurrentSessionContext implementation can also be specified in custom * <p>This CurrentSessionContext implementation can also be specified in custom
* SessionFactory setup through the "hibernate.current_session_context_class" * SessionFactory setup through the "hibernate.current_session_context_class"
@ -110,7 +110,8 @@ public class SpringSessionContext implements CurrentSessionContext {
if (this.transactionManager.getStatus() == Status.STATUS_ACTIVE) { if (this.transactionManager.getStatus() == Status.STATUS_ACTIVE) {
Session session = this.jtaSessionContext.currentSession(); Session session = this.jtaSessionContext.currentSession();
if (TransactionSynchronizationManager.isSynchronizationActive()) { if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.registerSynchronization(new SpringFlushSynchronization(session)); TransactionSynchronizationManager.registerSynchronization(
new SpringFlushSynchronization(session));
} }
return session; return session;
} }

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

@ -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"); * 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.
@ -24,9 +24,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Holder wrapping a JPA EntityManager. * Resource holder wrapping a JPA {@link EntityManager}.
* JpaTransactionManager binds instances of this class to the thread, * {@link JpaTransactionManager} binds instances of this class to the thread,
* for a given EntityManagerFactory. * for a given {@link javax.persistence.EntityManagerFactory}.
* *
* <p>Note: This is an SPI class, not intended to be used by applications. * <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 @@
/* /*
* 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"); * 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.
@ -138,7 +138,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
/** /**
* Create a new JpaTransactionManager instance. * Create a new JpaTransactionManager instance.
* @param emf EntityManagerFactory to manage transactions for * @param emf the EntityManagerFactory to manage transactions for
*/ */
public JpaTransactionManager(EntityManagerFactory emf) { public JpaTransactionManager(EntityManagerFactory emf) {
this(); this();
@ -255,7 +255,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
* @see org.springframework.jdbc.core.JdbcTemplate * @see org.springframework.jdbc.core.JdbcTemplate
*/ */
public void setDataSource(@Nullable DataSource dataSource) { 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 // If we got a TransactionAwareDataSourceProxy, we need to perform transactions
// for its underlying target DataSource, else data access code won't see // for its underlying target DataSource, else data access code won't see
// properly exposed transactions (i.e. transactions for the target DataSource). // 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 @@
/* /*
* 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"); * 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.
@ -39,7 +39,8 @@ import static org.junit.Assert.*;
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public abstract class AbstractContainerEntityManagerFactoryIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests { public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
extends AbstractEntityManagerFactoryIntegrationTests {
@Test @Test
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() { public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
@ -78,7 +79,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
} }
@Test @Test
@SuppressWarnings({ "unused", "unchecked" }) @SuppressWarnings("unchecked")
public void testEntityManagerProxyIsProxy() { public void testEntityManagerProxyIsProxy() {
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass())); assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
Query q = sharedEntityManager.createQuery("select p from Person as p"); Query q = sharedEntityManager.createQuery("select p from Person as p");
@ -107,9 +108,8 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
try { try {
Person notThere = sharedEntityManager.getReference(Person.class, 666); Person notThere = sharedEntityManager.getReference(Person.class, 666);
// We may get here (as with Hibernate). // We may get here (as with Hibernate). Either behaviour is valid:
// Either behaviour is valid: throw exception on first access // throw exception on first access or on getReference itself.
// or on getReference itself.
notThere.getFirstName(); notThere.getFirstName();
fail("Should have thrown an EntityNotFoundException"); fail("Should have thrown an EntityNotFoundException");
} }
@ -209,6 +209,8 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testQueryNoPersonsNotTransactional() { public void testQueryNoPersonsNotTransactional() {
endTransaction();
EntityManager em = entityManagerFactory.createEntityManager(); EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p"); Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList(); List<Person> people = q.getResultList();
@ -223,12 +225,12 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
} }
@Test @Test
@SuppressWarnings({ "unused", "unchecked" }) @SuppressWarnings("unchecked")
public void testQueryNoPersonsShared() { public void testQueryNoPersonsShared() {
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory); Query q = this.sharedEntityManager.createQuery("select p from Person as p");
Query q = em.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO); q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList(); List<Person> people = q.getResultList();
assertEquals(0, people.size());
try { try {
assertNull(q.getSingleResult()); assertNull(q.getSingleResult());
fail("Should have thrown NoResultException"); fail("Should have thrown NoResultException");
@ -243,7 +245,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte
public void testQueryNoPersonsSharedNotTransactional() { public void testQueryNoPersonsSharedNotTransactional() {
endTransaction(); endTransaction();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory); EntityManager em = this.sharedEntityManager;
Query q = em.createQuery("select p from Person as p"); Query q = em.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO); q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList(); List<Person> people = q.getResultList();

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

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

Loading…
Cancel
Save