Search in sources :

Example 1 with VersionMetadata

use of javax.jdo.metadata.VersionMetadata 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 2 with VersionMetadata

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

the class EntityMetadataBuilderImpl method addVersioningMetadata.

private void addVersioningMetadata(ClassMetadata cmd, Class<?> definition) {
    Class<Version> ann = ReflectionsUtil.getAnnotationClass(definition, Version.class);
    Version versionAnnotation = AnnotationUtils.findAnnotation(definition, ann);
    if (versionAnnotation != null) {
        VersionMetadata vmd = cmd.newVersionMetadata();
        vmd.setColumn(versionAnnotation.column());
        vmd.setStrategy(versionAnnotation.strategy());
        if (versionAnnotation.extensions().length == 0 || !"field-name".equals(versionAnnotation.extensions()[0].key())) {
            throw new MdsException(String.format("Cannot create metadata fo %s. Extension not found in @Version annotation.", cmd.getName()));
        }
        Extension extension = versionAnnotation.extensions()[0];
        vmd.newExtensionMetadata(DATANUCLEUS, "field-name", extension.value());
    }
}
Also used : Extension(javax.jdo.annotations.Extension) Version(javax.jdo.annotations.Version) VersionMetadata(javax.jdo.metadata.VersionMetadata) MdsException(org.motechproject.mds.exception.MdsException)

Aggregations

VersionMetadata (javax.jdo.metadata.VersionMetadata)2 Extension (javax.jdo.annotations.Extension)1 Version (javax.jdo.annotations.Version)1 ClassMetadata (javax.jdo.metadata.ClassMetadata)1 DiscriminatorMetadata (javax.jdo.metadata.DiscriminatorMetadata)1 FieldMetadata (javax.jdo.metadata.FieldMetadata)1 InheritanceMetadata (javax.jdo.metadata.InheritanceMetadata)1 PackageMetadata (javax.jdo.metadata.PackageMetadata)1 MdsException (org.motechproject.mds.exception.MdsException)1