private static OIndexDefinition createSingleFieldIndexDefinition(OClass oClass, final String field, final OType type,
OCollate collate) {
final String fieldName = adjustFieldName(oClass, extractFieldName(field));
final OIndexDefinition indexDefinition;
final OProperty propertyToIndex = oClass.getProperty(fieldName);
final OType indexType;
if (type == OType.EMBEDDEDMAP || type == OType.LINKMAP) {
final OPropertyMapIndexDefinition.INDEX_BY indexBy = extractMapIndexSpecifier(field);
if (indexBy.equals(OPropertyMapIndexDefinition.INDEX_BY.KEY))
indexType = OType.STRING;
else {
if (type == OType.LINKMAP)
indexType = OType.LINK;
else {
indexType = propertyToIndex.getLinkedType();
if (indexType == null)
throw new OIndexException("Linked type was not provided."
+ " You should provide linked type for embedded collections that are going to be indexed.");
}
}
indexDefinition = new OPropertyMapIndexDefinition(oClass.getName(), fieldName, indexType, indexBy);
} else if (type.equals(OType.EMBEDDEDLIST) || type.equals(OType.EMBEDDEDSET) || type.equals(OType.LINKLIST)
|| type.equals(OType.LINKSET)) {
if (type.equals(OType.LINKSET))
indexType = OType.LINK;
else if (type.equals(OType.LINKLIST)) {
indexType = OType.LINK;
} else {
indexType = propertyToIndex.getLinkedType();
if (indexType == null)
throw new OIndexException("Linked type was not provided."
+ " You should provide linked type for embedded collections that are going to be indexed.");
}
indexDefinition = new OPropertyListIndexDefinition(oClass.getName(), fieldName, indexType);
} else if (type.equals(OType.LINKBAG)) {
indexDefinition = new OPropertyRidBagIndexDefinition(oClass.getName(), fieldName);
} else
indexDefinition = new OPropertyIndexDefinition(oClass.getName(), fieldName, type);
if (collate == null && propertyToIndex != null)
collate = propertyToIndex.getCollate();
if (collate != null)
indexDefinition.setCollate(collate);
return indexDefinition;