Class UpdateBuilder

java.lang.Object
org.apache.jena.arq.querybuilder.UpdateBuilder

public class UpdateBuilder extends Object
Class to build update requests.
  • Constructor Details

    • UpdateBuilder

      public UpdateBuilder()
      Creates an UpdateBuilder with an empty prefix mapping.
    • UpdateBuilder

      public UpdateBuilder(PrologClause<?> prologClause)
      Creates an UpdateBuilder with the prefixes defined in the prolog clause. May modify the contents of the prefix mapping in the prolog handler
      Parameters:
      prologClause - the default prefixes for this builder.
    • UpdateBuilder

      public UpdateBuilder(PrefixMapping pMap)
      Creates an UpdateBuilder with the specified PrefixMapping. May modify the contents of the prefix mapping
      Parameters:
      pMap - the prefix mapping to use.
  • Method Details

    • build

      public Update build()
      Build the update. Note: the update does not include the prefix statements use buildRequest() or appendTo() methods to include the prefix statements.
      Returns:
      the update.
    • buildRequest

      public UpdateRequest buildRequest()
      Build as an UpdateRequest with prefix mapping set.
      Returns:
      a new UpdateRequest
    • appendTo

      public UpdateRequest appendTo(UpdateRequest req)
      Appends the new Update to the UpdateRequest.
      Parameters:
      req - the UpdateRequest to append this Update to.
      Returns:
      the req parameter for chaining.
    • makeTriplePath

      public TriplePath makeTriplePath(Object s, Object p, Object o)
      Make a triple path from the objects. For subject, predicate and objects nodes
      • Will return Node.ANY if object is null.
      • Will return the enclosed Node from a FrontsNode
      • Will return the object if it is a Node.
      • If the object is a String
        • For predicate only will attempt to parse as a path
        • for subject, predicate and object will call NodeFactoryExtra.parseNode() using the currently defined prefixes if the object is a String
      • Will create a literal representation if the parseNode() fails or for any other object type.
      Parameters:
      s - The subject object
      p - the predicate object
      o - the object object.
      Returns:
      a TriplePath
    • makeNode

      public Node makeNode(Object o)
      Convert the object to a node. Shorthand for AbstractQueryBuilder.makeNode( o, prefixes )
      Parameters:
      o - the object to convert to a node.
      Returns:
      the Node.
      See Also:
    • makeVar

      @Deprecated public Var makeVar(Object o)
      Convert the object to a node. Shorthand for AbstractQueryBuilder.makeVar( o )
      Parameters:
      o - the object to convert to a var.
      Returns:
      the Var.
      See Also:
    • quote

      @Deprecated public String quote(String s)
      Deprecated.
      Use quoted()
      Quote a string. Shorthand for AbstractQueryBuilder.quote( s )
      Parameters:
      s - the string to quote.
      Returns:
      the quoted string.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Object g, Object s, Object p, Object o)
      Add a quad to the insert statement. Arguments are converted to nodes using the makeNode() method.
      Parameters:
      g - the graph
      s - the subject
      p - the predicate
      o - the object
      Returns:
      this builder for chaining.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Quad quad)
      Add a quad to the insert statement.
      Parameters:
      quad - the quad to add.
      Returns:
      this builder for chaining.
    • addInsert

      public UpdateBuilder addInsert(Object s, Object p, Object o)
      Add a triple to the insert statement. Arguments are converted to nodes using the makeNode() method.
      Parameters:
      s - the subject
      p - the predicate
      o - the object
      Returns:
      this builder for chaining.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Triple t)
      Add a triple to the insert statement.
      Parameters:
      t - the triple to add.
      Returns:
      this builder for chaining.
    • addInsert

      public UpdateBuilder addInsert(Object g, Triple t)
      Add a triple in a specified graph to the insert statement. The graph object is converted by a call to makeNode().
      Parameters:
      g - the graph for the triple.
      t - the triple to add.
      Returns:
      this builder for chaining.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Model model)
      Add all the statements in the model to the insert statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      model - The model to insert.
      Returns:
      this builder for chaining.
    • addInsert

      public UpdateBuilder addInsert(Collection<Triple> collection)
      Add all the triples in the model to the insert statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      collection - The triples to insert.
      Returns:
      this builder for chaining.
      See Also:
    • addInsertQuads

      public UpdateBuilder addInsertQuads(Collection<Quad> collection)
      Add all the quads in the collection to the insert statement.
      Parameters:
      collection - The quads to insert.
      Returns:
      this builder for chaining.
    • addInsert

      public UpdateBuilder addInsert(Iterator<Triple> iter)
      Add all the triples to the insert statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      iter - The iterator of triples to insert.
      Returns:
      this builder for chaining.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Object g, Model model)
      Add all the statements in the model a specified graph to the insert statement. The graph object is converted by a call to makeNode().
      Parameters:
      g - the graph for the triple.
      model - the model to add.
      Returns:
      this builder for chaining.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Object g, Collection<Triple> collection)
      Add triples to the insert statement.
      Parameters:
      g - the name of the graph to add the triples to.
      collection - The triples to insert.
      Returns:
      this builder for chaining.
    • addInsert

      public UpdateBuilder addInsert(Object g, Iterator<Triple> iter)
      Add triples to the insert statement.
      Parameters:
      g - the name of the graph to add the triples to.
      iter - The iterator of triples to insert.
      Returns:
      this builder for chaining.
    • addInsert

      public UpdateBuilder addInsert(AbstractQueryBuilder<?> queryBuilder)
      Add the statements from the where clause in the specified query builder to the insert statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      queryBuilder - The query builder to extract the where clause from.
      Returns:
      this builder for chaining.
      See Also:
    • addInsert

      public UpdateBuilder addInsert(Object graph, AbstractQueryBuilder<?> queryBuilder)
      Add the statements from the where clause in the specified query builder to the insert statements for the specified graph. The graph object is converted by a call to makeNode().
      Parameters:
      graph - the graph to add the statements to.
      queryBuilder - The query builder to extract the where clause from.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Object g, Object s, Object p, Object o)
      Add a quad to the delete statement. Arguments are converted to nodes using the makeNode() method.
      Parameters:
      g - the graph
      s - the subject
      p - the predicate
      o - the object
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Quad quad)
      Add a quad to the delete statement.
      Parameters:
      quad - the quad to add.
      Returns:
      this builder for chaining.
    • addDeleteQuads

      public UpdateBuilder addDeleteQuads(Collection<Quad> collection)
      Add all the quads collection to the delete statement.
      Parameters:
      collection - The quads to insert.
      Returns:
      this builder for chaining.
    • addDelete

      public UpdateBuilder addDelete(Object s, Object p, Object o)
      Add a triple to the delete statement. Arguments are converted to nodes using the makeNode() method.
      Parameters:
      s - the subject
      p - the predicate
      o - the object
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Triple t)
      Add a triple to the delete statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      t - the triple to add.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Object g, Triple t)
      Add a triple to the delete statement. The graph object is converted by a call to makeNode().
      Parameters:
      g - the graph for the triple.
      t - the triple to add.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Model model)
      Add all the statements in the model to the delete statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      model - The model to insert.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Collection<Triple> collection)
      Add all triples to the delete statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      collection - The collection of triples to insert.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Iterator<Triple> iter)
      Add all the triples in the iterator to the delete statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      iter - The iterator of triples to insert.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Object g, Model model)
      Add all the statements in the model a specified graph to the delete statement. The graph object is converted by a call to makeNode().
      Parameters:
      g - the graph for the triples.
      model - the model to add.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Object g, Collection<Triple> collection)
      Add all the statements in the model to the delete statement.
      Parameters:
      g - the graph for the triples.
      collection - The collection of triples to insert.
      Returns:
      this builder for chaining.
    • addDelete

      public UpdateBuilder addDelete(Object g, Iterator<Triple> iter)
      Add all the statements in the model to the delete statement.
      Parameters:
      g - the graph for the triples.
      iter - The iterator of triples to insert.
      Returns:
      this builder for chaining.
    • addDelete

      public UpdateBuilder addDelete(AbstractQueryBuilder<?> queryBuilder)
      Add the statements from the where clause in the specified query builder to the delete statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
      Parameters:
      queryBuilder - The query builder to extract the where clause from.
      Returns:
      this builder for chaining.
      See Also:
    • addDelete

      public UpdateBuilder addDelete(Object graph, AbstractQueryBuilder<?> queryBuilder)
      Add the statements from the where clause in the specified query builder to the delete statements for the specified graph. The graph object is converted by a call to makeNode().
      Parameters:
      graph - the graph to add the statements to.
      queryBuilder - The query builder to extract the where clause from.
      Returns:
      this builder for chaining.
      See Also:
    • addPrefix

      public UpdateBuilder addPrefix(String pfx, Resource uri)
      Add the prefix to the prefix mapping.
      Parameters:
      pfx - the prefix to add.
      uri - the uri for the prefix.
      Returns:
      this builder for chaining
    • addPrefix

      public UpdateBuilder addPrefix(String pfx, Node uri)
      Add the prefix to the prefix mapping.
      Parameters:
      pfx - the prefix to add.
      uri - the uri for the prefix.
      Returns:
      this builder for chaining
    • addPrefix

      public UpdateBuilder addPrefix(String pfx, String uri)
      Add the prefix to the prefix mapping.
      Parameters:
      pfx - the prefix to add.
      uri - the uri for the prefix.
      Returns:
      this builder for chaining
    • addPrefixes

      public UpdateBuilder addPrefixes(Map<String,String> prefixes)
      Add the prefixes to the prefix mapping.
      Parameters:
      prefixes - the prefixes to add.
      Returns:
      this builder for chaining
    • addPrefixes

      public UpdateBuilder addPrefixes(PrefixMapping prefixes)
      Add the prefixes to the prefix mapping.
      Parameters:
      prefixes - the prefix mapping to add.
      Returns:
      this builder for chaining
    • getExprFactory

      public ExprFactory getExprFactory()
      Get an ExprFactory that uses the prefixes from this builder.
      Returns:
      the ExpressionFactory.
    • setVar

      public void setVar(Var var, Node value)
      Set a variable replacement. During build all instances of var in the query will be replaced with value. If value is null the replacement is cleared.
      Parameters:
      var - The variable to replace
      value - The value to replace it with or null to remove the replacement.
    • setVar

      public void setVar(Object var, Object value)
      Set a variable replacement. During build all instances of var in the query will be replaced with value. If value is null the replacement is cleared. See makeVar(java.lang.Object) for conversion of the var param. See makeNode(java.lang.Object) for conversion of the value param.
      Parameters:
      var - The variable to replace.
      value - The value to replace it with or null to remove the replacement.
    • addAll

      public UpdateBuilder addAll(WhereHandler whereHandler)
      Add all where attributes from the Where Handler argument.
      Parameters:
      whereHandler - The Where Handler to copy from.
    • addWhere

      Add the triple path to the where clause
      Parameters:
      t - The triple path to add.
      Throws:
      IllegalArgumentException - If the triple path is not a valid triple path for a where clause.
    • addWhere

      public UpdateBuilder addWhere(WhereClause<?> whereClause) throws IllegalArgumentException
      Add the WhereClause
      Parameters:
      whereClause -
      Throws:
      IllegalArgumentException - If the triple path is not a valid triple path for a where clause.
    • addOptional

      public UpdateBuilder addOptional(TriplePath t) throws IllegalArgumentException
      Add an optional triple to the where clause
      Parameters:
      t - The triple path to add.
      Returns:
      The Builder for chaining.
      Throws:
      IllegalArgumentException - If the triple is not a valid triple for a where clause.
    • addOptional

      public UpdateBuilder addOptional(WhereHandler whereHandler)
      Add the contents of a where handler as an optional statement.
      Parameters:
      whereHandler - The where handler to use as the optional statement.
    • addFilter

      public UpdateBuilder addFilter(String expression) throws ParseException
      Add an expression string as a filter.
      Parameters:
      expression - The expression string to add.
      Returns:
      The Builder for chaining.
      Throws:
      ParseException - If the expression can not be parsed.
    • addSubQuery

      public UpdateBuilder addSubQuery(AbstractQueryBuilder<?> subQuery)
      Add a subquery to the where clause.
      Parameters:
      subQuery - The sub query to add.
      Returns:
      The Builder for chaining.
    • addUnion

      public UpdateBuilder addUnion(AbstractQueryBuilder<?> subQuery)
      Add a union to the where clause.
      Parameters:
      subQuery - The subquery to add as the union.
      Returns:
      The Builder for chaining.
    • addGraph

      public UpdateBuilder addGraph(Node graph, WhereHandler subQuery)
      Add a graph to the where clause.
      Parameters:
      graph - The name of the graph.
      subQuery - The where handler that defines the graph.
    • addBind

      public UpdateBuilder addBind(Expr expr, Var var)
      Add a binding to the where clause.
      Parameters:
      expr - The expression to bind.
      var - The variable to bind it to.
    • addBind

      public UpdateBuilder addBind(String expression, Var var) throws ParseException
      Add a binding to the where clause.
      Parameters:
      expression - The expression to bind.
      var - The variable to bind it to.
      Throws:
      ParseException
    • list

      public Node list(Object... objs)
      Create a list node from a list of objects as per RDF Collections. http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections See AbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the param values.

      usage:

      • list( param1, param2, param3, ... )
      • addWhere( list( param1, param2, param3, ... ), p, o )
      • addOptional( list( param1, param2, param3, ... ), p, o )

      Parameters:
      objs - the list of objects for the list.
      Returns:
      the first blank node in the list.
    • addWhere

      public UpdateBuilder addWhere(Triple t)
      Adds a triple to the where clause.
      Parameters:
      t - The triple path to add
      Returns:
      The Builder for chaining.
    • addWhere

      public UpdateBuilder addWhere(FrontsTriple t)
      Adds a triple to the where clause.
      Parameters:
      t - The triple to add
      Returns:
      The Builder for chaining.
    • addWhere

      public UpdateBuilder addWhere(Object s, Object p, Object o)
      Adds a triple or triple path to the where clause. See AbstractQueryBuilder.makeTriplePath(java.lang.Object, java.lang.Object, java.lang.Object) for conversion of the param values.
      Parameters:
      s - The subject.
      p - The predicate.
      o - The object.
      Returns:
      The Builder for chaining.
    • addOptional

      public UpdateBuilder addOptional(Triple t)
      Adds an optional triple to the where clause.
      Parameters:
      t - The triple to add
      Returns:
      The Builder for chaining.
    • addOptional

      public UpdateBuilder addOptional(FrontsTriple t)
      Adds an optional triple as to the where clause.
      Parameters:
      t - The triple to add
      Returns:
      The Builder for chaining.
    • addOptional

      public UpdateBuilder addOptional(Object s, Object p, Object o)
      Adds an optional triple or triple path to the where clause. See AbstractQueryBuilder.makeTriplePath(java.lang.Object, java.lang.Object, java.lang.Object) for conversion of the param values.
      Parameters:
      s - The subject.
      p - The predicate.
      o - The object.
      Returns:
      The Builder for chaining.
    • addOptional

      public UpdateBuilder addOptional(AbstractQueryBuilder<?> t)
      Adds an optional group pattern to the where clause.
      Parameters:
      t - The select builder to add as an optional pattern
      Returns:
      The Builder for chaining.
    • addFilter

      public UpdateBuilder addFilter(Expr expression)
      Adds a filter to the where clause Use ExprFactory or NodeValue static or the AbstractQueryBuilder.makeExpr methods to create the expression.
      Parameters:
      expression - the expression to evaluate for the filter.
      Returns:
      See Also:
    • addGraph

      public UpdateBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery)
      Add a graph statement to the query as per http://www.w3.org/TR/2013/REC-sparql11 -query-20130321/#rGraphGraphPattern. See AbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph param.
      Parameters:
      graph - The iri or variable identifying the graph.
      subQuery - The graph to add.
      Returns:
      This builder for chaining.
    • addBind

      public UpdateBuilder addBind(Expr expression, Object var)
      Add a bind statement to the query * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
      Parameters:
      expression - The expression to bind to the var.
      var - The variable to bind to.
      Returns:
      This builder for chaining.
    • addBind

      public UpdateBuilder addBind(String expression, Object var) throws ParseException
      Add a bind statement to the query http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
      Parameters:
      expression - The expression to bind to the var.
      var - The variable to bind to.
      Returns:
      This builder for chaining.
      Throws:
      ParseException
    • addMinus

      public UpdateBuilder addMinus(AbstractQueryBuilder<?> t)
      Add a minus clause to the query. https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rMinusGraphPattern
      Parameters:
      t - The select builder to add as a minus pattern
      Returns:
      this builder for chaining
    • with

      public UpdateBuilder with(Object iri)
      Specify the graph for all inserts and deletes.
      Parameters:
      iri - the IRI for the graph to use.
      Returns:
      this builder for chaining.
      See Also:
    • buildDeleteWhere

      public UpdateDeleteWhere buildDeleteWhere()
      Create a DeleteWhere from the where clause.
      Returns:
      a DeleteWhere update.
    • buildDeleteWhere

      public UpdateDeleteWhere buildDeleteWhere(AbstractQueryBuilder<?> queryBuilder)
      Create a DeleteWhere from the where clause.
      Parameters:
      queryBuilder - the query builder to extract the where clause from.
      Returns:
      a DeleteWhere update.