diff --git a/spring-orm-hibernate4/src/test/java/org/springframework/orm/hibernate4/HibernateTransactionManagerTests.java b/spring-orm-hibernate4/src/test/java/org/springframework/orm/hibernate4/HibernateTransactionManagerTests.java index 590db0654c..9192ca9d7e 100644 --- a/spring-orm-hibernate4/src/test/java/org/springframework/orm/hibernate4/HibernateTransactionManagerTests.java +++ b/spring-orm-hibernate4/src/test/java/org/springframework/orm/hibernate4/HibernateTransactionManagerTests.java @@ -69,7 +69,7 @@ import static org.mockito.BDDMockito.*; * @author Juergen Hoeller * @since 3.2 */ -@SuppressWarnings({ "rawtypes", "unchecked" }) +@SuppressWarnings({"rawtypes", "unchecked"}) public class HibernateTransactionManagerTests { @After diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index 0d784527e5..872ba91f37 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -55,15 +55,15 @@ import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; /** - * Abstract {@link org.springframework.beans.factory.FactoryBean} that - * creates a local JPA {@link javax.persistence.EntityManagerFactory} - * instance within a Spring application context. + * Abstract {@link org.springframework.beans.factory.FactoryBean} that creates + * a local JPA {@link javax.persistence.EntityManagerFactory} instance within + * a Spring application context. * - *

Encapsulates the common functionality between the different JPA - * bootstrap contracts (standalone as well as container). + *

Encapsulates the common functionality between the different JPA bootstrap + * contracts (standalone as well as container). * - *

Implements support for standard JPA configuration as well as - * Spring's {@link JpaVendorAdapter} abstraction, and controls the + *

Implements support for standard JPA configuration conventions as well as + * Spring's customizable {@link JpaVendorAdapter} mechanism, and controls the * EntityManagerFactory's lifecycle. * *

This class also implements the diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java index dba34467c9..7e0eb82a05 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -33,8 +33,8 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** - * Base class for any class that needs to access an EntityManagerFactory, - * usually in order to obtain an EntityManager. Defines common properties. + * Base class for any class that needs to access a JPA {@link EntityManagerFactory}, + * usually in order to obtain a JPA {@link EntityManager}. Defines common properties. * * @author Juergen Hoeller * @since 2.0 diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java index 52cde50b70..c434bbd954 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -80,6 +80,7 @@ public abstract class EntityManagerFactoryUtils { private static final Log logger = LogFactory.getLog(EntityManagerFactoryUtils.class); + private static Method createEntityManagerWithSynchronizationTypeMethod; private static Object synchronizationTypeUnsynchronized; @@ -144,9 +145,8 @@ public abstract class EntityManagerFactoryUtils { } /** - * Obtain a JPA EntityManager from the given factory. Is aware of a - * corresponding EntityManager bound to the current thread, - * for example when using JpaTransactionManager. + * Obtain a JPA EntityManager from the given factory. Is aware of a corresponding + * EntityManager bound to the current thread, e.g. when using JpaTransactionManager. *

Note: Will return {@code null} if no thread-bound EntityManager found! * @param emf EntityManagerFactory to create the EntityManager with * @return the EntityManager, or {@code null} if none found @@ -160,9 +160,8 @@ public abstract class EntityManagerFactoryUtils { } /** - * Obtain a JPA EntityManager from the given factory. Is aware of a - * corresponding EntityManager bound to the current thread, - * for example when using JpaTransactionManager. + * Obtain a JPA EntityManager from the given factory. Is aware of a corresponding + * EntityManager bound to the current thread, e.g. when using JpaTransactionManager. *

Note: Will return {@code null} if no thread-bound EntityManager found! * @param emf EntityManagerFactory to create the EntityManager with * @param properties the properties to be passed into the {@code createEntityManager} @@ -182,9 +181,8 @@ public abstract class EntityManagerFactoryUtils { } /** - * Obtain a JPA EntityManager from the given factory. Is aware of a - * corresponding EntityManager bound to the current thread, - * for example when using JpaTransactionManager. + * Obtain a JPA EntityManager from the given factory. Is aware of a corresponding + * EntityManager bound to the current thread, e.g. when using JpaTransactionManager. *

Same as {@code getEntityManager}, but throwing the original PersistenceException. * @param emf EntityManagerFactory to create the EntityManager with * @param properties the properties to be passed into the {@code createEntityManager} @@ -201,9 +199,8 @@ public abstract class EntityManagerFactoryUtils { } /** - * Obtain a JPA EntityManager from the given factory. Is aware of a - * corresponding EntityManager bound to the current thread, - * for example when using JpaTransactionManager. + * Obtain a JPA EntityManager from the given factory. Is aware of a corresponding + * EntityManager bound to the current thread, e.g. when using JpaTransactionManager. *

Same as {@code getEntityManager}, but throwing the original PersistenceException. * @param emf EntityManagerFactory to create the EntityManager with * @param properties the properties to be passed into the {@code createEntityManager} @@ -285,8 +282,8 @@ public abstract class EntityManagerFactoryUtils { em = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); } - // Use same EntityManager for further JPA actions within the transaction. - // Thread object will get removed by synchronization at transaction completion. + // Use same EntityManager for further JPA operations within the transaction. + // Thread-bound object will get removed by synchronization at transaction completion. logger.debug("Registering transaction synchronization for JPA EntityManager"); emHolder = new EntityManagerHolder(em); if (synchronizedWithTransaction) { @@ -296,7 +293,7 @@ public abstract class EntityManagerFactoryUtils { emHolder.setSynchronizedWithTransaction(true); } else { - // unsynchronized - just scope it for the transaction, as demanded by the JPA 2.1 spec + // Unsynchronized - just scope it for the transaction, as demanded by the JPA 2.1 spec... TransactionSynchronizationManager.registerSynchronization( new TransactionScopedEntityManagerSynchronization(emHolder, emf)); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java index e70845a20b..1faa723508 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java @@ -95,6 +95,7 @@ public abstract class ExtendedEntityManagerCreator { * transactions (according to the JPA 2.1 SynchronizationType rules) * @return an application-managed EntityManager that can join transactions * but does not participate in them automatically + * @since 4.0 */ public static EntityManager createApplicationManagedEntityManager( EntityManager rawEntityManager, EntityManagerFactoryInfo emfInfo, boolean synchronizedWithTransaction) { @@ -156,6 +157,7 @@ public abstract class ExtendedEntityManagerCreator { * @return a container-managed EntityManager that expects container-driven lifecycle * management but may opt out of automatic transaction synchronization * @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map) + * @since 4.0 */ public static EntityManager createContainerManagedEntityManager( EntityManagerFactory emf, Map properties, boolean synchronizedWithTransaction) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index 6bb859a9ae..8f2151eeb5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -68,7 +68,9 @@ import org.springframework.util.ClassUtils; * metadata as assembled by this FactoryBean. * *

NOTE: Spring's JPA support requires JPA 2.0 or higher, as of Spring 4.0. - * Spring's persistence unit bootstrapping automatically detects JPA 2.1 at runtime. + * JPA 1.0 based applications are still supported; however, a JPA 2.0/2.1 compliant + * persistence provider is needed at runtime. Spring's persistence unit bootstrapping + * automatically detects JPA 2.0 vs 2.1 through checking the JPA API on the classpath. * * @author Juergen Hoeller * @author Rod Johnson diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java index 9df7e08ef9..ab6d60db1e 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java @@ -41,7 +41,7 @@ import javax.persistence.spi.PersistenceProvider; *

This EntityManagerFactory bootstrap is appropriate for standalone applications * which solely use JPA for data access. If you want to set up your persistence * provider for an external DataSource and/or for global transactions which span - * multiple resources, you will need to either deploy it into a full Java EE 5 + * multiple resources, you will need to either deploy it into a full Java EE * application server and access the deployed EntityManagerFactory via JNDI, * or use Spring's {@link LocalContainerEntityManagerFactoryBean} with appropriate * configuration for local setup according to JPA's container contract. @@ -53,6 +53,8 @@ import javax.persistence.spi.PersistenceProvider; * {@link LocalContainerEntityManagerFactoryBean} instead. * *

NOTE: Spring's JPA support requires JPA 2.0 or higher, as of Spring 4.0. + * JPA 1.0 based applications are still supported; however, a JPA 2.0/2.1 compliant + * persistence provider is needed at runtime. * * @author Juergen Hoeller * @author Rod Johnson diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java index ce364d5285..e7d9398b3c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java @@ -110,6 +110,7 @@ public abstract class SharedEntityManagerCreator { * @param synchronizedWithTransaction whether to automatically join ongoing * transactions (according to the JPA 2.1 SynchronizationType rules) * @return a shareable transaction EntityManager proxy + * @since 4.0 */ public static EntityManager createSharedEntityManager( EntityManagerFactory emf, Map properties, boolean synchronizedWithTransaction) { @@ -145,6 +146,7 @@ public abstract class SharedEntityManagerCreator { * @param entityManagerInterfaces the interfaces to be implemented by the * EntityManager. Allows the addition or specification of proprietary interfaces. * @return a shareable transactional EntityManager proxy + * @since 4.0 */ public static EntityManager createSharedEntityManager(EntityManagerFactory emf, Map properties, boolean synchronizedWithTransaction, Class... entityManagerInterfaces) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java index f392734cd3..c6595279de 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -30,7 +30,7 @@ import org.springframework.util.Assert; * {@link FactoryBean} that exposes a shared JPA {@link javax.persistence.EntityManager} * reference for a given EntityManagerFactory. Typically used for an EntityManagerFactory * created by {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean}, - * as direct alternative to a JNDI lookup for a Java EE 5 server's EntityManager reference. + * as direct alternative to a JNDI lookup for a Java EE server's EntityManager reference. * *

The shared EntityManager will behave just like an EntityManager fetched from an * application server's JNDI environment, as defined by the JPA specification. diff --git a/spring-orm/src/test/java/org/springframework/orm/hibernate3/HibernateTransactionManagerTests.java b/spring-orm/src/test/java/org/springframework/orm/hibernate3/HibernateTransactionManagerTests.java index 325e0fe344..99cdbd1b6d 100644 --- a/spring-orm/src/test/java/org/springframework/orm/hibernate3/HibernateTransactionManagerTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/hibernate3/HibernateTransactionManagerTests.java @@ -66,7 +66,7 @@ import static org.mockito.BDDMockito.*; * @author Phillip Webb * @since 05.03.2005 */ -@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" }) +@SuppressWarnings({"rawtypes", "unchecked", "deprecation"}) public class HibernateTransactionManagerTests { @After diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java index 3bf359af58..bc32b66800 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java @@ -132,7 +132,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte newTony.getDriversLicense().getSerialNumber(); } finally { - deleteFromTables(new String[] { "person", "drivers_license" }); + deleteFromTables("person", "drivers_license"); } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java index 90f5ec5741..defd17c00e 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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. @@ -88,9 +88,11 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr protected int countRowsInTable(EntityManager em, String tableName) { Query query = em.createNativeQuery("SELECT COUNT(0) FROM " + tableName); return ((Number) query.getSingleResult()).intValue(); - }; + } + public enum Provider { + ECLIPSELINK, HIBERNATE, OPENJPA } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java index d411480269..4c80efca33 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java @@ -120,15 +120,13 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt doInstantiateAndSave(em); setComplete(); endTransaction(); // Should rollback - assertEquals("Tx must have committed back", - 1, countRowsInTable(em, "person")); + assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person")); // Now clean up the database startNewTransaction(); em.joinTransaction(); deleteAllPeopleUsingEntityManager(em); - assertEquals("People have been killed", - 0, countRowsInTable(em, "person")); + assertEquals("People have been killed", 0, countRowsInTable(em, "person")); setComplete(); } @@ -141,8 +139,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt em.joinTransaction(); doInstantiateAndSave(em); endTransaction(); // Should rollback - assertEquals("Tx must have been rolled back", - 0, countRowsInTable(em, "person")); + assertEquals("Tx must have been rolled back", 0, countRowsInTable(em, "person")); } public void testCommitOccurs() { @@ -152,11 +149,10 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt setComplete(); endTransaction(); // Should rollback - assertEquals("Tx must have committed back", - 1, countRowsInTable(em, "person")); + assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person")); // Now clean up the database - deleteFromTables(new String[] { "person" }); + deleteFromTables("person"); } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java index 2d88d3c3bb..2e658c3e25 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java @@ -114,8 +114,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit } public void doInstantiateAndSave(EntityManager em) { - assertEquals("Should be no people from previous transactions", - 0, countRowsInTable(em, "person")); + assertEquals("Should be no people from previous transactions", 0, countRowsInTable(em, "person")); Person p = new Person(); p.setFirstName("Tony"); @@ -141,19 +140,17 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit doInstantiateAndSave(em); setComplete(); endTransaction(); // Should rollback - assertEquals("Tx must have committed back", - 1, countRowsInTable(em, "person")); + assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person")); // Now clean up the database - deleteFromTables(new String[] { "person" }); + deleteFromTables("person"); } public void testRollbackOccurs() { EntityManager em = createContainerManagedEntityManager(); doInstantiateAndSave(em); endTransaction(); // Should rollback - assertEquals("Tx must have been rolled back", - 0, countRowsInTable(em, "person")); + assertEquals("Tx must have been rolled back", 0, countRowsInTable(em, "person")); } public void testCommitOccurs() { @@ -161,11 +158,10 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit doInstantiateAndSave(em); setComplete(); endTransaction(); // Should rollback - assertEquals("Tx must have committed back", - 1, countRowsInTable(em, "person")); + assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person")); // Now clean up the database - deleteFromTables(new String[] { "person" }); + deleteFromTables("person"); } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java index 78d70fca57..4c6a886728 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/JpaTransactionManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -49,13 +49,13 @@ import static org.mockito.BDDMockito.*; */ public class JpaTransactionManagerTests { + private EntityManagerFactory factory; + private EntityManager manager; private EntityTransaction tx; - private EntityManagerFactory factory; - - private JpaTransactionManager transactionManager; + private JpaTransactionManager tm; private TransactionTemplate tt; @@ -66,8 +66,8 @@ public class JpaTransactionManagerTests { manager = mock(EntityManager.class); tx = mock(EntityTransaction.class); - transactionManager = new JpaTransactionManager(factory); - tt = new TransactionTemplate(transactionManager); + tm = new JpaTransactionManager(factory); + tt = new TransactionTemplate(tm); given(factory.createEntityManager()).willReturn(manager); given(manager.getTransaction()).willReturn(tx); @@ -82,6 +82,7 @@ public class JpaTransactionManagerTests { assertFalse(TransactionSynchronizationManager.isActualTransactionActive()); } + @Test public void testTransactionCommit() { given(manager.getTransaction()).willReturn(tx); @@ -455,7 +456,7 @@ public class JpaTransactionManagerTests { @Override public Object doInTransaction(TransactionStatus status) { assertFalse(TransactionSynchronizationManager.hasResource(factory)); - TransactionTemplate tt2 = new TransactionTemplate(transactionManager); + TransactionTemplate tt2 = new TransactionTemplate(tm); tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); return tt2.execute(new TransactionCallback() { @Override @@ -496,7 +497,7 @@ public class JpaTransactionManagerTests { EntityManagerFactoryUtils.getTransactionalEntityManager(factory); assertTrue(TransactionSynchronizationManager.hasResource(factory)); - TransactionTemplate tt2 = new TransactionTemplate(transactionManager); + TransactionTemplate tt2 = new TransactionTemplate(tm); tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); return tt2.execute(new TransactionCallback() { @Override @@ -659,7 +660,6 @@ public class JpaTransactionManagerTests { @Test public void testTransactionRollbackWithPrebound() { - given(manager.getTransaction()).willReturn(tx); given(tx.isActive()).willReturn(true); @@ -693,7 +693,6 @@ public class JpaTransactionManagerTests { @Test public void testTransactionCommitWithPreboundAndPropagationSupports() { - final List l = new ArrayList(); l.add("test"); @@ -729,7 +728,6 @@ public class JpaTransactionManagerTests { @Test public void testTransactionRollbackWithPreboundAndPropagationSupports() { - tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS); assertTrue(!TransactionSynchronizationManager.hasResource(factory)); @@ -764,7 +762,7 @@ public class JpaTransactionManagerTests { @Test public void testTransactionCommitWithDataSource() throws SQLException { DataSource ds = mock(DataSource.class); - transactionManager.setDataSource(ds); + tm.setDataSource(ds); given(manager.getTransaction()).willReturn(tx); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/SharedEntityManagerCreatorTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/SharedEntityManagerCreatorTests.java index b35931ab07..06b705ab22 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/SharedEntityManagerCreatorTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/SharedEntityManagerCreatorTests.java @@ -38,8 +38,7 @@ public class SharedEntityManagerCreatorTests { EntityManagerFactory emf = mock(EntityManagerFactory.class, withSettings().extraInterfaces(EntityManagerFactoryInfo.class)); // EntityManagerFactoryInfo.getEntityManagerInterface returns null - assertThat(SharedEntityManagerCreator.createSharedEntityManager(emf), - is(notNullValue())); + assertThat(SharedEntityManagerCreator.createSharedEntityManager(emf), is(notNullValue())); } @Test(expected = TransactionRequiredException.class) diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/inject.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/inject.xml index 09aa0eb7f3..33edf99a8d 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/inject.xml +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/inject.xml @@ -2,7 +2,7 @@ @@ -11,13 +11,13 @@ - - - + + + - - - - + + + + diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionIntegrationTests.java index 4e708c81fb..6873b500bb 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionIntegrationTests.java @@ -52,11 +52,6 @@ public class PersistenceInjectionIntegrationTests extends AbstractEntityManagerF assertNotNull("Default PersistenceContext Setter was injected", injectedEm); } - public void testInjectedEntityManagerImplmentsPortableEntityManagerPlus() { - EntityManager injectedEm = defaultSetterInjected.getEntityManager(); - assertNotNull("Default PersistenceContext Setter was injected", injectedEm); - } - public void testSetterInjectionOfNamedPersistenceContext() { assertNotNull("Named PersistenceContext Setter was injected", namedSetterInjected.getEntityManagerFactory()); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java index 04c4ce0ac3..b907a2d5df 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java @@ -330,8 +330,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT assertSame(mockEmf2, bean2.emf); } + @Test @Ignore - public void ignoreTestPersistenceUnitsFromJndi() { + public void testPersistenceUnitsFromJndi() { EntityManager mockEm = mock(EntityManager.class); given(mockEmf.createEntityManager()).willReturn(mockEm); @@ -542,9 +543,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT @Test public void testFieldOfWrongTypeAnnotatedWithPersistenceUnit() { - PersistenceAnnotationBeanPostProcessor babpp = new PersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor(); try { - babpp.postProcessPropertyValues(null, null, new FieldOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); + pabpp.postProcessPropertyValues(null, null, new FieldOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); fail("Can't inject this field"); } catch (IllegalStateException ex) { @@ -554,9 +555,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT @Test public void testSetterOfWrongTypeAnnotatedWithPersistenceUnit() { - PersistenceAnnotationBeanPostProcessor babpp = new PersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor(); try { - babpp.postProcessPropertyValues(null, null, new SetterOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); + pabpp.postProcessPropertyValues(null, null, new SetterOfWrongTypeAnnotatedWithPersistenceUnit(), "bean"); fail("Can't inject this setter"); } catch (IllegalStateException ex) { @@ -566,9 +567,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT @Test public void testSetterWithNoArgs() { - PersistenceAnnotationBeanPostProcessor babpp = new PersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor(); try { - babpp.postProcessPropertyValues(null, null, new SetterWithNoArgs(), "bean"); + pabpp.postProcessPropertyValues(null, null, new SetterWithNoArgs(), "bean"); fail("Can't inject this setter"); } catch (IllegalStateException ex) { @@ -576,28 +577,28 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT } } - @Ignore - public void ignoreTestNoPropertiesPassedIn() { + @Test + public void testNoPropertiesPassedIn() { EntityManager mockEm = mock(EntityManager.class); given(mockEmf.createEntityManager()).willReturn(mockEm); - PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); DefaultPrivatePersistenceContextFieldExtended dppcf = new DefaultPrivatePersistenceContextFieldExtended(); - babpp.postProcessAfterInstantiation(dppcf, "bean name does not matter"); + pabpp.postProcessPropertyValues(null, null, dppcf, "bean"); assertNotNull(dppcf.em); } - @Ignore - public void ignoreTestPropertiesPassedIn() { + @Test + public void testPropertiesPassedIn() { Properties props = new Properties(); props.put("foo", "bar"); EntityManager mockEm = mock(EntityManager.class); given(mockEmf.createEntityManager(props)).willReturn(mockEm); - PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); DefaultPrivatePersistenceContextFieldExtendedWithProps dppcf = new DefaultPrivatePersistenceContextFieldExtendedWithProps(); - babpp.postProcessAfterInstantiation(dppcf, "bean name does not matter"); + pabpp.postProcessPropertyValues(null, null, dppcf, "bean"); assertNotNull(dppcf.em); } @@ -610,10 +611,10 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT given(em.getDelegate()).willReturn(new Object()); given(em.isOpen()).willReturn(true); - PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); DefaultPrivatePersistenceContextFieldWithProperties transactionalField = new DefaultPrivatePersistenceContextFieldWithProperties(); - babpp.postProcessPropertyValues(null, null, transactionalField, "bean"); + pabpp.postProcessPropertyValues(null, null, transactionalField, "bean"); assertNotNull(transactionalField.em); assertNotNull(transactionalField.em.getDelegate()); @@ -635,13 +636,13 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT given(em.getDelegate()).willReturn(new Object()); given(em.isOpen()).willReturn(true); - PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties = new DefaultPrivatePersistenceContextFieldWithProperties(); DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField(); - babpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); - babpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); + pabpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); + pabpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); assertNotNull(transactionalFieldWithProperties.em); assertNotNull(transactionalField.em); @@ -668,13 +669,13 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT given(em.getDelegate()).willReturn(new Object(), 2); given(em.isOpen()).willReturn(true); - PersistenceAnnotationBeanPostProcessor babpp = new MockPersistenceAnnotationBeanPostProcessor(); + PersistenceAnnotationBeanPostProcessor pabpp = new MockPersistenceAnnotationBeanPostProcessor(); DefaultPrivatePersistenceContextFieldWithProperties transactionalFieldWithProperties = new DefaultPrivatePersistenceContextFieldWithProperties(); DefaultPrivatePersistenceContextField transactionalField = new DefaultPrivatePersistenceContextField(); - babpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); - babpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); + pabpp.postProcessPropertyValues(null, null, transactionalFieldWithProperties, "bean1"); + pabpp.postProcessPropertyValues(null, null, transactionalField, "bean2"); assertNotNull(transactionalFieldWithProperties.em); assertNotNull(transactionalField.em); diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java index 540d110db7..16b9c577b5 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java @@ -49,8 +49,7 @@ import org.springframework.test.jdbc.JdbcTestUtils; * ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests}) */ @Deprecated -public abstract class AbstractTransactionalDataSourceSpringContextTests - extends AbstractTransactionalSpringContextTests { +public abstract class AbstractTransactionalDataSourceSpringContextTests extends AbstractTransactionalSpringContextTests { protected JdbcTemplate jdbcTemplate; @@ -106,11 +105,11 @@ public abstract class AbstractTransactionalDataSourceSpringContextTests * {@code setComplete()} impossible. * @see #setComplete */ - protected void deleteFromTables(String[] names) { - for (int i = 0; i < names.length; i++) { - int rowCount = this.jdbcTemplate.update("DELETE FROM " + names[i]); + protected void deleteFromTables(String... names) { + for (String name : names) { + int rowCount = this.jdbcTemplate.update("DELETE FROM " + name); if (logger.isInfoEnabled()) { - logger.info("Deleted " + rowCount + " rows from table " + names[i]); + logger.info("Deleted " + rowCount + " rows from table " + name); } } this.zappedTables = true;