Search in sources :

Example 1 with PackageMetadata

use of javax.jdo.metadata.PackageMetadata 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 PackageMetadata

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

the class JDOMetadataAPITest method testClassInPackageAndJDO.

/**
 * Simple test that checks that classes retrieved have a parent package etc
 */
public void testClassInPackageAndJDO() {
    TypeMetadata typemd = pmf.getMetadata(Computer.class.getName());
    PackageMetadata pmd = (PackageMetadata) typemd.getParent();
    assertNotNull("Package of class is null!", pmd);
    assertEquals("Package name is different to expected", Computer.class.getName().substring(0, Computer.class.getName().lastIndexOf('.')), pmd.getName());
    JDOMetadata jdomd = (JDOMetadata) pmd.getParent();
    assertNotNull("JDOMetadata of package is null!", jdomd);
}
Also used : TypeMetadata(javax.jdo.metadata.TypeMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata) JDOMetadata(javax.jdo.metadata.JDOMetadata) Computer(org.datanucleus.samples.annotations.embedded.Computer)

Example 3 with PackageMetadata

use of javax.jdo.metadata.PackageMetadata 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 PackageMetadata

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

the class EntityMetadataBuilderImpl method fixEnhancerIssuesInMetadata.

@Override
public void fixEnhancerIssuesInMetadata(JDOMetadata jdoMetadata, SchemaHolder schemaHolder) {
    for (PackageMetadata pmd : jdoMetadata.getPackages()) {
        for (ClassMetadata cmd : pmd.getClasses()) {
            String className = String.format("%s.%s", pmd.getName(), cmd.getName());
            EntityType entityType = EntityType.forClassName(className);
            if (entityType == EntityType.STANDARD) {
                EntityDto entity = schemaHolder.getEntityByClassName(className);
                if (null != entity) {
                    for (MemberMetadata mmd : cmd.getMembers()) {
                        CollectionMetadata collMd = mmd.getCollectionMetadata();
                        FieldDto field = schemaHolder.getFieldByName(entity, mmd.getName());
                        if (null != collMd) {
                            fixCollectionMetadata(collMd, field);
                        }
                        if (null != field && field.getType().isRelationship()) {
                            fixRelationMetadata(pmd, entity, field);
                        }
                        // Defining column name for join and element results in setting it both as XML attribute and child element
                        fixDuplicateColumnDefinitions(mmd);
                    }
                }
            }
        }
    }
}
Also used : ClassMetadata(javax.jdo.metadata.ClassMetadata) EntityType(org.motechproject.mds.domain.EntityType) EntityDto(org.motechproject.mds.dto.EntityDto) CollectionMetadata(javax.jdo.metadata.CollectionMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata) MemberMetadata(javax.jdo.metadata.MemberMetadata) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 5 with PackageMetadata

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

the class EntityMetadataBuilderImpl method addEntityMetadata.

@Override
public void addEntityMetadata(JDOMetadata jdoMetadata, EntityDto entity, Class<?> definition, SchemaHolder schemaHolder) {
    String className = (entity.isDDE()) ? entity.getClassName() : ClassName.getEntityClassName(entity.getClassName());
    String packageName = ClassName.getPackage(className);
    String tableName = ClassTableName.getTableName(entity.getClassName(), entity.getModule(), entity.getNamespace(), entity.getTableName(), null);
    PackageMetadata pmd = getPackageMetadata(jdoMetadata, packageName);
    ClassMetadata cmd = getClassMetadata(pmd, ClassName.getSimpleName(ClassName.getEntityClassName(entity.getClassName())));
    cmd.setTable(tableName);
    cmd.setDetachable(true);
    cmd.setIdentityType(IdentityType.APPLICATION);
    cmd.setPersistenceModifier(ClassPersistenceModifier.PERSISTENCE_CAPABLE);
    addInheritanceMetadata(cmd, definition);
    if (!entity.isSubClassOfMdsEntity() && !entity.isSubClassOfMdsVersionedEntity()) {
        addIdField(cmd, entity, schemaHolder, definition);
        // we add versioning metadata only for Standard class.
        addVersioningMetadata(cmd, definition);
    }
    addMetadataForFields(cmd, null, entity, EntityType.STANDARD, definition, schemaHolder);
}
Also used : ClassMetadata(javax.jdo.metadata.ClassMetadata) PackageMetadata(javax.jdo.metadata.PackageMetadata)

Aggregations

PackageMetadata (javax.jdo.metadata.PackageMetadata)6 ClassMetadata (javax.jdo.metadata.ClassMetadata)4 InheritanceMetadata (javax.jdo.metadata.InheritanceMetadata)2 JDOMetadata (javax.jdo.metadata.JDOMetadata)2 CollectionMetadata (javax.jdo.metadata.CollectionMetadata)1 DiscriminatorMetadata (javax.jdo.metadata.DiscriminatorMetadata)1 FieldMetadata (javax.jdo.metadata.FieldMetadata)1 MemberMetadata (javax.jdo.metadata.MemberMetadata)1 TypeMetadata (javax.jdo.metadata.TypeMetadata)1 VersionMetadata (javax.jdo.metadata.VersionMetadata)1 JDOMetadataImpl (org.datanucleus.api.jdo.metadata.JDOMetadataImpl)1 FileMetaData (org.datanucleus.metadata.FileMetaData)1 Computer (org.datanucleus.samples.annotations.embedded.Computer)1 EntityType (org.motechproject.mds.domain.EntityType)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 FieldDto (org.motechproject.mds.dto.FieldDto)1