Search in sources :

Example 1 with OTransactionIndexChangesPerKey

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

the class OIndexAbstract method addTxOperation.

public void addTxOperation(final OTransactionIndexChanges changes) {
    acquireSharedLock();
    try {
        final IndexTxSnapshot indexTxSnapshot = txSnapshot.get();
        if (changes.cleared)
            clearSnapshot(indexTxSnapshot);
        final Map<Object, Object> snapshot = indexTxSnapshot.indexSnapshot;
        for (final OTransactionIndexChangesPerKey entry : changes.changesPerKey.values()) {
            applyIndexTxEntry(snapshot, entry);
        }
        applyIndexTxEntry(snapshot, changes.nullKeyChanges);
    } finally {
        releaseSharedLock();
    }
}
Also used : OTransactionIndexChangesPerKey(com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey)

Example 2 with OTransactionIndexChangesPerKey

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

Example 3 with OTransactionIndexChangesPerKey

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

Example 4 with OTransactionIndexChangesPerKey

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

Example 5 with OTransactionIndexChangesPerKey

use of com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey 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);
}
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)

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