Search in sources :

Example 1 with Collector

use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.

the class CollectionIndexTest method testIndexCollectionUpdateRemoveItemInTx.

public void testIndexCollectionUpdateRemoveItemInTx() 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().remove("spam");
        loadedCollector = 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(), 1);
    for (ODocument d : result) {
        Assert.assertTrue(d.containsField("key"));
        Assert.assertTrue(d.containsField("rid"));
        if (!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 2 with Collector

use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.

the class CollectionIndexTest method testIndexCollection.

public void testIndexCollection() {
    Collector collector = new Collector();
    collector.setStringCollection(Arrays.asList("spam", "eggs"));
    collector = database.save(collector);
    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 3 with Collector

use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.

the class CollectionIndexTest method testIndexCollectionUpdate.

public void testIndexCollectionUpdate() {
    Collector collector = new Collector();
    collector.setStringCollection(Arrays.asList("spam", "eggs"));
    collector = database.save(collector);
    collector.setStringCollection(Arrays.asList("spam", "bacon"));
    collector = database.save(collector);
    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("bacon")) {
            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 4 with Collector

use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.

the class CollectionIndexTest method testIndexCollectionUpdateAddItem.

public void testIndexCollectionUpdateAddItem() {
    Collector collector = new Collector();
    collector.setStringCollection(Arrays.asList("spam", "eggs"));
    collector = database.save(collector);
    database.command(new OCommandSQL("UPDATE " + collector.getId() + " add stringCollection = 'cookies'")).execute();
    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) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with Collector

use of com.orientechnologies.orient.test.domain.whiz.Collector in project orientdb by orientechnologies.

the class CollectionIndexTest method testIndexCollectionRemove.

public void testIndexCollectionRemove() {
    Collector collector = new Collector();
    collector.setStringCollection(Arrays.asList("spam", "eggs"));
    collector = database.save(collector);
    database.delete(collector);
    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