/** * @param storage TODO * @param indexType index type * * @return OIndexInternal * * @throws OConfigurationException if index creation failed * @throws OIndexException if index type does not exist */ public static OIndexInternal<?> createIndex(OStorage storage, String name, String indexType, String algorithm, String valueContainerAlgorithm, ODocument metadata, int version) throws OConfigurationException, OIndexException { if (indexType.equalsIgnoreCase(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.name()) || indexType .equalsIgnoreCase(OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX.name()) || indexType .equalsIgnoreCase(OClass.INDEX_TYPE.DICTIONARY_HASH_INDEX.name())) { if (!algorithm.equalsIgnoreCase("autosharding")) { algorithm = OHashIndexFactory.HASH_INDEX_ALGORITHM; } } return findFactoryByAlgorithmAndType(algorithm, indexType) .createIndex(name, storage, indexType, algorithm, valueContainerAlgorithm, metadata, version); }
public static OBaseIndexEngine createIndexEngine(final String name, final String algorithm, final String type, final Boolean durableInNonTxMode, final OStorage storage, final int version, int apiVersion, boolean multivalue, final Map<String, String> indexProperties, ODocument metadata) { final OIndexFactory factory = findFactoryByAlgorithmAndType(algorithm, type); return factory .createIndexEngine(algorithm, name, durableInNonTxMode, storage, version, apiVersion, multivalue, indexProperties); }
public static OIndexFactory getFactory(String indexType, String algorithm) { if (algorithm == null) { algorithm = chooseDefaultIndexAlgorithm(indexType); } algorithm = algorithm.toUpperCase(Locale.ENGLISH); final Iterator<OIndexFactory> ite = getAllFactories(); while (ite.hasNext()) { final OIndexFactory factory = ite.next(); if (factory.getTypes().contains(indexType) && factory.getAlgorithms().contains(algorithm)) { return factory; } } throw new OIndexException("Index with type " + indexType + " and algorithm " + algorithm + " does not exist."); }
private OIndex<?> createDictionary() { final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); return createIndex(DICTIONARY_NAME, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.STRING), null, null, null); }
/** * Iterates on all factories and append all index types. * * @return Set of all index types. */ private static Set<String> getIndexTypes() { final Set<String> types = new HashSet<>(); final Iterator<OIndexFactory> ite = getAllFactories(); while (ite.hasNext()) { types.addAll(ite.next().getTypes()); } return types; }
/** * Iterates on all factories and append all index engines. * * @return Set of all index engines. */ public static Set<String> getIndexEngines() { final Set<String> engines = new HashSet<>(); final Iterator<OIndexFactory> ite = getAllFactories(); while (ite.hasNext()) { engines.addAll(ite.next().getAlgorithms()); } return engines; }
new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK), null, null, null);
final OType keyType = OType.valueOf(keyTypeStr.toUpperCase(Locale.ENGLISH)); loadedIndexDefinition = new OSimpleKeyIndexDefinition(factory.getLastVersion(), keyType);
private static OIndexFactory findFactoryByAlgorithmAndType(String algorithm, String indexType) { for (OIndexFactory factory : getFactories()) { if (indexType == null || indexType.isEmpty() || (factory.getTypes().contains(indexType)) && factory.getAlgorithms() .contains(algorithm)) { return factory; } } throw new OIndexException( "Index type " + indexType + " with engine " + algorithm + " is not supported. Types are " + OCollections .toString(getIndexTypes())); }
final OIndexFactory indexFactory = it.next(); final OBaseIndexEngine engine = indexFactory .createIndexEngine(index.getAlgorithm(), index.getName(), false, storage, 0, 1, indexDefinition.getTypes().length > 1, null);
private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) { this.indexClass = indexClass; if (iKeyType == null) iKeyType = OType.STRING; final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); this.recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex("__@recordmap@___" + indexName, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null)); final String className; if (Vertex.class.isAssignableFrom(indexClass)) className = VERTEX; else if (Edge.class.isAssignableFrom(indexClass)) className = EDGE; else className = indexClass.getName(); final ODocument metadata = new ODocument(); metadata.field(CONFIG_CLASSNAME, className); metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName()); final OIndexFactory nuFactory = OIndexes.getFactory(OClass.INDEX_TYPE.NOTUNIQUE.toString(), null); // CREATE THE MAP this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Collection<OIdentifiable>>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata)); }
new OSimpleKeyIndexDefinition(keyTypes, collatesList, factory.getLastVersion()), null, null, metadataDoc, engine); else if (serializerKeyId != 0) { idx = database.getMetadata().getIndexManager() .createIndex(indexName, indexType.toString(), new ORuntimeKeyIndexDefinition(serializerKeyId, factory.getLastVersion()), null, null, metadataDoc, engine); } else {
private OIndex<?> buildKeyValueIndex(final ODocument metadata) { final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); final OIndex<?> recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex("__@recordmap@___" + underlying.getName(), OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null)); final List<ODocument> entries = graph.getRawGraph().query( new OSQLSynchQuery<Object>("select from index:" + underlying.getName())); for (ODocument entry : entries) { final OIdentifiable rid = entry.field("rid"); if (rid != null) recordKeyValueIndex.put(new OCompositeKey(rid, entry.field("key")), rid); } metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName()); return recordKeyValueIndex; }
public void create(ODatabaseDocumentInternal database) { acquireExclusiveLock(); try { try { save(OMetadataDefault.CLUSTER_INTERNAL_NAME); } catch (Exception e) { OLogManager.instance().error(this, "Error during storing of index manager metadata," + " will try to allocate new document to store index manager metadata", e); // RESET RID TO ALLOCATE A NEW ONE if (ORecordId.isPersistent(document.getIdentity().getClusterPosition())) { document.getIdentity().reset(); save(OMetadataDefault.CLUSTER_INTERNAL_NAME); } } database.getStorage().setIndexMgrRecordId(document.getIdentity().toString()); OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); createIndex(DICTIONARY_NAME, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.STRING), null, null, null); } finally { releaseExclusiveLock(); } }
new OSimpleKeyIndexDefinition(keyTypes, collatesList, factory.getLastVersion()), null, null, metadataDoc, engine); } else if (keyTypes != null && keyTypes.length == 0 && "LUCENE_CROSS_CLASS".equalsIgnoreCase(engine)) { factory.getLastVersion()); idx = database.getMetadata().getIndexManager() .createIndex(name.getValue(), type.getStringValue(), keyDef, null, null, metadataDoc, engine);