use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderTest method shouldMarkEudeFieldsAsUnique.
@Test
public void shouldMarkEudeFieldsAsUnique() {
when(entity.getName()).thenReturn(ENTITY_NAME);
when(jdoMetadata.newPackageMetadata(anyString())).thenReturn(packageMetadata);
when(packageMetadata.newClassMetadata(anyString())).thenReturn(classMetadata);
FieldDto eudeField = mock(FieldDto.class);
FieldBasicDto eudeBasic = mock(FieldBasicDto.class);
when(eudeField.getBasic()).thenReturn(eudeBasic);
when(eudeBasic.getName()).thenReturn("uniqueField");
when(eudeField.isReadOnly()).thenReturn(false);
when(eudeBasic.isUnique()).thenReturn(true);
when(eudeField.getType()).thenReturn(TypeDto.STRING);
FieldDto ddeField = mock(FieldDto.class);
FieldBasicDto ddeBasic = mock(FieldBasicDto.class);
when(ddeField.getBasic()).thenReturn(ddeBasic);
when(ddeBasic.getName()).thenReturn("uniqueField2");
when(ddeField.isReadOnly()).thenReturn(true);
when(ddeBasic.isUnique()).thenReturn(true);
when(ddeField.getType()).thenReturn(TypeDto.STRING);
when(schemaHolder.getFields(entity)).thenReturn(asList(ddeField, eudeField));
FieldMetadata fmdEude = mock(FieldMetadata.class);
when(fmdEude.getName()).thenReturn("uniqueField");
when(classMetadata.newFieldMetadata("uniqueField")).thenReturn(fmdEude);
FieldMetadata fmdDde = mock(FieldMetadata.class);
when(fmdDde.getName()).thenReturn("uniqueField2");
when(classMetadata.newFieldMetadata("uniqueField2")).thenReturn(fmdDde);
UniqueMetadata umd = mock(UniqueMetadata.class);
when(fmdEude.newUniqueMetadata()).thenReturn(umd);
entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
verify(fmdDde, never()).newUniqueMetadata();
verify(fmdDde, never()).setUnique(anyBoolean());
verify(fmdEude).newUniqueMetadata();
verify(umd).setName("unq_Sample_uniqueField");
}
use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderTest method shouldNotSetDefaultFetchGroupIfSpecified.
@Test
public void shouldNotSetDefaultFetchGroupIfSpecified() {
when(entity.getName()).thenReturn(ENTITY_NAME);
when(entity.getTableName()).thenReturn(TABLE_NAME);
when(jdoMetadata.newPackageMetadata(anyString())).thenReturn(packageMetadata);
when(packageMetadata.newClassMetadata(anyString())).thenReturn(classMetadata);
FieldDto field = fieldDto("notInDefFg", OneToOneRelationship.class);
when(schemaHolder.getFields(CLASS_NAME)).thenReturn(singletonList(field));
FieldMetadata fmd = mock(FieldMetadata.class);
when(fmd.getName()).thenReturn("notInDefFg");
when(classMetadata.newFieldMetadata("notInDefFg")).thenReturn(fmd);
entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
verify(fmd, never()).setDefaultFetchGroup(anyBoolean());
}
use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setComboboxMetadata.
private FieldMetadata setComboboxMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field, Class<?> definition, EntityType entityType) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
String fieldName = getNameForMetadata(field);
FieldMetadata fmd = cmd.newFieldMetadata(fieldName);
if (holder.isCollection()) {
addDefaultFetchGroupMetadata(fmd, definition);
fmd.setTable(ClassTableName.getTableName(cmd.getTable(), fieldName));
JoinMetadata jm = fmd.newJoinMetadata();
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jm);
fkmd.setName(KeyNames.cbForeignKeyName(entity.getName(), entity.getId(), fieldName, entityType));
jm.setDeleteAction(ForeignKeyAction.CASCADE);
jm.newColumnMetadata().setName(fieldName + "_OID");
}
return fmd;
}
use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setRelationshipMetadata.
private FieldMetadata setRelationshipMetadata(ClassMetadata cmd, ClassData classData, EntityDto entity, FieldDto field, EntityType entityType, Class<?> definition) {
RelationshipHolder holder = new RelationshipHolder(classData, field);
FieldMetadata fmd = cmd.newFieldMetadata(getNameForMetadata(field));
addDefaultFetchGroupMetadata(fmd, definition);
if (entityType == EntityType.STANDARD) {
processRelationship(fmd, holder, entity, field, definition);
} else {
processHistoryTrashRelationship(cmd, fmd, holder);
}
return fmd;
}
use of javax.jdo.metadata.FieldMetadata 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;
}
Aggregations