use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemoveDuringIterationSBTreeContainsValues.
public void testAddRemoveDuringIterationSBTreeContainsValues() {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
assertEmbedded(bag.isEmbedded());
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database.activateOnCurrentThread();
database.resetInitialization();
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.remove(new ORecordId("#77:1"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
rids.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:5"));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
Iterator<OIdentifiable> iterator = bag.iterator();
while (iterator.hasNext()) {
final OIdentifiable identifiable = iterator.next();
if (identifiable.equals(new ORecordId("#77:4"))) {
iterator.remove();
assertTrue(rids.remove(identifiable));
}
}
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
for (OIdentifiable identifiable : bag) rids.add(identifiable);
assertEmbedded(bag.isEmbedded());
doc = new ODocument();
final ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
assertEmbedded(otherBag.isEmbedded());
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testFromEmbeddedToSBTreeAndBackTx.
public void testFromEmbeddedToSBTreeAndBackTx() throws IOException {
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(7);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(-1);
if (database.getStorage() instanceof OStorageProxy) {
OServerAdmin server = new OServerAdmin(database.getURL()).connect("root", ODatabaseHelper.getServerRootPassword());
server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD, 7);
server.setGlobalConfiguration(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD, -1);
server.close();
}
ORidBag ridBag = new ORidBag();
ODocument document = new ODocument();
document.field("ridBag", ridBag);
Assert.assertTrue(ridBag.isEmbedded());
database.begin();
document.save();
database.commit();
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
List<OIdentifiable> addedItems = new ArrayList<OIdentifiable>();
database.begin();
for (int i = 0; i < 6; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
addedItems.add(docToAdd);
}
document.save();
database.commit();
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
addedItems.add(docToAdd);
database.begin();
document.save();
database.commit();
Assert.assertTrue(!ridBag.isEmbedded());
List<OIdentifiable> addedItemsCopy = new ArrayList<OIdentifiable>(addedItems);
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(!ridBag.isEmbedded());
addedItems.addAll(addedItemsCopy);
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
addedItems.addAll(addedItemsCopy);
for (int i = 0; i < 3; i++) ridBag.remove(addedItems.remove(i));
addedItemsCopy.clear();
addedItemsCopy.addAll(addedItems);
database.begin();
document.save();
database.commit();
Assert.assertTrue(!ridBag.isEmbedded());
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(!ridBag.isEmbedded());
addedItems.addAll(addedItemsCopy);
for (OIdentifiable id : ridBag) Assert.assertTrue(addedItems.remove(id));
Assert.assertTrue(addedItems.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemoveSBTreeContainsValues.
public void testAddRemoveSBTreeContainsValues() {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.remove(new ORecordId("#77:1"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:6"));
final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
rids.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:5"));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc = new ODocument();
ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
assertEmbedded(otherBag.isEmbedded());
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddSBTreeAddInMemoryIterate.
public void testAddSBTreeAddInMemoryIterate() {
List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
ORidBag bag = new ORidBag();
assertEmbedded(bag.isEmbedded());
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
assertEmbedded(bag.isEmbedded());
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
bag.add(new ORecordId("#77:0"));
rids.add(new ORecordId("#77:0"));
bag.add(new ORecordId("#77:1"));
rids.add(new ORecordId("#77:1"));
bag.add(new ORecordId("#77:2"));
rids.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:5"));
rids.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
rids.add(new ORecordId("#77:6"));
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc = new ODocument();
final ORidBag otherBag = new ORidBag();
for (OIdentifiable id : bag) otherBag.add(id);
doc.field("ridbag", otherBag);
doc.save();
rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testSaveInBackOrder.
public void testSaveInBackOrder() throws Exception {
ODocument docA = new ODocument().field("name", "A");
ODocument docB = new ODocument().field("name", "B").save();
ORidBag ridBag = new ORidBag();
ridBag.add(docA);
ridBag.add(docB);
docA.save();
ridBag.remove(docB);
assertEmbedded(ridBag.isEmbedded());
HashSet<OIdentifiable> result = new HashSet<OIdentifiable>();
for (OIdentifiable oIdentifiable : ridBag) {
result.add(oIdentifiable);
}
Assert.assertTrue(result.contains(docA));
Assert.assertFalse(result.contains(docB));
Assert.assertEquals(1, result.size());
Assert.assertEquals(1, ridBag.size());
}
Aggregations