use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setTimeMetadata.
private FieldMetadata setTimeMetadata(ClassMetadata cmd, String name) {
// for time we register our converter which persists as string
FieldMetadata fmd = cmd.newFieldMetadata(name);
fmd.setPersistenceModifier(PersistenceModifier.PERSISTENT);
fmd.setDefaultFetchGroup(true);
fmd.newExtensionMetadata(DATANUCLEUS, "type-converter-name", "dn.time-string");
return fmd;
}
use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method addIdField.
private void addIdField(ClassMetadata cmd, EntityDto entity, SchemaHolder schemaHolder, Class<?> definition) {
boolean containsID = null != schemaHolder.getFieldByName(entity, ID_FIELD_NAME);
boolean isBaseClass = entity.isBaseEntity();
if (containsID && isBaseClass) {
FieldMetadata metadata = cmd.newFieldMetadata(ID_FIELD_NAME);
metadata.setValueStrategy(getIdGeneratorStrategy(metadata, definition));
metadata.setPrimaryKey(true);
}
}
use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setAutoGenerationMetadata.
private FieldMetadata setAutoGenerationMetadata(ClassMetadata cmd, String name) {
FieldMetadata fmd = cmd.newFieldMetadata(name);
fmd.setPersistenceModifier(PersistenceModifier.PERSISTENT);
fmd.setDefaultFetchGroup(true);
fmd.newExtensionMetadata(DATANUCLEUS, VALUE_GENERATOR, "ovg." + name);
return fmd;
}
use of javax.jdo.metadata.FieldMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method processField.
public void processField(ClassMetadata cmd, ClassData classData, EntityDto entity, EntityType entityType, Class<?> definition, String fieldName, FieldDto field, SchemaHolder schemaHolder) {
// Metadata for ID field has been added earlier in addIdField() method
if (!fieldName.equals(ID_FIELD_NAME)) {
FieldMetadata fmd = null;
if (isFieldNotInherited(fieldName, entity, schemaHolder)) {
fmd = setFieldMetadata(cmd, classData, entity, entityType, field, definition);
}
// when field is in Lookup, we set field metadata indexed to retrieve instance faster
if (!field.getLookups().isEmpty() && entityType.equals(EntityType.STANDARD)) {
if (fmd == null) {
String inheritedFieldName = ClassName.getSimpleName(entity.getSuperClass()) + "." + fieldName;
fmd = cmd.newFieldMetadata(inheritedFieldName);
}
if (!isBlobOrClob(field)) {
IndexMetadata imd = getOrCreateIndexMetadata(fmd);
imd.setName(KeyNames.lookupIndexKeyName(entity.getName(), entity.getId(), fieldName, entityType));
}
fmd.setIndexed(false);
for (LookupDto lookupDto : field.getLookups()) {
if (lookupDto.isIndexRequired()) {
fmd.setIndexed(true);
break;
}
}
}
if (fmd != null) {
customizeFieldMd(fmd, entity, field, entityType, definition);
}
}
}
use of javax.jdo.metadata.FieldMetadata 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");
}
Aggregations