Search in sources :

Example 76 with ClassMetaData

use of org.datanucleus.metadata.ClassMetaData 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)

Example 77 with ClassMetaData

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

the class AnnotationTest 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_AN_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_AN_PETROL_CUST_SUPP");
    // non-owner side
    ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(PetroleumSupplier.class.getName(), clr);
    assertEquals("Supplier has incorrect table name", cmd2.getTable(), "JPA_AN_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 78 with ClassMetaData

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

the class AnnotationTest method testOrderBy.

/**
 * Test of @OrderBy.
 */
public void testOrderBy() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(UserGroup.class.getName(), clr);
    OrderMetaData omd = cmd1.getMetaDataForMember("members").getOrderMetaData();
    assertNotNull("UserGroup.members has no OrderMetaData!", omd);
    FieldOrder[] orderTerms = omd.getFieldOrders();
    assertFalse("UserGroup.members is not marked as using an ordered list", omd.isIndexedList());
    assertNotNull("UserGroup.members has null field ordering info", orderTerms);
    assertEquals("UserGroup.members has incorrect number of field ordering terms", orderTerms.length, 1);
    assertEquals("UserGroup.members has incorrect field ordering field-name", orderTerms[0].getFieldName(), "name");
    assertTrue("UserGroup.members has incorrect field ordering direction", orderTerms[0].isForward());
}
Also used : OrderMetaData(org.datanucleus.metadata.OrderMetaData) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) FieldOrder(org.datanucleus.metadata.OrderMetaData.FieldOrder) 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 79 with ClassMetaData

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

the class AnnotationTest method testEmbeddedId.

/**
 * Test of basic JPA @EmbeddedId.
 */
public void testEmbeddedId() {
    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(Department.class.getName(), clr);
    assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
}
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 80 with ClassMetaData

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

the class AnnotationTest method testOneToOneUni.

/**
 * Test of JPA 1-1 unidir relation
 */
public void testOneToOneUni() {
    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(LoginAccount.class.getName(), clr);
    assertEquals("LoginAccount has incorrect table name", cmd1.getTable(), "JPA_AN_LOGINACCOUNT");
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("login");
    assertNotNull("LoginAccount.login is null!", fmd1);
    assertEquals("LoginAccount.login mapped-by is incorrect", fmd1.getMappedBy(), null);
    assertEquals("LoginAccount.login relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_ONE_UNI);
    assertNotNull("LoginAccount.login has no column info", fmd1.getColumnMetaData());
    assertEquals("LoginAccount.login has incorrect number of columns", fmd1.getColumnMetaData().length, 1);
    assertEquals("LoginAccount.login column name is wrong", fmd1.getColumnMetaData()[0].getName(), "LOGIN_ID");
    ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Login.class.getName(), clr);
    assertEquals("LoginAccount has incorrect table name", cmd2.getTable(), "JPA_AN_LOGIN");
}
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) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Aggregations

ClassMetaData (org.datanucleus.metadata.ClassMetaData)109 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)55 MetaDataManager (org.datanucleus.metadata.MetaDataManager)55 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)53 NucleusContext (org.datanucleus.NucleusContext)52 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)51 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)38 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)18 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)14 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)14 ElementMetaData (org.datanucleus.metadata.ElementMetaData)14 JoinMetaData (org.datanucleus.metadata.JoinMetaData)14 PackageMetaData (org.datanucleus.metadata.PackageMetaData)14 Label (org.datanucleus.enhancer.asm.Label)6 FileMetaData (org.datanucleus.metadata.FileMetaData)6 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)6 PropertyMetaData (org.datanucleus.metadata.PropertyMetaData)6 KeyMetaData (org.datanucleus.metadata.KeyMetaData)5 MapMetaData (org.datanucleus.metadata.MapMetaData)5