Search in sources :

Example 6 with OTransactionIndexChangesPerKey

use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey 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);
}
Also used : OTransactionIndexChangesPerKey(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey) OTransactionIndexEntry(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 7 with OTransactionIndexChangesPerKey

use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey in project orientdb by orientechnologies.

the class OIndexTxAware method getLastKey.

@Override
public Object getLastKey() {
    final OTransactionIndexChanges indexChanges = database.getTransaction().getIndexChanges(delegate.getName());
    if (indexChanges == null)
        return delegate.getLastKey();
    Object indexLastKey;
    if (indexChanges.cleared)
        indexLastKey = null;
    else
        indexLastKey = delegate.getLastKey();
    Object lastKey = indexChanges.getLastKey();
    while (true) {
        OTransactionIndexChangesPerKey changesPerKey = indexChanges.getChangesPerKey(lastKey);
        for (OTransactionIndexEntry indexEntry : changesPerKey.entries) {
            if (indexEntry.operation.equals(OPERATION.REMOVE))
                lastKey = null;
            else
                lastKey = changesPerKey.key;
        }
        if (changesPerKey.key.equals(indexLastKey))
            indexLastKey = lastKey;
        if (lastKey != null) {
            if (indexLastKey != null && ((Comparable) indexLastKey).compareTo(lastKey) > 0)
                return indexLastKey;
            return lastKey;
        }
        lastKey = indexChanges.getLowerKey(changesPerKey.key);
        if (lastKey == null)
            return indexLastKey;
    }
}
Also used : OTransactionIndexChangesPerKey(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey) OTransactionIndexChanges(com.orientechnologies.orient.core.tx.OTransactionIndexChanges) OTransactionIndexEntry(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry)

Aggregations

OTransactionIndexChangesPerKey (com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey)7 OTransactionIndexEntry (com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry)6 OTransactionIndexChanges (com.orientechnologies.orient.core.tx.OTransactionIndexChanges)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2