final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final OIndexCursor entries = dictionary.getIndex().iterateEntriesMajor(startkey, true, true); while (entries.hasNext()) { final ODocument document = entries.next().getRecord();
@Override public Status delete(String table, String key) { while (true) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); dictionary.remove(key); return Status.OK; } catch (OConcurrentModificationException cme) { continue; } catch (Exception e) { e.printStackTrace(); return Status.ERROR; } } }
/** * {@inheritDoc} */ @Override public boolean hasNext() { if (source.isRebuilding()) throwRebuildException(); final boolean isNext = delegate.hasNext(); if (source.getRebuildVersion() != indexRebuildVersion) throwRebuildException(); return isNext; }
private static void addIndexEntry(ODocument document, OIdentifiable rid, OIndex<?> index, List<IndexChange> changes) { final OIndexDefinition indexDefinition = index.getDefinition(); final Object key = indexDefinition.getDocumentValueToIndex(document); if (key instanceof Collection) { for (final Object keyItem : (Collection<?>) key) if (!indexDefinition.isNullValuesIgnored() || keyItem != null) addPut(changes, index, keyItem, rid); } else if (!indexDefinition.isNullValuesIgnored() || key != null) addPut(changes, index, key, rid); }
private static void deleteIndexKey(final OIndex<?> index, final ODocument iRecord, final Object origValue, List<IndexChange> changes) { final OIndexDefinition indexDefinition = index.getDefinition(); if (origValue instanceof Collection) { for (final Object valueItem : (Collection<?>) origValue) { if (!indexDefinition.isNullValuesIgnored() || valueItem != null) addRemove(changes, index, valueItem, iRecord); } } else if (!indexDefinition.isNullValuesIgnored() || origValue != null) { addRemove(changes, index, origValue, iRecord); } }
public OIndex<?> preProcessBeforeReturn(ODatabaseDocumentInternal database, final OIndex<?> index) { if (index instanceof OIndexMultiValues) //noinspection unchecked return new OIndexTxAwareMultiValue(database, (OIndex<Collection<OIdentifiable>>) index); else if (index instanceof OIndexDictionary) //noinspection unchecked return new OIndexTxAwareDictionary(database, (OIndex<OIdentifiable>) index); else if (index instanceof OIndexOneValue) //noinspection unchecked return new OIndexTxAwareOneValue(database, (OIndex<OIdentifiable>) index); return index; }
public OIndexInternal<?> resolveAssociatedIndex(String indexName, OIndexManager indexManager) { if (resolvedIndex == null) { final OIndex<?> index = indexManager.getIndex(indexName); if (index != null) resolvedIndex = index.getInternal(); } return resolvedIndex; }
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); }
public OType[] getKeyTypes() { acquireSharedLock(); try { if (indexDefinition == null) return null; return indexDefinition.getTypes(); } finally { releaseSharedLock(); } }
/** * {@inheritDoc} */ @Override public Map.Entry<Object, OIdentifiable> nextEntry() { if (source.isRebuilding()) throwRebuildException(); final Map.Entry<Object, OIdentifiable> entry = delegate.nextEntry(); if (source.getRebuildVersion() != indexRebuildVersion) throwRebuildException(); return entry; }
/** * {@inheritDoc} */ @Override public Set<OIdentifiable> toValues() { if (source.isRebuilding()) throwRebuildException(); final Set<OIdentifiable> values = delegate.toValues(); if (source.getRebuildVersion() != indexRebuildVersion) throwRebuildException(); return values; }
/** * {@inheritDoc} */ @Override public OIdentifiable next() { if (source.isRebuilding()) throwRebuildException(); final OIdentifiable next = delegate.next(); if (source.getRebuildVersion() != indexRebuildVersion) throwRebuildException(); return next; }
/** * {@inheritDoc} */ @Override public Set<Map.Entry<Object, OIdentifiable>> toEntries() { if (source.isRebuilding()) throwRebuildException(); final Set<Map.Entry<Object, OIdentifiable>> entries = delegate.toEntries(); if (source.getRebuildVersion() != indexRebuildVersion) throwRebuildException(); return entries; }
@Override public void setType(OType type) { indexDefinition = new OSimpleKeyIndexDefinition(version, type); updateConfiguration(); }
public OIndexManager dropIndex(final String iIndexName) { if (isDistributedCommand()) { distributedDropIndex(iIndexName); return this; } return delegate.dropIndex(iIndexName); }
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 OIndex<?> preProcessBeforeReturn(ODatabaseDocumentInternal database, final OIndex<?> index) { if (index instanceof OIndexRemoteMultiValue) return new OIndexTxAwareMultiValue(database, (OIndex<Collection<OIdentifiable>>) index); else if (index instanceof OIndexDictionary) return new OIndexTxAwareDictionary(database, (OIndex<OIdentifiable>) index); else if (index instanceof OIndexRemoteOneValue) return new OIndexTxAwareOneValue(database, (OIndex<OIdentifiable>) index); return index; }
@Override public Status insert(String table, String key, Map<String, ByteIterator> values) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODocument document = new ODocument(CLASS); for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); dictionary.put(key, document); return Status.OK; } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { while (true) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final ODocument document = dictionary.get(key); if (document != null) { for (Map.Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) { document.field(entry.getKey(), entry.getValue()); } document.save(); return Status.OK; } } catch (OConcurrentModificationException cme) { continue; } catch (Exception e) { e.printStackTrace(); return Status.ERROR; } } }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try (ODatabaseDocumentTx db = databasePool.acquire()) { final ODictionary<ORecord> dictionary = db.getMetadata().getIndexManager().getDictionary(); final ODocument document = dictionary.get(key); if (document != null) { if (fields != null) { for (String field : fields) { result.put(field, new StringByteIterator((String) document.field(field))); } } else { for (String field : document.fieldNames()) { result.put(field, new StringByteIterator((String) document.field(field))); } } return Status.OK; } } catch (Exception e) { e.printStackTrace(); } return Status.ERROR; }