use of javax.jdo.metadata.ForeignKeyMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setElementMetadata.
private void setElementMetadata(FieldMetadata fmd, Element element, RelationshipHolder holder, EntityDto entity) {
if (element == null || StringUtils.isEmpty(element.column())) {
ElementMetadata emd = fmd.newElementMetadata();
emd.setColumn((ClassName.getSimpleName(holder.getRelatedClass()) + ID_SUFFIX).toUpperCase());
ForeignKeyMetadata fkmd = emd.newForeignKeyMetadata();
fkmd.setName(KeyNames.foreignKeyName(ClassName.getSimpleName(holder.getRelatedClass()), entity.getId(), holder.getRelatedField(), EntityType.STANDARD));
}
}
use of javax.jdo.metadata.ForeignKeyMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method processRelationship.
private void processRelationship(FieldMetadata fmd, RelationshipHolder holder, EntityDto entity, FieldDto field, Class<?> definition) {
String relatedClass = holder.getRelatedClass();
fmd.newExtensionMetadata(DATANUCLEUS, "cascade-persist", holder.isCascadePersist() ? TRUE : FALSE);
fmd.newExtensionMetadata(DATANUCLEUS, "cascade-update", holder.isCascadeUpdate() ? TRUE : FALSE);
if (holder.isOneToMany() || holder.isManyToMany()) {
setUpCollectionMetadata(fmd, relatedClass, holder, EntityType.STANDARD);
} else if (holder.isOneToOne()) {
processOneToOneRelationship(fmd, holder);
}
if (shouldSetNullDelete(holder, field)) {
ForeignKeyMetadata fkmd = getOrCreateRelFkMetadata(fmd, entity, field);
fkmd.setDeleteAction(ForeignKeyAction.NULL);
}
if (holder.isManyToMany()) {
addManyToManyMetadata(fmd, holder, entity, field, definition);
}
if (shouldSetCascadeDelete(holder, EntityType.STANDARD)) {
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(fmd);
fkmd.setDeleteAction(ForeignKeyAction.CASCADE);
}
}
use of javax.jdo.metadata.ForeignKeyMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setMapMetadata.
private FieldMetadata setMapMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field, Class<?> definition, EntityType entityType) {
FieldMetadata fmd = cmd.newFieldMetadata(getNameForMetadata(field));
MetadataDto keyMetadata = field.getMetadata(MAP_KEY_TYPE);
MetadataDto valueMetadata = field.getMetadata(MAP_VALUE_TYPE);
boolean serialized = shouldSerializeMap(keyMetadata, valueMetadata);
// Depending on the types of key and value of the map we either serialize the map or create a separate table for it
fmd.setSerialized(serialized);
addDefaultFetchGroupMetadata(fmd, definition);
MapMetadata mmd = fmd.newMapMetadata();
if (serialized) {
mmd.setSerializedKey(true);
mmd.setSerializedValue(true);
} else {
mmd.setKeyType(keyMetadata.getValue());
mmd.setValueType(valueMetadata.getValue());
fmd.setTable(ClassTableName.getTableName(cmd.getTable(), getNameForMetadata(field)));
JoinMetadata jmd = fmd.newJoinMetadata();
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jmd);
fkmd.setDeleteAction(ForeignKeyAction.CASCADE);
fkmd.setName(KeyNames.mapForeignKeyName(entity.getName(), entity.getId(), field.getBasic().getName(), entityType));
}
return fmd;
}
use of javax.jdo.metadata.ForeignKeyMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method fixRelationMetadata.
private void fixRelationMetadata(PackageMetadata pmd, EntityDto entity, FieldDto field) {
RelationshipHolder holder = new RelationshipHolder(field);
// this must be set here cause we can't get related class metadata before metadata enhancement
if (shouldSetCascadeDelete(holder, EntityType.STANDARD)) {
String relatedClass = ClassName.getSimpleName(holder.getRelatedClass());
MemberMetadata rfmd = getFieldMetadata(getClassMetadata(pmd, relatedClass), holder.getRelatedField());
ForeignKeyMetadata rfkmd = getOrCreateRelFkMetadata(rfmd, entity, field);
rfkmd.setDeleteAction(ForeignKeyAction.CASCADE);
}
}
Aggregations