use of com.orientechnologies.orient.core.sql.OCommandSQL 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"));
}
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapRemoveInTxRollback.
public void testIndexMapRemoveInTxRollback() 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);
database.begin();
database.delete(mapper);
database.rollback();
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(20)) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class MapIndexTest method testIndexMapRemove.
public void testIndexMapRemove() {
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);
database.delete(mapper);
final List<ODocument> resultByKey = database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();
Assert.assertNotNull(resultByKey);
Assert.assertEquals(resultByKey.size(), 0);
final List<ODocument> resultByValue = database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();
Assert.assertNotNull(resultByValue);
Assert.assertEquals(resultByValue.size(), 0);
}
use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.
the class LinkSetIndexTest method testIndexLinkSetUpdateRemoveItemInTxRollback.
public void testIndexLinkSetUpdateRemoveItemInTxRollback() throws Exception {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument("LinkSetIndexTestClass");
final Set<OIdentifiable> linkSet = new HashSet<OIdentifiable>();
linkSet.add(docOne);
linkSet.add(docTwo);
document.field("linkSet", linkSet);
document.save();
database.begin();
ODocument loadedDocument = database.load(document.getIdentity());
loadedDocument.<Set<OIdentifiable>>field("linkSet").remove(docTwo);
loadedDocument.save();
database.rollback();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:linkSetIndex")).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.sql.OCommandSQL in project orientdb by orientechnologies.
the class LinkSetIndexTest method testIndexLinkSet.
public void testIndexLinkSet() {
final ODocument docOne = new ODocument();
docOne.save();
final ODocument docTwo = new ODocument();
docTwo.save();
final ODocument document = new ODocument("LinkSetIndexTestClass");
final Set<OIdentifiable> linkSet = new HashSet<OIdentifiable>();
linkSet.add(docOne);
linkSet.add(docTwo);
document.field("linkSet", linkSet);
document.save();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:linkSetIndex")).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"));
}
}
}
Aggregations