use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class DirectedAcyclicGraphStrategy method getChildren.
@SuppressWarnings("unchecked")
@Override
public ServerChildGraphNode getChildren(VertexServerGeoObject parent, Boolean recursive, Date date) {
ServerChildGraphNode tnRoot = new ServerChildGraphNode(parent, this.type, date, null, null);
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", parent.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND( outE(");
statement.append("'" + this.type.getMdEdgeDAO().getDBClassName() + "'");
statement.append(")");
if (date != null) {
statement.append("[:date BETWEEN startDate AND endDate]");
parameters.put("date", date);
}
statement.append(") FROM :rid");
GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
List<EdgeObject> edges = query.getResults();
for (EdgeObject edge : edges) {
final VertexObject childVertex = edge.getChild();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) childVertex.getMdClass();
ServerGeoObjectType childType = ServerGeoObjectType.get(mdVertex);
VertexServerGeoObject child = new VertexServerGeoObject(childType, childVertex, date);
ServerChildGraphNode tnParent;
if (recursive) {
tnParent = this.getChildren(child, recursive, date);
tnParent.setOid(edge.getOid());
} else {
tnParent = new ServerChildGraphNode(child, this.type, date, null, edge.getOid());
}
tnRoot.addChild(tnParent);
}
return tnRoot;
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class DirectedAcyclicGraphStrategy method getParents.
@SuppressWarnings("unchecked")
@Override
public ServerParentGraphNode getParents(VertexServerGeoObject child, Boolean recursive, Date date) {
ServerParentGraphNode tnRoot = new ServerParentGraphNode(child, this.type, date, null, null);
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", child.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND( inE(");
statement.append("'" + this.type.getMdEdgeDAO().getDBClassName() + "'");
statement.append(")");
if (date != null) {
statement.append("[:date BETWEEN startDate AND endDate]");
parameters.put("date", date);
}
statement.append(") FROM :rid");
GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
List<EdgeObject> edges = query.getResults();
for (EdgeObject edge : edges) {
final VertexObject parentVertex = edge.getParent();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
ServerParentGraphNode tnParent;
if (recursive) {
tnParent = this.getParents(parent, recursive, date);
tnParent.setOid(edge.getOid());
} else {
tnParent = new ServerParentGraphNode(parent, this.type, date, null, edge.getOid());
}
tnRoot.addParent(tnParent);
}
return tnRoot;
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class ServerHierarchyStrategy method getParents.
@SuppressWarnings("unchecked")
@Override
public ServerParentGraphNode getParents(VertexServerGeoObject child, Boolean recursive, Date date) {
ServerParentGraphNode tnRoot = new ServerParentGraphNode(child, this.hierarchy, date, null, null);
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", child.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND( inE(");
statement.append("'" + this.hierarchy.getMdEdge().getDBClassName() + "'");
statement.append(")");
if (date != null) {
statement.append("[:date BETWEEN startDate AND endDate]");
parameters.put("date", date);
}
statement.append(") FROM :rid");
GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
List<EdgeObject> edges = query.getResults();
for (EdgeObject edge : edges) {
final VertexObject parentVertex = edge.getParent();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) parentVertex.getMdClass();
ServerGeoObjectType parentType = ServerGeoObjectType.get(mdVertex);
VertexServerGeoObject parent = new VertexServerGeoObject(parentType, parentVertex, date);
ServerParentGraphNode tnParent;
if (recursive) {
tnParent = this.getParents(parent, recursive, date);
tnParent.setOid(edge.getOid());
} else {
tnParent = new ServerParentGraphNode(parent, this.hierarchy, date, null, edge.getOid());
}
tnRoot.addParent(tnParent);
}
return tnRoot;
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class UndirectedGraphStrategy method isCycle.
public boolean isCycle(VertexServerGeoObject geoObject, VertexServerGeoObject parent, Date startDate, Date endDate) {
VertexObject vertex = geoObject.getVertex();
StringBuffer statement = new StringBuffer();
statement.append("SELECT count(*) FROM (");
statement.append("MATCH {class: " + geoObject.getType().getMdVertex().getDBClassName() + ", where: (@rid = :rid)}.(outE('" + this.type.getMdEdgeDAO().getDBClassName() + "')");
statement.append(" {where: (:startDate BETWEEN startDate AND endDate OR :endDate BETWEEN startDate AND endDate)}.outV())");
statement.append(" {as: friend, while: ($depth < 10)} RETURN friend.code AS code");
statement.append(")");
statement.append(" WHERE code = :code");
GraphQuery<Long> query = new GraphQuery<Long>(statement.toString());
query.setParameter("rid", vertex.getRID());
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
query.setParameter("code", parent.getCode());
Long count = query.getSingleResult();
return (count != null && count > 0);
}
use of com.runwaysdk.business.graph.GraphQuery in project geoprism-registry by terraframe.
the class VertexServerGeoObject method internalGetChildGeoObjects.
private static ServerChildTreeNode internalGetChildGeoObjects(VertexServerGeoObject parent, String[] childrenTypes, Boolean recursive, ServerHierarchyType htIn, Date date) {
ServerChildTreeNode tnRoot = new ServerChildTreeNode(parent, htIn, date, null, null);
Map<String, Object> parameters = new HashedMap<String, Object>();
parameters.put("rid", parent.getVertex().getRID());
StringBuilder statement = new StringBuilder();
statement.append("SELECT EXPAND(outE(");
if (htIn != null) {
statement.append("'" + htIn.getMdEdge().getDBClassName() + "'");
}
statement.append(")");
if (childrenTypes != null && childrenTypes.length > 0) {
statement.append("[");
for (int i = 0; i < childrenTypes.length; i++) {
ServerGeoObjectType type = ServerGeoObjectType.get(childrenTypes[i]);
final String paramName = "p" + Integer.toString(i);
if (i > 0) {
statement.append(" OR ");
}
statement.append("in.@class = :" + paramName);
parameters.put(paramName, type.getMdVertex().getDBClassName());
}
statement.append("]");
}
statement.append(") FROM :rid");
GraphQuery<EdgeObject> query = new GraphQuery<EdgeObject>(statement.toString(), parameters);
List<EdgeObject> edges = query.getResults();
for (EdgeObject edge : edges) {
MdEdgeDAOIF mdEdge = (MdEdgeDAOIF) edge.getMdClass();
if (HierarchicalRelationshipType.isEdgeAHierarchyType(mdEdge)) {
VertexObject childVertex = edge.getChild();
MdVertexDAOIF mdVertex = (MdVertexDAOIF) childVertex.getMdClass();
ServerHierarchyType ht = ServerHierarchyType.get(mdEdge);
ServerGeoObjectType childType = ServerGeoObjectType.get(mdVertex);
VertexServerGeoObject child = new VertexServerGeoObject(childType, childVertex, date);
ServerChildTreeNode tnChild;
if (recursive) {
tnChild = internalGetChildGeoObjects(child, childrenTypes, recursive, ht, date);
} else {
tnChild = new ServerChildTreeNode(child, ht, date, null, edge.getOid());
}
tnRoot.addChild(tnChild);
}
}
return tnRoot;
}
Aggregations