/** * Creates an instance of {@link OIndexDefinition} for automatic index. * * @param oClass * class which will be indexed * @param fieldNames * list of properties which will be indexed. Format should be '<property> [by key|value]', use 'by key' or 'by value' to * describe how to index maps. By default maps indexed by key * @param types * types of indexed properties * @param collates * @param indexKind * @param algorithm * @return index definition instance */ public static OIndexDefinition createIndexDefinition(final OClass oClass, final List<String> fieldNames, final List<OType> types, List<OCollate> collates, String indexKind, String algorithm) { checkTypes(oClass, fieldNames, types); if (fieldNames.size() == 1) return createSingleFieldIndexDefinition(oClass, fieldNames.get(0), types.get(0), collates == null ? null : collates.get(0), indexKind, algorithm); else return createMultipleFieldIndexDefinition(oClass, fieldNames, types, collates, indexKind, algorithm); }
private static OIndexDefinition createMultipleFieldIndexDefinition(final OClass oClass, final List<String> fieldsToIndex, final List<OType> types, List<OCollate> collates, String indexKind, String algorithm) { final OIndexFactory factory = OIndexes.getFactory(indexKind, algorithm); final String className = oClass.getName(); final OCompositeIndexDefinition compositeIndex = new OCompositeIndexDefinition(className); for (int i = 0, fieldsToIndexSize = fieldsToIndex.size(); i < fieldsToIndexSize; i++) { OCollate collate = null; if (collates != null) collate = collates.get(i); compositeIndex .addIndex(createSingleFieldIndexDefinition(oClass, fieldsToIndex.get(i), types.get(i), collate, indexKind, algorithm)); } return compositeIndex; }