use of com.tinkerpop.blueprints.impls.orient.OrientElement in project orientdb by orientechnologies.
the class OServerCommandGetGephi method execute.
@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: gephi/<database>/<language>/<query-text>[/<limit>][/<fetchPlan>].<br>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");
final String language = urlParts[2];
final String text = urlParts[3];
final int limit = urlParts.length > 4 ? Integer.parseInt(urlParts[4]) : 20;
final String fetchPlan = urlParts.length > 5 ? urlParts[5] : null;
iRequest.data.commandInfo = "Gephi";
iRequest.data.commandDetail = text;
final ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
final OModifiableBoolean shutdownFlag = new OModifiableBoolean();
final OrientBaseGraph graph = OGraphCommandExecutorSQLFactory.getAnyGraph(shutdownFlag);
try {
final Iterable<OrientElement> vertices;
if (language.equals("sql"))
vertices = graph.command(new OSQLSynchQuery<OrientVertex>(text, limit).setFetchPlan(fetchPlan)).execute();
else if (language.equals("gremlin")) {
List<Object> result = new ArrayList<Object>();
OGremlinHelper.execute(graph, text, null, null, result, null, null);
vertices = new ArrayList<OrientElement>(result.size());
for (Object o : result) {
((ArrayList<OrientElement>) vertices).add(graph.getVertex(o));
}
} else
throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");
sendRecordsContent(iRequest, iResponse, vertices, fetchPlan);
} finally {
if (graph != null && shutdownFlag.getValue())
graph.shutdown(false, false);
if (db != null)
db.close();
}
return false;
}
use of com.tinkerpop.blueprints.impls.orient.OrientElement in project orientdb by orientechnologies.
the class TestGraphUnwindOut method testUwindLightweightEdges.
@Test
public void testUwindLightweightEdges() {
OrientGraph graph = new OrientGraph("memory:" + TestGraphUnwindOut.class.getSimpleName());
graph.setUseLightweightEdges(true);
try {
OrientVertexType type = graph.createVertexType("edgetest");
graph.createEdgeType("edgetestedge");
type.createEdgeProperty(Direction.IN, "edgetestedge");
type.createEdgeProperty(Direction.OUT, "edgetestedge");
OrientVertex test = graph.addVertex("class:edgetest");
test.setProperty("ida", "parentckt1");
test.save();
OrientVertex test1 = graph.addVertex("class:edgetest");
test1.setProperty("ida", "childckt2");
test1.save();
OrientVertex test2 = graph.addVertex("class:edgetest");
test2.setProperty("ida", "childckt3");
test2.save();
OrientVertex test3 = graph.addVertex("class:edgetest");
test3.setProperty("ida", "childckt4");
test3.save();
graph.commit();
graph.command(new OCommandSQL("create edge edgetestedge from (select from edgetest where ida='parentckt1') to (select from edgetest where ida like 'childckt%')")).execute();
graph.commit();
Iterable<OrientElement> res = graph.command(new OSQLSynchQuery("select out_edgetestedge[0] from v where out_edgetestedge.size() > 0 unwind out_edgetestedge ")).execute();
for (OrientElement oDocument : res) {
assertNotNull(oDocument.getRecord().field("out_edgetestedge"));
ODocument doc = oDocument.getRecord().field("out_edgetestedge");
assertEquals(doc.getClassName(), "edgetest");
}
} finally {
graph.drop();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientElement in project orientdb by orientechnologies.
the class OServerCommandGetGephi method generateGraphDbOutput.
protected void generateGraphDbOutput(final Iterable<OrientElement> iVertices, final OJSONWriter json) throws IOException {
if (iVertices == null)
return;
// CREATE A SET TO SPEED UP SEARCHES ON VERTICES
final Set<OrientVertex> vertexes = new HashSet<OrientVertex>();
final Set<OrientEdge> edges = new HashSet<OrientEdge>();
for (OrientElement id : iVertices) if (id instanceof OrientVertex)
vertexes.add((OrientVertex) id);
else
edges.add((OrientEdge) id);
for (OrientVertex vertex : vertexes) {
json.resetAttributes();
json.beginObject(0, false, null);
json.beginObject(1, false, "an");
json.beginObject(2, false, vertex.getIdentity());
// ADD ALL THE EDGES
for (Edge e : vertex.getEdges(Direction.BOTH)) edges.add((OrientEdge) e);
// ADD ALL THE PROPERTIES
for (String field : vertex.getPropertyKeys()) {
final Object v = vertex.getProperty(field);
if (v != null)
json.writeAttribute(3, false, field, v);
}
json.endObject(2, false);
json.endObject(1, false);
json.endObject(0, false);
json.newline();
}
for (OrientEdge edge : edges) {
final ORID sourceVertex = (ORID) edge.getVertex(Direction.OUT).getId();
final ORID targetVertex = (ORID) edge.getVertex(Direction.IN).getId();
if (!vertexes.contains(sourceVertex) || !vertexes.contains(targetVertex))
continue;
json.resetAttributes();
json.beginObject();
json.beginObject(1, false, "ae");
json.beginObject(2, false, edge.getId());
json.writeAttribute(3, false, "directed", false);
json.writeAttribute(3, false, "source", sourceVertex);
json.writeAttribute(3, false, "target", targetVertex);
for (String field : edge.getPropertyKeys()) {
final Object v = edge.getProperty(field);
if (v != null)
json.writeAttribute(3, false, field, v);
}
json.endObject(2, false);
json.endObject(1, false);
json.endObject(0, false);
json.newline();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientElement in project orientdb by orientechnologies.
the class TestGraphCreateEdgeWithoutClass method testCreateEdgeWithoutClass.
@Test
public void testCreateEdgeWithoutClass() {
OrientGraph graph = new OrientGraph("memory:" + TestGraphCreateEdgeWithoutClass.class.getSimpleName());
graph.setUseClassForEdgeLabel(false);
graph.setUseVertexFieldsForEdgeLabels(true);
try {
OrientVertex test = graph.addVertex("class:V");
test.setProperty("name", "foo");
test.save();
OrientVertex test1 = graph.addVertex("class:V");
test1.setProperty("name", "bar");
test1.save();
graph.commit();
graph.command(new OCommandSQL("create edge FooBar from (select from V where name='foo') to (select from V where name = 'bar')")).execute();
graph.commit();
Iterable<OrientElement> res = graph.command(new OSQLSynchQuery("select out as f1, out_ as f2, out_edgetestedge as f3, out_FooBar as f4, outE() as f5 from v where name = 'foo'")).execute();
boolean found = false;
for (OrientElement oDocument : res) {
assertNull(oDocument.getRecord().field("f1"));
assertNull(oDocument.getRecord().field("f2"));
assertNull(oDocument.getRecord().field("f3"));
assertNotNull(oDocument.getRecord().field("f4"));
Iterable<ODocument> f5 = oDocument.getRecord().field("f5");
assertNotNull(f5);
for (ODocument e : f5) {
assertEquals(e.field("label"), "FooBar");
found = true;
}
}
assertTrue(found);
} finally {
graph.drop();
}
}
Aggregations