use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionShortestPath method walkLeft.
protected List<ORID> walkLeft(final OSQLFunctionShortestPath.OShortestPathContext ctx) {
ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>();
while (!ctx.queueLeft.isEmpty()) {
ctx.current = ctx.queueLeft.poll();
Iterable<Vertex> neighbors;
if (ctx.edgeType == null) {
neighbors = ctx.current.getVertices(ctx.directionLeft);
} else {
neighbors = ctx.current.getVertices(ctx.directionLeft, ctx.edgeTypeParam);
}
for (Vertex neighbor : neighbors) {
final OrientVertex v = (OrientVertex) neighbor;
final ORID neighborIdentity = v.getIdentity();
if (ctx.rightVisited.contains(neighborIdentity)) {
ctx.previouses.put(neighborIdentity, ctx.current.getIdentity());
return computePath(ctx.previouses, ctx.nexts, neighborIdentity);
}
if (!ctx.leftVisited.contains(neighborIdentity)) {
ctx.previouses.put(neighborIdentity, ctx.current.getIdentity());
nextLevelQueue.offer(v);
ctx.leftVisited.add(neighborIdentity);
}
}
}
ctx.queueLeft = nextLevelQueue;
return null;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionShortestPath method walkRight.
protected List<ORID> walkRight(final OSQLFunctionShortestPath.OShortestPathContext ctx) {
final ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>();
while (!ctx.queueRight.isEmpty()) {
ctx.currentRight = ctx.queueRight.poll();
Iterable<Vertex> neighbors;
if (ctx.edgeType == null) {
neighbors = ctx.currentRight.getVertices(ctx.directionRight);
} else {
neighbors = ctx.currentRight.getVertices(ctx.directionRight, ctx.edgeTypeParam);
}
for (Vertex neighbor : neighbors) {
final OrientVertex v = (OrientVertex) neighbor;
final ORID neighborIdentity = v.getIdentity();
if (ctx.leftVisited.contains(neighborIdentity)) {
ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity());
return computePath(ctx.previouses, ctx.nexts, neighborIdentity);
}
if (!ctx.rightVisited.contains(neighborIdentity)) {
ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity());
nextLevelQueue.offer(v);
ctx.rightVisited.add(neighborIdentity);
}
}
}
ctx.queueRight = nextLevelQueue;
return null;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionGremlin method execute.
public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, final OCommandContext iContext) {
final ODatabaseDocumentTx db = OGremlinHelper.getGraphDatabase(ODatabaseRecordThreadLocal.INSTANCE.get());
result = new ArrayList<Object>();
OGremlinHelper.execute(db, (String) iParams[0], null, (Map) iContext.getVariables(), result, new OGremlinHelper.OGremlinCallback() {
@Override
public boolean call(final ScriptEngine iEngine, final OrientBaseGraph iGraph) {
if (iCurrentRecord == null)
// IGNORE PRE-PROCESSING
return true;
final ODocument document = (ODocument) iCurrentRecord;
OClass clazz = ODocumentInternal.getImmutableSchemaClass(document);
if (clazz != null && clazz.isSubClassOf(OrientEdgeType.CLASS_NAME)) {
// EDGE TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientEdge graphElement = (OrientEdge) new OrientElementIterable<OrientEdge>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
} else {
// VERTEX TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientVertex graphElement = (OrientVertex) new OrientElementIterable<OrientVertex>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
}
return true;
}
}, null);
return result;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionHeuristicPathFinderAbstract method getNeighbors.
protected Set<OrientVertex> getNeighbors(final OrientVertex node) {
context.incrementVariable("getNeighbors");
final Set<OrientVertex> neighbors = new HashSet<OrientVertex>();
if (node != null) {
for (Vertex v : node.getVertices(paramDirection, paramEdgeTypeNames)) {
final OrientVertex ov = (OrientVertex) v;
if (ov != null)
neighbors.add(ov);
}
}
return neighbors;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class OSQLFunctionIn method fetchFromIndex.
private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
String edgeClassName = null;
if (iEdgeTypes == null) {
edgeClassName = "E";
} else if (iEdgeTypes.length == 1) {
edgeClassName = iEdgeTypes[0];
} else {
return null;
}
OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
if (edgeClass == null) {
return null;
}
Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
if (indexes == null || indexes.size() == 0) {
return null;
}
OIndex index = indexes.iterator().next();
OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
for (OIdentifiable to : iTo) {
OCompositeKey key = new OCompositeKey(iFrom, to);
Object indexResult = index.get(key);
if (indexResult instanceof OIdentifiable) {
indexResult = Collections.singleton(indexResult);
}
Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
}
result.add(identities);
}
return result;
}
Aggregations