Search in sources :

Example 41 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkSetIndexTest method testIndexLinkSetUpdate.

public void testIndexLinkSetUpdate() {
    final ODocument docOne = new ODocument();
    docOne.save();
    final ODocument docTwo = new ODocument();
    docTwo.save();
    final ODocument docThree = new ODocument();
    docThree.save();
    final ODocument document = new ODocument("LinkSetIndexTestClass");
    final Set<OIdentifiable> linkSetOne = new HashSet<OIdentifiable>();
    linkSetOne.add(docOne);
    linkSetOne.add(docTwo);
    document.field("linkSet", linkSetOne);
    document.save();
    final Set<OIdentifiable> linkSetTwo = new HashSet<OIdentifiable>();
    linkSetTwo.add(docOne);
    linkSetTwo.add(docThree);
    document.field("linkSet", linkSetTwo);
    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(docThree.getIdentity())) {
            Assert.fail("Unknown key found: " + d.field("key"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet)

Example 42 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkSetIndexTest method testIndexLinkSetRemove.

public void testIndexLinkSetRemove() {
    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();
    document.delete();
    List<ODocument> result = database.command(new OCommandSQL("select key, rid from index:linkSetIndex")).execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(result.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) HashSet(java.util.HashSet)

Example 43 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class LinkSetIndexTest method afterMethod.

@AfterMethod
public void afterMethod() throws Exception {
    database.command(new OCommandSQL("DELETE FROM LinkSetIndexTestClass")).execute();
    List<ODocument> result = database.command(new OCommandSQL("select from LinkSetIndexTestClass")).execute();
    Assert.assertEquals(result.size(), 0);
    result = database.command(new OCommandSQL("select key, rid from index:linkSetIndex")).execute();
    Assert.assertEquals(result.size(), 0);
    database.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) AfterMethod(org.testng.annotations.AfterMethod)

Example 44 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class MapIndexTest method testIndexMap.

public void testIndexMap() {
    final Mapper mapper = new Mapper();
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("key1", 10);
    map.put("key2", 20);
    mapper.setIntMap(map);
    database.save(mapper);
    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"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Mapper(com.orientechnologies.orient.test.domain.whiz.Mapper) HashMap(java.util.HashMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 45 with OCommandSQL

use of com.orientechnologies.orient.core.sql.OCommandSQL in project orientdb by orientechnologies.

the class MapIndexTest method testIndexMapUpdateOneTxRollback.

public void testIndexMapUpdateOneTxRollback() throws Exception {
    Mapper mapper = new Mapper();
    Map<String, Integer> mapOne = new HashMap<String, Integer>();
    mapOne.put("key1", 10);
    mapOne.put("key2", 20);
    mapper.setIntMap(mapOne);
    mapper = database.save(mapper);
    database.begin();
    final Map<String, Integer> mapTwo = new HashMap<String, Integer>();
    mapTwo.put("key3", 30);
    mapTwo.put("key2", 20);
    mapper.setIntMap(mapTwo);
    mapper = database.save(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("key2") && !d.field("key").equals("key1")) {
            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"));
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Mapper(com.orientechnologies.orient.test.domain.whiz.Mapper) HashMap(java.util.HashMap) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)646 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)440 Test (org.junit.Test)109 Test (org.testng.annotations.Test)93 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)85 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)83 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)81 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)65 ORID (com.orientechnologies.orient.core.id.ORID)65 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)54 Set (java.util.Set)53 HashMap (java.util.HashMap)48 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)42 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)42 List (java.util.List)27 Before (org.junit.Before)25 OStorage (com.orientechnologies.orient.core.storage.OStorage)23 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)23 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)22 ORecordId (com.orientechnologies.orient.core.id.ORecordId)21