use of com.tinkerpop.gremlin.java.GremlinPipeline in project orientdb by orientechnologies.
the class TestDirtyTrackingTreeRidBagRemote method test.
@Test
public void test() {
final int max = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
OrientGraph graph = new OrientGraph("remote:localhost:3064/" + TestDirtyTrackingTreeRidBagRemote.class.getSimpleName(), "root", "root");
try {
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
graph.createEdgeType("Edge");
OIdentifiable oneVertex = null;
Map<Object, Vertex> vertices = new HashMap<Object, Vertex>();
for (int i = 0; i < max; i++) {
Vertex v = graph.addVertex("class:V");
v.setProperty("key", "foo" + i);
graph.commit();
vertices.put(v.getProperty("key"), v);
if (i == max / 2 + 1)
oneVertex = ((OrientVertex) v).getIdentity();
}
graph.commit();
// Add the edges
for (int i = 0; i < max; i++) {
String codeUCD1 = "foo" + i;
// Take the first vertex
Vertex med1 = (Vertex) vertices.get(codeUCD1);
// For the 2nd term
for (int j = 0; j < max; j++) {
String key = "foo" + j;
// Take the second vertex
Vertex med2 = (Vertex) vertices.get(key);
// ((OrientVertex)med2).getRecord().reload();
OrientEdge eInteraction = graph.addEdge(null, med1, med2, "Edge");
assertNotNull(graph.getRawGraph().getTransaction().getRecordEntry(((OrientVertex) med2).getIdentity()));
}
// COMMIT
graph.commit();
}
graph.getRawGraph().getLocalCache().clear();
OrientVertex vertex = graph.getVertex(oneVertex);
assertEquals(new GremlinPipeline<Vertex, Long>().start(vertex).in("Edge").count(), max);
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project orientdb by orientechnologies.
the class OGremlinHelper method execute.
public static Object execute(final OrientBaseGraph graph, final String iText, final Map<Object, Object> iConfiguredParameters, Map<Object, Object> iCurrentParameters, final List<Object> iResult, final OGremlinCallback iBeforeExecution, final OGremlinCallback iAfterExecution) {
try {
final ScriptEngine engine = getGremlinEngine(graph);
try {
final String output = OGremlinHelper.bindParameters(engine, iConfiguredParameters, iCurrentParameters);
if (iBeforeExecution != null)
if (!iBeforeExecution.call(engine, graph))
return null;
if (iText == null) {
return null;
}
final Object scriptResult = engine.eval(iText);
if (iAfterExecution != null)
if (!iAfterExecution.call(engine, graph))
return null;
// - Map -> ODocument
if (output != null) {
if (scriptResult instanceof GremlinPipeline) {
Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
while (it.hasNext()) // ignore iCurrentRecord but traverse still required
it.next();
}
final Map<String, Object> map = (Map<String, Object>) engine.get(output);
ODocument oDocument = new ODocument(map);
iResult.add(oDocument);
return oDocument;
}
// returned for this call in the last pipe
if (scriptResult instanceof GremlinPipeline) {
final Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
Object finalResult = null;
List<Object> resultCollection = null;
while (it.hasNext()) {
Object current = it.next();
if (finalResult != null) {
if (resultCollection == null) {
// CONVERT IT INTO A COLLECTION
resultCollection = new ArrayList<Object>();
resultCollection.add(finalResult);
}
resultCollection.add(current);
} else
finalResult = current;
}
if (resultCollection != null) {
iResult.addAll(resultCollection);
return resultCollection;
} else {
if (finalResult != null)
iResult.add(finalResult);
return finalResult;
}
} else if (scriptResult != null)
iResult.add(scriptResult);
return scriptResult;
} catch (Exception e) {
throw OException.wrapException(new OCommandExecutionException("Error on execution of the GREMLIN script"), e);
} finally {
OGremlinHelper.global().releaseEngine(engine);
}
} finally {
OGremlinHelper.global().releaseGraph(graph);
}
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.
the class OrderStepTest method test_g_V_orderXa_nameXb_nameX_name.
public void test_g_V_orderXa_nameXb_nameX_name() {
super.test_g_V_orderXa_nameXb_nameX_name(new GremlinPipeline(g.getVertices()).order(new PipeFunction<Pair<Vertex, Vertex>, Integer>() {
public Integer compute(Pair<Vertex, Vertex> argument) {
return ((String) argument.getB().getProperty("name")).compareTo((String) argument.getA().getProperty("name"));
}
}).property("name"));
super.test_g_V_orderXa_nameXb_nameX_name(new GremlinPipeline(g.getVertices()).optimize(false).order(new PipeFunction<Pair<Vertex, Vertex>, Integer>() {
public Integer compute(Pair<Vertex, Vertex> argument) {
return ((String) argument.getB().getProperty("name")).compareTo((String) argument.getA().getProperty("name"));
}
}).property("name"));
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.
the class OrderStepTest method test_g_V_name_order.
public void test_g_V_name_order() {
super.test_g_V_name_order(new GremlinPipeline(g.getVertices()).property("name").order());
super.test_g_V_name_order(new GremlinPipeline(g).optimize(false).V().property("name").order());
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.
the class PathStepTest method test_g_v1_out_pathXage__nameX.
public void test_g_v1_out_pathXage__nameX() {
super.test_g_v1_out_pathXage__nameX(new GremlinPipeline(g.getVertex(1)).out().path(new PipeFunction<Vertex, Integer>() {
public Integer compute(Vertex vertex) {
return (Integer) vertex.getProperty("age");
}
}, new PipeFunction<Vertex, String>() {
public String compute(Vertex vertex) {
return (String) vertex.getProperty("name");
}
}));
super.test_g_v1_out_pathXage__nameX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().path(new PipeFunction<Vertex, Integer>() {
public Integer compute(Vertex vertex) {
return (Integer) vertex.getProperty("age");
}
}, new PipeFunction<Vertex, String>() {
public String compute(Vertex vertex) {
return (String) vertex.getProperty("name");
}
}));
}
Aggregations