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);
}
}
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);
}
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);
}
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);
}
}
}
}
}
}
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);
}
Aggregations