Search in sources :

Example 46 with PersistenceUnitMetaData

use of org.datanucleus.metadata.PersistenceUnitMetaData in project tests by datanucleus.

the class XMLTest method testOneToManyBiFK.

/**
 * Test of JPA 1-N bidir FK relation
 */
public void testOneToManyBiFK() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
    metaDataMgr.loadPersistenceUnit(pumd, null);
    // owner side
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("departments");
    assertNotNull("Manager.departments is null!", fmd1);
    assertEquals("Manager.departments mapped-by is incorrect", fmd1.getMappedBy(), "manager");
    assertEquals("Manager.departments relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_BI);
    ElementMetaData elemmd = fmd1.getElementMetaData();
    assertNull("Manager.departments has join column info but shouldnt (specified on N side)", elemmd);
    // non-owner side
    ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
    AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("manager");
    assertNotNull("Department.manager is null!", fmd2);
    assertEquals("Department.manager mapped-by is incorrect", fmd2.getMappedBy(), null);
    assertEquals("Department.manager relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_ONE_BI);
    ColumnMetaData[] colmds = fmd2.getColumnMetaData();
    assertNotNull("Department.manager has no join column info", colmds);
    assertEquals("Department.manager has incorrect number of joincolumns", colmds.length, 1);
    assertEquals("Department.manager joincolumn name is wrong", "MGR_ID", colmds[0].getName());
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) ElementMetaData(org.datanucleus.metadata.ElementMetaData) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 47 with PersistenceUnitMetaData

use of org.datanucleus.metadata.PersistenceUnitMetaData in project tests by datanucleus.

the class XMLTest method testOneToManyUniMapFK.

/**
 * Test of JPA 1-N unidir Map relation.
 */
public void testOneToManyUniMapFK() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
    metaDataMgr.loadPersistenceUnit(pumd, null);
    // owner side
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("phoneNumbers");
    assertNotNull("Department.phoneNumbers is null!", fmd1);
    assertEquals("Department.phoneNumbers mapped-by is incorrect", fmd1.getMappedBy(), null);
    assertEquals("Department.phoneNumbers relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_UNI);
    assertEquals("Department.phoneNumbers jointable name is incorrect", fmd1.getTable(), null);
    MapMetaData mmd = fmd1.getMap();
    assertNotNull("Department.phoneNumbers has no Map metadata!", mmd);
    KeyMetaData keymd = fmd1.getKeyMetaData();
    assertNotNull("Department.phoneNumbers has no Key metadata!", keymd);
    assertEquals("Department.phoneNumbers has incorrect key mapped-by", keymd.getMappedBy(), "name");
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) KeyMetaData(org.datanucleus.metadata.KeyMetaData) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) MapMetaData(org.datanucleus.metadata.MapMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 48 with PersistenceUnitMetaData

use of org.datanucleus.metadata.PersistenceUnitMetaData in project tests by datanucleus.

the class XMLTest method testSequenceGenerator.

/**
 * Test of JPA <sequence-generator>
 */
public void testSequenceGenerator() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
    metaDataMgr.loadPersistenceUnit(pumd, null);
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
    PackageMetaData pmd = cmd1.getPackageMetaData();
    assertEquals("Number of Sequences registered for Department class is wrong", pmd.getNoOfSequences(), 1);
    SequenceMetaData seqmd = pmd.getSequences()[0];
    assertEquals("SequenceGenerator has incorrect name", seqmd.getName(), "DepartmentGenerator");
    assertEquals("SequenceGenerator has incorrect sequence name", seqmd.getDatastoreSequence(), "DEPT_SEQ");
    assertEquals("SequenceGenerator has incorrect initial value", seqmd.getInitialValue(), 1);
    assertEquals("SequenceGenerator has incorrect allocation size", seqmd.getAllocationSize(), 50);
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) PackageMetaData(org.datanucleus.metadata.PackageMetaData) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) SequenceMetaData(org.datanucleus.metadata.SequenceMetaData)

Aggregations

PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)48 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)40 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)40 NucleusContext (org.datanucleus.NucleusContext)39 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)38 ClassMetaData (org.datanucleus.metadata.ClassMetaData)38 MetaDataManager (org.datanucleus.metadata.MetaDataManager)38 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)23 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 JoinMetaData (org.datanucleus.metadata.JoinMetaData)9 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)6 PackageMetaData (org.datanucleus.metadata.PackageMetaData)6 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)4 EventListenerMetaData (org.datanucleus.metadata.EventListenerMetaData)3 KeyMetaData (org.datanucleus.metadata.KeyMetaData)3 MapMetaData (org.datanucleus.metadata.MapMetaData)3 SequenceMetaData (org.datanucleus.metadata.SequenceMetaData)3 TableGeneratorMetaData (org.datanucleus.metadata.TableGeneratorMetaData)3 ArrayList (java.util.ArrayList)2 PersistenceManager (javax.jdo.PersistenceManager)2