- if (graph.isInstanceOf(resource, ES.PropertyCondition)) {
- String propertyName = graph.getRelatedValue(resource, ES.PropertyCondition_HasPropertyName);
- Double lowerLimit = graph.getPossibleRelatedValue(resource, ES.PropertyCondition_HasLowerLimit);
- Double upperLimit = graph.getPossibleRelatedValue(resource, ES.PropertyCondition_HasUpperLimit);
- cond = new PropertyCondition(resource, propertyName, lowerLimit, upperLimit);
+ if (graph.isInstanceOf(resource, ES.PropertyCondition))
+ cond = new PropertyCondition(graph, resource);
+ else if (graph.isInstanceOf(resource, ES.RegionCondition))
+ cond = new RegionCondition(graph, resource);
+ else if (graph.isInstanceOf(resource, ES.RouteCondition))
+ cond = new RouteCondition(graph, resource);
+ else if (graph.isInstanceOf(resource, ES.AggregateCondition))
+ cond = new AggregateCondition(graph, resource);
+ else
+ throw new IllegalArgumentException("Unknown condition type " + graph.getURI(graph.getSingleType(resource)));
+
+ return cond;
+ }
+
+ private static String buildExpression(ReadGraph graph, Resource r) throws DatabaseException {
+ if (graph.isInstanceOf(r, ES.Selection))
+ return buildSelectionExpression(graph, r);
+ else if (graph.isInstanceOf(r, ES.Condition))
+ return buildConditionExpression(graph, r);
+ else if (graph.isInstanceOf(r, ES.Selector))
+ return buildSelectorExpression(graph, r);
+ else if (graph.isInstanceOf(r, ES.Generator))
+ return buildGeneratorExpression(graph, r);
+ else
+ throw new DatabaseException("Unsupported resource type <" + graph.getURI(graph.getSingleType(r)) + ">");
+ }
+
+ private static String buildSelectionExpression(ReadGraph graph, Resource r) throws DatabaseException,
+ NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException {
+ String exp = "select " + getExpression(graph, graph.getSingleObject(r, ES.Selection_HasSelector)) +
+ " from " + getExpression(graph, graph.getSingleObject(r, ES.Selection_HasGenerator));
+
+ Resource cond = graph.getPossibleObject(r, ES.Selection_HasCondition);
+ return cond != null ? exp + " where {" + getExpression(graph, cond) + "}" : exp;
+ }
+
+ private static String buildGeneratorExpression(ReadGraph graph, Resource r)
+ throws ServiceException, NoSingleResultException, DoesNotContainValueException,
+ ManyObjectsForFunctionalRelationException, DatabaseException, AssumptionException, ValidationException {
+ if (graph.isInstanceOf(r, ES.Generator_Model)) {
+ return "model";