use of javax.jdo.metadata.CollectionMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setUpCollectionMetadata.
private void setUpCollectionMetadata(FieldMetadata fmd, String relatedClass, RelationshipHolder holder, EntityType entityType) {
CollectionMetadata colMd = getOrCreateCollectionMetadata(fmd);
colMd.setElementType(relatedClass);
colMd.setEmbeddedElement(false);
colMd.setSerializedElement(false);
// for 1:N we're setting foreign key with cascade deletion after metadata enhancement
if (holder.isManyToMany()) {
colMd.setDependentElement(holder.isCascadeDelete() || entityType == EntityType.TRASH);
}
if (holder.isSetManyToMany() && !holder.isOwningSide() && entityType.equals(EntityType.STANDARD)) {
fmd.setMappedBy(holder.getRelatedField());
}
}
use of javax.jdo.metadata.CollectionMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method processHistoryTrashRelationship.
private void processHistoryTrashRelationship(ClassMetadata cmd, FieldMetadata fmd, RelationshipHolder holder) {
if (holder.isOneToOne() || holder.isManyToOne()) {
fmd.setColumn(holder.getFieldName() + ID_SUFFIX);
} else {
fmd.setTable(cmd.getTable() + '_' + holder.getFieldName());
CollectionMetadata collMd = fmd.newCollectionMetadata();
collMd.setElementType(Long.class.getName());
JoinMetadata joinMd = fmd.newJoinMetadata();
ColumnMetadata joinColumnMd = joinMd.newColumnMetadata();
joinColumnMd.setName(cmd.getName() + ID_SUFFIX);
ElementMetadata elementMd = fmd.newElementMetadata();
elementMd.setColumn(holder.getFieldName() + ID_SUFFIX);
}
}
use of javax.jdo.metadata.CollectionMetadata in project motech by motech.
the class EntityMetadataBuilderTest method shouldAddOneToManyRelationshipMetadata.
@Test
public void shouldAddOneToManyRelationshipMetadata() {
FieldDto oneToManyField = fieldDto("oneToManyName", OneToManyRelationship.class);
oneToManyField.addMetadata(new MetadataDto(RELATED_CLASS, "org.motechproject.test.MyClass"));
FieldMetadata fmd = mock(FieldMetadata.class);
CollectionMetadata collMd = mock(CollectionMetadata.class);
when(entity.getName()).thenReturn(ENTITY_NAME);
when(entity.getId()).thenReturn(2L);
when(schemaHolder.getFields(entity)).thenReturn(singletonList(oneToManyField));
when(entity.getTableName()).thenReturn(TABLE_NAME);
when(jdoMetadata.newPackageMetadata(PACKAGE)).thenReturn(packageMetadata);
when(packageMetadata.newClassMetadata(ENTITY_NAME)).thenReturn(classMetadata);
when(classMetadata.newFieldMetadata("oneToManyName")).thenReturn(fmd);
when(fmd.getCollectionMetadata()).thenReturn(collMd);
when(fmd.getName()).thenReturn("oneToManyName");
entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
verifyCommonClassMetadata();
verify(fmd).setDefaultFetchGroup(true);
verify(collMd).setEmbeddedElement(false);
verify(collMd).setSerializedElement(false);
verify(collMd).setElementType("org.motechproject.test.MyClass");
}
use of javax.jdo.metadata.CollectionMetadata 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);
}
}
}
}
}
}
Aggregations