Search in sources :

Example 51 with OSQLSynchQuery

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

the class TraverseTest method traverseAndFilterWithNamedParam.

@Test
public void traverseAndFilterWithNamedParam() {
    // issue #5225
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("param1", "a.b");
    List<ODocument> result1 = database.command(new OSQLSynchQuery<ODocument>("select from (traverse out_married, in[attributeWithDotValue = :param1]  from " + tomCruise.getIdentity() + ")")).execute(params);
    Assert.assertTrue(result1.size() > 0);
    boolean found = false;
    for (ODocument doc : result1) {
        String name = doc.field("name");
        if ("Nicole Kidman".equals(name)) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(found);
}
Also used : HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 52 with OSQLSynchQuery

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

the class TraverseTest method traverseSQLMoviesOnlyDepth.

@Test
public void traverseSQLMoviesOnlyDepth() {
    List<ODocument> result1 = database.command(new OSQLSynchQuery<ODocument>("select from ( traverse * from " + tomCruise.getIdentity() + " while $depth <= 1 ) where @class = 'Movie'")).execute();
    Assert.assertTrue(result1.isEmpty());
    List<ODocument> result2 = database.command(new OSQLSynchQuery<ODocument>("select from ( traverse * from " + tomCruise.getIdentity() + " while $depth <= 2 ) where @class = 'Movie'")).execute();
    Assert.assertTrue(result2.size() > 0);
    for (ODocument d : result2) {
        Assert.assertEquals(d.getClassName(), "Movie");
    }
    List<ODocument> result3 = database.command(new OSQLSynchQuery<ODocument>("select from ( traverse * from " + tomCruise.getIdentity() + " ) where @class = 'Movie'")).execute();
    Assert.assertTrue(result3.size() > 0);
    Assert.assertTrue(result3.size() > result2.size());
    for (ODocument d : result3) {
        Assert.assertEquals(d.getClassName(), "Movie");
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 53 with OSQLSynchQuery

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

the class TraverseTest method traverseSQLMoviesOnly.

@Test
public void traverseSQLMoviesOnly() {
    List<ODocument> result1 = database.command(new OSQLSynchQuery<ODocument>("select from ( traverse any() from Movie ) where @class = 'Movie'")).execute();
    Assert.assertTrue(result1.size() > 0);
    for (ODocument d : result1) {
        Assert.assertEquals(d.getClassName(), "Movie");
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 54 with OSQLSynchQuery

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

the class TruncateClassTest method testTruncateVertexClassSubclassesWithIndex.

@Test
public void testTruncateVertexClassSubclassesWithIndex() {
    database.command(new OCommandSQL("create class TestTruncateVertexClassSuperclassWithIndex")).execute();
    database.command(new OCommandSQL("create property TestTruncateVertexClassSuperclassWithIndex.name STRING")).execute();
    database.command(new OCommandSQL("create index TestTruncateVertexClassSuperclassWithIndex_index on TestTruncateVertexClassSuperclassWithIndex (name) NOTUNIQUE")).execute();
    database.command(new OCommandSQL("create class TestTruncateVertexClassSubclassWithIndex extends TestTruncateVertexClassSuperclassWithIndex")).execute();
    database.command(new OCommandSQL("insert into TestTruncateVertexClassSuperclassWithIndex set name = 'foo'")).execute();
    database.command(new OCommandSQL("insert into TestTruncateVertexClassSubclassWithIndex set name = 'bar'")).execute();
    List<?> result = database.query(new OSQLSynchQuery("select from index:TestTruncateVertexClassSuperclassWithIndex_index"));
    Assert.assertEquals(result.size(), 2);
    database.command(new OCommandSQL("truncate class TestTruncateVertexClassSubclassWithIndex")).execute();
    result = database.query(new OSQLSynchQuery("select from index:TestTruncateVertexClassSuperclassWithIndex_index"));
    Assert.assertEquals(result.size(), 1);
    database.command(new OCommandSQL("truncate class TestTruncateVertexClassSuperclassWithIndex polymorphic")).execute();
    result = database.query(new OSQLSynchQuery("select from index:TestTruncateVertexClassSuperclassWithIndex_index"));
    Assert.assertEquals(result.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Test(org.testng.annotations.Test)

Example 55 with OSQLSynchQuery

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

the class TruncateClassTest method testTruncateVertexClass.

@Test
public void testTruncateVertexClass() {
    database.command(new OCommandSQL("create class TestTruncateVertexClass extends V")).execute();
    database.command(new OCommandSQL("create vertex TestTruncateVertexClass set name = 'foo'")).execute();
    try {
        database.command(new OCommandSQL("truncate class TestTruncateVertexClass ")).execute();
        Assert.fail();
    } catch (Exception e) {
    }
    List<?> result = database.query(new OSQLSynchQuery("select from TestTruncateVertexClass"));
    Assert.assertEquals(result.size(), 1);
    database.command(new OCommandSQL("truncate class TestTruncateVertexClass unsafe")).execute();
    result = database.query(new OSQLSynchQuery("select from TestTruncateVertexClass"));
    Assert.assertEquals(result.size(), 0);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Test(org.testng.annotations.Test)

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)506 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)426 Test (org.testng.annotations.Test)282 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)78 Test (org.junit.Test)60 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)57 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)47 ORID (com.orientechnologies.orient.core.id.ORID)34 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)31 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)22 List (java.util.List)21 HashMap (java.util.HashMap)20 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 Collection (java.util.Collection)15 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)13 Set (java.util.Set)12 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)11