From ceb9a05ecb76bbfde66774232bdced86f074093a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 19 Mar 2013 18:34:04 +0100 Subject: [PATCH] General JPA 2.0+ requirement; upgraded build and tests to EclipseLink 2.4, OpenJPA 2.2, Hibernate 3.6 --- build.gradle | 40 ++---- .../FilterDefinitionFactoryBean.java | 33 +---- .../hibernate3/LocalCacheProviderProxy.java | 73 ----------- .../hibernate3/LocalSessionFactoryBean.java | 50 +------- .../DefaultPersistenceUnitManager.java | 69 +--------- .../MutablePersistenceUnitInfo.java | 26 +++- .../PersistenceUnitReader.java | 8 +- .../SpringPersistenceUnitInfo.java | 31 +---- .../orm/jpa/vendor/EclipseLinkJpaDialect.java | 9 +- .../vendor/EclipseLinkJpaVendorAdapter.java | 12 +- .../orm/jpa/vendor/HibernateJpaDialect.java | 4 +- .../jpa/vendor/HibernateJpaVendorAdapter.java | 2 +- .../orm/jpa/vendor/OpenJpaDialect.java | 2 +- .../orm/jpa/vendor/OpenJpaVendorAdapter.java | 2 +- .../orm/jpa/vendor/TopLinkJpaDialect.java | 114 ----------------- .../jpa/vendor/TopLinkJpaVendorAdapter.java | 120 ------------------ .../LocalSessionFactoryBeanTests.java | 41 +----- ...rEntityManagerFactoryIntegrationTests.java | 3 +- ...tEntityManagerFactoryIntegrationTests.java | 17 +-- ...rManagedEntityManagerIntegrationTests.java | 15 --- ...ontainerEntityManagerFactoryBeanTests.java | 8 +- .../LocalEntityManagerFactoryBeanTests.java | 6 + .../orm/jpa/domain/ContextualPerson.java | 1 - .../orm/jpa/domain/Person.java | 1 - ...kEntityManagerFactoryIntegrationTests.java | 6 +- ...kEntityManagerFactoryIntegrationTests.java | 49 ------- ...iEntityManagerFactoryIntegrationTests.java | 70 ---------- .../orm/jpa/toplink/toplink-manager-multi.xml | 16 --- .../orm/jpa/toplink/toplink-manager.xml | 18 --- 29 files changed, 86 insertions(+), 760 deletions(-) delete mode 100644 spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalCacheProviderProxy.java delete mode 100644 spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaDialect.java delete mode 100644 spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaVendorAdapter.java delete mode 100644 spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkEntityManagerFactoryIntegrationTests.java delete mode 100644 spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkMultiEntityManagerFactoryIntegrationTests.java delete mode 100644 spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager-multi.xml delete mode 100644 spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager.xml diff --git a/build.gradle b/build.gradle index 00ad2ad23e2..5be18e08352 100644 --- a/build.gradle +++ b/build.gradle @@ -305,7 +305,7 @@ project("spring-context") { optional("javax.ejb:ejb-api:3.0") optional("javax.inject:javax.inject:1") optional("org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1") - optional("javax.persistence:persistence-api:1.0") + optional("org.eclipse.persistence:javax.persistence:2.0.0") optional("javax.validation:validation-api:1.0.0.GA") optional("org.beanshell:bsh:2.0b4") optional("org.codehaus.groovy:groovy-all:1.8.8") @@ -336,7 +336,7 @@ project("spring-tx") { optional("javax.resource:connector-api:1.5") optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1") optional("javax.ejb:ejb-api:3.0") - testCompile("javax.persistence:persistence-api:1.0") + testCompile("org.eclipse.persistence:javax.persistence:2.0.0") testCompile("org.aspectj:aspectjweaver:${aspectjVersion}") } } @@ -478,31 +478,19 @@ project("spring-web") { project("spring-orm") { description = "Spring Object/Relational Mapping" - compileTestJava { - // necessary to avoid java.lang.VerifyError on toplink compilation - // TODO: remove this block when we remove toplink - sourceCompatibility=1.6 - targetCompatibility=1.6 - } - dependencies { compile("aopalliance:aopalliance:1.0") - optional("org.hibernate:hibernate-core:3.3.2.GA") - optional("org.hibernate:hibernate-annotations:3.4.0.GA") - optional("org.hibernate:hibernate-entitymanager:3.4.0.GA") - optional("org.apache.openjpa:openjpa:1.1.0") - optional("org.eclipse.persistence:org.eclipse.persistence.core:1.0.1") - optional("org.eclipse.persistence:org.eclipse.persistence.jpa:1.0.1") - optional("toplink.essentials:toplink-essentials:2.0-41b") + optional("org.eclipse.persistence:javax.persistence:2.0.0") + optional("org.eclipse.persistence:org.eclipse.persistence.core:2.4.0") + optional("org.eclipse.persistence:org.eclipse.persistence.jpa:2.4.0") + optional("org.hibernate:hibernate-core:3.6.9.Final") + optional("org.hibernate:hibernate-entitymanager:3.6.9.Final") + optional("org.apache.openjpa:openjpa:2.2.1") optional("javax.jdo:jdo-api:3.0") - optional("org.apache.ibatis:ibatis-sqlmap:2.3.4.726") - optional("javax.persistence:persistence-api:1.0") provided("javax.servlet:servlet-api:2.5") testCompile("javax.servlet:javax.servlet-api:3.0.1") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") testCompile("commons-dbcp:commons-dbcp:1.2.2") - testCompile("org.eclipse.persistence:org.eclipse.persistence.asm:1.0.1") - testCompile("org.eclipse.persistence:org.eclipse.persistence.antlr:1.0.1") testCompile("hsqldb:hsqldb:${hsqldbVersion}") compile(project(":spring-core")) compile(project(":spring-beans")) @@ -520,8 +508,8 @@ project("spring-orm-hibernate4") { dependencies { provided(project(":spring-tx")) provided(project(":spring-jdbc")) - optional("org.hibernate:hibernate-core:4.1.0.Final") - optional("org.hibernate:hibernate-entitymanager:4.1.0.Final") + optional("org.hibernate:hibernate-core:4.1.9.Final") + optional("org.hibernate:hibernate-entitymanager:4.1.9.Final") optional(project(":spring-web")) optional("javax.servlet:servlet-api:2.5") } @@ -666,9 +654,9 @@ project("spring-test") { optional("javax.servlet:servlet-api:2.5") optional("javax.servlet.jsp:jsp-api:2.1") optional("javax.portlet:portlet-api:2.0") - optional("javax.persistence:persistence-api:1.0") + optional("org.eclipse.persistence:javax.persistence:2.0.0") optional("org.aspectj:aspectjweaver:${aspectjVersion}") - testCompile("org.hibernate:hibernate-core:3.3.2.GA") + testCompile("org.hibernate:hibernate-core:3.6.9.Final") provided("javax.inject:javax.inject:1") provided("javax.activation:activation:1.1") provided("javax.servlet:jstl:1.2") @@ -738,7 +726,7 @@ project("spring-aspects") { optional(project(":spring-tx")) // for JPA, @Transactional support optional(project(":spring-orm")) // for JPA exception translation support aspects(project(":spring-orm")) - provided("javax.persistence:persistence-api:1.0") + provided("org.eclipse.persistence:javax.persistence:2.0.0") testCompile("javax.mail:mail:1.4") ajc("org.aspectj:aspectjtools:${aspectjVersion}") rt("org.aspectj:aspectjrt:${aspectjVersion}") @@ -786,7 +774,7 @@ configure(rootProject) { testCompile(project(":spring-web")) testCompile(project(":spring-webmvc-portlet")) testCompile(project(":spring-orm")) - testCompile("org.hibernate:hibernate-core:4.1.0.Final") + testCompile("org.hibernate:hibernate-core:4.1.9.Final") testCompile("javax.servlet:servlet-api:2.5") testCompile("javax.portlet:portlet-api:2.0") testCompile("javax.inject:javax.inject:1") diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/FilterDefinitionFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/FilterDefinitionFactoryBean.java index 54bc662c7d6..9b70367e8ae 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/FilterDefinitionFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/FilterDefinitionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -16,18 +16,16 @@ package org.springframework.orm.hibernate3; -import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import org.hibernate.engine.FilterDefinition; import org.hibernate.type.Type; -import org.hibernate.type.TypeFactory; +import org.hibernate.type.TypeResolver; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.ReflectionUtils; /** * Convenient FactoryBean for defining Hibernate FilterDefinitions. @@ -66,29 +64,7 @@ import org.springframework.util.ReflectionUtils; */ public class FilterDefinitionFactoryBean implements FactoryBean, BeanNameAware, InitializingBean { - private static Method heuristicTypeMethod; - - private static Object typeResolver; - - static { - // Hibernate 3.6 TypeResolver class available? - try { - Class trClass = FilterDefinitionFactoryBean.class.getClassLoader().loadClass( - "org.hibernate.type.TypeResolver"); - heuristicTypeMethod = trClass.getMethod("heuristicType", String.class); - typeResolver = trClass.newInstance(); - } - catch (Exception ex) { - try { - heuristicTypeMethod = TypeFactory.class.getMethod("heuristicType", String.class); - typeResolver = null; - } - catch (Exception ex2) { - throw new IllegalStateException("Cannot find Hibernate's heuristicType method", ex2); - } - } - } - + private final TypeResolver typeResolver = new TypeResolver(); private String filterName; @@ -116,8 +92,7 @@ public class FilterDefinitionFactoryBean implements FactoryBean(parameterTypes.size()); for (Map.Entry entry : parameterTypes.entrySet()) { - this.parameterTypeMap.put(entry.getKey(), - (Type) ReflectionUtils.invokeMethod(heuristicTypeMethod, typeResolver, entry.getValue())); + this.parameterTypeMap.put(entry.getKey(), this.typeResolver.heuristicType(entry.getValue())); } } else { diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalCacheProviderProxy.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalCacheProviderProxy.java deleted file mode 100644 index 1c7353697ad..00000000000 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalCacheProviderProxy.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.hibernate3; - -import java.util.Properties; - -import org.hibernate.cache.Cache; -import org.hibernate.cache.CacheException; -import org.hibernate.cache.CacheProvider; - -/** - * Proxy for a Hibernate CacheProvider, delegating to a Spring-managed - * CacheProvider instance, determined by LocalSessionFactoryBean's - * "cacheProvider" property. - * - * @author Juergen Hoeller - * @since 2.5.1 - * @see LocalSessionFactoryBean#setCacheProvider - * @deprecated as of Spring 3.0, following Hibernate 3.3's deprecation - * of the CacheProvider SPI - */ -@Deprecated -public class LocalCacheProviderProxy implements CacheProvider { - - private final CacheProvider cacheProvider; - - - public LocalCacheProviderProxy() { - CacheProvider cp = LocalSessionFactoryBean.getConfigTimeCacheProvider(); - // absolutely needs thread-bound CacheProvider to initialize - if (cp == null) { - throw new IllegalStateException("No Hibernate CacheProvider found - " + - "'cacheProvider' property must be set on LocalSessionFactoryBean"); - } - this.cacheProvider = cp; - } - - - public Cache buildCache(String regionName, Properties properties) throws CacheException { - return this.cacheProvider.buildCache(regionName, properties); - } - - public long nextTimestamp() { - return this.cacheProvider.nextTimestamp(); - } - - public void start(Properties properties) throws CacheException { - this.cacheProvider.start(properties); - } - - public void stop() { - this.cacheProvider.stop(); - } - - public boolean isMinimalPutsEnabledByDefault() { - return this.cacheProvider.isMinimalPutsEnabledByDefault(); - } - -} diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java index 9310853b6e8..858cf93cabc 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java @@ -34,6 +34,7 @@ import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.hibernate.cache.RegionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.cfg.NamingStrategy; @@ -159,19 +160,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen return configTimeRegionFactoryHolder.get(); } - /** - * Return the CacheProvider for the currently configured Hibernate SessionFactory, - * to be used by LocalCacheProviderProxy. - *

This instance will be set before initialization of the corresponding - * SessionFactory, and reset immediately afterwards. It is thus only available - * during configuration. - * @see #setCacheProvider - */ - @SuppressWarnings("deprecation") - public static org.hibernate.cache.CacheProvider getConfigTimeCacheProvider() { - return configTimeCacheProviderHolder.get(); - } - /** * Return the LobHandler for the currently configured Hibernate SessionFactory, * to be used by UserType implementations like ClobStringType. @@ -206,10 +194,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen private TransactionManager jtaTransactionManager; - private Object cacheRegionFactory; - - @SuppressWarnings("deprecation") - private org.hibernate.cache.CacheProvider cacheProvider; + private RegionFactory cacheRegionFactory; private LobHandler lobHandler; @@ -381,32 +366,14 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen /** * Set the Hibernate RegionFactory to use for the SessionFactory. * Allows for using a Spring-managed RegionFactory instance. - *

As of Hibernate 3.3, this is the preferred mechanism for configuring - * caches, superseding the {@link #setCacheProvider CacheProvider SPI}. - * For Hibernate 3.2 compatibility purposes, the accepted reference is of type - * Object: the actual type is {@code org.hibernate.cache.RegionFactory}. *

Note: If this is set, the Hibernate settings should not define a * cache provider to avoid meaningless double configuration. * @see org.hibernate.cache.RegionFactory */ - public void setCacheRegionFactory(Object cacheRegionFactory) { + public void setCacheRegionFactory(RegionFactory cacheRegionFactory) { this.cacheRegionFactory = cacheRegionFactory; } - /** - * Set the Hibernate CacheProvider to use for the SessionFactory. - * Allows for using a Spring-managed CacheProvider instance. - *

Note: If this is set, the Hibernate settings should not define a - * cache provider to avoid meaningless double configuration. - * @deprecated as of Spring 3.0, following Hibernate 3.3's deprecation - * of the CacheProvider SPI - * @see #setCacheRegionFactory - */ - @Deprecated - public void setCacheProvider(org.hibernate.cache.CacheProvider cacheProvider) { - this.cacheProvider = cacheProvider; - } - /** * Set the LobHandler to be used by the SessionFactory. * Will be exposed at config time for UserType implementations. @@ -564,10 +531,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen // Make Spring-provided Hibernate RegionFactory available. configTimeRegionFactoryHolder.set(this.cacheRegionFactory); } - if (this.cacheProvider != null) { - // Make Spring-provided Hibernate CacheProvider available. - configTimeCacheProviderHolder.set(this.cacheProvider); - } if (this.lobHandler != null) { // Make given LobHandler available for SessionFactory configuration. // Do early because because mapping resource might refer to custom types. @@ -668,10 +631,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen config.setProperty(Environment.CACHE_REGION_FACTORY, "org.springframework.orm.hibernate3.LocalRegionFactoryProxy"); } - else if (this.cacheProvider != null) { - // Expose Spring-provided Hibernate CacheProvider. - config.setProperty(Environment.CACHE_PROVIDER, LocalCacheProviderProxy.class.getName()); - } if (this.mappingResources != null) { // Register given Hibernate mapping definitions, contained in resource files. @@ -792,9 +751,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen if (this.cacheRegionFactory != null) { configTimeRegionFactoryHolder.remove(); } - if (this.cacheProvider != null) { - configTimeCacheProviderHolder.remove(); - } if (this.lobHandler != null) { configTimeLobHandlerHolder.remove(); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java index 233ae1fbf5c..bdfd0304439 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -17,9 +17,6 @@ package org.springframework.orm.jpa.persistenceunit; import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.net.URL; import java.util.HashMap; import java.util.HashSet; @@ -96,8 +93,6 @@ public class DefaultPersistenceUnitManager private static final String ENTITY_CLASS_RESOURCE_PATTERN = "/**/*.class"; - private static final boolean jpa2ApiPresent = ClassUtils.hasMethod(PersistenceUnitInfo.class, "getSharedCacheMode"); - private static final TypeFilter[] entityTypeFilters = new TypeFilter[] { new AnnotationTypeFilter(Entity.class, false), new AnnotationTypeFilter(Embeddable.class, false), @@ -384,12 +379,7 @@ public class DefaultPersistenceUnitManager msg.append(this.persistenceUnitInfos.get(name).getPersistenceUnitRootUrl()); throw new IllegalStateException(msg.toString()); } - PersistenceUnitInfo puiToStore = pui; - if (jpa2ApiPresent) { - puiToStore = (PersistenceUnitInfo) Proxy.newProxyInstance(SmartPersistenceUnitInfo.class.getClassLoader(), - new Class[] {SmartPersistenceUnitInfo.class}, new Jpa2PersistenceUnitInfoDecorator(pui)); - } - this.persistenceUnitInfos.put(name, puiToStore); + this.persistenceUnitInfos.put(name, pui); } } @@ -503,15 +493,7 @@ public class DefaultPersistenceUnitManager */ protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) { PersistenceUnitInfo pui = this.persistenceUnitInfos.get(persistenceUnitName); - if (pui != null && Proxy.isProxyClass(pui.getClass())) { - // JPA 2.0 PersistenceUnitInfo decorator with a SpringPersistenceUnitInfo as target - Jpa2PersistenceUnitInfoDecorator dec = (Jpa2PersistenceUnitInfoDecorator) Proxy.getInvocationHandler(pui); - return dec.getTarget(); - } - else { - // Must be a raw JPA 1.0 SpringPersistenceUnitInfo instance - return (MutablePersistenceUnitInfo) pui; - } + return (MutablePersistenceUnitInfo) pui; } /** @@ -574,49 +556,4 @@ public class DefaultPersistenceUnitManager return pui; } - - /** - * Decorator that exposes a JPA 2.0 compliant PersistenceUnitInfo interface for a - * JPA 1.0 based SpringPersistenceUnitInfo object, adapting the {@code getSharedCacheMode} - * and {@code getValidationMode} methods from String names to enum return values. - */ - private static class Jpa2PersistenceUnitInfoDecorator implements InvocationHandler { - - private final SpringPersistenceUnitInfo target; - - private final Class sharedCacheModeEnum; - - private final Class validationModeEnum; - - @SuppressWarnings("unchecked") - public Jpa2PersistenceUnitInfoDecorator(SpringPersistenceUnitInfo target) { - this.target = target; - try { - this.sharedCacheModeEnum = (Class) - ClassUtils.forName("javax.persistence.SharedCacheMode", PersistenceUnitInfo.class.getClassLoader()); - this.validationModeEnum = (Class) - ClassUtils.forName("javax.persistence.ValidationMode", PersistenceUnitInfo.class.getClassLoader()); - } - catch (Exception ex) { - throw new IllegalStateException("JPA 2.0 API enum types not present", ex); - } - } - - public final SpringPersistenceUnitInfo getTarget() { - return this.target; - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if (method.getName().equals("getSharedCacheMode")) { - return Enum.valueOf(this.sharedCacheModeEnum, this.target.getSharedCacheModeName()); - } - else if (method.getName().equals("getValidationMode")) { - return Enum.valueOf(this.validationModeEnum, this.target.getValidationModeName()); - } - else { - return method.invoke(this.target, args); - } - } - } - } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java index 423af5f0261..2b75c78e7b8 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -20,6 +20,8 @@ import java.net.URL; import java.util.LinkedList; import java.util.List; import java.util.Properties; +import javax.persistence.SharedCacheMode; +import javax.persistence.ValidationMode; import javax.persistence.spi.ClassTransformer; import javax.persistence.spi.PersistenceUnitTransactionType; import javax.sql.DataSource; @@ -61,9 +63,13 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { private boolean excludeUnlistedClasses = false; + private SharedCacheMode sharedCacheMode = SharedCacheMode.UNSPECIFIED; + + private ValidationMode validationMode = ValidationMode.AUTO; + private Properties properties = new Properties(); - private String persistenceXMLSchemaVersion = "1.0"; + private String persistenceXMLSchemaVersion = "2.0"; private String persistenceProviderPackageName; @@ -154,6 +160,22 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { return this.excludeUnlistedClasses; } + public void setSharedCacheMode(SharedCacheMode sharedCacheMode) { + this.sharedCacheMode = sharedCacheMode; + } + + public SharedCacheMode getSharedCacheMode() { + return this.sharedCacheMode; + } + + public void setValidationMode(ValidationMode validationMode) { + this.validationMode = validationMode; + } + + public ValidationMode getValidationMode() { + return this.validationMode; + } + public void addProperty(String name, String value) { if (this.properties == null) { this.properties = new Properties(); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java index 78f00a9f2e9..d2af772d348 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,6 +21,8 @@ import java.io.InputStream; import java.net.URL; import java.util.LinkedList; import java.util.List; +import javax.persistence.SharedCacheMode; +import javax.persistence.ValidationMode; import javax.persistence.spi.PersistenceUnitTransactionType; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -273,13 +275,13 @@ class PersistenceUnitReader { // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { - unitInfo.setSharedCacheModeName(cacheMode); + unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { - unitInfo.setValidationModeName(validationMode); + unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java index 6d7e94956fd..a3d91715972 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2013 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. @@ -22,7 +22,6 @@ import org.springframework.core.DecoratingClassLoader; import org.springframework.instrument.classloading.LoadTimeWeaver; import org.springframework.instrument.classloading.SimpleThrowawayClassLoader; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; /** * Subclass of {@link MutablePersistenceUnitInfo} that adds instrumentation hooks based on @@ -38,39 +37,11 @@ import org.springframework.util.StringUtils; */ class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo { - private static final String DEFAULT_SHARED_CACHE_MODE_NAME = "UNSPECIFIED"; - - private static final String DEFAULT_VALIDATION_MODE_NAME = "AUTO"; - - - private String sharedCacheModeName = DEFAULT_SHARED_CACHE_MODE_NAME; - - private String validationModeName = DEFAULT_VALIDATION_MODE_NAME; - private LoadTimeWeaver loadTimeWeaver; private ClassLoader classLoader; - public void setSharedCacheModeName(String sharedCacheModeName) { - this.sharedCacheModeName = - (StringUtils.hasLength(sharedCacheModeName) ? sharedCacheModeName : DEFAULT_SHARED_CACHE_MODE_NAME); - } - - public String getSharedCacheModeName() { - return this.sharedCacheModeName; - } - - public void setValidationModeName(String validationModeName) { - this.validationModeName = - (StringUtils.hasLength(validationModeName) ? validationModeName : DEFAULT_VALIDATION_MODE_NAME); - } - - public String getValidationModeName() { - return this.validationModeName; - } - - /** * Initialize this PersistenceUnitInfo with the LoadTimeWeaver SPI interface * used by Spring to add instrumentation to the current class loader. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java index 9d0160f436e..81523404a92 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,8 +34,7 @@ import org.springframework.transaction.TransactionException; /** * {@link org.springframework.orm.jpa.JpaDialect} implementation for Eclipse - * Persistence Services (EclipseLink). Developed and tested against EclipseLink - * 1.0 as well as 2.0-2.3. + * Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.4. * *

By default, this class acquires a EclipseLink transaction to get the JDBC Connection * early. This allows mixing JDBC and JPA/EclipseLink operations in the same transaction. @@ -46,10 +45,6 @@ import org.springframework.transaction.TransactionException; * to ensure that the cost of connection acquisition is near zero until code actually * needs a JDBC Connection. * - *

This class is very analogous to {@link TopLinkJpaDialect}, since - * EclipseLink is effectively the next generation of the TopLink product. - * Thanks to Mike Keith for the original EclipseLink support prototype! - * * @author Juergen Hoeller * @since 2.5.2 * @see #setLazyDatabaseTransaction diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java index 1dd5764059c..a977c087397 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaVendorAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,19 +30,11 @@ import org.springframework.orm.jpa.JpaDialect; /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Eclipse - * Persistence Services (EclipseLink). Developed and tested against EclipseLink - * 1.0 as well as 2.0-2.3. + * Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.4. * *

Exposes EclipseLink's persistence provider and EntityManager extension interface, * and supports {@link AbstractJpaVendorAdapter}'s common configuration settings. * - *

This class is very analogous to {@link TopLinkJpaVendorAdapter}, since - * EclipseLink is effectively the next generation of the TopLink product. - * Thanks to Mike Keith for the original EclipseLink support prototype! - * - *

NOTE: No need to filter out classes from the JPA providers package for - * EclipseLink (see SPR-6040) - * * @author Juergen Hoeller * @author Thomas Risberg * @since 2.5.2 diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java index 1293b335d4a..b859b1049ae 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java @@ -39,9 +39,7 @@ import org.springframework.util.ReflectionUtils; /** * {@link org.springframework.orm.jpa.JpaDialect} implementation for - * Hibernate EntityManager. Developed against Hibernate 3.3; - * tested against 3.3, 3.5, 3.6 and 4.0 (with the latter including - * Hibernate EntityManager in the Hibernate core distribution). + * Hibernate EntityManager. Developed against Hibernate 3.6 and 4.2. * * @author Costin Leau * @author Juergen Hoeller diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java index d48a7b762ea..b3eec049125 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java @@ -41,7 +41,7 @@ import org.springframework.orm.jpa.JpaDialect; /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for - * Hibernate EntityManager. Developed and tested against Hibernate 3.3. + * Hibernate EntityManager. Developed and tested against Hibernate 3.6 and 4.2. * *

Exposes Hibernate's persistence provider and EntityManager extension interface, * and supports {@link AbstractJpaVendorAdapter}'s common configuration settings. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java index e7db382d0ed..fd03de26353 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaDialect.java @@ -34,7 +34,7 @@ import org.springframework.transaction.TransactionException; /** * {@link org.springframework.orm.jpa.JpaDialect} implementation for Apache OpenJPA. - * Developed and tested against OpenJPA 1.1 as well as 2.0/2.1. + * Developed and tested against OpenJPA 2.2. * * @author Costin Leau * @author Juergen Hoeller diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java index 34fc0d4a1c3..abadbf8b297 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/OpenJpaVendorAdapter.java @@ -30,7 +30,7 @@ import org.springframework.orm.jpa.JpaDialect; /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Apache OpenJPA. - * Developed and tested against OpenJPA 1.1 as well as 2.0/2.1. + * Developed and tested against OpenJPA 2.2. * *

Exposes OpenJPA's persistence provider and EntityManager extension interface, * and supports {@link AbstractJpaVendorAdapter}'s common configuration settings. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaDialect.java deleted file mode 100644 index 16c789efb54..00000000000 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaDialect.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.jpa.vendor; - -import java.sql.Connection; -import java.sql.SQLException; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; - -import oracle.toplink.essentials.internal.sessions.AbstractSession; -import oracle.toplink.essentials.sessions.Session; -import oracle.toplink.essentials.sessions.UnitOfWork; - -import org.springframework.jdbc.datasource.ConnectionHandle; -import org.springframework.jdbc.datasource.SimpleConnectionHandle; -import org.springframework.orm.jpa.DefaultJpaDialect; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionException; - -/** - * {@link org.springframework.orm.jpa.JpaDialect} implementation for - * Oracle TopLink Essentials. Developed and tested against TopLink Essentials v2. - * - *

By default, this class acquires a TopLink transaction to get the JDBC Connection - * early. This allows mixing JDBC and JPA/TopLink operations in the same transaction. - * In some cases, this eager acquisition of a transaction/connection may impact - * scalability. In that case, set the "lazyDatabaseTransaction" flag to true if you - * do not require mixing JDBC and JPA operations in the same transaction. Otherwise, - * use a {@link org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy} - * to ensure that the cost of connection acquisition is near zero until code actually - * needs a JDBC Connection. - * - * @author Rod Johnson - * @author Juergen Hoeller - * @since 2.0 - * @see #setLazyDatabaseTransaction - * @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy - * @deprecated as of Spring 3.1, in favor of the EclipseLink project and - * Spring's corresponding {@link EclipseLinkJpaDialect} - */ -@Deprecated -@SuppressWarnings("serial") -public class TopLinkJpaDialect extends DefaultJpaDialect { - - private boolean lazyDatabaseTransaction = false; - - - /** - * Set whether to lazily start a database transaction within a TopLink - * transaction. - *

By default, database transactions are started early. This allows - * for reusing the same JDBC Connection throughout an entire transaction, - * including read operations, and also for exposing TopLink transactions - * to JDBC access code (working on the same DataSource). - *

It is only recommended to switch this flag to "true" when no JDBC access - * code is involved in any of the transactions, and when it is acceptable to - * perform read operations outside of the transactional JDBC Connection. - * @see oracle.toplink.essentials.sessions.UnitOfWork#beginEarlyTransaction() - */ - public void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) { - this.lazyDatabaseTransaction = lazyDatabaseTransaction; - } - - - @Override - public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) - throws PersistenceException, SQLException, TransactionException { - - super.beginTransaction(entityManager, definition); - if (!definition.isReadOnly() && !this.lazyDatabaseTransaction) { - // This is the magic bit. As with the existing Spring TopLink integration, - // begin an early transaction to force TopLink to get a JDBC Connection - // so that Spring can manage transactions with JDBC as well as TopLink. - UnitOfWork uow = (UnitOfWork) getSession(entityManager); - uow.beginEarlyTransaction(); - } - // Could return the UOW, if there were any advantage in having it later. - return null; - } - - @Override - public ConnectionHandle getJdbcConnection(EntityManager em, boolean readOnly) - throws PersistenceException, SQLException { - - AbstractSession session = (AbstractSession) getSession(em); - // The connection was already acquired eagerly in beginTransaction, - // unless lazyDatabaseTransaction was set to true. - Connection con = session.getAccessor().getConnection(); - return (con != null ? new SimpleConnectionHandle(con) : null); - } - - /** - * Get a traditional TopLink Session from the given EntityManager. - */ - protected Session getSession(EntityManager em) { - oracle.toplink.essentials.ejb.cmp3.EntityManager emi = (oracle.toplink.essentials.ejb.cmp3.EntityManager) em; - return emi.getActiveSession(); - } - -} diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaVendorAdapter.java deleted file mode 100644 index 36e18be4ef0..00000000000 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/TopLinkJpaVendorAdapter.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.jpa.vendor; - -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import javax.persistence.EntityManager; -import javax.persistence.spi.PersistenceProvider; - -import oracle.toplink.essentials.config.TargetDatabase; -import oracle.toplink.essentials.config.TopLinkProperties; -import oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider; - -import org.springframework.orm.jpa.JpaDialect; - -/** - * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for - * Oracle TopLink Essentials. Developed and tested against TopLink Essentials v2. - * - *

Exposes TopLink's persistence provider and EntityManager extension interface, - * and supports {@link AbstractJpaVendorAdapter}'s common configuration settings. - * - * @author Rod Johnson - * @author Juergen Hoeller - * @since 2.0 - * @see oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider - * @see oracle.toplink.essentials.ejb.cmp3.EntityManager - * @deprecated as of Spring 3.1, in favor of the EclipseLink project and - * Spring's corresponding {@link EclipseLinkJpaVendorAdapter} - */ -@Deprecated -public class TopLinkJpaVendorAdapter extends AbstractJpaVendorAdapter { - - private final PersistenceProvider persistenceProvider = new EntityManagerFactoryProvider(); - - private final JpaDialect jpaDialect = new TopLinkJpaDialect(); - - - public PersistenceProvider getPersistenceProvider() { - return this.persistenceProvider; - } - - @Override - public String getPersistenceProviderRootPackage() { - return "oracle.toplink.essentials"; - } - - @Override - public Map getJpaPropertyMap() { - Map jpaProperties = new HashMap(); - - if (getDatabasePlatform() != null) { - jpaProperties.put(TopLinkProperties.TARGET_DATABASE, getDatabasePlatform()); - } - else if (getDatabase() != null) { - String targetDatabase = determineTargetDatabaseName(getDatabase()); - if (targetDatabase != null) { - jpaProperties.put(TopLinkProperties.TARGET_DATABASE, targetDatabase); - } - } - - if (isGenerateDdl()) { - jpaProperties.put(EntityManagerFactoryProvider.DDL_GENERATION, - EntityManagerFactoryProvider.CREATE_ONLY); - jpaProperties.put(EntityManagerFactoryProvider.DDL_GENERATION_MODE, - EntityManagerFactoryProvider.DDL_DATABASE_GENERATION); - } - if (isShowSql()) { - jpaProperties.put(TopLinkProperties.LOGGING_LEVEL, Level.FINE.toString()); - } - - return jpaProperties; - } - - /** - * Determine the TopLink target database name for the given database. - * @param database the specified database - * @return the TopLink target database name, or {@code null} if none found - */ - protected String determineTargetDatabaseName(Database database) { - switch (database) { - case DB2: return TargetDatabase.DB2; - case DERBY: return TargetDatabase.Derby; - case HSQL: return TargetDatabase.HSQL; - case INFORMIX: return TargetDatabase.Informix; - case MYSQL: return TargetDatabase.MySQL4; - case ORACLE: return TargetDatabase.Oracle; - case POSTGRESQL: return TargetDatabase.PostgreSQL; - case SQL_SERVER: return TargetDatabase.SQLServer; - case SYBASE: return TargetDatabase.Sybase; - default: return null; - } - } - - @Override - public JpaDialect getJpaDialect() { - return this.jpaDialect; - } - - @Override - public Class getEntityManagerInterface() { - return oracle.toplink.essentials.ejb.cmp3.EntityManager.class; - } - -} diff --git a/spring-orm/src/test/java/org/springframework/orm/hibernate3/LocalSessionFactoryBeanTests.java b/spring-orm/src/test/java/org/springframework/orm/hibernate3/LocalSessionFactoryBeanTests.java index 91972e57b09..d7368ee8e33 100644 --- a/spring-orm/src/test/java/org/springframework/orm/hibernate3/LocalSessionFactoryBeanTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/hibernate3/LocalSessionFactoryBeanTests.java @@ -138,43 +138,6 @@ public class LocalSessionFactoryBeanTests { assertEquals("newSessionFactory", invocations.get(0)); } - @Test - @SuppressWarnings("serial") - public void testLocalSessionFactoryBeanWithCacheProvider() throws Exception { - final CacheProvider cacheProvider = new NoCacheProvider(); - final List invocations = new ArrayList(); - LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() { - @Override - protected Configuration newConfiguration() { - return new Configuration() { - @Override - public Configuration addInputStream(InputStream is) { - try { - is.close(); - } - catch (IOException ex) { - } - invocations.add("addResource"); - return this; - } - }; - } - - @Override - protected SessionFactory newSessionFactory(Configuration config) { - assertEquals(LocalCacheProviderProxy.class.getName(), - config.getProperty(Environment.CACHE_PROVIDER)); - assertSame(cacheProvider, LocalSessionFactoryBean.getConfigTimeCacheProvider()); - invocations.add("newSessionFactory"); - return null; - } - }; - sfb.setCacheProvider(cacheProvider); - sfb.afterPropertiesSet(); - assertTrue(sfb.getConfiguration() != null); - assertEquals("newSessionFactory", invocations.get(0)); - } - @Test @SuppressWarnings("serial") public void testLocalSessionFactoryBeanWithTransactionAwareDataSource() throws Exception { @@ -513,10 +476,10 @@ public class LocalSessionFactoryBeanTests { @Override protected Configuration newConfiguration() { return new Configuration() { - // changed from return type 'void' to 'Configuration' in Hibernate 3.6 @Override - public void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) { + public Configuration setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) { registeredClassCache.setProperty(clazz, concurrencyStrategy + "," + regionName); + return this; } @Override public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String regionName) { 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 aac1b766bef..c4ae64b3c86 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -94,7 +94,6 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests @ExpectedException(EntityNotFoundException.class) public void testGetReferenceWhenNoRow() { - // Fails here with TopLink Person notThere = sharedEntityManager.getReference(Person.class, 666); // We may get here (as with Hibernate). 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 8b40e31b1eb..66c93e0a417 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 @@ -25,10 +25,6 @@ import org.springframework.transaction.support.TransactionSynchronizationManager */ public abstract class AbstractEntityManagerFactoryIntegrationTests extends AbstractJpaTests { - public static final String[] TOPLINK_CONFIG_LOCATIONS = new String[] { - "/org/springframework/orm/jpa/toplink/toplink-manager.xml", "/org/springframework/orm/jpa/memdb.xml", - "/org/springframework/orm/jpa/inject.xml"}; - public static final String[] ECLIPSELINK_CONFIG_LOCATIONS = new String[] { "/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml", "/org/springframework/orm/jpa/memdb.xml", "/org/springframework/orm/jpa/inject.xml"}; @@ -45,9 +41,6 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr public static Provider getProvider() { String provider = System.getProperty("org.springframework.orm.jpa.provider"); if (provider != null) { - if (provider.toLowerCase().contains("eclipselink")) { - return Provider.ECLIPSELINK; - } if (provider.toLowerCase().contains("hibernate")) { return Provider.HIBERNATE; } @@ -55,7 +48,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr return Provider.OPENJPA; } } - return Provider.TOPLINK; + return Provider.ECLIPSELINK; } @@ -69,10 +62,10 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr protected String[] getConfigLocations() { Provider provider = getProvider(); switch (provider) { + case ECLIPSELINK: + return ECLIPSELINK_CONFIG_LOCATIONS; case HIBERNATE: return HIBERNATE_CONFIG_LOCATIONS; - case TOPLINK: - return TOPLINK_CONFIG_LOCATIONS; case OPENJPA: return OPENJPA_CONFIG_LOCATIONS; default: @@ -90,7 +83,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr public enum Provider { - TOPLINK, ECLIPSELINK, HIBERNATE, OPENJPA - }; + ECLIPSELINK, HIBERNATE, OPENJPA + } } 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 391a067a580..04a40587115 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 @@ -158,19 +158,4 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit deleteFromTables(new String[] { "person" }); } - /* - * TODO: This displays incorrect behavior in TopLink because of its EJBQLException - - * which is not a subclass of PersistenceException but rather of TopLinkException! - public void testEntityManagerProxyException() { - EntityManager em = entityManagerFactory.createEntityManager(); - try { - em.createQuery("select p from Person p where p.o=0").getResultList(); - fail("Semantic nonsense should be rejected"); - } - catch (PersistenceException ex) { - // expected - } - } - */ - } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBeanTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBeanTests.java index 7ab71bc860a..7d035b05a04 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBeanTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBeanTests.java @@ -18,7 +18,6 @@ package org.springframework.orm.jpa; import java.util.Map; import java.util.Properties; - import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.EntityTransaction; @@ -27,8 +26,10 @@ import javax.persistence.PersistenceException; import javax.persistence.spi.PersistenceProvider; import javax.persistence.spi.PersistenceUnitInfo; import javax.persistence.spi.PersistenceUnitTransactionType; +import javax.persistence.spi.ProviderUtil; import org.junit.Test; + import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.dao.DataAccessException; import org.springframework.dao.OptimisticLockingFailureException; @@ -317,6 +318,11 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM public EntityManagerFactory createEntityManagerFactory(String emfName, Map properties) { throw new UnsupportedOperationException(); } + + @Override + public ProviderUtil getProviderUtil() { + throw new UnsupportedOperationException(); + } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java index bbf407b3807..afe4572b044 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBeanTests.java @@ -22,6 +22,7 @@ import java.util.Properties; import javax.persistence.EntityManagerFactory; import javax.persistence.spi.PersistenceProvider; import javax.persistence.spi.PersistenceUnitInfo; +import javax.persistence.spi.ProviderUtil; import org.junit.After; import org.junit.Test; @@ -94,6 +95,11 @@ public class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFac actualProps = properties; return mockEmf; } + + @Override + public ProviderUtil getProviderUtil() { + throw new UnsupportedOperationException(); + } } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java index 754baa1c87f..b9e6fcff087 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java @@ -45,7 +45,6 @@ public class ContextualPerson { private transient TestBean testBean; // Lazy relationship to force use of instrumentation in JPA implementation. - // TopLink, at least, will not instrument classes unless absolutely necessary. @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) @JoinColumn(name="DRIVERS_LICENSE_ID") private DriversLicense driversLicense; diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java index c1080b493ff..cb850b1ab92 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java @@ -45,7 +45,6 @@ public class Person { private transient TestBean testBean; // Lazy relationship to force use of instrumentation in JPA implementation. - // TopLink, at least, will not instrument classes unless absolutely necessary. @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) @JoinColumn(name="DRIVERS_LICENSE_ID") private DriversLicense driversLicense; diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/eclipselink/EclipseLinkEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/eclipselink/EclipseLinkEntityManagerFactoryIntegrationTests.java index 1802b16d2f9..f621f7ea67f 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/eclipselink/EclipseLinkEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/eclipselink/EclipseLinkEntityManagerFactoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,12 +34,12 @@ public class EclipseLinkEntityManagerFactoryIntegrationTests extends AbstractCon } - public void testCanCastNativeEntityManagerFactoryToTopLinkEntityManagerFactoryImpl() { + public void testCanCastNativeEntityManagerFactoryToEclipseLinkEntityManagerFactoryImpl() { EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl")); } - public void testCanCastSharedEntityManagerProxyToTopLinkEntityManager() { + public void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() { assertTrue(sharedEntityManager instanceof JpaEntityManager); JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager; assertNotNull(eclipselinkEntityManager.getActiveSession()); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkEntityManagerFactoryIntegrationTests.java deleted file mode 100644 index c3bef0c2837..00000000000 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkEntityManagerFactoryIntegrationTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.jpa.toplink; - -import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; -import org.springframework.orm.jpa.EntityManagerFactoryInfo; - -/** - * TopLink-specific JPA tests. - * - * @author Costin Leau - * @author Rod Johnson - * @author Juergen Hoeller - */ -public class TopLinkEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests { - - @Override - protected String[] getConfigLocations() { - return TOPLINK_CONFIG_LOCATIONS; - } - - - public void testCanCastNativeEntityManagerFactoryToTopLinkEntityManagerFactoryImpl() { - EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; - assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl")); - } - - public void testCanCastSharedEntityManagerProxyToTopLinkEntityManager() { - assertTrue(sharedEntityManager instanceof oracle.toplink.essentials.ejb.cmp3.EntityManager); - oracle.toplink.essentials.ejb.cmp3.EntityManager toplinkEntityManager = - (oracle.toplink.essentials.ejb.cmp3.EntityManager) sharedEntityManager; - assertNotNull(toplinkEntityManager.getActiveSession()); - } - -} diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkMultiEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkMultiEntityManagerFactoryIntegrationTests.java deleted file mode 100644 index 7b743131143..00000000000 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/TopLinkMultiEntityManagerFactoryIntegrationTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2002-2013 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.orm.jpa.toplink; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -import org.junit.Ignore; -import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; - -/** - * Toplink-specific JPA tests with multiple EntityManagerFactory instances. - * - * @author Costin Leau - * @author Chris Beams - */ -@Ignore("This test causes gradle to hang. See SPR-10333.") -public class TopLinkMultiEntityManagerFactoryIntegrationTests extends - AbstractContainerEntityManagerFactoryIntegrationTests { - - private EntityManagerFactory entityManagerFactory2; - - - @SuppressWarnings("deprecation") - public TopLinkMultiEntityManagerFactoryIntegrationTests() { - setAutowireMode(AUTOWIRE_BY_NAME); - } - - public void setEntityManagerFactory2(EntityManagerFactory entityManagerFactory2) { - this.entityManagerFactory2 = entityManagerFactory2; - } - - @Override - protected String[] getConfigLocations() { - return new String[] { - "/org/springframework/orm/jpa/toplink/toplink-manager-multi.xml", - "/org/springframework/orm/jpa/memdb.xml" - }; - } - - - public void testEntityManagerFactory2() { - EntityManager em = this.entityManagerFactory2.createEntityManager(); - try { - em.createQuery("select tb from TestBean"); - fail("Should have thrown IllegalArgumentException"); - } - catch (IllegalArgumentException ex) { - // expected - } - finally { - em.close(); - } - } - -} diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager-multi.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager-multi.xml deleted file mode 100644 index a6869f952b5..00000000000 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager-multi.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager.xml deleted file mode 100644 index a3cbcfc899f..00000000000 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/toplink/toplink-manager.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - -