use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexTxAwareMultiValue method get.
@Override
public Set<OIdentifiable> get(Object key) {
final OTransactionIndexChanges indexChanges = database.getTransaction().getIndexChanges(delegate.getName());
if (indexChanges == null)
return super.get(key);
key = getCollatingValue(key);
final Set<OIdentifiable> result = new HashSet<OIdentifiable>();
if (!indexChanges.cleared) {
// BEGIN FROM THE UNDERLYING RESULT SET
final Collection<OIdentifiable> subResult = super.get(key);
if (subResult != null)
for (OIdentifiable oid : subResult) result.add(oid);
}
final Set<OIdentifiable> processed = new HashSet<OIdentifiable>();
for (OIdentifiable identifiable : result) {
Map.Entry<Object, OIdentifiable> entry = calculateTxIndexEntry(key, identifiable, indexChanges);
if (entry != null)
processed.add(entry.getValue());
}
Set<OIdentifiable> txChanges = calculateTxValue(key, indexChanges);
if (txChanges != null)
processed.addAll(txChanges);
if (!processed.isEmpty())
return processed;
return null;
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OIndexTxAwareMultiValue method calculateTxValue.
private Set<OIdentifiable> calculateTxValue(final Object key, OTransactionIndexChanges indexChanges) {
final OTransactionIndexChangesPerKey changesPerKey = indexChanges.getChangesPerKey(key);
if (changesPerKey.entries.isEmpty())
return null;
final List<OIdentifiable> result = new ArrayList<OIdentifiable>();
for (OTransactionIndexEntry entry : changesPerKey.entries) {
if (entry.operation == OPERATION.REMOVE) {
if (entry.value == null)
result.clear();
else
result.remove(entry.value);
} else
result.add(entry.value);
}
if (result.isEmpty())
return null;
return new HashSet<OIdentifiable>(result);
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OPropertyRidBagIndexDefinition method createValue.
@Override
public Object createValue(final Object... params) {
if (!(params[0] instanceof ORidBag))
return null;
final ORidBag ridBag = (ORidBag) params[0];
final List<Object> values = new ArrayList<Object>();
for (final OIdentifiable item : ridBag) {
values.add(createSingleValue(item));
}
return values;
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OPropertyRidBagIndexDefinition method createValue.
@Override
public Object createValue(final List<?> params) {
if (!(params.get(0) instanceof ORidBag))
return null;
final ORidBag ridBag = (ORidBag) params.get(0);
final List<Object> values = new ArrayList<Object>();
for (final OIdentifiable item : ridBag) {
values.add(createSingleValue(item));
}
return values;
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class OHashTableIndexEngine method cursor.
@Override
public OIndexCursor cursor(final ValuesTransformer valuesTransformer) {
return new OIndexAbstractCursor() {
private int nextEntriesIndex;
private OHashIndexBucket.Entry<Object, Object>[] entries;
private Iterator<OIdentifiable> currentIterator = new OEmptyIterator<OIdentifiable>();
private Object currentKey;
{
OHashIndexBucket.Entry<Object, Object> firstEntry = hashTable.firstEntry();
if (firstEntry == null)
entries = OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
else
entries = hashTable.ceilingEntries(firstEntry.key);
if (entries.length == 0)
currentIterator = null;
}
@Override
public Map.Entry<Object, OIdentifiable> nextEntry() {
if (currentIterator == null)
return null;
if (currentIterator.hasNext())
return nextCursorValue();
while (currentIterator != null && !currentIterator.hasNext()) {
if (entries.length == 0) {
currentIterator = null;
return null;
}
final OHashIndexBucket.Entry<Object, Object> bucketEntry = entries[nextEntriesIndex];
currentKey = bucketEntry.key;
Object value = bucketEntry.value;
if (valuesTransformer != null)
currentIterator = valuesTransformer.transformFromValue(value).iterator();
else
currentIterator = Collections.singletonList((OIdentifiable) value).iterator();
nextEntriesIndex++;
if (nextEntriesIndex >= entries.length) {
entries = hashTable.higherEntries(entries[entries.length - 1].key);
nextEntriesIndex = 0;
}
}
if (currentIterator != null && !currentIterator.hasNext())
return nextCursorValue();
currentIterator = null;
return null;
}
private Map.Entry<Object, OIdentifiable> nextCursorValue() {
final OIdentifiable identifiable = currentIterator.next();
return new Map.Entry<Object, OIdentifiable>() {
@Override
public Object getKey() {
return currentKey;
}
@Override
public OIdentifiable getValue() {
return identifiable;
}
@Override
public OIdentifiable setValue(OIdentifiable value) {
throw new UnsupportedOperationException();
}
};
}
};
}
Aggregations