use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexFullText method put.
/**
* Indexes a value and save the index. Splits the value in single words and index each one. Save of the index is responsibility of
* the caller.
*/
@Override
public OIndexFullText put(Object key, final OIdentifiable singleValue) {
if (key == null)
return this;
key = getCollatingValue(key);
final ODatabase database = getDatabase();
final boolean txIsActive = database.getTransaction().isActive();
if (!txIsActive)
keyLockManager.acquireExclusiveLock(key);
try {
final Set<String> words = splitIntoWords(key.toString());
// FOREACH WORD CREATE THE LINK TO THE CURRENT DOCUMENT
for (final String word : words) {
acquireSharedLock();
try {
Set<OIdentifiable> refs;
while (true) {
try {
refs = (Set<OIdentifiable>) storage.getIndexValue(indexId, word);
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
final boolean durable;
if (metadata != null && Boolean.TRUE.equals(metadata.field("durableInNonTxMode")))
durable = true;
else
durable = false;
final Set<OIdentifiable> refsc = refs;
// SAVE THE INDEX ENTRY
while (true) {
try {
storage.updateIndexEntry(indexId, word, new Callable<Object>() {
@Override
public Object call() throws Exception {
Set<OIdentifiable> result = null;
if (refsc == null) {
// WORD NOT EXISTS: CREATE THE KEYWORD CONTAINER THE FIRST TIME THE WORD IS FOUND
if (ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER.equals(valueContainerAlgorithm)) {
result = new OIndexRIDContainer(getName(), durable);
} else {
throw new IllegalStateException("MBRBTreeContainer is not supported any more");
}
} else {
result = refsc;
}
// ADD THE CURRENT DOCUMENT AS REF FOR THAT WORD
result.add(singleValue);
return result;
}
});
break;
} catch (OInvalidIndexEngineIdException e) {
doReloadIndexEngine();
}
}
} finally {
releaseSharedLock();
}
}
return this;
} finally {
if (!txIsActive)
keyLockManager.releaseExclusiveLock(key);
}
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexRemoteOneValue method iterator.
public Iterator<Entry<Object, OIdentifiable>> iterator() {
final OCommandRequest cmd = formatCommand(QUERY_ENTRIES, name);
final Collection<ODocument> result = getDatabase().command(cmd).execute();
final Map<Object, OIdentifiable> map = new LinkedHashMap<Object, OIdentifiable>();
for (final ODocument d : result) {
d.setLazyLoad(false);
map.put(d.field("key"), (OIdentifiable) d.field("rid"));
}
return map.entrySet().iterator();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexRemoteOneValue method inverseIterator.
public Iterator<Entry<Object, OIdentifiable>> inverseIterator() {
final OCommandRequest cmd = formatCommand(QUERY_ENTRIES, name);
final List<ODocument> result = getDatabase().command(cmd).execute();
final Map<Object, OIdentifiable> map = new LinkedHashMap<Object, OIdentifiable>();
for (ListIterator<ODocument> it = result.listIterator(); it.hasPrevious(); ) {
ODocument d = it.previous();
d.setLazyLoad(false);
map.put(d.field("key"), (OIdentifiable) d.field("rid"));
}
return map.entrySet().iterator();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexRemoteOneValue method get.
public OIdentifiable get(final Object iKey) {
final OCommandRequest cmd = formatCommand(QUERY_GET, name);
final List<OIdentifiable> result = getDatabase().command(cmd).execute(iKey);
if (result != null && !result.isEmpty())
return ((OIdentifiable) ((ODocument) result.get(0).getRecord()).field("rid")).getIdentity();
return null;
// return (OIdentifiable) ((OStorageProxy) getDatabase().getStorage()).indexGet(name, iKey, null);
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexTxAwareMultiValue method iterateEntries.
@Override
public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder) {
final OTransactionIndexChanges indexChanges = database.getTransaction().getIndexChanges(delegate.getName());
if (indexChanges == null)
return super.iterateEntries(keys, ascSortOrder);
final List<Object> sortedKeys = new ArrayList<Object>(keys.size());
for (Object key : keys) sortedKeys.add(getCollatingValue(key));
if (ascSortOrder)
Collections.sort(sortedKeys, ODefaultComparator.INSTANCE);
else
Collections.sort(sortedKeys, Collections.reverseOrder(ODefaultComparator.INSTANCE));
final OIndexCursor txCursor = new OIndexAbstractCursor() {
private Iterator<Object> keysIterator = sortedKeys.iterator();
private Iterator<OIdentifiable> valuesIterator = new OEmptyIterator<OIdentifiable>();
private Object key;
@Override
public Map.Entry<Object, OIdentifiable> nextEntry() {
if (valuesIterator.hasNext())
return nextEntryInternal();
if (keysIterator == null)
return null;
Set<OIdentifiable> result = null;
while (result == null && keysIterator.hasNext()) {
key = keysIterator.next();
result = calculateTxValue(key, indexChanges);
if (result != null && result.isEmpty())
result = null;
}
if (result == null) {
keysIterator = null;
return null;
}
valuesIterator = result.iterator();
return nextEntryInternal();
}
private Map.Entry<Object, OIdentifiable> nextEntryInternal() {
final OIdentifiable identifiable = valuesIterator.next();
return new Map.Entry<Object, OIdentifiable>() {
@Override
public Object getKey() {
return key;
}
@Override
public OIdentifiable getValue() {
return identifiable;
}
@Override
public OIdentifiable setValue(OIdentifiable value) {
throw new UnsupportedOperationException("setValue");
}
};
}
};
if (indexChanges.cleared)
return txCursor;
final OIndexCursor backedCursor = super.iterateEntries(keys, ascSortOrder);
return new OIndexTxCursor(txCursor, backedCursor, ascSortOrder, indexChanges);
}
Aggregations