use of javax.jdo.metadata.IndexMetadata 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.IndexMetadata in project tests by datanucleus.
the class JDOMetadataAPITest method assertFields.
private void assertFields(final Class<?> clazz, final List<IndexMetadata> indexes, final String... fieldNames) {
if (fieldNames == null) {
assertTrue("More indices than expected returned! " + clazz.getSimpleName(), indexes.isEmpty());
} else {
assertFalse("More indices than expected returned! " + clazz.getSimpleName(), indexes.size() > fieldNames.length);
Set<String> indexesNames = new HashSet<String>();
for (final IndexMetadata indexMetada : indexes) {
MemberMetadata[] members = indexMetada.getMembers();
if (members == null) {
FieldMetadata fieldMetadata = (FieldMetadata) indexMetada.getParent();
indexesNames.add(fieldMetadata.getName());
} else {
for (MemberMetadata memberMetadata : members) {
memberMetadata.getIndexMetadata();
indexesNames.add(memberMetadata.getName());
}
}
}
for (final String name : fieldNames) {
assertTrue("Index not returned: " + name, indexesNames.contains(name));
}
}
}
use of javax.jdo.metadata.IndexMetadata in project tests by datanucleus.
the class JDOMetadataAPITest method getIndexes.
/**
* Return a list of the declared indexes at class and field level.
* @param clazz The class to read the metadata from
* @param uniqueFlag If true returns only the indexes that are marked as true. If false returns only indexes that
* are NOT marked as unique.
*/
List<IndexMetadata> getIndexes(final Class<?> clazz, final boolean uniqueFlag) {
final List<IndexMetadata> indexes = new ArrayList<IndexMetadata>();
final TypeMetadata metadata = pmf.getMetadata(clazz.getName());
// Class level
final IndexMetadata[] indices = metadata.getIndices();
if (indices != null) {
for (final IndexMetadata indexMetadata : indices) {
if ((uniqueFlag && indexMetadata.getUnique()) || (!uniqueFlag && !indexMetadata.getUnique())) {
indexes.add(indexMetadata);
}
}
}
// Field level
final MemberMetadata[] members = metadata.getMembers();
for (final MemberMetadata memberMetadata : members) {
final IndexMetadata indexMetadata = memberMetadata.getIndexMetadata();
if (indexMetadata != null) {
if ((uniqueFlag && indexMetadata.getUnique()) || (!uniqueFlag && !indexMetadata.getUnique())) {
indexes.add(indexMetadata);
}
}
}
return indexes;
}
Aggregations