Search in sources :

Example 51 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class AnnotationPlusXMLTest 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 52 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class AnnotationPlusXMLTest method testManyToMany.

/**
 * Test of JPA M-N relation
 */
public void testManyToMany() {
    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(PetroleumCustomer.class.getName(), clr);
    assertEquals("Customer has incorrect table name", cmd1.getTable(), "JPA_AX_PETROL_CUSTOMER");
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("suppliers");
    assertNotNull("Customer.suppliers is null!", fmd1);
    assertEquals("Customer.suppliers mapped-by is incorrect", fmd1.getMappedBy(), "customers");
    assertEquals("Customer.suppliers relationType is incorrect", fmd1.getRelationType(clr), RelationType.MANY_TO_MANY_BI);
    assertEquals("Customer.suppliers jointable name is incorrect", fmd1.getTable(), "JPA_AX_PETROL_CUST_SUPP");
    // non-owner side
    ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(PetroleumSupplier.class.getName(), clr);
    assertEquals("Supplier has incorrect table name", cmd2.getTable(), "JPA_AX_PETROL_SUPPLIER");
    AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("customers");
    assertNotNull("Supplier.customers is null!", fmd2);
    assertEquals("Supplier.customers mapped-by is incorrect", fmd2.getMappedBy(), null);
    assertEquals("Supplier.customers relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_MANY_BI);
    assertEquals("Supplier.customers jointable name is incorrect", fmd2.getTable(), null);
    // join table info
    JoinMetaData joinmd = fmd1.getJoinMetaData();
    assertNotNull("Customer.suppliers has no join table!", joinmd);
    assertNotNull("Customer.suppliers has incorrect join columns", joinmd.getColumnMetaData());
    assertEquals("Customer.suppliers has incorrect number of join columns", joinmd.getColumnMetaData().length, 1);
    assertEquals("Customer.suppliers has incorrect owner join column name", joinmd.getColumnMetaData()[0].getName(), "CUSTOMER_ID");
    ElementMetaData elemmd = fmd1.getElementMetaData();
    assertNotNull("Customer.suppliers has no element column info but should", elemmd);
    assertNotNull("Customer.suppliers has incorrect element columns", elemmd.getColumnMetaData());
    assertEquals("Customer.suppliers has incorrect number of element columns", elemmd.getColumnMetaData().length, 1);
    assertEquals("Customer.suppliers has incorrect element join column name", elemmd.getColumnMetaData()[0].getName(), "SUPPLIER_ID");
}
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) JoinMetaData(org.datanucleus.metadata.JoinMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 53 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class AnnotationPlusXMLTest method testOneToManyUniJoin.

/**
 * Test of JPA 1-N unidir JoinTable relation
 */
public void testOneToManyUniJoin() {
    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(Department.class.getName(), clr);
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("projects");
    assertNotNull("Department.projects is null!", fmd1);
    assertEquals("Department.projects mapped-by is incorrect", null, fmd1.getMappedBy());
    assertEquals("Department.projects relationType is incorrect", RelationType.ONE_TO_MANY_UNI, fmd1.getRelationType(clr));
    assertEquals("Department.projects jointable name is incorrect", "JPA_AX_DEPT_PROJECTS", fmd1.getTable());
    JoinMetaData joinmd = fmd1.getJoinMetaData();
    assertNotNull("Department.projects has no join table!", joinmd);
    assertNotNull("Department.projects has incorrect join columns", joinmd.getColumnMetaData());
    assertEquals("Department.projects has incorrect number of join columns", 1, joinmd.getColumnMetaData().length);
    assertEquals("Department.projects has incorrect join column name", joinmd.getColumnMetaData()[0].getName(), "DEPT_ID");
    ElementMetaData elemmd = fmd1.getElementMetaData();
    assertNotNull("Department.projects has no element column info but should", elemmd);
    ColumnMetaData[] colmds = elemmd.getColumnMetaData();
    assertNotNull("Department.projects has incorrect element columns", colmds);
    assertEquals("Department.projects has incorrect number of element columns", 1, colmds.length);
    assertEquals("Department.projects has incorrect element column name", "PROJECT_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) JoinMetaData(org.datanucleus.metadata.JoinMetaData) ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 54 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class AnnotationTest method testEmbeddable.

/**
 * Test of JPA @Embeddable.
 */
public void testEmbeddable() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    // Retrieve the metadata from the MetaDataManager (populates and initialises everything)
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(DepartmentPK.class.getName(), clr);
    assertNotNull(cmd1);
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) ClassMetaData(org.datanucleus.metadata.ClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 55 with PersistenceNucleusContextImpl

use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.

the class AnnotationTest method testIdClassAccessors.

/**
 * Test of JPA @IdClass with pk using acessors.
 */
public void testIdClassAccessors() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(IdClassAccessors.class.getName(), clr);
    assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
    assertTrue(cmd1.getAbsolutePositionOfMember("free") >= 0);
    assertEquals("FFFF", cmd1.getMetaDataForManagedMemberAtAbsolutePosition(cmd1.getRelativePositionOfMember("free")).getColumnMetaData()[0].getName());
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) ClassMetaData(org.datanucleus.metadata.ClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)86 MetaDataManager (org.datanucleus.metadata.MetaDataManager)69 NucleusContext (org.datanucleus.NucleusContext)59 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)56 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 ClassMetaData (org.datanucleus.metadata.ClassMetaData)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)40 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)35 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)32 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)29 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)18 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)7 MetaDataParser (org.datanucleus.metadata.xml.MetaDataParser)7 PackageMetaData (org.datanucleus.metadata.PackageMetaData)6 FetchPlan (org.datanucleus.FetchPlan)5 FetchPlanForClass (org.datanucleus.FetchPlanForClass)5 JDOFetchPlan (org.datanucleus.api.jdo.JDOFetchPlan)5 ArrayList (java.util.ArrayList)4