Search in sources :

Example 6 with OCommandScript

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

the class OCommandExecutorSQLUpdateTest method testDottedTargetInScript.

@Test
public void testDottedTargetInScript() throws Exception {
    // #issue #5397
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OCommandExecutorSQLUpdateTestDottedTargetInScript");
    db.create();
    db.command(new OCommandSQL("create class A")).execute();
    db.command(new OCommandSQL("create class B")).execute();
    db.command(new OCommandSQL("insert into A set name = 'foo'")).execute();
    db.command(new OCommandSQL("insert into B set name = 'bar', a = (select from A)")).execute();
    StringBuilder script = new StringBuilder();
    script.append("let $a = select from B;\n");
    script.append("update $a.a set name = 'baz';\n");
    db.command(new OCommandScript(script.toString())).execute();
    List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from A"));
    assertNotNull(result);
    assertEquals(result.size(), 1);
    assertEquals(result.get(0).field("name"), "baz");
    db.close();
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 7 with OCommandScript

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

the class OConsoleDatabaseApp method js.

@SuppressWarnings("unchecked")
@ConsoleCommand(splitInWords = false, description = "Execute javascript commands in the console")
public void js(@ConsoleParameter(name = "text", description = "The javascript to execute. Use 'db' to reference to a document database, 'gdb' for a graph database") final String iText) {
    if (iText == null)
        return;
    resetResultSet();
    long start = System.currentTimeMillis();
    while (true) {
        try {
            final OCommandExecutorScript cmd = new OCommandExecutorScript();
            cmd.parse(new OCommandScript("Javascript", iText));
            currentResult = cmd.execute(null);
            break;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    float elapsedSeconds = getElapsedSecs(start);
    parseResult();
    if (currentResultSet != null) {
        dumpResultSet(-1);
        message("\nClient side script executed in %f sec(s). Returned %d records", elapsedSeconds, currentResultSet.size());
    } else
        message("\nClient side script executed in %f sec(s). Value returned is: %s", elapsedSeconds, currentResult);
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OCommandExecutorScript(com.orientechnologies.orient.core.command.script.OCommandExecutorScript) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 8 with OCommandScript

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

the class ConcurrentCommandAndOpenTest method concurrentCommands.

@Test
public void concurrentCommands() throws Exception {
    OGlobalConfiguration.DB_POOL_MIN.setValue(1);
    OGlobalConfiguration.DB_POOL_MAX.setValue(MAX_CONNS);
    final Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
            try {
                //System.out.println("Start sleeping...");
                db.command(new OCommandScript("SQL", "sleep 5000")).execute();
            //System.out.println("Sleeping done!");
            } finally {
                db.close();
            }
        }
    }, "Test long sleep");
    thread.start();
    Thread.sleep(1000);
    int commandExecuted = 0;
    int iterations = MAX_CONNS * 5;
    for (int i = 0; i < iterations; ++i) {
        //System.out.println("Open database " + i);
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
        try {
            db.command(new OCommandSQL("select from OUser")).execute();
            //System.out.println("Command executed " + i);
            commandExecuted++;
        } finally {
            db.close();
        }
    }
    //System.out.println("Waiting for the sleeping thread...");
    thread.join();
    //System.out.println("Done!");
    Assert.assertEquals(commandExecuted, iterations);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 9 with OCommandScript

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

the class OCommandTransformer method executeTransform.

@Override
public Object executeTransform(final Object input) throws Exception {
    String runtimeCommand = (String) resolve(command);
    final OCommandRequest cmd;
    if (language.equals("sql")) {
        cmd = new OCommandSQL(runtimeCommand);
        log(OETLProcessor.LOG_LEVELS.DEBUG, "executing command=%s...", runtimeCommand);
    } else if (language.equals("gremlin")) {
        cmd = new OCommandGremlin(runtimeCommand);
    } else {
        cmd = new OCommandScript(language, runtimeCommand);
    }
    cmd.setContext(context);
    try {
        Object result = pipeline.getDocumentDatabase().command(cmd).execute();
        log(OETLProcessor.LOG_LEVELS.DEBUG, "executed command=%s, result=%s", cmd, result);
        return result;
    } catch (Exception e) {
        log(OETLProcessor.LOG_LEVELS.ERROR, "exception=%s - input=%s - command=%s ", e.getMessage(), input, cmd);
        throw e;
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) OCommandGremlin(com.orientechnologies.orient.graph.gremlin.OCommandGremlin) OCommandRequest(com.orientechnologies.orient.core.command.OCommandRequest)

Example 10 with OCommandScript

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

the class TestGraphTransactionOnBatch method testAbsoluteDuplicateEdgeRollback.

@Test
public void testAbsoluteDuplicateEdgeRollback() {
    OClass clazz = db.getMetadata().getSchema().createClass("Test");
    clazz.setSuperClass(E);
    clazz.createProperty("in", OType.LINK);
    clazz.createProperty("out", OType.LINK);
    clazz.createIndex("Unique", INDEX_TYPE.UNIQUE, "in", "out");
    try {
        db.command(new OCommandScript("sql", "BEGIN \n LET a = create vertex V \n LET b = create vertex V \n LET c =create edge Test from $a to $b  \n LET d =create edge Test from $a to $b  \n COMMIT \n" + " RETURN $c")).execute();
        Assert.fail("expected record duplicate exception");
    } catch (ORecordDuplicatedException ex) {
    }
    List<ODocument> res = db.query(new OSQLSynchQuery("select from Test"));
    Assert.assertEquals(0, res.size());
}
Also used : ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) 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.junit.Test)

Aggregations

OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)43 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)21 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)18 Test (org.junit.Test)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)9 InputStream (java.io.InputStream)9 Test (org.testng.annotations.Test)9 Before (org.junit.Before)8 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4 IOException (java.io.IOException)4 Collection (java.util.Collection)3 List (java.util.List)3 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 OException (com.orientechnologies.common.exception.OException)2 OCommandRequest (com.orientechnologies.orient.core.command.OCommandRequest)2