public List<OType> extractFieldTypes(final String[] fieldNames) { final List<OType> types = new ArrayList<OType>(fieldNames.length); for (String fieldName : fieldNames) { if (!fieldName.equals("@rid")) types.add(getProperty(decodeClassName(OIndexDefinitionFactory.extractFieldName(fieldName))).getType()); else types.add(OType.LINK); } return types; }
public OIndex<?> createIndex(final String name, String type, final OProgressListener progressListener, ODocument metadata, String algorithm, final String... fields) { if (type == null) throw new IllegalArgumentException("Index type is null"); type = type.toUpperCase(Locale.ENGLISH); if (fields.length == 0) { throw new OIndexException("List of fields to index cannot be empty."); } final String localName = this.name; final int[] localPolymorphicClusterIds = polymorphicClusterIds; for (final String fieldToIndex : fields) { final String fieldName = decodeClassName(OIndexDefinitionFactory.extractFieldName(fieldToIndex)); if (!fieldName.equals("@rid") && !existsProperty(fieldName)) throw new OIndexException( "Index with name '" + name + "' cannot be created on class '" + localName + "' because the field '" + fieldName + "' is absent in class definition"); } final OIndexDefinition indexDefinition = OIndexDefinitionFactory .createIndexDefinition(this, Arrays.asList(fields), extractFieldTypes(fields), null, type, algorithm); return getDatabase().getMetadata().getIndexManager() .createIndex(name, type, indexDefinition, localPolymorphicClusterIds, progressListener, metadata, algorithm); }
private static OIndexDefinition createSingleFieldIndexDefinition(OClass oClass, final String field, final OType type, OCollate collate, String indexKind, String algorithm) { final String fieldName = OClassImpl.decodeClassName(adjustFieldName(oClass, extractFieldName(field))); final OIndexDefinition indexDefinition;