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();
}
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);
}
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);
}
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;
}
}
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());
}
Aggregations