Search in sources :

Example 6 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method updateSize.

/**
   * Recalculates real bag size.
   *
   * @return real size
   */
private int updateSize() {
    int size = 0;
    if (collectionPointer != null) {
        final OSBTreeBonsai<OIdentifiable, Integer> tree = loadTree();
        try {
            size = tree.getRealBagSize(changes);
        } finally {
            releaseTree();
        }
    } else {
        for (Change change : changes.values()) {
            size += change.applyTo(0);
        }
    }
    for (OModifiableInteger diff : newEntries.values()) {
        size += diff.getValue();
    }
    this.size = size;
    return size;
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)

Example 7 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method remove.

public void remove(OIdentifiable identifiable) {
    if (removeFromNewEntries(identifiable)) {
        if (size >= 0)
            size--;
    } else {
        final Change counter = changes.get(identifiable);
        if (counter == null) {
            // Not persistent keys can only be in changes or newEntries
            if (identifiable.getIdentity().isPersistent()) {
                changes.put(identifiable, new DiffChange(-1));
                size = -1;
            } else
                // Return immediately to prevent firing of event
                return;
        } else {
            counter.decrement();
            if (size >= 0)
                if (counter.isUndefined())
                    size = -1;
                else
                    size--;
        }
    }
    if (this.owner != null)
        ORecordInternal.unTrack(this.owner, identifiable);
    if (updateOwner)
        fireCollectionChangedEvent(new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.REMOVE, identifiable, null, identifiable, false));
}
Also used : Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)

Example 8 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method add.

public void add(final OIdentifiable identifiable) {
    if (identifiable == null)
        throw new NullPointerException("Impossible to add a null identifiable in a ridbag");
    if (identifiable.getIdentity().isValid()) {
        Change counter = changes.get(identifiable);
        if (counter == null)
            changes.put(identifiable, new DiffChange(1));
        else {
            if (counter.isUndefined()) {
                counter = getAbsoluteValue(identifiable);
                changes.put(identifiable, counter);
            }
            counter.increment();
        }
    } else {
        final OModifiableInteger counter = newEntries.get(identifiable);
        if (counter == null)
            newEntries.put(identifiable, new OModifiableInteger(1));
        else
            counter.increment();
    }
    if (size >= 0)
        size++;
    if (this.owner != null)
        ORecordInternal.track(this.owner, identifiable);
    if (updateOwner)
        fireCollectionChangedEvent(new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.ADD, identifiable, identifiable, null, false));
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)

Example 9 with Change

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change in project orientdb by orientechnologies.

the class OSBTreeRidBag method mergeChanges.

public void mergeChanges(OSBTreeRidBag treeRidBag) {
    for (Map.Entry<OIdentifiable, OModifiableInteger> entry : treeRidBag.newEntries.entrySet()) {
        mergeDiffEntry(entry.getKey(), entry.getValue().getValue());
    }
    for (Map.Entry<OIdentifiable, Change> entry : treeRidBag.changes.entrySet()) {
        final OIdentifiable rec = entry.getKey();
        final Change change = entry.getValue();
        final int diff;
        if (change instanceof DiffChange)
            diff = ((DiffChange) change).delta;
        else if (change instanceof AbsoluteChange)
            diff = ((AbsoluteChange) change).value - getAbsoluteValue(rec).value;
        else
            throw new IllegalArgumentException("change type is not supported");
        mergeDiffEntry(rec, diff);
    }
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Aggregations

Change (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change)9 OModifiableInteger (com.orientechnologies.common.types.OModifiableInteger)6 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)4 ORecord (com.orientechnologies.orient.core.record.ORecord)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)1 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)1 ORecordSerializationContext (com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext)1 ORidBagUpdateSerializationOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.ORidBagUpdateSerializationOperation)1