use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.
the class CollectionIndexTest method testIndexCollectionUpdateRemoveItemInTxRollback.
public void testIndexCollectionUpdateRemoveItemInTxRollback() throws Exception {
Collector collector = new Collector();
collector.setStringCollection(new ArrayList<String>(Arrays.asList("spam", "eggs")));
collector = database.save(collector);
database.begin();
Collector loadedCollector = (Collector) database.load(new ORecordId(collector.getId()));
loadedCollector.getStringCollection().remove("spam");
loadedCollector = database.save(loadedCollector);
database.rollback();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:Collector.stringCollection")).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("spam") && !d.field("key").equals("eggs")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.
the class CollectionIndexTest method testIndexCollectionSQL.
public void testIndexCollectionSQL() {
Collector collector = new Collector();
collector.setStringCollection(Arrays.asList("spam", "eggs"));
collector = database.save(collector);
List<Collector> result = database.query(new OSQLSynchQuery<Collector>("select * from Collector where stringCollection contains ?"), "eggs");
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 1);
Assert.assertEquals(Arrays.asList("spam", "eggs"), result.get(0).getStringCollection());
}
use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.
the class CollectionIndexTest method testIndexCollectionUpdateInTxRollback.
public void testIndexCollectionUpdateInTxRollback() throws Exception {
Collector collector = new Collector();
collector.setStringCollection(Arrays.asList("spam", "eggs"));
collector = database.save(collector);
database.begin();
collector.setStringCollection(Arrays.asList("spam", "bacon"));
collector = database.save(collector);
database.rollback();
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:Collector.stringCollection")).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("spam") && !d.field("key").equals("eggs")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.
the class CollectionIndexTest method testIndexCollectionUpdateAddItemInTx.
public void testIndexCollectionUpdateAddItemInTx() throws Exception {
Collector collector = new Collector();
collector.setStringCollection(new ArrayList<String>(Arrays.asList("spam", "eggs")));
collector = database.save(collector);
try {
database.begin();
Collector loadedCollector = (Collector) database.load(new ORecordId(collector.getId()));
loadedCollector.getStringCollection().add("cookies");
database.save(loadedCollector);
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:Collector.stringCollection")).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("spam") && !d.field("key").equals("eggs") && !d.field("key").equals("cookies")) {
Assert.fail("Unknown key found: " + d.field("key"));
}
}
}
use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.
the class CollectionIndexTest method testIndexCollectionRemoveInTx.
public void testIndexCollectionRemoveInTx() throws Exception {
Collector collector = new Collector();
collector.setStringCollection(Arrays.asList("spam", "eggs"));
collector = database.save(collector);
try {
database.begin();
database.delete(collector);
database.commit();
} catch (Exception e) {
database.rollback();
throw e;
}
List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:Collector.stringCollection")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 0);
}
Aggregations