Search in sources :

Example 1 with OTransactionIndexEntry

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;
}
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 2 with OTransactionIndexEntry

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;
    }
}
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 OTransactionIndexEntry

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

Example 4 with OTransactionIndexEntry

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);
}
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 5 with OTransactionIndexEntry

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);
}
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

OTransactionIndexEntry (com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey.OTransactionIndexEntry)7 OTransactionIndexChangesPerKey (com.orientechnologies.orient.core.tx.OTransactionIndexChangesPerKey)6 OTransactionIndexChanges (com.orientechnologies.orient.core.tx.OTransactionIndexChanges)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORecordElement (com.orientechnologies.orient.core.db.record.ORecordElement)1 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)1 OCompositeKey (com.orientechnologies.orient.core.index.OCompositeKey)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OSerializableStream (com.orientechnologies.orient.core.serialization.OSerializableStream)1 IOException (java.io.IOException)1