Search in sources :

Example 1 with ClassMetadata

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

use of javax.jdo.metadata.ClassMetadata 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 3 with ClassMetadata

use of javax.jdo.metadata.ClassMetadata 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 4 with ClassMetadata

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

ClassMetadata (javax.jdo.metadata.ClassMetadata)4 PackageMetadata (javax.jdo.metadata.PackageMetadata)4 InheritanceMetadata (javax.jdo.metadata.InheritanceMetadata)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 VersionMetadata (javax.jdo.metadata.VersionMetadata)1 EntityType (org.motechproject.mds.domain.EntityType)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 FieldDto (org.motechproject.mds.dto.FieldDto)1