mirror of https://github.com/apache/openjpa.git
Added test for deep mapped superclass inheritance hierarchy, which is what
my last metadata changes fixed. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@441702 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
37aa91d2af
commit
ddf3631bcc
|
@ -0,0 +1,19 @@
|
|||
package org.apache.openjpa.persistence.inheritance;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class EntityL3
|
||||
extends MappedSuperclassL2 {
|
||||
|
||||
private int l3data;
|
||||
|
||||
public int getL3Data() {
|
||||
return l3data;
|
||||
}
|
||||
|
||||
public void setL3Data(int data) {
|
||||
l3data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.openjpa.persistence.inheritance;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public class MappedSuperclassBase {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.AUTO)
|
||||
private long id;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.openjpa.persistence.inheritance;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public class MappedSuperclassL2
|
||||
extends MappedSuperclassBase {
|
||||
|
||||
private int l2data;
|
||||
|
||||
public int getL2Data() {
|
||||
return l2data;
|
||||
}
|
||||
|
||||
public void setL2Data(int data) {
|
||||
l2data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2006 The Apache Software Foundation.
|
||||
*
|
||||
* 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.apache.openjpa.persistence.inheritance;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.EntityTransaction;
|
||||
import javax.persistence.Persistence;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.textui.TestRunner;
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||
|
||||
/**
|
||||
* Perform basic operations on an inheritance hierarchy involving multiple
|
||||
* @MappedSuperclasses.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestMultipleMappedSuperclassHierarchy
|
||||
extends TestCase {
|
||||
|
||||
private EntityManagerFactory emf;
|
||||
|
||||
public void setUp() {
|
||||
String types = MappedSuperclassBase.class.getName() + ";"
|
||||
+ MappedSuperclassL2.class.getName() + ";"
|
||||
+ EntityL3.class.getName();
|
||||
Map props = new HashMap();
|
||||
props.put("openjpa.MetaDataFactory", "jpa(Types=" + types + ")");
|
||||
emf = Persistence.createEntityManagerFactory("test", props);
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
if (emf == null)
|
||||
return;
|
||||
try {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.createQuery("delete from EntityL3").executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
emf.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testPersist() {
|
||||
EntityL3 ent = new EntityL3();
|
||||
ent.setL2Data(99);
|
||||
ent.setL3Data(100);
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist(ent);
|
||||
em.getTransaction().commit();
|
||||
long id = ent.getId();
|
||||
assertTrue(id != 0);
|
||||
em.close();
|
||||
|
||||
em = emf.createEntityManager();
|
||||
ent = em.find(EntityL3.class, id);
|
||||
assertNotNull(ent);
|
||||
assertEquals(99, ent.getL2Data());
|
||||
assertEquals(100, ent.getL3Data());
|
||||
em.close();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(TestMultipleMappedSuperclassHierarchy.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package org.apache.openjpa.persistence.simple;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.EntityTransaction;
|
||||
|
@ -34,23 +36,18 @@ public class TestPersistence
|
|||
|
||||
private EntityManagerFactory emf;
|
||||
|
||||
protected EntityManager getEM() {
|
||||
if (emf == null)
|
||||
emf = Persistence.createEntityManagerFactory("simple-emf-test");
|
||||
assertNotNull(emf);
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
assertNotNull(em);
|
||||
|
||||
return em;
|
||||
public void setUp() {
|
||||
Map props = new HashMap();
|
||||
props.put("openjpa.MetaDataFactory",
|
||||
"jpa(Types=" + AllFieldTypes.class.getName() + ")");
|
||||
emf = Persistence.createEntityManagerFactory("test", props);
|
||||
}
|
||||
|
||||
public void tearDown()
|
||||
throws Exception {
|
||||
super.tearDown();
|
||||
|
||||
public void tearDown() {
|
||||
if (emf == null)
|
||||
return;
|
||||
try {
|
||||
EntityManager em = getEM();
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.createQuery("delete from AllFieldTypes").executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
|
@ -61,11 +58,10 @@ public class TestPersistence
|
|||
}
|
||||
|
||||
public void testCreateEntityManager() {
|
||||
EntityManager em = getEM();
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
EntityTransaction t = em.getTransaction();
|
||||
assertNotNull(t);
|
||||
|
||||
t.begin();
|
||||
t.setRollbackOnly();
|
||||
t.rollback();
|
||||
|
@ -75,14 +71,11 @@ public class TestPersistence
|
|||
OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
|
||||
ojem.getFetchPlan().setMaxFetchDepth(-1);
|
||||
assertEquals(-1, ojem.getFetchPlan().getMaxFetchDepth());
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testPersist() {
|
||||
EntityManager em;
|
||||
|
||||
em = getEM();
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
em.persist(new AllFieldTypes());
|
||||
em.getTransaction().commit();
|
||||
|
@ -90,9 +83,7 @@ public class TestPersistence
|
|||
}
|
||||
|
||||
public void testQuery() {
|
||||
EntityManager em;
|
||||
|
||||
em = getEM();
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
AllFieldTypes aft = new AllFieldTypes();
|
||||
aft.setStringField("foo");
|
||||
|
@ -101,7 +92,7 @@ public class TestPersistence
|
|||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
em = getEM();
|
||||
em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertEquals(1, em.createQuery
|
||||
("select x from AllFieldTypes x where x.stringField = 'foo'").
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
version="1.0">
|
||||
|
||||
<persistence-unit name="simple-emf-test">
|
||||
|
||||
<!-- This is not needed if OpenJPA is the only persistence provider
|
||||
in the classpath.
|
||||
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
|
||||
-->
|
||||
|
||||
<class>org.apache.openjpa.persistence.simple.AllFieldTypes</class>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
version="1.0">
|
||||
|
||||
<persistence-unit name="test">
|
||||
<!--
|
||||
<provider>
|
||||
org.apache.openjpa.persistence.PersistenceProviderImpl
|
||||
</provider>
|
||||
-->
|
||||
<properties>
|
||||
<property name="openjpa.ConnectionDriverName"
|
||||
value="org.apache.commons.dbcp.BasicDataSource"/>
|
||||
value="org.apache.commons.dbcp.BasicDataSource"/>
|
||||
<property name="openjpa.ConnectionProperties"
|
||||
value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
|
||||
value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/openjpa-test-database;create=true,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
|
||||
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||
value="buildSchema(ForeignKeys=true)"/>
|
||||
value="buildSchema(ForeignKeys=true)"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
|
|
Loading…
Reference in New Issue