Exemplo n.º 1
0
    public void visit(UpdateModify update) {
      out.ensureStartOfLine();
      if (update.getWithIRI() != null) {
        // out.ensureStartOfLine() ;
        out.print("WITH ");
        output(update.getWithIRI());
      }

      if (update.hasDeleteClause()) {
        List<Quad> deleteQuads = update.getDeleteQuads();
        out.ensureStartOfLine();
        out.print("DELETE ");
        outputQuadsBraced(deleteQuads);
      }

      if (update.hasInsertClause()) {
        List<Quad> insertQuads = update.getInsertQuads();
        out.ensureStartOfLine();
        out.print("INSERT ");
        outputQuadsBraced(insertQuads);
      }

      if (!update.hasInsertClause() && !update.hasDeleteClause()) {
        // Fake a clause to make it legal syntax.
        out.ensureStartOfLine();
        out.println("INSERT { }");
      }

      for (Node x : update.getUsing()) {
        out.ensureStartOfLine();
        out.print("USING ");
        output(x);
      }

      for (Node x : update.getUsingNamed()) {
        out.ensureStartOfLine();
        out.print("USING NAMED ");
        output(x);
      }

      Element el = update.getWherePattern();
      out.ensureStartOfLine();
      out.print("WHERE");
      out.incIndent(BLOCK_INDENT);
      out.newline();

      if (el != null) {
        FormatterElement fmtElement = new FormatterElement(out, sCxt);
        fmtElement.visitAsGroup(el);
      } else out.print("{}");
      out.decIndent(BLOCK_INDENT);
    }
    /** Finishes the query for execution. */
    public void finishQuery() {
      finishMigrationPathFilter();
      finishDependencyLabelFilter();
      finishMigrationPathSource();
      finishHandlesMimetypes();

      IndentedLineBuffer formatBuffer = new IndentedLineBuffer();
      FormatterElement.format(formatBuffer, new SerializationContext(prefixMapping), query);

      try {
        String encqs = URLEncoder.encode(formatBuffer.toString(), "UTF-8");
        String encpf = URLEncoder.encode(prefixes, "UTF-8");
        resource = resource.queryParam(PREFIX_NAME, encpf).queryParam(QUERY_NAME, encqs);
      } catch (UnsupportedEncodingException e) {
        LOG.error("Error encoding query", e);
      }
    }