use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry in project orientdb by orientechnologies.
the class OIndexTxAware method getSize.
@Override
public long getSize() {
long tot = delegate.getSize();
final OTransactionIndexChanges indexChanges = database.getTransaction().getIndexChanges(delegate.getName());
if (indexChanges != null) {
if (indexChanges.cleared)
// BEGIN FROM 0
tot = 0;
for (final Entry<Object, OTransactionIndexChangesPerKey> entry : indexChanges.changesPerKey.entrySet()) {
for (final OTransactionIndexEntry e : entry.getValue().entries) {
if (e.operation == OPERATION.REMOVE) {
if (e.value == null)
// KEY REMOVED
tot--;
}
}
}
for (final OTransactionIndexEntry e : indexChanges.nullKeyChanges.entries) {
if (e.operation == OPERATION.REMOVE) {
if (e.value == null)
// KEY REMOVED
tot--;
}
}
}
return tot;
}
use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry in project orientdb by orientechnologies.
the class OIndexTxAware method getFirstKey.
@Override
public Object getFirstKey() {
final OTransactionIndexChanges indexChanges = database.getTransaction().getIndexChanges(delegate.getName());
if (indexChanges == null)
return delegate.getFirstKey();
Object indexFirstKey;
if (indexChanges.cleared)
indexFirstKey = null;
else
indexFirstKey = delegate.getFirstKey();
Object firstKey = indexChanges.getFirstKey();
while (true) {
OTransactionIndexChangesPerKey changesPerKey = indexChanges.getChangesPerKey(firstKey);
for (OTransactionIndexEntry indexEntry : changesPerKey.entries) {
if (indexEntry.operation.equals(OPERATION.REMOVE))
firstKey = null;
else
firstKey = changesPerKey.key;
}
if (changesPerKey.key.equals(indexFirstKey))
indexFirstKey = firstKey;
if (firstKey != null) {
if (indexFirstKey != null && ((Comparable) indexFirstKey).compareTo(firstKey) < 0)
return indexFirstKey;
return firstKey;
}
firstKey = indexChanges.getHigherKey(changesPerKey.key);
if (firstKey == null)
return indexFirstKey;
}
}
use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry in project orientdb by orientechnologies.
the class OIndexTxAwareMultiValue method calculateTxIndexEntry.
private Map.Entry<Object, OIdentifiable> calculateTxIndexEntry(final Object key, final OIdentifiable backendValue, OTransactionIndexChanges indexChanges) {
final OTransactionIndexChangesPerKey changesPerKey = indexChanges.getChangesPerKey(key);
if (changesPerKey.entries.isEmpty())
return createMapEntry(key, backendValue);
int putCounter = 1;
for (OTransactionIndexEntry entry : changesPerKey.entries) {
if (entry.operation == OPERATION.PUT && entry.value.equals(backendValue))
putCounter++;
else if (entry.operation == OPERATION.REMOVE) {
if (entry.value == null)
putCounter = 0;
else if (entry.value.equals(backendValue) && putCounter > 0)
putCounter--;
}
}
if (putCounter <= 0)
return null;
return createMapEntry(key, backendValue);
}
use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry 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.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry in project orientdb by orientechnologies.
the class OIndexTxAwareOneValue method calculateTxIndexEntry.
private Map.Entry<Object, OIdentifiable> calculateTxIndexEntry(final Object key, final OIdentifiable backendValue, final OTransactionIndexChanges indexChanges) {
final OTransactionIndexChangesPerKey changesPerKey = indexChanges.getChangesPerKey(key);
if (changesPerKey.entries.isEmpty()) {
if (backendValue == null)
return null;
else
return createMapEntry(key, backendValue);
}
OIdentifiable result = backendValue;
for (OTransactionIndexEntry entry : changesPerKey.entries) {
if (entry.operation == OPERATION.REMOVE)
result = null;
else if (entry.operation == OPERATION.PUT)
result = entry.value;
}
if (result == null)
return null;
final OIdentifiable resultValue = result;
return createMapEntry(key, resultValue);
}
Aggregations