Search in sources :

Example 16 with NucleusContext

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

the class AnnotationTest method testMapKeyColumn.

/**
 * Test of persistent properties using annotations.
 */
/*public void testPersistentProperties()
    {
        NucleusContext nucleusCtx = new NucleusContext("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(JPAGetter.class.getName(), clr);
        assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
    }*/
/**
 * Test of column name for property instead of field
 */
/*public void testPropertyColumName()
    {
        NucleusContext nucleusCtx = new NucleusContext("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(Employee.class.getName(), clr);

        // it is valid according JPA to have property accessor instead of field accessors. property accessors are persistent while field not.
        assertNotNull("Employee.lastName has no field information", cmd1.getMetaDataForMember("lastName"));
        assertNotNull("Employee.lastName has no column information", cmd1.getMetaDataForMember("lastName").getColumnMetaData());
        assertEquals("Employee.lastName has incorrect number of columns", 
            1, cmd1.getMetaDataForMember("lastName").getColumnMetaData().length);
        assertEquals("Employee.last has incorrect column spec", 
            "LASTNAME", cmd1.getMetaDataForMember("lastName").getColumnMetaData()[0].getName());

        ClassMetaData cmd2 = (ClassMetaData)metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);

        // it is valid according JPA to have property accessor instead of field accessors. property accessors are persistent while field not.
        assertNotNull(cmd2.getMetaDataForMember("age"));
        assertNotNull("AGE_COL",cmd2.getMetaDataForMember("age").getColumnMetaData()[0].getName());
        assertNotNull(cmd2.getMetaDataForMember("maidenName"));
        assertEquals(FieldPersistenceModifier.NONE,cmd2.getMetaDataForMember("_maidenName").getPersistenceModifier());
        assertEquals(FieldPersistenceModifier.PERSISTENT,cmd2.getMetaDataForMember("maidenName").getPersistenceModifier());
    }*/
/**
 * Test of JPA @MapKeyColumn.
 */
public void testMapKeyColumn() {
    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(Person.class.getName(), clr);
    assertEquals("phoneNumbers_key1", cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().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 17 with NucleusContext

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

the class AnnotationTest method testByteArrayEmbeddedByDefault.

/**
 * Test of JPA Byte[] is embedded by default
 */
public void testByteArrayEmbeddedByDefault() {
    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(ByteArray.class.getName(), clr);
    assertTrue(cmd1.getMetaDataForMember("array1").isEmbedded());
}
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 18 with NucleusContext

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

the class AnnotationTest method testOneToOneBi.

/**
 * Test of JPA 1-1 bidir relation
 */
public void testOneToOneBi() {
    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);
    // non-owner side
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Boiler.class.getName(), clr);
    assertEquals("Boiler has incorrect table name", "JPA_AN_BOILER", cmd1.getTable());
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("timer");
    assertNotNull("Boiler.timer is null!", fmd1);
    assertEquals("Boiler.timer mapped-by is incorrect", "boiler", fmd1.getMappedBy());
    assertEquals("Boiler.timer relationType is incorrect", RelationType.ONE_TO_ONE_BI, fmd1.getRelationType(clr));
    // owner side
    ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Timer.class.getName(), clr);
    assertEquals("Timer has incorrect table name", "JPA_AN_TIMER", cmd2.getTable());
    AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("boiler");
    assertNotNull("Timer.boiler is null!", fmd2);
    assertEquals("Timer.boiler mapped-by is incorrect", null, fmd2.getMappedBy());
    assertEquals("Timer.boiler relationType is incorrect", RelationType.ONE_TO_ONE_BI, fmd2.getRelationType(clr));
    assertNotNull("Timer.boiler has no column info", fmd2.getColumnMetaData());
    assertEquals("Timer.boiler has incorrect number of columns", 1, fmd2.getColumnMetaData().length);
    assertEquals("Timer.boiler column name is wrong", "BOILER_ID", fmd2.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) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 19 with NucleusContext

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

the class XMLTest method testOneToOneUni.

/**
 * Test of 1-1 uni 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);
    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");
}
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)

Example 20 with NucleusContext

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

the class XMLTest 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_MD_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)

Aggregations

NucleusContext (org.datanucleus.NucleusContext)78 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)68 MetaDataManager (org.datanucleus.metadata.MetaDataManager)65 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)59 ClassMetaData (org.datanucleus.metadata.ClassMetaData)52 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)39 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)32 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)15 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)14 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)10 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ArrayList (java.util.ArrayList)7 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)7 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)7 PackageMetaData (org.datanucleus.metadata.PackageMetaData)7 MetaDataParser (org.datanucleus.metadata.xml.MetaDataParser)7 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)7 IOException (java.io.IOException)4