Search in sources :

Example 21 with OSQLSynchQuery

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

the class OCommandExecutorSQLSelectTest method testBasicQueryOrdered.

// /*** from issue #2743
@Test
public void testBasicQueryOrdered() {
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT from alphabet ORDER BY letter");
    List<ODocument> results = db.query(sql);
    assertEquals(26, results.size());
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 22 with OSQLSynchQuery

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

the class OChainIndexFetchTest method testFetchChaninedIndex.

@Test
public void testFetchChaninedIndex() {
    OClass baseClass = db.getMetadata().getSchema().createClass("BaseClass");
    OProperty propr = baseClass.createProperty("ref", OType.LINK);
    OClass linkedClass = db.getMetadata().getSchema().createClass("LinkedClass");
    OProperty id = linkedClass.createProperty("id", OType.STRING);
    id.createIndex(INDEX_TYPE.UNIQUE);
    propr.setLinkedClass(linkedClass);
    propr.createIndex(INDEX_TYPE.NOTUNIQUE);
    ODocument doc = new ODocument(linkedClass);
    doc.field("id", "referred");
    db.save(doc);
    ODocument doc1 = new ODocument(baseClass);
    doc1.field("ref", doc);
    db.save(doc1);
    List<ODocument> res = db.query(new OSQLSynchQuery(" select from BaseClass where ref.id ='wrong_referred' "));
    assertEquals(0, res.size());
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 23 with OSQLSynchQuery

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

the class OCommandExecutorSQLUpdateTest method testUpdateAddOnNonExistingSet.

@Test
public void testUpdateAddOnNonExistingSet() throws Exception {
    // issue #7194
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:testUpdateAddOnNonExistingSet");
    db.create();
    try {
        db.command(new OCommandSQL("CREATE class Foo")).execute();
        db.command(new OCommandSQL("CREATE property Foo.tags EMBEDDEDSET")).execute();
        db.command(new OCommandSQL("insert into Foo set name = 'a'")).execute();
        db.command(new OCommandSQL("update Foo add tags = 'foo'")).execute();
        List<ODocument> result = db.query(new OSQLSynchQuery("SELECT FROM Foo"));
        assertEquals(result.size(), 1);
        ODocument doc = result.get(0);
        Set tags = doc.field("tags");
        assertEquals(tags.size(), 1);
        assertTrue(tags.contains("foo"));
    } finally {
        db.drop();
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 24 with OSQLSynchQuery

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

the class OCommandExecutorSQLCreateSequenceTest method testStartIncrement.

@Test
public void testStartIncrement() {
    db.command(new OCommandSQL("CREATE SEQUENCE SequenceStartIncrement TYPE ORDERED START 3 INCREMENT 10")).execute();
    List<ODocument> results = db.query(new OSQLSynchQuery("select sequence('SequenceStartIncrement').next() as val"));
    assertEquals(results.size(), 1);
    for (ODocument result : results) {
        assertEquals(result.field("val"), 13L);
    }
    results = db.query(new OSQLSynchQuery("select sequence('SequenceStartIncrement').next() as val"));
    assertEquals(results.size(), 1);
    for (ODocument result : results) {
        assertEquals(result.field("val"), 23L);
    }
    results = db.query(new OSQLSynchQuery("select sequence('SequenceStartIncrement').next() as val"));
    assertEquals(results.size(), 1);
    for (ODocument result : results) {
        assertEquals(result.field("val"), 33L);
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 25 with OSQLSynchQuery

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

the class LuceneTransactionQueryTest method testRollback.

@Test
public void testRollback() {
    ODocument doc = new ODocument("c1");
    doc.field("p1", "abc");
    db.begin();
    db.save(doc);
    String query = "select from C1 where p1 lucene \"abc\" ";
    List<ODocument> vertices = ODatabaseRecordThreadLocal.INSTANCE.get().command(new OSQLSynchQuery<ODocument>(query)).execute();
    Assert.assertEquals(vertices.size(), 1);
    db.rollback();
    query = "select from C1 where p1 lucene \"abc\" ";
    vertices = ODatabaseRecordThreadLocal.INSTANCE.get().command(new OSQLSynchQuery<ODocument>(query)).execute();
    Assert.assertEquals(vertices.size(), 0);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)530 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)445 Test (org.testng.annotations.Test)287 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)83 Test (org.junit.Test)73 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)59 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)53 ORID (com.orientechnologies.orient.core.id.ORID)36 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)23 HashMap (java.util.HashMap)23 List (java.util.List)22 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)15 Collection (java.util.Collection)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)12