Search in sources :

Example 51 with ClassMetaData

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

the class AnnotationPlusXMLTest method testPersistent.

/**
 * Test of @Persistent on a field.
 */
public void testPersistent() {
    // Person
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    // "bestFriend" - explicitly set
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("bestFriend");
    assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
    // "lastName" - not annotated, but default
    fmd = cmd.getMetaDataForMember("lastName");
    assertNotNull(prefix + "doesnt have required field", fmd);
    assertEquals(prefix + "should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 52 with ClassMetaData

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

the class AnnotationPlusXMLTest method testValueStrategy.

/**
 * Test of @Persistent(primaryKey="true", valueStrategy=IDENTITY) on a field.
 */
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());
    assertEquals(prefix + "pk value strategy incorrect", ValueGenerationStrategy.IDENTITY, fmd.getValueStrategy());
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 53 with ClassMetaData

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

the class AnnotationTest method testCollectionJoinTable.

/**
 * Test for use of collection with join table
 */
public void testCollectionJoinTable() {
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
    String prefix = cmd1.getFullClassName() + " : ";
    AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("subordinates");
    assertNotNull(prefix + "doesnt have required field", fmd);
    CollectionMetaData colmd = fmd.getCollection();
    assertNotNull(prefix + "CollectionMetaData is null!", colmd);
    assertEquals(prefix + "CollectionMetaData elementType is incorrect", Employee.class.getName(), colmd.getElementType());
    JoinMetaData joinmd = fmd.getJoinMetaData();
    assertNotNull(prefix + "field \"subordinates\" has no join information!", joinmd);
    assertEquals(prefix + "field \"subordinates\" is stored in wrong table", "MANAGER_EMPLOYEES", fmd.getTable());
    assertEquals(prefix + "field \"subordinates\" join table has incorrect column", "MANAGER_ID", joinmd.getColumnName());
}
Also used : Employee(org.datanucleus.samples.annotations.models.company.Employee) JoinMetaData(org.datanucleus.metadata.JoinMetaData) CollectionMetaData(org.datanucleus.metadata.CollectionMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 54 with ClassMetaData

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

the class AnnotationTest method testStrategyValue.

/**
 * Test of basic JDO strategy value
 */
public void testStrategyValue() {
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    assertEquals(ValueGenerationStrategy.INCREMENT, cmd1.getMetaDataForMember("personNum").getValueStrategy());
}
Also used : ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 55 with ClassMetaData

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

the class AnnotationTest method testIndexOnField.

/**
 * Test of Index at field level
 */
public void testIndexOnField() {
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("age");
    assertNotNull("JDOPerson.age metadata should have had an Index constraint but didnt", fmd.getIndexMetaData());
    IndexMetaData idxmd = fmd.getIndexMetaData();
    assertEquals("PERSON_AGE_IDX", idxmd.getName());
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) IndexMetaData(org.datanucleus.metadata.IndexMetaData)

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