mirror of https://github.com/apache/openjpa.git
OPENJPA-670 committing patch provided by Jeremy Bauer
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@681370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4af04f30d9
commit
68f051fccf
|
@ -24,6 +24,7 @@ import java.security.PrivilegedActionException;
|
|||
import java.sql.Types;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -312,6 +313,20 @@ public class MappingRepository
|
|||
ClassMapping sup = mapping.getPCSuperclassMapping();
|
||||
if (sup != null && (mapping.getResolve() & MODE_MAPPING) != 0)
|
||||
return;
|
||||
|
||||
// if this mapping is not for a managed interface, ensure that if
|
||||
// we have an inheritance hierarchy there is a default strategy
|
||||
// applied to the root class
|
||||
if (!mapping.getDescribedType().isInterface() &&
|
||||
!mapping.isEmbeddedOnly()) {
|
||||
// if an inheritance strategy has not been set on this mapping
|
||||
// determine if needs one and if so, set it
|
||||
if (!hasInheritanceStrategy(mapping)) {
|
||||
ClassMapping baseMapping = findBaseClassMapping(mapping);
|
||||
if (baseMapping != null)
|
||||
setDefaultInheritanceStrategy(baseMapping);
|
||||
}
|
||||
}
|
||||
|
||||
// define superclass fields after mapping class, so we can tell whether
|
||||
// the class is mapped and needs to redefine abstract superclass fields
|
||||
|
@ -1256,4 +1271,77 @@ public class MappingRepository
|
|||
((Configurable) _schema).endConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the base class mapping for the specified mapping. Loads all
|
||||
* persistent types if necessary, since all persistent subclasses of this
|
||||
* mapping may not have been resolved before this method is called.
|
||||
*/
|
||||
protected ClassMapping findBaseClassMapping(ClassMapping mapping) {
|
||||
ClassMapping baseMapping = null;
|
||||
ClassMapping sup = mapping.getPCSuperclassMapping();
|
||||
if (sup == null) {
|
||||
// no superclass metadata was provided. check to see if this class
|
||||
// has any persistent subclasses.
|
||||
if (mapping.getPCSubclasses().length > 0)
|
||||
baseMapping = mapping;
|
||||
else {
|
||||
// persistent subclasses may not have been resolved yet.
|
||||
// run through the persistent types to see if any of them
|
||||
// or their superclass is a subclass of this class.
|
||||
Collection classes = loadPersistentTypes(false,
|
||||
mapping.getEnvClassLoader());
|
||||
Class cls;
|
||||
for (Iterator itr = classes.iterator(); itr.hasNext();) {
|
||||
cls = (Class) itr.next();
|
||||
Class supcl = cls.getSuperclass();
|
||||
while (supcl != null &&
|
||||
!supcl.getClass().equals(java.lang.Object.class)) {
|
||||
if (!supcl.isInterface() &&
|
||||
supcl.equals(mapping.getDescribedType())) {
|
||||
baseMapping = mapping;
|
||||
break;
|
||||
}
|
||||
supcl = supcl.getSuperclass();
|
||||
}
|
||||
if (baseMapping != null) break;
|
||||
}
|
||||
}
|
||||
} else if (!sup.getDescribedType().isInterface()) {
|
||||
// if the superclass is not a managed interface, find the root
|
||||
// superclass and get its mapping info
|
||||
ClassMapping supcm = sup;
|
||||
while (supcm != null &&
|
||||
!supcm.getDescribedType().isInterface() &&
|
||||
!supcm.isEmbeddedOnly()) {
|
||||
ClassMapping supcm2 = supcm.getPCSuperclassMapping();
|
||||
if (supcm2 == null)
|
||||
baseMapping = supcm;
|
||||
supcm = supcm2;
|
||||
}
|
||||
}
|
||||
return baseMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* If an inheritance strategy has not been set on this mapping, set it
|
||||
* to the default (flat). This method should be called before strategies
|
||||
* are created for the specified mapping.
|
||||
*/
|
||||
protected void setDefaultInheritanceStrategy(ClassMapping mapping) {
|
||||
ClassMappingInfo info = mapping.getMappingInfo();
|
||||
if (info != null && info.getHierarchyStrategy() == null)
|
||||
info.setHierarchyStrategy(FlatClassStrategy.ALIAS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an inhertance strategy has been set on the
|
||||
* specified mapping.
|
||||
*/
|
||||
protected boolean hasInheritanceStrategy(ClassMapping mapping) {
|
||||
ClassMappingInfo info = mapping.getMappingInfo();
|
||||
if (info != null && info.getHierarchyStrategy() != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,622 @@
|
|||
package org.apache.openjpa.persistence.inheritance;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.apache.openjpa.jdbc.meta.ClassMapping;
|
||||
import org.apache.openjpa.jdbc.meta.Discriminator;
|
||||
import org.apache.openjpa.jdbc.schema.Column;
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.AbstractClass;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.BaseClass;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.BaseClass2;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.BaseClass3;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.BaseClass4;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.BaseClass5;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.BaseClass6;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.ManagedIface;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.ManagedIface2;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.MappedSuper;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.MidClass;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.MidClass2;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.MidClass3;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassA;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassB;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassC;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassD;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassE;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.ImplClassA;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassF;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassG;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassH;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassI;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassJ;
|
||||
import org.apache.openjpa.persistence.inheritance.entity.SubclassK;
|
||||
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||
|
||||
/**
|
||||
* This test verifies that OpenJPA uses a single-table inheritance
|
||||
* strategy and default discriminator column if no inheritance strategy
|
||||
* is defined.
|
||||
*
|
||||
* OpenJPA JIRA: {@link http://issues.apache.org/jira/browse/OPENJPA-670}
|
||||
|
||||
* @author Jeremy Bauer
|
||||
*
|
||||
*/
|
||||
public class TestDefaultInheritanceStrategy
|
||||
extends SingleEMFTestCase {
|
||||
|
||||
public void setUp() {
|
||||
setUp(BaseClass.class, SubclassA.class, SubclassB.class,
|
||||
SubclassC.class, MappedSuper.class, SubclassD.class,
|
||||
BaseClass2.class, MidClass.class, SubclassE.class,
|
||||
ManagedIface.class, ImplClassA.class,
|
||||
ManagedIface2.class, BaseClass3.class, SubclassF.class,
|
||||
BaseClass4.class, SubclassG.class,
|
||||
BaseClass5.class, MidClass2.class, SubclassH.class,
|
||||
AbstractClass.class, SubclassI.class, SubclassJ.class,
|
||||
BaseClass6.class, SubclassK.class);
|
||||
}
|
||||
|
||||
private Class[] classArray(Class... classes) {
|
||||
return classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation tests a default simple class hierarchy with no inheritance
|
||||
* or discriminator column annotations defined.
|
||||
*/
|
||||
public void testSimpleDefaultInheritance() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
// Create some entities
|
||||
SubclassA sca = new SubclassA();
|
||||
sca.setId(0);
|
||||
sca.setName("SubclassABaseClassName0");
|
||||
sca.setClassAName("SubclassAName0");
|
||||
|
||||
SubclassA sca2 = new SubclassA();
|
||||
sca2.setId(1);
|
||||
sca2.setName("SubclassABaseClassName1");
|
||||
sca2.setClassAName("SubclassAName1");
|
||||
|
||||
SubclassB scb = new SubclassB();
|
||||
scb.setId(2);
|
||||
scb.setName("SubclassBBaseClassName");
|
||||
scb.setClassBName("SubclassBName");
|
||||
|
||||
BaseClass b = new BaseClass();
|
||||
b.setName("BaseClassName");
|
||||
b.setId(3);
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(sca);
|
||||
em.persist(sca2);
|
||||
em.persist(scb);
|
||||
em.persist(b);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
verifyDtypeColumnEntriesAndMapping(em, "BASECLASS", 4, BaseClass.class);
|
||||
|
||||
verifyInheritanceQueryResult(em, "SubclassA",
|
||||
classArray(SubclassA.class), 0, 1);
|
||||
|
||||
verifyInheritanceQueryResult(em, "SubclassB",
|
||||
classArray(SubclassB.class), 2);
|
||||
|
||||
verifyInheritanceQueryResult(em, "BaseClass",
|
||||
classArray(BaseClass.class), 0, 1, 2, 3);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation ensures that a mapped superclass does not cause the
|
||||
* production of a discriminator column.
|
||||
*/
|
||||
public void testMappedSuperclass() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
// Add two entities, each extending the same mapped interface
|
||||
em.getTransaction().begin();
|
||||
SubclassC sc = new SubclassC();
|
||||
sc.setId(0);
|
||||
sc.setName("SubclassCMappedSuperName");
|
||||
sc.setClassCName("SubclassCName");
|
||||
|
||||
SubclassD sd = new SubclassD();
|
||||
sd.setId(1);
|
||||
sd.setName("SubclassDMappedSuperName");
|
||||
sd.setClassDName("SubclassDName");
|
||||
|
||||
em.persist(sc);
|
||||
em.persist(sd);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
// The subclasses should not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassC");
|
||||
verifyNoDypeColumn(em, "SubclassD");
|
||||
|
||||
// Query the subclass entities. Make sure the counts are correct and
|
||||
// the result is castable to the mapped sc.
|
||||
verifyInheritanceQueryResult(em, "SubclassC",
|
||||
classArray(SubclassC.class, MappedSuper.class), 0);
|
||||
|
||||
verifyInheritanceQueryResult(em, "SubclassD",
|
||||
classArray(SubclassD.class, MappedSuper.class), 1);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation ensures that a 3-level inheritance hierarchy uses
|
||||
* a discriminator column at the root class level.
|
||||
*/
|
||||
public void testTwoLevelInheritance() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
// Add two entities, each extending the same mapped interface
|
||||
em.getTransaction().begin();
|
||||
SubclassE sc = new SubclassE();
|
||||
sc.setId(0);
|
||||
sc.setName("SubclassEBaseClassName");
|
||||
sc.setMidClassName("SubclassEMidClassName");
|
||||
sc.setClassEName("SubclassCName");
|
||||
|
||||
MidClass mc = new MidClass();
|
||||
mc.setId(1);
|
||||
mc.setName("MidClassBaseClassName");
|
||||
mc.setMidClassName("MidClassName");
|
||||
|
||||
BaseClass2 b2 = new BaseClass2();
|
||||
b2.setName("BaseClass2Name");
|
||||
b2.setId(2);
|
||||
|
||||
em.persist(sc);
|
||||
em.persist(mc);
|
||||
em.persist(b2);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
// Verify that baseclass2 contains a discriminator column
|
||||
verifyDtypeColumnEntriesAndMapping(em, "BASECLASS2", 3,
|
||||
BaseClass2.class);
|
||||
|
||||
// Verify that the subclass tables do not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "MidClass");
|
||||
verifyNoDypeColumn(em, "SubclassE");
|
||||
|
||||
// Query the subclass tables. Make sure the counts are correct and
|
||||
// the result is castable to the mapped sc.
|
||||
verifyInheritanceQueryResult(em, "SubclassE",
|
||||
classArray(SubclassE.class, MidClass.class, BaseClass2.class),
|
||||
0);
|
||||
|
||||
verifyInheritanceQueryResult(em, "MidClass",
|
||||
classArray(MidClass.class), 0, 1);
|
||||
|
||||
verifyInheritanceQueryResult(em, "BaseClass2",
|
||||
classArray(BaseClass2.class), 0, 1, 2);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation verifies that an entity with a managed interface
|
||||
* does not use a discriminator column.
|
||||
*/
|
||||
public void testManagedInterface() {
|
||||
OpenJPAEntityManager em = emf.createEntityManager();
|
||||
|
||||
// Add some entities
|
||||
em.getTransaction().begin();
|
||||
ManagedIface mif = em.createInstance(ManagedIface.class);
|
||||
mif.setIntFieldSup(10);
|
||||
|
||||
ImplClassA ica = new ImplClassA();
|
||||
ica.setImplClassAName("ImplClassAName");
|
||||
ica.setIntFieldSup(11);
|
||||
|
||||
em.persist(mif);
|
||||
em.persist(ica);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
// Verify that the iface table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "ManagedIface");
|
||||
|
||||
// Verify that the impl table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "ImplClassA");
|
||||
|
||||
// Query the subclass tables. Make sure the counts are correct and
|
||||
// the result is castable to the entity and interface types.
|
||||
verifyInheritanceQueryResult(em, "ImplClassA",
|
||||
classArray(ImplClassA.class, ManagedIface.class), ica.getId());
|
||||
|
||||
// Query the interface2 table. Make sure the count is correct and
|
||||
// the result is castable to the interface type.
|
||||
verifyInheritanceQueryResult(em, "ManagedIface",
|
||||
classArray(ManagedIface.class), mif.getId(),
|
||||
ica.getId());
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation verifies that an entity with managed interface
|
||||
* and a superclass DOES use a discriminator column.
|
||||
*/
|
||||
public void testManagedInterfaceAndBase() {
|
||||
OpenJPAEntityManager em = emf.createEntityManager();
|
||||
|
||||
// Add some entities
|
||||
em.getTransaction().begin();
|
||||
ManagedIface2 mif2 = em.createInstance(ManagedIface2.class);
|
||||
mif2.setIntFieldSup(12);
|
||||
|
||||
SubclassF scf = new SubclassF();
|
||||
scf.setClassFName("SubclassFName");
|
||||
scf.setIntFieldSup(13);
|
||||
|
||||
BaseClass3 bc3 = new BaseClass3();
|
||||
bc3.setName("BaseClass3");
|
||||
|
||||
em.persist(mif2);
|
||||
em.persist(scf);
|
||||
em.persist(bc3);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
// Verify that the iface table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "ManagedIface2");
|
||||
|
||||
// Verify that the subclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassF");
|
||||
|
||||
// Verify that the base class does contain a discriminator column
|
||||
verifyDtypeColumnEntriesAndMapping(em, "BASECLASS3", 2,
|
||||
BaseClass3.class);
|
||||
|
||||
// Query the subclass table. Make sure the counts are correct and
|
||||
// the result is castable to the entity and interface types.
|
||||
verifyInheritanceQueryResult(em, "SubclassF",
|
||||
classArray(SubclassF.class, ManagedIface2.class, BaseClass3.class),
|
||||
scf.getId());
|
||||
|
||||
// Query the base class table. Make sure the counts are correct and
|
||||
// the result is castable to the entity and interface types.
|
||||
verifyInheritanceQueryResult(em, "BaseClass3",
|
||||
classArray(BaseClass3.class),
|
||||
scf.getId(), bc3.getId());
|
||||
|
||||
// Query the interface2 table. Make sure the count is correct and
|
||||
// the result is castable to the interface type.
|
||||
verifyInheritanceQueryResult(em, "ManagedIface2",
|
||||
classArray(ManagedIface2.class),
|
||||
scf.getId(), mif2.getId());
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation tests a default simple class hierarchy with a inheritance
|
||||
* annotation defined on the subclass.
|
||||
*/
|
||||
public void testSubclassSpecifiedInheritance() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
// Create some entities
|
||||
SubclassG scg = new SubclassG();
|
||||
scg.setId(0);
|
||||
scg.setName("SubclassGBaseClass4Name");
|
||||
scg.setClassGName("SubclassGName");
|
||||
|
||||
BaseClass4 b = new BaseClass4();
|
||||
b.setName("BaseClass4Name");
|
||||
b.setId(1);
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(scg);
|
||||
em.persist(b);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
verifyDtypeColumnEntriesAndMapping(em, "BASECLASS4", 2,
|
||||
BaseClass4.class);
|
||||
|
||||
// Verify that the subclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassG");
|
||||
|
||||
// Run queries for each type. They should return only those values
|
||||
// which match their respective types. This will not work for single
|
||||
// table inheritance unless a discriminator column is defined.
|
||||
verifyInheritanceQueryResult(em, "SubclassG",
|
||||
classArray(SubclassG.class, BaseClass4.class), 0);
|
||||
|
||||
verifyInheritanceQueryResult(em, "BaseClass4",
|
||||
classArray(BaseClass4.class), 0, 1);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation tests a default inheritance hierarchy with circular
|
||||
* relationships:
|
||||
* BaseClass5 has rel to SubclassH
|
||||
* MidClass2 extends BaseClass5 inherits rel to SubclassH
|
||||
* SubClassH extends MidClass2 has rel to BaseClass5
|
||||
*/
|
||||
public void testCircularInheritedRelationships() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
// Create and persist some related & inherited entities
|
||||
SubclassH sch = new SubclassH();
|
||||
sch.setId(1);
|
||||
sch.setClassHName("SubclassHName");
|
||||
sch.setName("SubclassHBaseClass5Name");
|
||||
sch.setMidClass2Name("SubclassHMidClass2Name");
|
||||
|
||||
BaseClass5 bc5 = new BaseClass5();
|
||||
bc5.setId(2);
|
||||
bc5.setName("BaseClass5Name");
|
||||
bc5.setSubclassh(sch);
|
||||
|
||||
sch.setBaseclass5(bc5);
|
||||
|
||||
MidClass2 mc2 = new MidClass2();
|
||||
mc2.setId(3);
|
||||
mc2.setMidClass2Name("MidClass2Name");
|
||||
mc2.setName("MidClass2BaseClass5Name");
|
||||
mc2.setSubclassh(sch);
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(sch);
|
||||
em.persist(bc5);
|
||||
em.persist(mc2);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
verifyDtypeColumnEntriesAndMapping(em, "BASECLASS5", 3,
|
||||
BaseClass5.class);
|
||||
|
||||
// Verify that the midclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "MidClass2");
|
||||
|
||||
// Verify that the subclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassH");
|
||||
|
||||
// Run queries for each type. They should return only those values
|
||||
// which match their respective types. This will not work for single
|
||||
// table inheritance unless a discriminator column is defined.
|
||||
verifyInheritanceQueryResult(em, "SubclassH",
|
||||
classArray(SubclassH.class, MidClass2.class, BaseClass5.class),
|
||||
1);
|
||||
|
||||
verifyInheritanceQueryResult(em, "MidClass2",
|
||||
classArray(MidClass2.class, BaseClass5.class),
|
||||
1, 3);
|
||||
|
||||
verifyInheritanceQueryResult(em, "BaseClass5",
|
||||
classArray(BaseClass5.class),
|
||||
1, 2, 3);
|
||||
|
||||
em.clear();
|
||||
|
||||
// Validate entity relationships
|
||||
sch = em.find(SubclassH.class, 1);
|
||||
assertEquals(sch.getName(),"SubclassHBaseClass5Name");
|
||||
assertEquals(sch.getMidClass2Name(), "SubclassHMidClass2Name");
|
||||
// SubclassH has relationship to BaseClass5
|
||||
assertEquals(sch.getBaseclass5().getId(), 2);
|
||||
|
||||
bc5 = em.find(BaseClass5.class, 3);
|
||||
assertEquals(bc5.getName(),"MidClass2BaseClass5Name");
|
||||
// BaseClass5 has relationship to SubclassH through MidClass2
|
||||
assertEquals(bc5.getSubclassh().getId(), 1);
|
||||
|
||||
bc5 = em.find(BaseClass5.class, 2);
|
||||
assertEquals(bc5.getName(),"BaseClass5Name");
|
||||
// BaseClass5 has relationship to SubclassH
|
||||
assertEquals(bc5.getSubclassh().getId(), 1);
|
||||
|
||||
mc2 = em.find(MidClass2.class, 3);
|
||||
assertEquals(mc2.getName(),"MidClass2BaseClass5Name");
|
||||
assertEquals(mc2.getMidClass2Name(), "MidClass2Name");
|
||||
// MidClass2 has relationship to SubclassH
|
||||
assertEquals(bc5.getSubclassh().getId(), 1);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation verifies default inheritance with an abstract
|
||||
* entity.
|
||||
*/
|
||||
public void testAbstractEntityInheritance() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
SubclassI sci = new SubclassI();
|
||||
sci.setId(1);
|
||||
sci.setClassIName("SubclassIName");
|
||||
sci.setName("SubclassIBaseClassName");
|
||||
|
||||
SubclassJ scj = new SubclassJ();
|
||||
scj.setId(2);
|
||||
scj.setClassJName("SubclassJName");
|
||||
scj.setName("SubclassJBaseClassName");
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(sci);
|
||||
em.persist(scj);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
verifyDtypeColumnEntriesAndMapping(em, "ABSTRACTCLASS", 2,
|
||||
AbstractClass.class);
|
||||
|
||||
// Verify that the midclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassI");
|
||||
|
||||
// Verify that the subclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassJ");
|
||||
|
||||
// Run queries for each type. They should return only those values
|
||||
// which match their respective types. This will not work for single
|
||||
// table inheritance unless a discriminator column is defined.
|
||||
verifyInheritanceQueryResult(em, "AbstractClass",
|
||||
classArray(AbstractClass.class), 1, 2);
|
||||
|
||||
verifyInheritanceQueryResult(em, "SubclassI",
|
||||
classArray(AbstractClass.class, SubclassI.class), 1);
|
||||
|
||||
verifyInheritanceQueryResult(em, "SubclassJ",
|
||||
classArray(AbstractClass.class, SubclassJ.class), 2);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This variation verifies that default inheritance is used when
|
||||
* there is a non-entity superclass in the mix:
|
||||
* non-entity MidClass3 extends BaseClass6
|
||||
* SubClassJ extends MidClass3
|
||||
*/
|
||||
public void testMidNonEntityInheritance() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
SubclassK sck = new SubclassK();
|
||||
sck.setId(1);
|
||||
sck.setClassKName("SubclassKName");
|
||||
sck.setMidClass3Name("SubclassKMidClass3Name");
|
||||
sck.setName("SubclassKBaseClass6Name");
|
||||
|
||||
BaseClass6 bk6 = new BaseClass6();
|
||||
bk6.setId(3);
|
||||
bk6.setName("BaseClass6Name");
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(sck);
|
||||
em.persist(bk6);
|
||||
em.getTransaction().commit();
|
||||
|
||||
em.clear();
|
||||
|
||||
verifyDtypeColumnEntriesAndMapping(em, "BASECLASS6", 2,
|
||||
BaseClass6.class);
|
||||
|
||||
// Verify that the subclass table does not contain a discriminator column
|
||||
verifyNoDypeColumn(em, "SubclassK");
|
||||
|
||||
// Run queries for each type. They should return only those values
|
||||
// which match their respective types. This will not work for single
|
||||
// table inheritance unless a discriminator column is defined.
|
||||
verifyInheritanceQueryResult(em, "BaseClass6",
|
||||
classArray(BaseClass6.class), 1, 3);
|
||||
|
||||
verifyInheritanceQueryResult(em, "SubclassK",
|
||||
classArray(BaseClass6.class, MidClass3.class, SubclassK.class),
|
||||
1);
|
||||
|
||||
em.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a table contains the specified number of entries
|
||||
* in its DTYPE (default discriminator) column.
|
||||
* @param em Entity nanager
|
||||
* @param table Name of the table to query
|
||||
* @param entries Expected column entry count
|
||||
* @param baseClass Class mapping to verify
|
||||
*/
|
||||
private void verifyDtypeColumnEntriesAndMapping(EntityManager em,
|
||||
String table, int entries, Class baseClass) {
|
||||
try {
|
||||
Query qry = em.createNativeQuery("SELECT DTYPE FROM " + table);
|
||||
List vals = qry.getResultList();
|
||||
assertTrue("Query should have returned " + entries + " values",
|
||||
vals.size() == entries);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Exception querying DTYPE column: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Check the discriminator column of the class mapping.
|
||||
ClassMapping cm = getMapping(baseClass);
|
||||
Discriminator d = cm.getDiscriminator();
|
||||
Column[] cols = d.getColumns();
|
||||
assertTrue("Discriminator should use DTYPE column",
|
||||
(cols != null && cols.length == 1 &&
|
||||
cols[0].getName().equals("DTYPE")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a table does not contain a DTYPE column.
|
||||
* @param em Entity manager
|
||||
* @param table Name of the table to query
|
||||
*/
|
||||
private void verifyNoDypeColumn(EntityManager em, String table) {
|
||||
try {
|
||||
Query qry = em.createNativeQuery("SELECT DTYPE FROM " + table);
|
||||
qry.getResultList();
|
||||
fail("Expected exception. DTYPE column should not exist on " +
|
||||
table);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Expected exception
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the resulting entity count and expected entity ids from a
|
||||
* simple entity query. This method requires a "getId" method on the
|
||||
* entity type in order to work properly.
|
||||
*
|
||||
* @param em entity manager
|
||||
* @param entity entity name
|
||||
* @param entityType entity class
|
||||
* @param expectedValues variable list of expected integral id values.
|
||||
*/
|
||||
private void verifyInheritanceQueryResult(EntityManager em, String entity,
|
||||
Class[] types, int... expectedValues) {
|
||||
Query qry = em.createQuery("SELECT e FROM " + entity + " e");
|
||||
List col = qry.getResultList();
|
||||
assertTrue("Query should return " + expectedValues.length + " entities",
|
||||
col.size() == expectedValues.length);
|
||||
int count = 0;
|
||||
for (int i = 0; i < col.size(); i++) {
|
||||
Object ent = col.get(i);
|
||||
// If a list of supers or interfaces is provided, make sure
|
||||
// the returned type is an instance of those types
|
||||
if (types != null) {
|
||||
for (int j = 0; j < types.length; j++ )
|
||||
assertTrue(types[j].isInstance(ent));
|
||||
}
|
||||
int id = -1;
|
||||
try {
|
||||
Method mth = ent.getClass().getMethod("getId", (Class[])null);
|
||||
id = (Integer)mth.invoke(ent, (Object[])null);
|
||||
} catch (Exception e) {
|
||||
fail("Caught unexepcted exception getting entity id: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
for (int j = 0; j < expectedValues.length; j++)
|
||||
if (expectedValues[j] == id)
|
||||
count++;
|
||||
}
|
||||
assertTrue("Returned expected entities",
|
||||
count == expectedValues.length);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public abstract class AbstractClass {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
abstract public void setVersion(int version);
|
||||
|
||||
abstract public int getVersion();
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Name=" + name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class BaseClass {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Version=" + version +
|
||||
";Name=" + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class BaseClass2 {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Version=" + version +
|
||||
";Name=" + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class BaseClass3 {
|
||||
|
||||
@Id @GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Version=" + version +
|
||||
";Name=" + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class BaseClass4 {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Version=" + version +
|
||||
";Name=" + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class BaseClass5 {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
@OneToOne
|
||||
private SubclassH subclassh;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Version=" + version +
|
||||
";Name=" + name;
|
||||
}
|
||||
|
||||
public void setSubclassh(SubclassH subclassh) {
|
||||
this.subclassh = subclassh;
|
||||
}
|
||||
|
||||
public SubclassH getSubclassh() {
|
||||
return subclassh;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class BaseClass6 {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Name=" + name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class ImplClassA implements ManagedIface {
|
||||
|
||||
@Basic
|
||||
private String implClassAName;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@Basic
|
||||
private int intFieldSup;
|
||||
|
||||
public void setImplClassAName(String implClassAName) {
|
||||
this.implClassAName = implClassAName;
|
||||
}
|
||||
|
||||
public String getImplClassAName() {
|
||||
return implClassAName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";implClassAName=" + implClassAName +
|
||||
";intFieldSup=" + intFieldSup;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getIntFieldSup() {
|
||||
return intFieldSup;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setIntFieldSup(int i) {
|
||||
this.intFieldSup = i;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.apache.openjpa.persistence.ManagedInterface;
|
||||
|
||||
@ManagedInterface
|
||||
@Entity
|
||||
public interface ManagedIface {
|
||||
@Id @GeneratedValue
|
||||
public int getId();
|
||||
public void setId(int id);
|
||||
|
||||
public int getIntFieldSup();
|
||||
public void setIntFieldSup(int i);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.apache.openjpa.persistence.ManagedInterface;
|
||||
|
||||
@ManagedInterface
|
||||
@Entity
|
||||
public interface ManagedIface2 {
|
||||
@Id @GeneratedValue
|
||||
public int getId();
|
||||
public void setId(int id);
|
||||
|
||||
public int getIntFieldSup();
|
||||
public void setIntFieldSup(int i);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
@MappedSuperclass
|
||||
public class MappedSuper {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Basic
|
||||
private String name;
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Id=" + id +
|
||||
";Name=" + name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class MidClass extends BaseClass2 {
|
||||
|
||||
@Basic
|
||||
private String midClassName;
|
||||
|
||||
public void setMidClassName(String midClassName) {
|
||||
this.midClassName = midClassName;
|
||||
}
|
||||
|
||||
public String getMidClassName() {
|
||||
return midClassName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";midClassName=" + midClassName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class MidClass2 extends BaseClass5 {
|
||||
|
||||
@Basic
|
||||
private String midClass2Name;
|
||||
|
||||
public void setMidClass2Name(String midClass2Name) {
|
||||
this.midClass2Name = midClass2Name;
|
||||
}
|
||||
|
||||
public String getMidClass2Name() {
|
||||
return midClass2Name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";midClass2Name=" + midClass2Name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
public class MidClass3 extends BaseClass6 {
|
||||
|
||||
private String midClass3Name;
|
||||
|
||||
public void setMidClass3Name(String midClass3Name) {
|
||||
this.midClass3Name = midClass3Name;
|
||||
}
|
||||
|
||||
public String getMidClass2Name() {
|
||||
return midClass3Name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";midClass3Name=" + midClass3Name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassA extends BaseClass {
|
||||
|
||||
@Basic
|
||||
private String classAName;
|
||||
|
||||
public void setClassAName(String classAName) {
|
||||
this.classAName = classAName;
|
||||
}
|
||||
|
||||
public String getClassAName() {
|
||||
return classAName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classAName=" + classAName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassB extends BaseClass {
|
||||
|
||||
@Basic
|
||||
private String classBName;
|
||||
|
||||
public void setClassBName(String classBName) {
|
||||
this.classBName = classBName;
|
||||
}
|
||||
|
||||
public String getClassBName() {
|
||||
return classBName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classBName=" + classBName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassC extends MappedSuper {
|
||||
|
||||
@Basic
|
||||
private String classCName;
|
||||
|
||||
public void setClassCName(String classCName) {
|
||||
this.classCName = classCName;
|
||||
}
|
||||
|
||||
public String getClassAName() {
|
||||
return classCName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classCName=" + classCName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassD extends MappedSuper {
|
||||
|
||||
@Basic
|
||||
private String classDName;
|
||||
|
||||
public void setClassDName(String classDName) {
|
||||
this.classDName = classDName;
|
||||
}
|
||||
|
||||
public String getClassDName() {
|
||||
return classDName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classDName=" + classDName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassE extends MidClass {
|
||||
|
||||
@Basic
|
||||
private String classEName;
|
||||
|
||||
public void setClassEName(String classEName) {
|
||||
this.classEName = classEName;
|
||||
}
|
||||
|
||||
public String getClassEName() {
|
||||
return classEName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classEName=" + classEName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassF extends BaseClass3 implements ManagedIface2 {
|
||||
|
||||
@Basic
|
||||
private String classFName;
|
||||
|
||||
@Basic
|
||||
private int intFieldSup;
|
||||
|
||||
public void setClassFName(String classFName) {
|
||||
this.classFName = classFName;
|
||||
}
|
||||
|
||||
public String getClassFName() {
|
||||
return classFName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classFName=" + classFName +
|
||||
";intFieldSup=" + intFieldSup;
|
||||
}
|
||||
|
||||
public int getIntFieldSup() {
|
||||
return intFieldSup;
|
||||
}
|
||||
|
||||
public void setIntFieldSup(int i) {
|
||||
this.intFieldSup = i;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
@Entity
|
||||
@Inheritance
|
||||
public class SubclassG extends BaseClass4 {
|
||||
|
||||
@Basic
|
||||
private String classGName;
|
||||
|
||||
@Basic
|
||||
private int intFieldSup;
|
||||
|
||||
public void setClassGName(String classGName) {
|
||||
this.classGName = classGName;
|
||||
}
|
||||
|
||||
public String getClassGName() {
|
||||
return classGName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classGName=" + classGName +
|
||||
";intFieldSup=" + intFieldSup;
|
||||
}
|
||||
|
||||
public int getIntFieldSup() {
|
||||
return intFieldSup;
|
||||
}
|
||||
|
||||
public void setIntFieldSup(int i) {
|
||||
this.intFieldSup = i;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class SubclassH extends MidClass2 {
|
||||
|
||||
@Basic
|
||||
private String classHName;
|
||||
|
||||
@Basic
|
||||
private int intFieldSup;
|
||||
|
||||
@OneToOne
|
||||
private BaseClass5 baseclass5;
|
||||
|
||||
public void setClassHName(String classHName) {
|
||||
this.classHName = classHName;
|
||||
}
|
||||
|
||||
public String getClassHName() {
|
||||
return classHName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classHName=" + classHName +
|
||||
";intFieldSup=" + intFieldSup;
|
||||
}
|
||||
|
||||
public int getIntFieldSup() {
|
||||
return intFieldSup;
|
||||
}
|
||||
|
||||
public void setIntFieldSup(int i) {
|
||||
this.intFieldSup = i;
|
||||
}
|
||||
|
||||
public void setBaseclass5(BaseClass5 baseclass5) {
|
||||
this.baseclass5 = baseclass5;
|
||||
}
|
||||
|
||||
public BaseClass5 getBaseclass5() {
|
||||
return baseclass5;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class SubclassI extends AbstractClass {
|
||||
|
||||
@Basic
|
||||
private String classIName;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
public void setClassIName(String classIName) {
|
||||
this.classIName = classIName;
|
||||
}
|
||||
|
||||
public String getClassIName() {
|
||||
return classIName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classIName=" + classIName +
|
||||
";Version=" + version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class SubclassJ extends AbstractClass {
|
||||
|
||||
@Basic
|
||||
private String classJName;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
public void setClassJName(String classJName) {
|
||||
this.classJName = classJName;
|
||||
}
|
||||
|
||||
public String getClassJName() {
|
||||
return classJName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classJName=" + classJName +
|
||||
";Version=" + version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.entity;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class SubclassK extends MidClass3 {
|
||||
|
||||
@Basic
|
||||
private String classKName;
|
||||
|
||||
public void setClassKName(String classKName) {
|
||||
this.classKName = classKName;
|
||||
}
|
||||
|
||||
public String getClassKName() {
|
||||
return classKName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ";classKName=" + classKName;
|
||||
}
|
||||
}
|
|
@ -226,7 +226,8 @@ public abstract class PersistenceTestCase
|
|||
em.getTransaction().begin();
|
||||
for (ClassMetaData meta : types) {
|
||||
if (!meta.isMapped() || meta.isEmbeddedOnly()
|
||||
|| Modifier.isAbstract(meta.getDescribedType().getModifiers()))
|
||||
|| Modifier.isAbstract(meta.getDescribedType().getModifiers())
|
||||
&& !isBaseManagedInterface(meta, types))
|
||||
continue;
|
||||
em.createQuery("DELETE FROM " + meta.getTypeAlias() + " o").
|
||||
executeUpdate();
|
||||
|
@ -242,6 +243,50 @@ public abstract class PersistenceTestCase
|
|||
ClassMetaData meta = JPAFacadeHelper.getMetaData(emf, c);
|
||||
return (meta == null) ? null : meta.getTypeAlias();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if the class assocated with the provided metadata is
|
||||
* a managed interface and does not extend another managed interface.
|
||||
* @param meta class metadata for the class to examine
|
||||
* @param types array of class meta data for persistent types
|
||||
* @return true if the cmd is for an interface and the interface does not
|
||||
* extend another managed interface
|
||||
*/
|
||||
private boolean isBaseManagedInterface(ClassMetaData meta,
|
||||
ClassMetaData... types) {
|
||||
|
||||
if (Modifier.isInterface(meta.getDescribedType().getModifiers()) &&
|
||||
!isExtendedManagedInterface(meta, types))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the class assocated with the provided metadata is
|
||||
* an interface and if it extends another managed interface.
|
||||
* @param meta class metadata for the class to examine
|
||||
* @param types array of class meta data for persistent types
|
||||
* @return true if the cmd is for an interface and the interface extends
|
||||
* another managed interface
|
||||
*/
|
||||
private boolean isExtendedManagedInterface(ClassMetaData meta,
|
||||
ClassMetaData... types) {
|
||||
|
||||
if (!Modifier.isInterface(meta.getDescribedType().getModifiers()))
|
||||
return false;
|
||||
|
||||
// Run through the interface this class extends. If any of them
|
||||
// are managed/have class metadata, return true.
|
||||
Class[] ifaces = meta.getDescribedType().getInterfaces();
|
||||
for (int i = 0; ifaces != null && i < ifaces.length; i++) {
|
||||
for (ClassMetaData meta2 : types) {
|
||||
if (ifaces[i].equals(meta2.getDescribedType()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void assertNotEquals(Object o1, Object o2) {
|
||||
if (o1 == o2)
|
||||
|
|
Loading…
Reference in New Issue