Search in sources :

Example 11 with Collector

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"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Collector(com.orientechnologies.orient.test.domain.whiz.Collector) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 12 with Collector

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());
}
Also used : Collector(com.orientechnologies.orient.test.domain.whiz.Collector)

Example 13 with Collector

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"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Collector(com.orientechnologies.orient.test.domain.whiz.Collector) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 14 with Collector

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"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Collector(com.orientechnologies.orient.test.domain.whiz.Collector) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 15 with Collector

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Collector(com.orientechnologies.orient.test.domain.whiz.Collector) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

Collector (com.orientechnologies.orient.test.domain.whiz.Collector)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)14 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4