use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddMixedValues.
public void testAddMixedValues() {
ORidBag ridBag = new ORidBag();
ODocument document = new ODocument();
document.field("ridBag", ridBag);
assertEmbedded(ridBag.isEmbedded());
List<OIdentifiable> itemsToAdd = new ArrayList<OIdentifiable>();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
}
assertEmbedded(ridBag.isEmbedded());
document.save();
document.reload();
ridBag = document.field("ridBag");
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
}
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
assertEmbedded(ridBag.isEmbedded());
document.save();
document.reload();
ridBag = document.field("ridBag");
database.begin();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
}
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
assertEmbedded(ridBag.isEmbedded());
document.save();
database.commit();
assertEmbedded(ridBag.isEmbedded());
Assert.assertEquals(ridBag.size(), itemsToAdd.size());
document.reload();
Assert.assertEquals(ridBag.size(), itemsToAdd.size());
for (OIdentifiable id : ridBag) Assert.assertTrue(itemsToAdd.remove(id));
Assert.assertTrue(itemsToAdd.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemove.
public void testAddRemove() {
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"));
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"));
Assert.assertTrue(bag.contains(new ORecordId("#77:3")));
Assert.assertTrue(bag.contains(new ORecordId("#77:4")));
Assert.assertTrue(bag.contains(new ORecordId("#77:5")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:2")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:6")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:0")));
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);
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
Assert.assertTrue(bag.contains(new ORecordId("#77:3")));
Assert.assertTrue(bag.contains(new ORecordId("#77:4")));
Assert.assertTrue(bag.contains(new ORecordId("#77:5")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:2")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:6")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:0")));
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 testSaveLoad.
public void testSaveLoad() throws Exception {
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"));
expected.add(new ORecordId("#77:17"));
expected.add(new ORecordId("#77:18"));
expected.add(new ORecordId("#77:19"));
expected.add(new ORecordId("#77:20"));
expected.add(new ORecordId("#77:21"));
expected.add(new ORecordId("#77:22"));
ODocument doc = new ODocument();
final ORidBag bag = new ORidBag();
bag.addAll(expected);
doc.field("ridbag", bag);
assertEmbedded(bag.isEmbedded());
doc.save();
final ORID id = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(id);
doc.setLazyLoad(false);
final ORidBag loaded = doc.field("ridbag");
assertEmbedded(loaded.isEmbedded());
Assert.assertEquals(loaded.size(), expected.size());
for (OIdentifiable identifiable : loaded) Assert.assertTrue(expected.remove(identifiable));
Assert.assertTrue(expected.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class ORidBagTest method testAddNewItemsAndRemoveThem.
public void testAddNewItemsAndRemoveThem() {
final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
ORidBag ridBag = new ORidBag();
int size = 0;
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
rids.add(docToAdd);
size++;
}
}
Assert.assertEquals(ridBag.size(), size);
ODocument document = new ODocument();
document.field("ridBag", ridBag);
document.save();
document = database.load(document.getIdentity(), "*:-1", true);
ridBag = document.field("ridBag");
Assert.assertEquals(ridBag.size(), size);
final List<OIdentifiable> newDocs = new ArrayList<OIdentifiable>();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
rids.add(docToAdd);
newDocs.add(docToAdd);
size++;
}
}
Assert.assertEquals(ridBag.size(), size);
Random rnd = new Random();
for (int i = 0; i < newDocs.size(); i++) {
if (rnd.nextBoolean()) {
OIdentifiable newDoc = newDocs.get(i);
rids.remove(newDoc);
ridBag.remove(newDoc);
newDocs.remove(newDoc);
size--;
}
}
for (OIdentifiable identifiable : ridBag) {
if (newDocs.contains(identifiable) && rnd.nextBoolean()) {
ridBag.remove(identifiable);
rids.remove(identifiable);
size--;
}
}
Assert.assertEquals(ridBag.size(), size);
List<OIdentifiable> ridsCopy = new ArrayList<OIdentifiable>(rids);
for (OIdentifiable identifiable : ridBag) {
Assert.assertTrue(rids.remove(identifiable));
}
Assert.assertTrue(rids.isEmpty());
document.save();
document = database.load(document.getIdentity(), "*:-1", false);
ridBag = document.field("ridBag");
rids.addAll(ridsCopy);
for (OIdentifiable identifiable : ridBag) {
Assert.assertTrue(rids.remove(identifiable));
}
Assert.assertTrue(rids.isEmpty());
Assert.assertEquals(ridBag.size(), size);
}
use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.
the class OCompositeIndexDefinitionTest method testDocumentToIndexRidBagValueSuccessfulOne.
@Test
public void testDocumentToIndexRidBagValueSuccessfulOne() {
final ODocument document = new ODocument();
final ORidBag ridBag = new ORidBag();
ridBag.setAutoConvertToRecord(false);
ridBag.add(new ORecordId("#1:10"));
ridBag.add(new ORecordId("#1:11"));
ridBag.add(new ORecordId("#1:11"));
document.field("fOne", 12);
document.field("fTwo", ridBag);
final OCompositeIndexDefinition compositeIndexDefinition = new OCompositeIndexDefinition("testCollectionClass");
compositeIndexDefinition.addIndex(new OPropertyIndexDefinition("testCollectionClass", "fOne", OType.INTEGER));
compositeIndexDefinition.addIndex(new OPropertyRidBagIndexDefinition("testCollectionClass", "fTwo"));
final Object result = compositeIndexDefinition.getDocumentValueToIndex(document);
final ArrayList<OCompositeKey> expectedResult = new ArrayList<OCompositeKey>();
expectedResult.add(new OCompositeKey(12, new ORecordId("#1:10")));
expectedResult.add(new OCompositeKey(12, new ORecordId("#1:11")));
expectedResult.add(new OCompositeKey(12, new ORecordId("#1:11")));
Assert.assertEquals(result, expectedResult);
}
Aggregations