Search in sources :

Example 16 with OBasicCommandContext

use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.

the class OFunctionSqlTest method functionSqlWithInnerFunctionJs.

@Test
public void functionSqlWithInnerFunctionJs() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:functionSqlWithInnerFunctionJs");
    db.create();
    // ODatabaseRecordThreadLocal.INSTANCE.set(db);
    ODocument doc1 = new ODocument("Test");
    doc1.field("name", "Enrico");
    db.save(doc1);
    doc1.reset();
    doc1.setClassName("Test");
    doc1.field("name", "Luca");
    db.save(doc1);
    OFunction function = new OFunction();
    function.setName("test");
    function.setCode("select name from Test where name = :name and hello(:name) = 'Hello Enrico'");
    function.setParameters(new ArrayList<String>() {

        {
            add("name");
        }
    });
    function.save();
    OFunction function1 = new OFunction();
    function1.setName("hello");
    function1.setLanguage("javascript");
    function1.setCode("return 'Hello ' + name");
    function1.setParameters(new ArrayList<String>() {

        {
            add("name");
        }
    });
    function1.save();
    Object result = function.executeInContext(new OBasicCommandContext(), "Enrico");
    System.out.println(result);
    Assert.assertEquals(((OResultSet) result).size(), 1);
    db.drop();
}
Also used : OBasicCommandContext(com.orientechnologies.orient.core.command.OBasicCommandContext) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OFunction(com.orientechnologies.orient.core.metadata.function.OFunction) Test(org.testng.annotations.Test)

Example 17 with OBasicCommandContext

use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.

the class OSQLFunctionAstarTest method test12Execute.

@Test
public void test12Execute() throws Exception {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(OSQLFunctionAstar.PARAM_DIRECTION, Direction.OUT);
    options.put(OSQLFunctionAstar.PARAM_PARALLEL, true);
    options.put(OSQLFunctionAstar.PARAM_TIE_BREAKER, false);
    options.put(OSQLFunctionAstar.PARAM_EMPTY_IF_MAX_DEPTH, false);
    options.put(OSQLFunctionAstar.PARAM_MAX_DEPTH, 3);
    options.put(OSQLFunctionAstar.PARAM_EDGE_TYPE_NAMES, new String[] { "has_path" });
    options.put(OSQLFunctionAstar.PARAM_VERTEX_AXIS_NAMES, new String[] { "lat", "lon" });
    options.put(OSQLFunctionAstar.PARAM_HEURISTIC_FORMULA, HeuristicFormula.CUSTOM);
    options.put(OSQLFunctionAstar.PARAM_CUSTOM_HEURISTIC_FORMULA, "myCustomHeuristic");
    final List<OrientVertex> result = functionAstar.execute(null, null, null, new Object[] { v6, v1, "'weight'", options }, new OBasicCommandContext());
    assertEquals(16, graph.countEdges("has_path"));
    assertEquals(4, result.size());
    assertEquals(v6, result.get(0));
    assertEquals(v5, result.get(1));
    assertEquals(v2, result.get(2));
    assertEquals(v3, result.get(3));
}
Also used : OBasicCommandContext(com.orientechnologies.orient.core.command.OBasicCommandContext) HashMap(java.util.HashMap) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 18 with OBasicCommandContext

use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.

the class OSQLFunctionAstarTest method test8Execute.

@Test
public void test8Execute() throws Exception {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(OSQLFunctionAstar.PARAM_DIRECTION, Direction.OUT);
    options.put(OSQLFunctionAstar.PARAM_PARALLEL, true);
    options.put(OSQLFunctionAstar.PARAM_TIE_BREAKER, false);
    options.put(OSQLFunctionAstar.PARAM_EDGE_TYPE_NAMES, new String[] { "has_path" });
    options.put(OSQLFunctionAstar.PARAM_VERTEX_AXIS_NAMES, new String[] { "lat", "lon" });
    options.put(OSQLFunctionAstar.PARAM_HEURISTIC_FORMULA, HeuristicFormula.EUCLIDEANNOSQR);
    final List<OrientVertex> result = functionAstar.execute(null, null, null, new Object[] { v6, v1, "'weight'", options }, new OBasicCommandContext());
    assertEquals(16, graph.countEdges("has_path"));
    assertEquals(5, result.size());
    assertEquals(v6, result.get(0));
    assertEquals(v5, result.get(1));
    assertEquals(v2, result.get(2));
    assertEquals(v4, result.get(3));
    assertEquals(v1, result.get(4));
}
Also used : OBasicCommandContext(com.orientechnologies.orient.core.command.OBasicCommandContext) HashMap(java.util.HashMap) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 19 with OBasicCommandContext

use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.

the class OSQLFunctionAstarTest method test3Execute.

@Test
public void test3Execute() throws Exception {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(OSQLFunctionAstar.PARAM_DIRECTION, "out");
    options.put(OSQLFunctionAstar.PARAM_PARALLEL, true);
    options.put(OSQLFunctionAstar.PARAM_EDGE_TYPE_NAMES, new String[] { "has_path" });
    options.put(OSQLFunctionAstar.PARAM_VERTEX_AXIS_NAMES, new String[] { "lat", "lon" });
    final List<OrientVertex> result = functionAstar.execute(null, null, null, new Object[] { v1, v6, "'weight'", options }, new OBasicCommandContext());
    assertEquals(16, graph.countEdges("has_path"));
    assertEquals(3, result.size());
    assertEquals(v1, result.get(0));
    assertEquals(v5, result.get(1));
    assertEquals(v6, result.get(2));
}
Also used : OBasicCommandContext(com.orientechnologies.orient.core.command.OBasicCommandContext) HashMap(java.util.HashMap) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 20 with OBasicCommandContext

use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.

the class OSQLFunctionAstarTest method test4Execute.

@Test
public void test4Execute() throws Exception {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(OSQLFunctionAstar.PARAM_DIRECTION, "out");
    options.put(OSQLFunctionAstar.PARAM_PARALLEL, true);
    options.put(OSQLFunctionAstar.PARAM_EDGE_TYPE_NAMES, new String[] { "has_path" });
    options.put(OSQLFunctionAstar.PARAM_VERTEX_AXIS_NAMES, new String[] { "lat", "lon", "alt" });
    final List<OrientVertex> result = functionAstar.execute(null, null, null, new Object[] { v1, v6, "'weight'", options }, new OBasicCommandContext());
    assertEquals(16, graph.countEdges("has_path"));
    assertEquals(3, result.size());
    assertEquals(v1, result.get(0));
    assertEquals(v5, result.get(1));
    assertEquals(v6, result.get(2));
}
Also used : OBasicCommandContext(com.orientechnologies.orient.core.command.OBasicCommandContext) HashMap(java.util.HashMap) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Aggregations

OBasicCommandContext (com.orientechnologies.orient.core.command.OBasicCommandContext)29 Test (org.junit.Test)22 HashMap (java.util.HashMap)16 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ORID (com.orientechnologies.orient.core.id.ORID)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 Test (org.testng.annotations.Test)5 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)3 OFunction (com.orientechnologies.orient.core.metadata.function.OFunction)3 OCommandContext (com.orientechnologies.orient.core.command.OCommandContext)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OException (com.orientechnologies.common.exception.OException)1 OPair (com.orientechnologies.common.util.OPair)1 OCommandScriptException (com.orientechnologies.orient.core.command.script.OCommandScriptException)1 ODocumentComparator (com.orientechnologies.orient.core.record.impl.ODocumentComparator)1 OETLBaseTest (com.orientechnologies.orient.etl.OETLBaseTest)1 OHttpRequestWrapper (com.orientechnologies.orient.server.network.protocol.http.OHttpRequestWrapper)1 OHttpResponseWrapper (com.orientechnologies.orient.server.network.protocol.http.OHttpResponseWrapper)1 IOException (java.io.IOException)1