Search in sources :

Example 46 with ClassMetaData

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

the class AnnotationTest method testFetchGroups.

/**
 * Test for use of annotations with fetch groups
 */
public void testFetchGroups() {
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd1.getFullClassName() + " : ";
    Set<FetchGroupMetaData> fgmds = cmd1.getFetchGroupMetaData();
    assertNotNull(prefix + "fetch group info is incorrect", fgmds);
    FetchGroupMetaData fgmd = fgmds.iterator().next();
    assertEquals(prefix + "fetch group name incorrect", "names", fgmd.getName());
    assertFalse(prefix + "fetch group fields incorrect", fgmd.getPostLoad());
    Set<FetchGroupMemberMetaData> fgmmds = fgmd.getMembers();
    assertNotNull(fgmmds);
    assertEquals(prefix + "number of fetch group fields is wrong", 2, fgmmds.size());
    Iterator<FetchGroupMemberMetaData> fgmmdIter = fgmmds.iterator();
    FetchGroupMemberMetaData fgmmd0 = fgmmdIter.next();
    FetchGroupMemberMetaData fgmmd1 = fgmmdIter.next();
    assertTrue(prefix + "fields in fetch group are incorrect", (fgmmd0.getName().equals("firstName") && fgmmd1.getName().equals("lastName")) || (fgmmd1.getName().equals("firstName") && fgmmd0.getName().equals("lastName")));
}
Also used : FetchGroupMemberMetaData(org.datanucleus.metadata.FetchGroupMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) FetchGroupMetaData(org.datanucleus.metadata.FetchGroupMetaData)

Example 47 with ClassMetaData

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

Example 48 with ClassMetaData

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

the class AnnotationPlusXMLOverrideTest method testDefaultFetchGroup.

/**
 * Test enabling forgotten DFG on a field in "package.jdo".
 */
public void testDefaultFetchGroup() {
    // Department
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    // "manager"
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("manager");
    assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
    assertTrue(prefix + "dfg is wrong", fmd.isDefaultFetchGroup());
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 49 with ClassMetaData

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

the class AnnotationPlusXMLOverrideTest method testValueStrategy.

/* Overriding features (required use-cases) ----------------------------- */
/**
 * Test of @Persistent(primaryKey="true", valueStrategy=SEQUENCE) on a field,
 * where annotation is set to NATIVE - which is the default anyway.
 */
public void testValueStrategy() {
    // Account
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Account.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    assertEquals(prefix + "number of PK members is wrong", 1, cmd.getNoOfPrimaryKeyMembers());
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("id");
    assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
    assertTrue(prefix + "pk is wrong", fmd.isPrimaryKey());
    // package.orm (overriding) - Annotation: NATIVE, .jdo: IDENTITY
    assertEquals(prefix + "PK value strategy incorrect", ValueGenerationStrategy.SEQUENCE, fmd.getValueStrategy());
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 50 with ClassMetaData

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

the class AnnotationPlusXMLTest method testColumn.

/**
 * Check explicit column information in "package.jdo" and/or "package.orm".
 */
public void testColumn() {
    // Person
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    // "lastName"
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("lastName");
    ColumnMetaData[] colmds = fmd.getColumnMetaData();
    assertEquals(prefix + "column identifier incorrect", "LASTNAME", colmds[0].getName());
    assertEquals(prefix + "column length incorrect", new Integer(64), colmds[0].getLength());
    assertEquals(prefix + "column JDBC type incorrect", JdbcType.VARCHAR, colmds[0].getJdbcType());
    // "firstName"
    fmd = cmd.getMetaDataForMember("firstName");
    colmds = fmd.getColumnMetaData();
    assertEquals(prefix + "column identifier incorrect", "FIRSTNAME", colmds[0].getName());
    assertEquals(prefix + "column length incorrect", new Integer(32), colmds[0].getLength());
    assertEquals(prefix + "column JDBC type incorrect", JdbcType.VARCHAR, colmds[0].getJdbcType());
    // "emailAddress"
    fmd = cmd.getMetaDataForMember("emailAddress");
    colmds = fmd.getColumnMetaData();
    assertEquals(prefix + "column identifier incorrect", "EMAILADDRESS", colmds[0].getName());
    assertEquals(prefix + "column length incorrect", new Integer(128), colmds[0].getLength());
    assertEquals(prefix + "column JDBC type incorrect", JdbcType.VARCHAR, colmds[0].getJdbcType());
    // "dateOfBirth"
    fmd = cmd.getMetaDataForMember("dateOfBirth");
    colmds = fmd.getColumnMetaData();
    assertEquals("column identifier incorrect", "DATEOFBIRTH", colmds[0].getName());
    assertEquals("column JDBC type incorrect", JdbcType.TIMESTAMP, colmds[0].getJdbcType());
    // package.orm (additional)
    Map<String, String> extmds = fmd.getExtensions();
    assertNotNull(prefix + "extension info is null!", extmds);
    assertEquals(prefix + "incorrect number of extensions", 1, extmds.size());
    assertTrue("extension not present", extmds.containsKey("insert-function"));
    assertEquals("extension value is incorrect", "CURRENT_TIMESTAMP", extmds.get("insert-function"));
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) 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