Search in sources :

Example 1 with JPAMetaDataManager

use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.

the class AnnotationPlusXMLTest 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 2 with JPAMetaDataManager

use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.

the class AnnotationPlusXMLTest method testOneToOneBi.

/**
 * Test of 1-1 bi 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_AX_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_AX_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 3 with JPAMetaDataManager

use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.

the class AnnotationPlusXMLTest 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);
    assertEquals("LoginAccount has incorrect table name", cmd1.getTable(), "JPA_AX_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_AX_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)

Example 4 with JPAMetaDataManager

use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.

the class AnnotationPlusXMLTest method testTableGenerator.

/**
 * Test of JPA <table-generator>
 */
public void testTableGenerator() {
    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(Employee.class.getName(), clr);
    PackageMetaData pmd = cmd1.getPackageMetaData();
    assertEquals("Number of TableGenerators registered for Employee class is wrong", pmd.getNoOfTableGenerators(), 1);
    TableGeneratorMetaData tgmd = pmd.getTableGenerators()[0];
    assertEquals("TableGenerator has incorrect name", tgmd.getName(), "EmployeeGenerator");
    assertEquals("TableGenerator has incorrect table", tgmd.getTableName(), "ID_TABLE");
    assertEquals("TableGenerator has incorrect pk column name", tgmd.getPKColumnName(), "TYPE");
    assertEquals("TableGenerator has incorrect value column name", tgmd.getValueColumnName(), "LATEST_VALUE");
    assertEquals("TableGenerator has incorrect pk column value", tgmd.getPKColumnValue(), "EMPLOYEE");
    assertEquals("TableGenerator has incorrect initial value", tgmd.getInitialValue(), 0);
    assertEquals("TableGenerator has incorrect allocation size", tgmd.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) TableGeneratorMetaData(org.datanucleus.metadata.TableGeneratorMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 5 with JPAMetaDataManager

use of org.datanucleus.api.jpa.metadata.JPAMetaDataManager in project tests by datanucleus.

the class AnnotationTest method testSecondaryTable.

/**
 * Test for use of annotations for secondary tables, in particular @SecondaryTable.
 * Uses Printer class, storing some fields in table "PRINTER" and some in "PRINTER_TONER".
 */
public void testSecondaryTable() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Printer.class.getName(), clr);
    assertEquals("detachable is wrong", cmd.isDetachable(), true);
    assertEquals("identity-type is wrong", cmd.getIdentityType(), IdentityType.APPLICATION);
    assertEquals("embedded-only is wrong", cmd.isEmbeddedOnly(), false);
    assertEquals("requires-extent is wrong", cmd.isRequiresExtent(), true);
    assertNull("catalog is wrong", cmd.getCatalog());
    assertNull("schema is wrong", cmd.getSchema());
    assertEquals("table is wrong", cmd.getTable(), "JPA_AN_PRINTER");
    assertEquals("has incorrect number of persistent fields", cmd.getNoOfManagedMembers(), 5);
    // Check JoinMetaData at class-level
    List<JoinMetaData> joinmds = cmd.getJoinMetaData();
    assertNotNull("JoinMetaData at class-level is null!", joinmds);
    assertEquals("Number of JoinMetaData at class-level is wrong!", joinmds.size(), 1);
    assertEquals("Table of JoinMetaData at class-level is wrong", "JPA_AN_PRINTER_TONER", joinmds.get(0).getTable());
    ColumnMetaData[] joinColmds = joinmds.get(0).getColumnMetaData();
    assertEquals("Number of columns with MetaData in secondary table is incorrect", 1, joinColmds.length);
    assertEquals("Column of JoinMetaData at class-level is wrong", joinColmds[0].getName(), "PRINTER_ID");
    // "model" (stored in primary-table)
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("model");
    assertNotNull("Doesnt have required field", fmd);
    assertNull("Field 'model' has non-null table!", fmd.getTable());
    // "tonerModel" (stored in secondary-table)
    fmd = cmd.getMetaDataForMember("tonerModel");
    assertNotNull("Doesnt have required field", fmd);
    assertEquals("Field 'tonerModel' has non-null table!", fmd.getTable(), "JPA_AN_PRINTER_TONER");
}
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) JoinMetaData(org.datanucleus.metadata.JoinMetaData) ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)51 NucleusContext (org.datanucleus.NucleusContext)51 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)51 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 ClassMetaData (org.datanucleus.metadata.ClassMetaData)51 MetaDataManager (org.datanucleus.metadata.MetaDataManager)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)38 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)29 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)12 ElementMetaData (org.datanucleus.metadata.ElementMetaData)12 JoinMetaData (org.datanucleus.metadata.JoinMetaData)10 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)7 PackageMetaData (org.datanucleus.metadata.PackageMetaData)6 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 QueryMetaData (org.datanucleus.metadata.QueryMetaData)2 QueryResultMetaData (org.datanucleus.metadata.QueryResultMetaData)2