General JPA 2.0+ requirement; upgraded build and tests to EclipseLink 2.4, OpenJPA 2.2, Hibernate 3.6
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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