Search in sources :

Example 1 with InheritanceMetadata

use of javax.jdo.metadata.InheritanceMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method addHelperClassMetadata.

@Override
public void addHelperClassMetadata(JDOMetadata jdoMetadata, ClassData classData, EntityDto entity, EntityType entityType, Class<?> definition, SchemaHolder schemaHolder) {
    String packageName = ClassName.getPackage(classData.getClassName());
    String simpleName = ClassName.getSimpleName(classData.getClassName());
    String tableName = ClassTableName.getTableName(classData.getClassName(), classData.getModule(), classData.getNamespace(), entity == null ? "" : entity.getTableName(), entityType);
    PackageMetadata pmd = getPackageMetadata(jdoMetadata, packageName);
    ClassMetadata cmd = getClassMetadata(pmd, simpleName);
    cmd.setTable(tableName);
    cmd.setDetachable(true);
    cmd.setIdentityType(IdentityType.APPLICATION);
    cmd.setPersistenceModifier(ClassPersistenceModifier.PERSISTENCE_CAPABLE);
    InheritanceMetadata imd = cmd.newInheritanceMetadata();
    imd.setCustomStrategy("complete-table");
    addIdField(cmd, classData.getClassName(), definition);
    if (entity != null) {
        addMetadataForFields(cmd, classData, entity, entityType, definition, schemaHolder);
    }
}
Also used : ClassMetadata(javax.jdo.metadata.ClassMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata) InheritanceMetadata(javax.jdo.metadata.InheritanceMetadata)

Example 2 with InheritanceMetadata

use of javax.jdo.metadata.InheritanceMetadata in project tests by datanucleus.

the class JDOMetadataAPITest method testInheritanceAndDiscrim.

/**
 * Test for use of annotations with inherited classes and discriminator
 */
public void testInheritanceAndDiscrim() {
    TypeMetadata typemd = pmf.getMetadata(Room.class.getName());
    assertFalse(typemd.getDetachable());
    assertEquals(IdentityType.APPLICATION, typemd.getIdentityType());
    assertFalse(typemd.getEmbeddedOnly());
    assertTrue(typemd.getRequiresExtent());
    InheritanceMetadata inhmd = typemd.getInheritanceMetadata();
    assertNotNull(inhmd);
    assertEquals(InheritanceStrategy.NEW_TABLE, inhmd.getStrategy());
    DiscriminatorMetadata dismd = inhmd.getDiscriminatorMetadata();
    assertNotNull(dismd);
    assertEquals(DiscriminatorStrategy.VALUE_MAP, dismd.getStrategy());
    assertEquals("ROOM", dismd.getValue());
    TypeMetadata typemd2 = pmf.getMetadata(MeetingRoom.class.getName());
    assertFalse(typemd2.getDetachable());
    assertEquals(IdentityType.APPLICATION, typemd2.getIdentityType());
    assertFalse(typemd2.getEmbeddedOnly());
    assertTrue(typemd2.getRequiresExtent());
    InheritanceMetadata inhmd2 = typemd2.getInheritanceMetadata();
    assertNotNull(inhmd2);
    assertEquals(InheritanceStrategy.SUPERCLASS_TABLE, inhmd2.getStrategy());
    DiscriminatorMetadata dismd2 = inhmd2.getDiscriminatorMetadata();
    assertNotNull(dismd2);
    assertEquals(DiscriminatorStrategy.VALUE_MAP, dismd2.getStrategy());
    assertEquals("MEETING_ROOM", dismd2.getValue());
}
Also used : DiscriminatorMetadata(javax.jdo.metadata.DiscriminatorMetadata) TypeMetadata(javax.jdo.metadata.TypeMetadata) MeetingRoom(org.datanucleus.samples.annotations.models.company.MeetingRoom) InheritanceMetadata(javax.jdo.metadata.InheritanceMetadata) MeetingRoom(org.datanucleus.samples.annotations.models.company.MeetingRoom) Room(org.datanucleus.samples.annotations.models.company.Room)

Example 3 with InheritanceMetadata

use of javax.jdo.metadata.InheritanceMetadata in project tests by datanucleus.

the class DynamicEnhanceSchemaToolTest method createMetadata.

private static void createMetadata(JDOMetadata filemd) {
    PackageMetadata pmd = filemd.newPackageMetadata("test");
    ClassMetadata cmd = pmd.newClassMetadata("Client");
    cmd.setTable("CLIENT").setDetachable(true).setIdentityType(javax.jdo.annotations.IdentityType.DATASTORE);
    cmd.setPersistenceModifier(javax.jdo.metadata.ClassPersistenceModifier.PERSISTENCE_CAPABLE);
    FieldMetadata fmd = cmd.newFieldMetadata("name");
    fmd.setNullValue(javax.jdo.annotations.NullValue.DEFAULT).setColumn("name").setIndexed(true).setUnique(true);
    InheritanceMetadata inhmd = cmd.newInheritanceMetadata();
    inhmd.setStrategy(javax.jdo.annotations.InheritanceStrategy.NEW_TABLE);
    DiscriminatorMetadata dmd = inhmd.newDiscriminatorMetadata();
    dmd.setColumn("disc").setValue("Client").setStrategy(javax.jdo.annotations.DiscriminatorStrategy.VALUE_MAP).setIndexed(Indexed.TRUE);
    VersionMetadata vermd = cmd.newVersionMetadata();
    vermd.setStrategy(javax.jdo.annotations.VersionStrategy.VERSION_NUMBER).setColumn("version").setIndexed(Indexed.TRUE);
}
Also used : ClassMetadata(javax.jdo.metadata.ClassMetadata) DiscriminatorMetadata(javax.jdo.metadata.DiscriminatorMetadata) FieldMetadata(javax.jdo.metadata.FieldMetadata) VersionMetadata(javax.jdo.metadata.VersionMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata) InheritanceMetadata(javax.jdo.metadata.InheritanceMetadata)

Example 4 with InheritanceMetadata

use of javax.jdo.metadata.InheritanceMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method addInheritanceMetadata.

private void addInheritanceMetadata(ClassMetadata cmd, Class<?> definition) {
    Class<Inheritance> ann = ReflectionsUtil.getAnnotationClass(definition, Inheritance.class);
    Inheritance annotation = AnnotationUtils.findAnnotation(definition, ann);
    if (annotation == null) {
        InheritanceMetadata imd = cmd.newInheritanceMetadata();
        imd.setCustomStrategy("complete-table");
    }
}
Also used : Inheritance(javax.jdo.annotations.Inheritance) InheritanceMetadata(javax.jdo.metadata.InheritanceMetadata)

Aggregations

InheritanceMetadata (javax.jdo.metadata.InheritanceMetadata)4 ClassMetadata (javax.jdo.metadata.ClassMetadata)2 DiscriminatorMetadata (javax.jdo.metadata.DiscriminatorMetadata)2 PackageMetadata (javax.jdo.metadata.PackageMetadata)2 Inheritance (javax.jdo.annotations.Inheritance)1 FieldMetadata (javax.jdo.metadata.FieldMetadata)1 TypeMetadata (javax.jdo.metadata.TypeMetadata)1 VersionMetadata (javax.jdo.metadata.VersionMetadata)1 MeetingRoom (org.datanucleus.samples.annotations.models.company.MeetingRoom)1 Room (org.datanucleus.samples.annotations.models.company.Room)1