use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class LinkBagIndexTest method testIndexRidBagRemove.
public void testIndexRidBagRemove() {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument("RidBagIndexTestClass");
final ORidBag ridBag = new ORidBag();
ridBag.add(docOne);
ridBag.add(docTwo);
document.field("ridBag", ridBag);
document.save();
document.delete();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 0);
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class LinkBagIndexTest method testIndexRidBagUpdateRemoveItemInTx.
public void testIndexRidBagUpdateRemoveItemInTx() throws Exception {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument("RidBagIndexTestClass");
final ORidBag ridBag = new ORidBag();
ridBag.add(docOne);
ridBag.add(docTwo);
document.field("ridBag", ridBag);
document.save();
try {
database.begin();
ODocument loadedDocument = database.load(document.getIdentity());
loadedDocument.<ORidBag>field("ridBag").remove(docTwo);
loadedDocument.save();
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 1);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(docOne.getIdentity())) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class LinkBagIndexTest method testIndexRidBagUpdate.
public void testIndexRidBagUpdate() {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument docThree = new ODocument();
docThree.save();
final ODocument document = new ODocument("RidBagIndexTestClass");
final ORidBag ridBagOne = new ORidBag();
ridBagOne.add(docOne);
ridBagOne.add(docTwo);
document.field("ridBag", ridBagOne);
document.save();
final ORidBag ridBagTwo = new ORidBag();
ridBagTwo.add(docOne);
ridBagTwo.add(docThree);
document.field("ridBag", ridBagTwo);
document.save();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(docOne.getIdentity()) && !d.field("key").equals(docThree.getIdentity())) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class LinkBagIndexTest method testIndexRidBagUpdateAddItem.
public void testIndexRidBagUpdateAddItem() {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument docThree = new ODocument();
docThree.save();
final ODocument document = new ODocument("RidBagIndexTestClass");
final ORidBag ridBag = new ORidBag();
ridBag.add(docOne);
ridBag.add(docTwo);
document.field("ridBag", ridBag);
document.save();
database.command(new OCommandSQL("UPDATE " + document.getIdentity() + " add ridBag = " + docThree.getIdentity())).execute();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:ridBagIndex")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 3);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(docOne.getIdentity()) && !d.field("key").equals(docTwo.getIdentity()) && !d.field("key").equals(docThree.getIdentity())) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testRemoveNotExistentElementAndAddIt.
@Test
public void testRemoveNotExistentElementAndAddIt() throws Exception {
ORidBag teamMates = new ORidBag();
final ODocument bob = new ODocument().save();
teamMates.remove(bob);
Assert.assertEquals(teamMates.size(), 0);
teamMates.add(bob);
Assert.assertEquals(teamMates.size(), 1);
Assert.assertEquals(teamMates.iterator().next().getIdentity(), bob.getIdentity());
}
Aggregations