use of com.orientechnologies.orient.core.id.ORecordId 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.id.ORecordId in project orientdb by orientechnologies.
the class ORidBagTest method massiveInsertionIteration.
private void massiveInsertionIteration(Random rnd, List<OIdentifiable> rids, ORidBag bag) {
Iterator<OIdentifiable> bagIterator = bag.iterator();
while (bagIterator.hasNext()) {
OIdentifiable bagValue = bagIterator.next();
Assert.assertTrue(rids.contains(bagValue));
}
Assert.assertEquals(bag.size(), rids.size());
for (int i = 0; i < 100; i++) {
if (rnd.nextDouble() < 0.2 & rids.size() > 5) {
final int index = rnd.nextInt(rids.size());
final OIdentifiable rid = rids.remove(index);
bag.remove(rid);
} else {
final int positionIndex = rnd.nextInt(300);
final long position = positionIndex;
final ORecordId recordId = new ORecordId(1, position);
rids.add(recordId);
bag.add(recordId);
}
}
bagIterator = bag.iterator();
while (bagIterator.hasNext()) {
final OIdentifiable bagValue = bagIterator.next();
Assert.assertTrue(rids.contains(bagValue));
if (rnd.nextDouble() < 0.05) {
bagIterator.remove();
Assert.assertTrue(rids.remove(bagValue));
}
}
Assert.assertEquals(bag.size(), rids.size());
bagIterator = bag.iterator();
while (bagIterator.hasNext()) {
final OIdentifiable bagValue = bagIterator.next();
Assert.assertTrue(rids.contains(bagValue));
}
}
use of com.orientechnologies.orient.core.id.ORecordId 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.id.ORecordId in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapRemoveItemInTx.
public void testIndexMapRemoveItemInTx() throws Exception {
Mapper mapper = new Mapper();
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key1", 10);
map.put("key2", 20);
map.put("key3", 30);
mapper.setIntMap(map);
mapper = database.save(mapper);
try {
database.begin();
Mapper loadedMapper = (Mapper) database.load(new ORecordId(mapper.getId()));
loadedMapper.getIntMap().remove("key2");
loadedMapper = database.save(loadedMapper);
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
Assert.assertNotNull(resultByKey);
Assert.assertEquals(resultByKey.size(), 2);
for (ODocument d : resultByKey) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals("key1") && !d.field("key").equals("key3")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
Assert.assertNotNull(resultByValue);
Assert.assertEquals(resultByValue.size(), 2);
for (ODocument d : resultByValue) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(10) && !d.field("key").equals(30)) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapUpdateItemInTx.
public void testIndexMapUpdateItemInTx() throws Exception {
Mapper mapper = new Mapper();
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key1", 10);
map.put("key2", 20);
mapper.setIntMap(map);
mapper = database.save(mapper);
try {
database.begin();
Mapper loadedMapper = (Mapper) database.load(new ORecordId(mapper.getId()));
loadedMapper.getIntMap().put("key2", 40);
loadedMapper = database.save(loadedMapper);
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
Assert.assertNotNull(resultByKey);
Assert.assertEquals(resultByKey.size(), 2);
for (ODocument d : resultByKey) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals("key1") && !d.field("key").equals("key2")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
Assert.assertNotNull(resultByValue);
Assert.assertEquals(resultByValue.size(), 2);
for (ODocument d : resultByValue) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (!d.field("key").equals(10) && !d.field("key").equals(40)) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
Aggregations