Search in sources :

Example 36 with ColumnMetaData

use of org.datanucleus.metadata.ColumnMetaData in project datanucleus-api-jdo by datanucleus.

the class DiscriminatorMetadataImpl method getColumns.

/* (non-Javadoc)
     * @see javax.jdo.metadata.DiscriminatorMetadata#getColumns()
     */
public ColumnMetadata[] getColumns() {
    ColumnMetaData internalColmd = getInternal().getColumnMetaData();
    if (internalColmd == null) {
        return null;
    }
    ColumnMetadataImpl[] colmds = new ColumnMetadataImpl[1];
    colmds[0] = new ColumnMetadataImpl(internalColmd);
    colmds[0].parent = this;
    return colmds;
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData)

Example 37 with ColumnMetaData

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

Example 38 with ColumnMetaData

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

the class AnnotationTest 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 39 with ColumnMetaData

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

Example 40 with ColumnMetaData

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

the class AnnotationTest method testPrimaryKeyColumns.

/**
 * Test for use of annotations to define PK columns, overriding those of the superclass
 */
public void testPrimaryKeyColumns() {
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
    String prefix = cmd1.getFullClassName() + " : ";
    PrimaryKeyMetaData pkmd = cmd1.getPrimaryKeyMetaData();
    assertNotNull(prefix + "has null primary-key metadata!", pkmd);
    assertNotNull(prefix + "has no primary-key columns!", pkmd.getColumnMetaData());
    assertEquals(prefix + "has incorrect no of PK columns", 2, pkmd.getColumnMetaData().length);
    ColumnMetaData[] colmds = pkmd.getColumnMetaData();
    assertEquals("Name of first col of pk is incorrect", "MGR_ID", colmds[0].getName());
    assertEquals("Target of first col of pk is incorrect", "PERSON_ID", colmds[0].getTarget());
    assertEquals("Name of second col of pk is incorrect", "MGR_GLOBAL_ID", colmds[1].getName());
    assertEquals("Target of second col of pk is incorrect", "PERSON_GLOB_ID", colmds[1].getTarget());
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) PrimaryKeyMetaData(org.datanucleus.metadata.PrimaryKeyMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Aggregations

ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)85 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)28 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)16 ClassMetaData (org.datanucleus.metadata.ClassMetaData)14 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)13 ElementMetaData (org.datanucleus.metadata.ElementMetaData)13 DatastoreIdentifier (org.datanucleus.store.rdbms.identifier.DatastoreIdentifier)11 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)10 JoinMetaData (org.datanucleus.metadata.JoinMetaData)9 MetaDataManager (org.datanucleus.metadata.MetaDataManager)9 MappingManager (org.datanucleus.store.rdbms.mapping.MappingManager)8 Column (org.datanucleus.store.rdbms.table.Column)8 NucleusContext (org.datanucleus.NucleusContext)7 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)7 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)7 PrimaryKeyMetaData (org.datanucleus.metadata.PrimaryKeyMetaData)7 IdentifierFactory (org.datanucleus.store.rdbms.identifier.IdentifierFactory)7 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)7 DiscriminatorMetaData (org.datanucleus.metadata.DiscriminatorMetaData)6 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)6