use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.
the class OETLProcessor method createDefaultContext.
protected static OCommandContext createDefaultContext() {
final OCommandContext context = new OBasicCommandContext();
context.setVariable("dumpEveryMs", 1000);
return context;
}
use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.
the class DocumentTest method testEvalInContext.
@Test
public void testEvalInContext() {
ODocument doc = new ODocument();
doc.field("amount", 300);
OCommandContext context = new OBasicCommandContext().setVariable("vat", 20);
Number amountPlusVat = (Number) doc.eval("amount * (100 + $vat) / 100", context);
Assert.assertEquals(amountPlusVat.longValue(), 360l);
}
use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.
the class SQLFunctionDifferenceTest method testExecute.
@Test
public void testExecute() {
final OSQLFunctionDifference function = new OSQLFunctionDifference();
List<List<Object>> incomes = Arrays.asList(Arrays.<Object>asList(1, 2, 3, 4, 5, 1), Arrays.<Object>asList(3, 5, 6, 7, 0, 1, 3, 3, 6), Arrays.<Object>asList(2, 2, 8, 9));
Set<Object> expectedResult = new HashSet<Object>(Arrays.<Object>asList(4));
Set<Object> actualResult = (Set<Object>) function.execute(null, null, null, incomes.toArray(), new OBasicCommandContext());
assertSetEquals(actualResult, expectedResult);
incomes = Arrays.asList(Arrays.<Object>asList(1, 2, 3, 4, 5, 1), Arrays.<Object>asList(3, 5, 6, 7, 0, 1, 3, 3, 6));
expectedResult = new HashSet<Object>(Arrays.<Object>asList(2, 4));
actualResult = (Set<Object>) function.execute(null, null, null, incomes.toArray(), new OBasicCommandContext());
assertSetEquals(actualResult, expectedResult);
}
use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.
the class OFunctionSqlTest method functionSqlWithParameters.
@Test
public void functionSqlWithParameters() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:functionSqlWithParameters");
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 from Test where name = :name");
function.setParameters(new ArrayList<String>() {
{
add("name");
}
});
function.save();
Object result = function.executeInContext(new OBasicCommandContext(), "Enrico");
System.out.println(result);
Assert.assertEquals(((OResultSet) result).size(), 1);
db.drop();
}
use of com.orientechnologies.orient.core.command.OBasicCommandContext in project orientdb by orientechnologies.
the class OSQLFunctionShortestPathTest method testExecuteOnlyEdge1.
@Test
public void testExecuteOnlyEdge1() throws Exception {
final List<ORID> result = function.execute(null, null, null, new Object[] { vertices.get(1), vertices.get(4), null, "Edge1" }, new OBasicCommandContext());
assertEquals(4, result.size());
assertEquals(vertices.get(1).getId(), result.get(0));
assertEquals(vertices.get(2).getId(), result.get(1));
assertEquals(vertices.get(3).getId(), result.get(2));
assertEquals(vertices.get(4).getId(), result.get(3));
}
Aggregations