use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemoveNotExisting.
public void testAddRemoveNotExisting() {
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"));
bag.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
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());
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:2"));
rids.add(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
rids.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:4"));
rids.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:2"));
rids.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
rids.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:7"));
rids.remove(new ORecordId("#77:7"));
bag.remove(new ORecordId("#77:8"));
rids.remove(new ORecordId("#77:8"));
bag.remove(new ORecordId("#77:8"));
rids.remove(new ORecordId("#77:8"));
bag.remove(new ORecordId("#77:8"));
rids.remove(new ORecordId("#77:8"));
assertEmbedded(bag.isEmbedded());
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
doc.save();
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 testRemove.
public void testRemove() {
final Set<OIdentifiable> expected = new HashSet<OIdentifiable>(8);
expected.add(new ORecordId("#77:12"));
expected.add(new ORecordId("#77:13"));
expected.add(new ORecordId("#77:14"));
expected.add(new ORecordId("#77:15"));
expected.add(new ORecordId("#77:16"));
final ORidBag bag = new ORidBag();
assertEmbedded(bag.isEmbedded());
bag.setAutoConvertToRecord(false);
bag.addAll(expected);
assertEmbedded(bag.isEmbedded());
bag.remove(new ORecordId("#77:23"));
assertEmbedded(bag.isEmbedded());
final Set<OIdentifiable> expectedTwo = new HashSet<OIdentifiable>(8);
expectedTwo.addAll(expected);
for (OIdentifiable identifiable : bag) {
assertTrue(expectedTwo.remove(identifiable));
}
Assert.assertTrue(expectedTwo.isEmpty());
expected.remove(new ORecordId("#77:14"));
bag.remove(new ORecordId("#77:14"));
assertEmbedded(bag.isEmbedded());
expectedTwo.addAll(expected);
for (OIdentifiable identifiable : bag) {
assertTrue(expectedTwo.remove(identifiable));
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAdd.
public void testAdd() throws Exception {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:1"));
Assert.assertTrue(bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#78:2")));
Iterator<OIdentifiable> iterator = bag.iterator();
Assert.assertTrue(iterator.hasNext());
OIdentifiable identifiable = iterator.next();
Assert.assertEquals(identifiable, new ORecordId("#77:1"));
Assert.assertTrue(!iterator.hasNext());
assertEmbedded(bag.isEmbedded());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testRemoveSavedInCommit.
public void testRemoveSavedInCommit() {
List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
ORidBag ridBag = new ORidBag();
ODocument document = new ODocument();
document.field("ridBag", ridBag);
for (int i = 0; i < 5; i++) {
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
docToAdd.save();
docsToAdd.add(docToAdd);
}
document.save();
assertEmbedded(ridBag.isEmbedded());
document.reload();
ridBag = document.field("ridBag");
assertEmbedded(ridBag.isEmbedded());
database.begin();
for (int i = 0; i < 5; i++) {
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
docsToAdd.add(docToAdd);
}
for (int i = 5; i < 10; i++) {
ODocument docToAdd = docsToAdd.get(i).getRecord();
docToAdd.save();
}
Iterator<OIdentifiable> iterator = docsToAdd.listIterator(7);
while (iterator.hasNext()) {
OIdentifiable docToAdd = iterator.next();
ridBag.remove(docToAdd);
iterator.remove();
}
document.save();
database.commit();
assertEmbedded(ridBag.isEmbedded());
List<OIdentifiable> docsToAddCopy = new ArrayList<OIdentifiable>(docsToAdd);
for (OIdentifiable id : ridBag) Assert.assertTrue(docsToAdd.remove(id));
Assert.assertTrue(docsToAdd.isEmpty());
docsToAdd.addAll(docsToAddCopy);
document.reload();
ridBag = document.field("ridBag");
for (OIdentifiable id : ridBag) Assert.assertTrue(docsToAdd.remove(id));
Assert.assertTrue(docsToAdd.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testFromEmbeddedToSBTreeAndBack.
public void testFromEmbeddedToSBTreeAndBack() 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());
document.save();
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
List<OIdentifiable> addedItems = new ArrayList<OIdentifiable>();
for (int i = 0; i < 6; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
addedItems.add(docToAdd);
}
document.save();
document.reload();
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
addedItems.add(docToAdd);
document.save();
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);
document.save();
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());
}
Aggregations