@Test public void Start_Flag() { final String PREFIX = "DEFINE input:inference \"ruleset\" "; RDFQueryImpl query = new RDFQueryImpl(null); query.addFlag(Position.START, PREFIX); query.where(Blocks.SPO); query.aggregateFilters(); QueryMetadata metadata = query.getMetadata(); metadata.addProjection(QNODE.s); visitor.visit(metadata, QueryLanguage.TUPLE); assertEquals(PREFIX + "SELECT ?s WHERE { ?s ?p ?o } ", stripWS(visitor.toString())); }
@Nullable public Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType) { metadata = md; QueryModifiers mod = md.getModifiers(); append(prefix); Set<QueryFlag> flags = metadata.getFlags(); serialize(Position.START, flags); if (queryType == QueryLanguage.TUPLE) { append("SELECT "); if (md.isDistinct()) { append("DISTINCT "); } if (!md.getProjection().isEmpty()) { for (Expression<?> expr : md.getProjection()) { if (expr instanceof TemplateExpression<?> || expr instanceof com.mysema.query.types.Operation<?>) { append("(").handle(expr).append(")"); } else { handle(expr); } append(" "); } } else { append("*"); } append("\n"); } else if (queryType == QueryLanguage.BOOLEAN) { append("ASK "); } else if (queryType == QueryLanguage.GRAPH) { if (md.getProjection().size() == 1 && md.getProjection().get(0) instanceof GroupBlock) { append("CONSTRUCT ").handle("", md.getProjection()).append("\n"); } else { append("CONSTRUCT { ").handle("", md.getProjection()).append("}\n"); } } lastPattern = null; for (JoinExpression je : md.getJoins()) { UID uid = (UID) ((Constant<?>) je.getTarget()).getConstant(); append("FROM <").append(uid.getId()).append(">\n"); } if (md.getWhere() != null) { if (queryType != QueryLanguage.BOOLEAN) { append("WHERE \n "); } if (md.getWhere() instanceof GroupBlock) { handle(md.getWhere()); } else { append("{ ").handle(md.getWhere()).append("}"); } append("\n"); } if (!md.getOrderBy().isEmpty()) { append("ORDER BY "); boolean first = true; for (OrderSpecifier<?> order : md.getOrderBy()) { if (!first) { append(" "); } if (order.isAscending()) { handle(order.getTarget()); } else { append("DESC(").handle(order.getTarget()).append(")"); } first = false; } append("\n"); } if (!md.getGroupBy().isEmpty()) { append("GROUP BY ").handle(" ", md.getGroupBy()).append("\n"); } if (md.getHaving() != null) { append("HAVING (").handle(md.getHaving()).append(")\n"); } if (mod.getLimit() != null) { append("LIMIT ").append(mod.getLimit().toString()).append("\n"); } if (mod.getOffset() != null) { append("OFFSET ").append(mod.getOffset().toString()).append("\n"); } metadata = null; return null; }
SPARQLVisitor extends SerializerBase<SPARQLVisitor> implements RDFVisitor<Void, Void> { @Nullable public Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType) { metadata = md; QueryModifiers mod = md.getModifiers(); append(prefix); Set<QueryFlag> flags = metadata.getFlags(); serialize(Position.START, flags); if (queryType == QueryLanguage.TUPLE) { append("SELECT "); if (md.isDistinct()) { append("DISTINCT "); } if (!md.getProjection().isEmpty()) { for (Expression<?> expr : md.getProjection()) { if (expr instanceof TemplateExpression<?> || expr instanceof com.mysema.query.types.Operation<?>) { append("(").handle(expr).append(")"); } else { handle(expr); } append(" "); } } else { append("*"); } append("\n"); } else if (queryType == QueryLanguage.BOOLEAN) { append("ASK "); } else if (queryType == QueryLanguage.GRAPH) { if (md.getProjection().size() == 1 && md.getProjection().get(0) instanceof GroupBlock) { append("CONSTRUCT ").handle("", md.getProjection()).append("\n"); } else { append("CONSTRUCT { ").handle("", md.getProjection()).append("}\n"); } } lastPattern = null; for (JoinExpression je : md.getJoins()) { UID uid = (UID) ((Constant<?>) je.getTarget()).getConstant(); append("FROM <").append(uid.getId()).append(">\n"); } if (md.getWhere() != null) { if (queryType != QueryLanguage.BOOLEAN) { append("WHERE \n "); } if (md.getWhere() instanceof GroupBlock) { handle(md.getWhere()); } else { append("{ ").handle(md.getWhere()).append("}"); } append("\n"); } if (!md.getOrderBy().isEmpty()) { append("ORDER BY "); boolean first = true; for (OrderSpecifier<?> order : md.getOrderBy()) { if (!first) { append(" "); } if (order.isAscending()) { handle(order.getTarget()); } else { append("DESC(").handle(order.getTarget()).append(")"); } first = false; } append("\n"); } if (!md.getGroupBy().isEmpty()) { append("GROUP BY ").handle(" ", md.getGroupBy()).append("\n"); } if (md.getHaving() != null) { append("HAVING (").handle(md.getHaving()).append(")\n"); } if (mod.getLimit() != null) { append("LIMIT ").append(mod.getLimit().toString()).append("\n"); } if (mod.getOffset() != null) { append("OFFSET ").append(mod.getOffset().toString()).append("\n"); } metadata = null; return null; } }
SPARQLVisitor extends SerializerBase<SPARQLVisitor> implements RDFVisitor<Void, Void> { @Nullable public Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType) { metadata = md; QueryModifiers mod = md.getModifiers(); append(prefix); Set<QueryFlag> flags = metadata.getFlags(); serialize(Position.START, flags); if (queryType == QueryLanguage.TUPLE) { append("SELECT "); if (md.isDistinct()) { append("DISTINCT "); } if (!md.getProjection().isEmpty()) { for (Expression<?> expr : md.getProjection()) { if (expr instanceof TemplateExpression<?> || expr instanceof com.mysema.query.types.Operation<?>) { append("(").handle(expr).append(")"); } else { handle(expr); } append(" "); } } else { append("*"); } append("\n"); } else if (queryType == QueryLanguage.BOOLEAN) { append("ASK "); } else if (queryType == QueryLanguage.GRAPH) { if (md.getProjection().size() == 1 && md.getProjection().get(0) instanceof GroupBlock) { append("CONSTRUCT ").handle("", md.getProjection()).append("\n"); } else { append("CONSTRUCT { ").handle("", md.getProjection()).append("}\n"); } } lastPattern = null; for (JoinExpression je : md.getJoins()) { UID uid = (UID) ((Constant<?>) je.getTarget()).getConstant(); append("FROM <").append(uid.getId()).append(">\n"); } if (md.getWhere() != null) { if (queryType != QueryLanguage.BOOLEAN) { append("WHERE \n "); } if (md.getWhere() instanceof GroupBlock) { handle(md.getWhere()); } else { append("{ ").handle(md.getWhere()).append("}"); } append("\n"); } if (!md.getOrderBy().isEmpty()) { append("ORDER BY "); boolean first = true; for (OrderSpecifier<?> order : md.getOrderBy()) { if (!first) { append(" "); } if (order.isAscending()) { handle(order.getTarget()); } else { append("DESC(").handle(order.getTarget()).append(")"); } first = false; } append("\n"); } if (!md.getGroupBy().isEmpty()) { append("GROUP BY ").handle(" ", md.getGroupBy()).append("\n"); } if (md.getHaving() != null) { append("HAVING (").handle(md.getHaving()).append(")\n"); } if (mod.getLimit() != null) { append("LIMIT ").append(mod.getLimit().toString()).append("\n"); } if (mod.getOffset() != null) { append("OFFSET ").append(mod.getOffset().toString()).append("\n"); } metadata = null; return null; } SPARQLVisitor();  SPARQLVisitor(SPARQLTemplates templates, String prefix); }
SPARQLVisitor extends SerializerBase<SPARQLVisitor> implements RDFVisitor<Void, Void> { @Nullable public Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType) { metadata = md; QueryModifiers mod = md.getModifiers(); append(prefix); Set<QueryFlag> flags = metadata.getFlags(); serialize(Position.START, flags); if (queryType == QueryLanguage.TUPLE) { append("SELECT "); if (md.isDistinct()) { append("DISTINCT "); } if (!md.getProjection().isEmpty()) { for (Expression<?> expr : md.getProjection()) { if (expr instanceof TemplateExpression<?> || expr instanceof com.mysema.query.types.Operation<?>) { append("(").handle(expr).append(")"); } else { handle(expr); } append(" "); } } else { append("*"); } append("\n"); } else if (queryType == QueryLanguage.BOOLEAN) { append("ASK "); } else if (queryType == QueryLanguage.GRAPH) { if (md.getProjection().size() == 1 && md.getProjection().get(0) instanceof GroupBlock) { append("CONSTRUCT ").handle("", md.getProjection()).append("\n"); } else { append("CONSTRUCT { ").handle("", md.getProjection()).append("}\n"); } } lastPattern = null; for (JoinExpression je : md.getJoins()) { UID uid = (UID) ((Constant<?>) je.getTarget()).getConstant(); append("FROM <").append(uid.getId()).append(">\n"); } if (md.getWhere() != null) { if (queryType != QueryLanguage.BOOLEAN) { append("WHERE \n "); } if (md.getWhere() instanceof GroupBlock) { handle(md.getWhere()); } else { append("{ ").handle(md.getWhere()).append("}"); } append("\n"); } if (!md.getOrderBy().isEmpty()) { append("ORDER BY "); boolean first = true; for (OrderSpecifier<?> order : md.getOrderBy()) { if (!first) { append(" "); } if (order.isAscending()) { handle(order.getTarget()); } else { append("DESC(").handle(order.getTarget()).append(")"); } first = false; } append("\n"); } if (!md.getGroupBy().isEmpty()) { append("GROUP BY ").handle(" ", md.getGroupBy()).append("\n"); } if (md.getHaving() != null) { append("HAVING (").handle(md.getHaving()).append(")\n"); } if (mod.getLimit() != null) { append("LIMIT ").append(mod.getLimit().toString()).append("\n"); } if (mod.getOffset() != null) { append("OFFSET ").append(mod.getOffset().toString()).append("\n"); } metadata = null; return null; } SPARQLVisitor();  SPARQLVisitor(SPARQLTemplates templates, String prefix); @Nullable Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType); @SuppressWarnings("unchecked") @Override Void visit(SubQueryExpression<?> expr, Void context); @Nullable Void visit(UnionBlock expr, @Nullable Void context); @Nullable Void visit(GroupBlock expr, @Nullable Void context); @Nullable Void visit(GraphBlock expr, @Nullable Void context); @Nullable Void visit(OptionalBlock expr, @Nullable Void context); @SuppressWarnings("unchecked") @Override void visitConstant(Object constant); @Nullable Void visit(PatternBlock expr, @Nullable Void context); @Override @Nullable Void visit(ParamExpression<?> param, @Nullable Void context); void addBindings(SPARQLQuery query, QueryMetadata md); void setInlineResources(boolean b); void setLikeAsMatches(boolean likeAsMatches); void setInlineAll(boolean inlineAll); void setInToOr(boolean inToOr); }
SPARQLVisitor extends SerializerBase<SPARQLVisitor> implements RDFVisitor<Void, Void> { @Nullable public Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType) { metadata = md; QueryModifiers mod = md.getModifiers(); append(prefix); Set<QueryFlag> flags = metadata.getFlags(); serialize(Position.START, flags); if (queryType == QueryLanguage.TUPLE) { append("SELECT "); if (md.isDistinct()) { append("DISTINCT "); } if (!md.getProjection().isEmpty()) { for (Expression<?> expr : md.getProjection()) { if (expr instanceof TemplateExpression<?> || expr instanceof com.mysema.query.types.Operation<?>) { append("(").handle(expr).append(")"); } else { handle(expr); } append(" "); } } else { append("*"); } append("\n"); } else if (queryType == QueryLanguage.BOOLEAN) { append("ASK "); } else if (queryType == QueryLanguage.GRAPH) { if (md.getProjection().size() == 1 && md.getProjection().get(0) instanceof GroupBlock) { append("CONSTRUCT ").handle("", md.getProjection()).append("\n"); } else { append("CONSTRUCT { ").handle("", md.getProjection()).append("}\n"); } } lastPattern = null; for (JoinExpression je : md.getJoins()) { UID uid = (UID) ((Constant<?>) je.getTarget()).getConstant(); append("FROM <").append(uid.getId()).append(">\n"); } if (md.getWhere() != null) { if (queryType != QueryLanguage.BOOLEAN) { append("WHERE \n "); } if (md.getWhere() instanceof GroupBlock) { handle(md.getWhere()); } else { append("{ ").handle(md.getWhere()).append("}"); } append("\n"); } if (!md.getOrderBy().isEmpty()) { append("ORDER BY "); boolean first = true; for (OrderSpecifier<?> order : md.getOrderBy()) { if (!first) { append(" "); } if (order.isAscending()) { handle(order.getTarget()); } else { append("DESC(").handle(order.getTarget()).append(")"); } first = false; } append("\n"); } if (!md.getGroupBy().isEmpty()) { append("GROUP BY ").handle(" ", md.getGroupBy()).append("\n"); } if (md.getHaving() != null) { append("HAVING (").handle(md.getHaving()).append(")\n"); } if (mod.getLimit() != null) { append("LIMIT ").append(mod.getLimit().toString()).append("\n"); } if (mod.getOffset() != null) { append("OFFSET ").append(mod.getOffset().toString()).append("\n"); } metadata = null; return null; } SPARQLVisitor();  SPARQLVisitor(SPARQLTemplates templates, String prefix); @Nullable Void visit(QueryMetadata md, QueryLanguage<?, ?> queryType); @SuppressWarnings("unchecked") @Override Void visit(SubQueryExpression<?> expr, Void context); @Nullable Void visit(UnionBlock expr, @Nullable Void context); @Nullable Void visit(GroupBlock expr, @Nullable Void context); @Nullable Void visit(GraphBlock expr, @Nullable Void context); @Nullable Void visit(OptionalBlock expr, @Nullable Void context); @SuppressWarnings("unchecked") @Override void visitConstant(Object constant); @Nullable Void visit(PatternBlock expr, @Nullable Void context); @Override @Nullable Void visit(ParamExpression<?> param, @Nullable Void context); void addBindings(SPARQLQuery query, QueryMetadata md); void setInlineResources(boolean b); void setLikeAsMatches(boolean likeAsMatches); void setInlineAll(boolean inlineAll); void setInToOr(boolean inToOr);  }