General JPA 2.0+ requirement; upgraded build and tests to EclipseLink 2.4, OpenJPA 2.2, Hibernate 3.6
This commit is contained in:
40
build.gradle
40
build.gradle
@@ -305,7 +305,7 @@ project("spring-context") {
|
|||||||
optional("javax.ejb:ejb-api:3.0")
|
optional("javax.ejb:ejb-api:3.0")
|
||||||
optional("javax.inject:javax.inject:1")
|
optional("javax.inject:javax.inject:1")
|
||||||
optional("org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.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("javax.validation:validation-api:1.0.0.GA")
|
||||||
optional("org.beanshell:bsh:2.0b4")
|
optional("org.beanshell:bsh:2.0b4")
|
||||||
optional("org.codehaus.groovy:groovy-all:1.8.8")
|
optional("org.codehaus.groovy:groovy-all:1.8.8")
|
||||||
@@ -336,7 +336,7 @@ project("spring-tx") {
|
|||||||
optional("javax.resource:connector-api:1.5")
|
optional("javax.resource:connector-api:1.5")
|
||||||
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
|
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
|
||||||
optional("javax.ejb:ejb-api:3.0")
|
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}")
|
testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,31 +478,19 @@ project("spring-web") {
|
|||||||
project("spring-orm") {
|
project("spring-orm") {
|
||||||
description = "Spring Object/Relational Mapping"
|
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 {
|
dependencies {
|
||||||
compile("aopalliance:aopalliance:1.0")
|
compile("aopalliance:aopalliance:1.0")
|
||||||
optional("org.hibernate:hibernate-core:3.3.2.GA")
|
optional("org.eclipse.persistence:javax.persistence:2.0.0")
|
||||||
optional("org.hibernate:hibernate-annotations:3.4.0.GA")
|
optional("org.eclipse.persistence:org.eclipse.persistence.core:2.4.0")
|
||||||
optional("org.hibernate:hibernate-entitymanager:3.4.0.GA")
|
optional("org.eclipse.persistence:org.eclipse.persistence.jpa:2.4.0")
|
||||||
optional("org.apache.openjpa:openjpa:1.1.0")
|
optional("org.hibernate:hibernate-core:3.6.9.Final")
|
||||||
optional("org.eclipse.persistence:org.eclipse.persistence.core:1.0.1")
|
optional("org.hibernate:hibernate-entitymanager:3.6.9.Final")
|
||||||
optional("org.eclipse.persistence:org.eclipse.persistence.jpa:1.0.1")
|
optional("org.apache.openjpa:openjpa:2.2.1")
|
||||||
optional("toplink.essentials:toplink-essentials:2.0-41b")
|
|
||||||
optional("javax.jdo:jdo-api:3.0")
|
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")
|
provided("javax.servlet:servlet-api:2.5")
|
||||||
testCompile("javax.servlet:javax.servlet-api:3.0.1")
|
testCompile("javax.servlet:javax.servlet-api:3.0.1")
|
||||||
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
||||||
testCompile("commons-dbcp:commons-dbcp:1.2.2")
|
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}")
|
testCompile("hsqldb:hsqldb:${hsqldbVersion}")
|
||||||
compile(project(":spring-core"))
|
compile(project(":spring-core"))
|
||||||
compile(project(":spring-beans"))
|
compile(project(":spring-beans"))
|
||||||
@@ -520,8 +508,8 @@ project("spring-orm-hibernate4") {
|
|||||||
dependencies {
|
dependencies {
|
||||||
provided(project(":spring-tx"))
|
provided(project(":spring-tx"))
|
||||||
provided(project(":spring-jdbc"))
|
provided(project(":spring-jdbc"))
|
||||||
optional("org.hibernate:hibernate-core:4.1.0.Final")
|
optional("org.hibernate:hibernate-core:4.1.9.Final")
|
||||||
optional("org.hibernate:hibernate-entitymanager:4.1.0.Final")
|
optional("org.hibernate:hibernate-entitymanager:4.1.9.Final")
|
||||||
optional(project(":spring-web"))
|
optional(project(":spring-web"))
|
||||||
optional("javax.servlet:servlet-api:2.5")
|
optional("javax.servlet:servlet-api:2.5")
|
||||||
}
|
}
|
||||||
@@ -666,9 +654,9 @@ project("spring-test") {
|
|||||||
optional("javax.servlet:servlet-api:2.5")
|
optional("javax.servlet:servlet-api:2.5")
|
||||||
optional("javax.servlet.jsp:jsp-api:2.1")
|
optional("javax.servlet.jsp:jsp-api:2.1")
|
||||||
optional("javax.portlet:portlet-api:2.0")
|
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}")
|
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.inject:javax.inject:1")
|
||||||
provided("javax.activation:activation:1.1")
|
provided("javax.activation:activation:1.1")
|
||||||
provided("javax.servlet:jstl:1.2")
|
provided("javax.servlet:jstl:1.2")
|
||||||
@@ -738,7 +726,7 @@ project("spring-aspects") {
|
|||||||
optional(project(":spring-tx")) // for JPA, @Transactional support
|
optional(project(":spring-tx")) // for JPA, @Transactional support
|
||||||
optional(project(":spring-orm")) // for JPA exception translation support
|
optional(project(":spring-orm")) // for JPA exception translation support
|
||||||
aspects(project(":spring-orm"))
|
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")
|
testCompile("javax.mail:mail:1.4")
|
||||||
ajc("org.aspectj:aspectjtools:${aspectjVersion}")
|
ajc("org.aspectj:aspectjtools:${aspectjVersion}")
|
||||||
rt("org.aspectj:aspectjrt:${aspectjVersion}")
|
rt("org.aspectj:aspectjrt:${aspectjVersion}")
|
||||||
@@ -786,7 +774,7 @@ configure(rootProject) {
|
|||||||
testCompile(project(":spring-web"))
|
testCompile(project(":spring-web"))
|
||||||
testCompile(project(":spring-webmvc-portlet"))
|
testCompile(project(":spring-webmvc-portlet"))
|
||||||
testCompile(project(":spring-orm"))
|
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.servlet:servlet-api:2.5")
|
||||||
testCompile("javax.portlet:portlet-api:2.0")
|
testCompile("javax.portlet:portlet-api:2.0")
|
||||||
testCompile("javax.inject:javax.inject:1")
|
testCompile("javax.inject:javax.inject:1")
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,18 +16,16 @@
|
|||||||
|
|
||||||
package org.springframework.orm.hibernate3;
|
package org.springframework.orm.hibernate3;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.engine.FilterDefinition;
|
import org.hibernate.engine.FilterDefinition;
|
||||||
import org.hibernate.type.Type;
|
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.BeanNameAware;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient FactoryBean for defining Hibernate FilterDefinitions.
|
* Convenient FactoryBean for defining Hibernate FilterDefinitions.
|
||||||
@@ -66,29 +64,7 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
*/
|
*/
|
||||||
public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition>, BeanNameAware, InitializingBean {
|
public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition>, BeanNameAware, InitializingBean {
|
||||||
|
|
||||||
private static Method heuristicTypeMethod;
|
private final TypeResolver typeResolver = new TypeResolver();
|
||||||
|
|
||||||
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 String filterName;
|
private String filterName;
|
||||||
|
|
||||||
@@ -116,8 +92,7 @@ public class FilterDefinitionFactoryBean implements FactoryBean<FilterDefinition
|
|||||||
if (parameterTypes != null) {
|
if (parameterTypes != null) {
|
||||||
this.parameterTypeMap = new HashMap<String, Type>(parameterTypes.size());
|
this.parameterTypeMap = new HashMap<String, Type>(parameterTypes.size());
|
||||||
for (Map.Entry<String, String> entry : parameterTypes.entrySet()) {
|
for (Map.Entry<String, String> entry : parameterTypes.entrySet()) {
|
||||||
this.parameterTypeMap.put(entry.getKey(),
|
this.parameterTypeMap.put(entry.getKey(), this.typeResolver.heuristicType(entry.getValue()));
|
||||||
(Type) ReflectionUtils.invokeMethod(heuristicTypeMethod, typeResolver, entry.getValue()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -34,6 +34,7 @@ import org.hibernate.HibernateException;
|
|||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cache.RegionFactory;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
@@ -159,19 +160,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||||||
return configTimeRegionFactoryHolder.get();
|
return configTimeRegionFactoryHolder.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the CacheProvider for the currently configured Hibernate SessionFactory,
|
|
||||||
* to be used by LocalCacheProviderProxy.
|
|
||||||
* <p>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,
|
* Return the LobHandler for the currently configured Hibernate SessionFactory,
|
||||||
* to be used by UserType implementations like ClobStringType.
|
* to be used by UserType implementations like ClobStringType.
|
||||||
@@ -206,10 +194,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||||||
|
|
||||||
private TransactionManager jtaTransactionManager;
|
private TransactionManager jtaTransactionManager;
|
||||||
|
|
||||||
private Object cacheRegionFactory;
|
private RegionFactory cacheRegionFactory;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private org.hibernate.cache.CacheProvider cacheProvider;
|
|
||||||
|
|
||||||
private LobHandler lobHandler;
|
private LobHandler lobHandler;
|
||||||
|
|
||||||
@@ -381,32 +366,14 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||||||
/**
|
/**
|
||||||
* Set the Hibernate RegionFactory to use for the SessionFactory.
|
* Set the Hibernate RegionFactory to use for the SessionFactory.
|
||||||
* Allows for using a Spring-managed RegionFactory instance.
|
* Allows for using a Spring-managed RegionFactory instance.
|
||||||
* <p>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}.
|
|
||||||
* <p>Note: If this is set, the Hibernate settings should not define a
|
* <p>Note: If this is set, the Hibernate settings should not define a
|
||||||
* cache provider to avoid meaningless double configuration.
|
* cache provider to avoid meaningless double configuration.
|
||||||
* @see org.hibernate.cache.RegionFactory
|
* @see org.hibernate.cache.RegionFactory
|
||||||
*/
|
*/
|
||||||
public void setCacheRegionFactory(Object cacheRegionFactory) {
|
public void setCacheRegionFactory(RegionFactory cacheRegionFactory) {
|
||||||
this.cacheRegionFactory = cacheRegionFactory;
|
this.cacheRegionFactory = cacheRegionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the Hibernate CacheProvider to use for the SessionFactory.
|
|
||||||
* Allows for using a Spring-managed CacheProvider instance.
|
|
||||||
* <p>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.
|
* Set the LobHandler to be used by the SessionFactory.
|
||||||
* Will be exposed at config time for UserType implementations.
|
* 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.
|
// Make Spring-provided Hibernate RegionFactory available.
|
||||||
configTimeRegionFactoryHolder.set(this.cacheRegionFactory);
|
configTimeRegionFactoryHolder.set(this.cacheRegionFactory);
|
||||||
}
|
}
|
||||||
if (this.cacheProvider != null) {
|
|
||||||
// Make Spring-provided Hibernate CacheProvider available.
|
|
||||||
configTimeCacheProviderHolder.set(this.cacheProvider);
|
|
||||||
}
|
|
||||||
if (this.lobHandler != null) {
|
if (this.lobHandler != null) {
|
||||||
// Make given LobHandler available for SessionFactory configuration.
|
// Make given LobHandler available for SessionFactory configuration.
|
||||||
// Do early because because mapping resource might refer to custom types.
|
// 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,
|
config.setProperty(Environment.CACHE_REGION_FACTORY,
|
||||||
"org.springframework.orm.hibernate3.LocalRegionFactoryProxy");
|
"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) {
|
if (this.mappingResources != null) {
|
||||||
// Register given Hibernate mapping definitions, contained in resource files.
|
// Register given Hibernate mapping definitions, contained in resource files.
|
||||||
@@ -792,9 +751,6 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
|||||||
if (this.cacheRegionFactory != null) {
|
if (this.cacheRegionFactory != null) {
|
||||||
configTimeRegionFactoryHolder.remove();
|
configTimeRegionFactoryHolder.remove();
|
||||||
}
|
}
|
||||||
if (this.cacheProvider != null) {
|
|
||||||
configTimeCacheProviderHolder.remove();
|
|
||||||
}
|
|
||||||
if (this.lobHandler != null) {
|
if (this.lobHandler != null) {
|
||||||
configTimeLobHandlerHolder.remove();
|
configTimeLobHandlerHolder.remove();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,9 +17,6 @@
|
|||||||
package org.springframework.orm.jpa.persistenceunit;
|
package org.springframework.orm.jpa.persistenceunit;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -96,8 +93,6 @@ public class DefaultPersistenceUnitManager
|
|||||||
private static final String ENTITY_CLASS_RESOURCE_PATTERN = "/**/*.class";
|
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[] {
|
private static final TypeFilter[] entityTypeFilters = new TypeFilter[] {
|
||||||
new AnnotationTypeFilter(Entity.class, false),
|
new AnnotationTypeFilter(Entity.class, false),
|
||||||
new AnnotationTypeFilter(Embeddable.class, false),
|
new AnnotationTypeFilter(Embeddable.class, false),
|
||||||
@@ -384,12 +379,7 @@ public class DefaultPersistenceUnitManager
|
|||||||
msg.append(this.persistenceUnitInfos.get(name).getPersistenceUnitRootUrl());
|
msg.append(this.persistenceUnitInfos.get(name).getPersistenceUnitRootUrl());
|
||||||
throw new IllegalStateException(msg.toString());
|
throw new IllegalStateException(msg.toString());
|
||||||
}
|
}
|
||||||
PersistenceUnitInfo puiToStore = pui;
|
this.persistenceUnitInfos.put(name, pui);
|
||||||
if (jpa2ApiPresent) {
|
|
||||||
puiToStore = (PersistenceUnitInfo) Proxy.newProxyInstance(SmartPersistenceUnitInfo.class.getClassLoader(),
|
|
||||||
new Class[] {SmartPersistenceUnitInfo.class}, new Jpa2PersistenceUnitInfoDecorator(pui));
|
|
||||||
}
|
|
||||||
this.persistenceUnitInfos.put(name, puiToStore);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,15 +493,7 @@ public class DefaultPersistenceUnitManager
|
|||||||
*/
|
*/
|
||||||
protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) {
|
protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) {
|
||||||
PersistenceUnitInfo pui = this.persistenceUnitInfos.get(persistenceUnitName);
|
PersistenceUnitInfo pui = this.persistenceUnitInfos.get(persistenceUnitName);
|
||||||
if (pui != null && Proxy.isProxyClass(pui.getClass())) {
|
return (MutablePersistenceUnitInfo) pui;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -574,49 +556,4 @@ public class DefaultPersistenceUnitManager
|
|||||||
return pui;
|
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<? extends Enum> sharedCacheModeEnum;
|
|
||||||
|
|
||||||
private final Class<? extends Enum> validationModeEnum;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Jpa2PersistenceUnitInfoDecorator(SpringPersistenceUnitInfo target) {
|
|
||||||
this.target = target;
|
|
||||||
try {
|
|
||||||
this.sharedCacheModeEnum = (Class<? extends Enum>)
|
|
||||||
ClassUtils.forName("javax.persistence.SharedCacheMode", PersistenceUnitInfo.class.getClassLoader());
|
|
||||||
this.validationModeEnum = (Class<? extends Enum>)
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,6 +20,8 @@ import java.net.URL;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import javax.persistence.SharedCacheMode;
|
||||||
|
import javax.persistence.ValidationMode;
|
||||||
import javax.persistence.spi.ClassTransformer;
|
import javax.persistence.spi.ClassTransformer;
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@@ -61,9 +63,13 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
|
|||||||
|
|
||||||
private boolean excludeUnlistedClasses = false;
|
private boolean excludeUnlistedClasses = false;
|
||||||
|
|
||||||
|
private SharedCacheMode sharedCacheMode = SharedCacheMode.UNSPECIFIED;
|
||||||
|
|
||||||
|
private ValidationMode validationMode = ValidationMode.AUTO;
|
||||||
|
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
|
|
||||||
private String persistenceXMLSchemaVersion = "1.0";
|
private String persistenceXMLSchemaVersion = "2.0";
|
||||||
|
|
||||||
private String persistenceProviderPackageName;
|
private String persistenceProviderPackageName;
|
||||||
|
|
||||||
@@ -154,6 +160,22 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
|
|||||||
return this.excludeUnlistedClasses;
|
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) {
|
public void addProperty(String name, String value) {
|
||||||
if (this.properties == null) {
|
if (this.properties == null) {
|
||||||
this.properties = new Properties();
|
this.properties = new Properties();
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,8 @@ import java.io.InputStream;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.persistence.SharedCacheMode;
|
||||||
|
import javax.persistence.ValidationMode;
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
@@ -273,13 +275,13 @@ class PersistenceUnitReader {
|
|||||||
// set JPA 2.0 shared cache mode
|
// set JPA 2.0 shared cache mode
|
||||||
String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
|
String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
|
||||||
if (StringUtils.hasText(cacheMode)) {
|
if (StringUtils.hasText(cacheMode)) {
|
||||||
unitInfo.setSharedCacheModeName(cacheMode);
|
unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
// set JPA 2.0 validation mode
|
// set JPA 2.0 validation mode
|
||||||
String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
|
String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
|
||||||
if (StringUtils.hasText(validationMode)) {
|
if (StringUtils.hasText(validationMode)) {
|
||||||
unitInfo.setValidationModeName(validationMode);
|
unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
parseProperties(persistenceUnit, unitInfo);
|
parseProperties(persistenceUnit, unitInfo);
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,7 +22,6 @@ import org.springframework.core.DecoratingClassLoader;
|
|||||||
import org.springframework.instrument.classloading.LoadTimeWeaver;
|
import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||||
import org.springframework.instrument.classloading.SimpleThrowawayClassLoader;
|
import org.springframework.instrument.classloading.SimpleThrowawayClassLoader;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclass of {@link MutablePersistenceUnitInfo} that adds instrumentation hooks based on
|
* Subclass of {@link MutablePersistenceUnitInfo} that adds instrumentation hooks based on
|
||||||
@@ -38,39 +37,11 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo {
|
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 LoadTimeWeaver loadTimeWeaver;
|
||||||
|
|
||||||
private ClassLoader classLoader;
|
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
|
* Initialize this PersistenceUnitInfo with the LoadTimeWeaver SPI interface
|
||||||
* used by Spring to add instrumentation to the current class loader.
|
* used by Spring to add instrumentation to the current class loader.
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,8 +34,7 @@ import org.springframework.transaction.TransactionException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.orm.jpa.JpaDialect} implementation for Eclipse
|
* {@link org.springframework.orm.jpa.JpaDialect} implementation for Eclipse
|
||||||
* Persistence Services (EclipseLink). Developed and tested against EclipseLink
|
* Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.4.
|
||||||
* 1.0 as well as 2.0-2.3.
|
|
||||||
*
|
*
|
||||||
* <p>By default, this class acquires a EclipseLink transaction to get the JDBC Connection
|
* <p>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.
|
* 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
|
* to ensure that the cost of connection acquisition is near zero until code actually
|
||||||
* needs a JDBC Connection.
|
* needs a JDBC Connection.
|
||||||
*
|
*
|
||||||
* <p>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
|
* @author Juergen Hoeller
|
||||||
* @since 2.5.2
|
* @since 2.5.2
|
||||||
* @see #setLazyDatabaseTransaction
|
* @see #setLazyDatabaseTransaction
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -30,19 +30,11 @@ import org.springframework.orm.jpa.JpaDialect;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Eclipse
|
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Eclipse
|
||||||
* Persistence Services (EclipseLink). Developed and tested against EclipseLink
|
* Persistence Services (EclipseLink). Developed and tested against EclipseLink 2.4.
|
||||||
* 1.0 as well as 2.0-2.3.
|
|
||||||
*
|
*
|
||||||
* <p>Exposes EclipseLink's persistence provider and EntityManager extension interface,
|
* <p>Exposes EclipseLink's persistence provider and EntityManager extension interface,
|
||||||
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
|
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
|
||||||
*
|
*
|
||||||
* <p>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!
|
|
||||||
*
|
|
||||||
* <p>NOTE: No need to filter out classes from the JPA providers package for
|
|
||||||
* EclipseLink (see SPR-6040)
|
|
||||||
*
|
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @since 2.5.2
|
* @since 2.5.2
|
||||||
|
|||||||
@@ -39,9 +39,7 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.orm.jpa.JpaDialect} implementation for
|
* {@link org.springframework.orm.jpa.JpaDialect} implementation for
|
||||||
* Hibernate EntityManager. Developed against Hibernate 3.3;
|
* Hibernate EntityManager. Developed against Hibernate 3.6 and 4.2.
|
||||||
* tested against 3.3, 3.5, 3.6 and 4.0 (with the latter including
|
|
||||||
* Hibernate EntityManager in the Hibernate core distribution).
|
|
||||||
*
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import org.springframework.orm.jpa.JpaDialect;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for
|
* {@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.
|
||||||
*
|
*
|
||||||
* <p>Exposes Hibernate's persistence provider and EntityManager extension interface,
|
* <p>Exposes Hibernate's persistence provider and EntityManager extension interface,
|
||||||
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
|
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import org.springframework.transaction.TransactionException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.orm.jpa.JpaDialect} implementation for Apache OpenJPA.
|
* {@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 Costin Leau
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.springframework.orm.jpa.JpaDialect;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Apache OpenJPA.
|
* {@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.
|
||||||
*
|
*
|
||||||
* <p>Exposes OpenJPA's persistence provider and EntityManager extension interface,
|
* <p>Exposes OpenJPA's persistence provider and EntityManager extension interface,
|
||||||
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
|
* and supports {@link AbstractJpaVendorAdapter}'s common configuration settings.
|
||||||
|
|||||||
@@ -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.
|
|
||||||
*
|
|
||||||
* <p>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.
|
|
||||||
* <p>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).
|
|
||||||
* <p>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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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.
|
|
||||||
*
|
|
||||||
* <p>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<String, Object> getJpaPropertyMap() {
|
|
||||||
Map<String, Object> jpaProperties = new HashMap<String, Object>();
|
|
||||||
|
|
||||||
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<? extends EntityManager> getEntityManagerInterface() {
|
|
||||||
return oracle.toplink.essentials.ejb.cmp3.EntityManager.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -138,43 +138,6 @@ public class LocalSessionFactoryBeanTests {
|
|||||||
assertEquals("newSessionFactory", invocations.get(0));
|
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
|
@Test
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public void testLocalSessionFactoryBeanWithTransactionAwareDataSource() throws Exception {
|
public void testLocalSessionFactoryBeanWithTransactionAwareDataSource() throws Exception {
|
||||||
@@ -513,10 +476,10 @@ public class LocalSessionFactoryBeanTests {
|
|||||||
@Override
|
@Override
|
||||||
protected Configuration newConfiguration() {
|
protected Configuration newConfiguration() {
|
||||||
return new Configuration() {
|
return new Configuration() {
|
||||||
// changed from return type 'void' to 'Configuration' in Hibernate 3.6
|
|
||||||
@Override
|
@Override
|
||||||
public void setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) {
|
public Configuration setCacheConcurrencyStrategy(String clazz, String concurrencyStrategy, String regionName) {
|
||||||
registeredClassCache.setProperty(clazz, concurrencyStrategy + "," + regionName);
|
registeredClassCache.setProperty(clazz, concurrencyStrategy + "," + regionName);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String regionName) {
|
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String regionName) {
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -94,7 +94,6 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
|
|||||||
|
|
||||||
@ExpectedException(EntityNotFoundException.class)
|
@ExpectedException(EntityNotFoundException.class)
|
||||||
public void testGetReferenceWhenNoRow() {
|
public void testGetReferenceWhenNoRow() {
|
||||||
// Fails here with TopLink
|
|
||||||
Person notThere = sharedEntityManager.getReference(Person.class, 666);
|
Person notThere = sharedEntityManager.getReference(Person.class, 666);
|
||||||
|
|
||||||
// We may get here (as with Hibernate).
|
// We may get here (as with Hibernate).
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractEntityManagerFactoryIntegrationTests extends AbstractJpaTests {
|
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[] {
|
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/eclipselink/eclipselink-manager.xml", "/org/springframework/orm/jpa/memdb.xml",
|
||||||
"/org/springframework/orm/jpa/inject.xml"};
|
"/org/springframework/orm/jpa/inject.xml"};
|
||||||
@@ -45,9 +41,6 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr
|
|||||||
public static Provider getProvider() {
|
public static Provider getProvider() {
|
||||||
String provider = System.getProperty("org.springframework.orm.jpa.provider");
|
String provider = System.getProperty("org.springframework.orm.jpa.provider");
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
if (provider.toLowerCase().contains("eclipselink")) {
|
|
||||||
return Provider.ECLIPSELINK;
|
|
||||||
}
|
|
||||||
if (provider.toLowerCase().contains("hibernate")) {
|
if (provider.toLowerCase().contains("hibernate")) {
|
||||||
return Provider.HIBERNATE;
|
return Provider.HIBERNATE;
|
||||||
}
|
}
|
||||||
@@ -55,7 +48,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr
|
|||||||
return Provider.OPENJPA;
|
return Provider.OPENJPA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Provider.TOPLINK;
|
return Provider.ECLIPSELINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,10 +62,10 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr
|
|||||||
protected String[] getConfigLocations() {
|
protected String[] getConfigLocations() {
|
||||||
Provider provider = getProvider();
|
Provider provider = getProvider();
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
|
case ECLIPSELINK:
|
||||||
|
return ECLIPSELINK_CONFIG_LOCATIONS;
|
||||||
case HIBERNATE:
|
case HIBERNATE:
|
||||||
return HIBERNATE_CONFIG_LOCATIONS;
|
return HIBERNATE_CONFIG_LOCATIONS;
|
||||||
case TOPLINK:
|
|
||||||
return TOPLINK_CONFIG_LOCATIONS;
|
|
||||||
case OPENJPA:
|
case OPENJPA:
|
||||||
return OPENJPA_CONFIG_LOCATIONS;
|
return OPENJPA_CONFIG_LOCATIONS;
|
||||||
default:
|
default:
|
||||||
@@ -90,7 +83,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr
|
|||||||
|
|
||||||
|
|
||||||
public enum Provider {
|
public enum Provider {
|
||||||
TOPLINK, ECLIPSELINK, HIBERNATE, OPENJPA
|
ECLIPSELINK, HIBERNATE, OPENJPA
|
||||||
};
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,19 +158,4 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit
|
|||||||
deleteFromTables(new String[] { "person" });
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package org.springframework.orm.jpa;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
@@ -27,8 +26,10 @@ import javax.persistence.PersistenceException;
|
|||||||
import javax.persistence.spi.PersistenceProvider;
|
import javax.persistence.spi.PersistenceProvider;
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
|
import javax.persistence.spi.ProviderUtil;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.OptimisticLockingFailureException;
|
import org.springframework.dao.OptimisticLockingFailureException;
|
||||||
@@ -317,6 +318,11 @@ public class LocalContainerEntityManagerFactoryBeanTests extends AbstractEntityM
|
|||||||
public EntityManagerFactory createEntityManagerFactory(String emfName, Map properties) {
|
public EntityManagerFactory createEntityManagerFactory(String emfName, Map properties) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProviderUtil getProviderUtil() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.Properties;
|
|||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.spi.PersistenceProvider;
|
import javax.persistence.spi.PersistenceProvider;
|
||||||
import javax.persistence.spi.PersistenceUnitInfo;
|
import javax.persistence.spi.PersistenceUnitInfo;
|
||||||
|
import javax.persistence.spi.ProviderUtil;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -94,6 +95,11 @@ public class LocalEntityManagerFactoryBeanTests extends AbstractEntityManagerFac
|
|||||||
actualProps = properties;
|
actualProps = properties;
|
||||||
return mockEmf;
|
return mockEmf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProviderUtil getProviderUtil() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ public class ContextualPerson {
|
|||||||
private transient TestBean testBean;
|
private transient TestBean testBean;
|
||||||
|
|
||||||
// Lazy relationship to force use of instrumentation in JPA implementation.
|
// 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)
|
@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
|
||||||
@JoinColumn(name="DRIVERS_LICENSE_ID")
|
@JoinColumn(name="DRIVERS_LICENSE_ID")
|
||||||
private DriversLicense driversLicense;
|
private DriversLicense driversLicense;
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ public class Person {
|
|||||||
private transient TestBean testBean;
|
private transient TestBean testBean;
|
||||||
|
|
||||||
// Lazy relationship to force use of instrumentation in JPA implementation.
|
// 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)
|
@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
|
||||||
@JoinColumn(name="DRIVERS_LICENSE_ID")
|
@JoinColumn(name="DRIVERS_LICENSE_ID")
|
||||||
private DriversLicense driversLicense;
|
private DriversLicense driversLicense;
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,12 +34,12 @@ public class EclipseLinkEntityManagerFactoryIntegrationTests extends AbstractCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testCanCastNativeEntityManagerFactoryToTopLinkEntityManagerFactoryImpl() {
|
public void testCanCastNativeEntityManagerFactoryToEclipseLinkEntityManagerFactoryImpl() {
|
||||||
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
|
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
|
||||||
assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl"));
|
assertTrue(emfi.getNativeEntityManagerFactory().getClass().getName().endsWith("EntityManagerFactoryImpl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCanCastSharedEntityManagerProxyToTopLinkEntityManager() {
|
public void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() {
|
||||||
assertTrue(sharedEntityManager instanceof JpaEntityManager);
|
assertTrue(sharedEntityManager instanceof JpaEntityManager);
|
||||||
JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
|
JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
|
||||||
assertNotNull(eclipselinkEntityManager.getActiveSession());
|
assertNotNull(eclipselinkEntityManager.getActiveSession());
|
||||||
|
|||||||
@@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
|
||||||
|
|
||||||
<beans>
|
|
||||||
|
|
||||||
<import resource="classpath:/org/springframework/orm/jpa/multi-jpa-emf.xml"/>
|
|
||||||
|
|
||||||
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
|
|
||||||
<property name="database" value="HSQL"/>
|
|
||||||
<property name="showSql" value="true"/>
|
|
||||||
<property name="generateDdl" value="true"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="jpaProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"/>
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
|
||||||
|
|
||||||
<beans>
|
|
||||||
|
|
||||||
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
|
|
||||||
<property name="persistenceXmlLocation" value="org/springframework/orm/jpa/domain/persistence.xml"/>
|
|
||||||
<property name="dataSource" ref="dataSource"/>
|
|
||||||
<property name="jpaVendorAdapter">
|
|
||||||
<bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
|
|
||||||
<property name="database" value="HSQL"/>
|
|
||||||
<property name="showSql" value="true"/>
|
|
||||||
<property name="generateDdl" value="true"/>
|
|
||||||
</bean>
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
Reference in New Issue
Block a user