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