use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class LinkBagIndexTest method testIndexRidBagRemoveInTxRollback.
public void testIndexRidBagRemoveInTxRollback() 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();
database.begin();
document.delete();
database.rollback();
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(docTwo.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 testIndexRidBag.
public void testIndexRidBag() {
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();
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(docTwo.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 testIndexRidBagUpdateRemoveItemInTxRollback.
public void testIndexRidBagUpdateRemoveItemInTxRollback() 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();
database.begin();
ODocument loadedDocument = database.load(document.getIdentity());
loadedDocument.<ORidBag>field("ridBag").remove(docTwo);
loadedDocument.save();
database.rollback();
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(docTwo.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 testIndexRidBagUpdateInTx.
public void testIndexRidBagUpdateInTx() throws Exception {
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();
try {
database.begin();
final ORidBag ridBagTwo = new ORidBag();
ridBagTwo.add(docOne);
ridBagTwo.add(docThree);
document.field("ridBag", ridBagTwo);
document.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(), 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 OSBTreeRidBagTest method crateTestDeleteDoc.
private ODocument crateTestDeleteDoc(ODocument realDoc) {
ODocument testDocument = new ODocument();
ORidBag highLevelRidBag = new ORidBag();
testDocument.field("ridBag", highLevelRidBag);
testDocument.field("realDoc", realDoc);
final List<ODocument> embeddedList = new ArrayList<ODocument>();
ODocument embeddedListDoc = new ODocument();
ORidBag embeddedListDocRidBag = new ORidBag();
embeddedListDoc.field("ridBag", embeddedListDocRidBag);
embeddedListDoc.field("realDoc", realDoc);
embeddedList.add(embeddedListDoc);
Set<ODocument> embeddedSet = new HashSet<ODocument>();
ODocument embeddedSetDoc = new ODocument();
ORidBag embeddedSetDocRidBag = new ORidBag();
embeddedSetDoc.field("ridBag", embeddedSetDocRidBag);
embeddedSetDoc.field("realDoc", realDoc);
embeddedSet.add(embeddedSetDoc);
Map<String, ODocument> embeddedMap = new HashMap<String, ODocument>();
ODocument embeddedMapDoc = new ODocument();
ORidBag embeddedMapDocRidBag = new ORidBag();
embeddedMapDoc.field("ridBag", embeddedMapDocRidBag);
embeddedMapDoc.field("realDoc", realDoc);
embeddedMap.put("k1", embeddedMapDoc);
testDocument.field("embeddedList", embeddedList, OType.EMBEDDEDLIST);
testDocument.field("embeddedSet", embeddedSet, OType.EMBEDDEDSET);
testDocument.field("embeddedMap", embeddedMap, OType.EMBEDDEDMAP);
testDocument.save("ridBagDeleteTest");
return testDocument;
}
Aggregations