Search in sources :

Example 21 with OCommandScript

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

the class LuceneSingleFieldEmbeddedTest method init.

@Before
public void init() {
    InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");
    db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
    db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
    db.command(new OCommandSQL("create index Song.author on Song (author) FULLTEXT ENGINE LUCENE")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) InputStream(java.io.InputStream) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) Before(org.junit.Before)

Example 22 with OCommandScript

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

the class LuceneSkipLimitTest method init.

@Before
public void init() {
    InputStream stream = ClassLoader.getSystemResourceAsStream("testLuceneIndex.sql");
    db.command(new OCommandScript("sql", getScriptFromStream(stream))).execute();
    db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();
    db.command(new OCommandSQL("create index Song.author on Song (author) FULLTEXT ENGINE LUCENE")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) InputStream(java.io.InputStream) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) Before(org.junit.Before)

Example 23 with OCommandScript

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

the class TransactionIsolationTest method testIsolationRepeatableReadScript.

@Test
public void testIsolationRepeatableReadScript() throws ExecutionException, InterruptedException {
    final ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
    db1.open("admin", "admin");
    final ODocument record1 = new ODocument();
    record1.field("name", "This is the first version").save();
    Future<List<OIdentifiable>> txFuture = Orient.instance().submit(new Callable<List<OIdentifiable>>() {

        @Override
        public List<OIdentifiable> call() throws Exception {
            String cmd = "";
            cmd += "begin isolation REPEATABLE_READ;";
            cmd += "let r1 = select from " + record1.getIdentity() + ";";
            cmd += "sleep 2000;";
            cmd += "let r2 = select from " + record1.getIdentity() + ";";
            cmd += "commit;";
            cmd += "return $r2;";
            db1.activateOnCurrentThread();
            return db1.command(new OCommandScript("sql", cmd)).execute();
        }
    });
    Thread.sleep(500);
    // CHANGE THE RECORD FROM DB2
    ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
    db2.open("admin", "admin");
    ODocument record2 = db2.load(record1.getIdentity());
    record2.field("name", "This is the second version").save();
    List<OIdentifiable> txRecord = txFuture.get();
    Assert.assertNotNull(txRecord);
    Assert.assertEquals(txRecord.size(), 1);
    Assert.assertEquals(((ODocument) txRecord.get(0).getRecord()).field("name"), "This is the first version");
    db1.activateOnCurrentThread();
    db1.close();
    db2.activateOnCurrentThread();
    db2.close();
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) List(java.util.List) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 24 with OCommandScript

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

the class OFunction method execute.

public Object execute(final Map<Object, Object> iArgs) {
    final long start = Orient.instance().getProfiler().startChrono();
    Object result;
    while (true) {
        try {
            if (callback != null)
                return callback.call(iArgs);
            final OCommandExecutorScript command = new OCommandExecutorScript();
            command.parse(new OCommandScript(getLanguage(), getCode()));
            result = command.execute(iArgs);
            break;
        } catch (ONeedRetryException e) {
            continue;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    if (Orient.instance().getProfiler().isRecording())
        Orient.instance().getProfiler().stopChrono("db." + ODatabaseRecordThreadLocal.INSTANCE.get().getName() + ".function.execute", "Time to execute a function", start, "db.*.function.execute");
    return result;
}
Also used : ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OCommandExecutorScript(com.orientechnologies.orient.core.command.script.OCommandExecutorScript)

Example 25 with OCommandScript

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

the class OCommandExecutorSQLScriptTest method testScriptSubContext.

@Test
public void testScriptSubContext() throws Exception {
    StringBuilder script = new StringBuilder();
    script.append("let $a = select from foo limit 1\n");
    script.append("select from (traverse doesnotexist from $a)\n");
    Iterable qResult = db.command(new OCommandScript("sql", script.toString())).execute();
    Assert.assertNotNull(qResult);
    Iterator iterator = qResult.iterator();
    Assert.assertTrue(iterator.hasNext());
    iterator.next();
    Assert.assertFalse(iterator.hasNext());
}
Also used : OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) Iterator(java.util.Iterator) Test(org.testng.annotations.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