You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2021/07/05 16:00:24 UTC
[jena] branch main updated: Replaced tabs with spaces
This is an automated email from the ASF dual-hosted git repository.
claude pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new 3112eae Replaced tabs with spaces
new e63e994 Merge pull request #1027 from Claudenw/querybuilder-replace-tabs
3112eae is described below
commit 3112eae73a2a03b93e6a146eb544557a0ce6008d
Author: Claude Warren <cl...@xenei.com>
AuthorDate: Mon Jul 5 10:02:16 2021 +0100
Replaced tabs with spaces
Cleaned up code formatting
---
.../arq/querybuilder/AbstractQueryBuilder.java | 1100 ++++---
.../apache/jena/arq/querybuilder/AskBuilder.java | 653 ++--
.../jena/arq/querybuilder/ConstructBuilder.java | 696 ++---
.../apache/jena/arq/querybuilder/Converters.java | 525 ++--
.../jena/arq/querybuilder/DescribeBuilder.java | 699 ++---
.../apache/jena/arq/querybuilder/ExprFactory.java | 3221 ++++++++++----------
.../org/apache/jena/arq/querybuilder/Order.java | 2 +-
.../jena/arq/querybuilder/SelectBuilder.java | 863 +++---
.../jena/arq/querybuilder/UpdateBuilder.java | 2274 +++++++-------
.../apache/jena/arq/querybuilder/WhereBuilder.java | 407 ++-
.../arq/querybuilder/clauses/ConstructClause.java | 73 +-
.../arq/querybuilder/clauses/DatasetClause.java | 74 +-
.../arq/querybuilder/clauses/PrologClause.java | 154 +-
.../arq/querybuilder/clauses/SelectClause.java | 103 +-
.../clauses/SolutionModifierClause.java | 297 +-
.../arq/querybuilder/clauses/ValuesClause.java | 263 +-
.../jena/arq/querybuilder/clauses/WhereClause.java | 795 +++--
.../arq/querybuilder/clauses/package-info.java | 3 +-
.../querybuilder/handlers/AggregationHandler.java | 142 +-
.../querybuilder/handlers/ConstructHandler.java | 104 +-
.../arq/querybuilder/handlers/DatasetHandler.java | 213 +-
.../jena/arq/querybuilder/handlers/Handler.java | 31 +-
.../arq/querybuilder/handlers/HandlerBlock.java | 463 ++-
.../arq/querybuilder/handlers/PrologHandler.java | 226 +-
.../arq/querybuilder/handlers/SelectHandler.java | 354 ++-
.../handlers/SolutionModifierHandler.java | 400 +--
.../arq/querybuilder/handlers/ValuesHandler.java | 361 ++-
.../arq/querybuilder/handlers/WhereHandler.java | 1018 +++----
.../arq/querybuilder/handlers/package-info.java | 10 +-
.../apache/jena/arq/querybuilder/package-info.java | 6 +-
.../querybuilder/rewriters/AbstractRewriter.java | 391 +--
.../rewriters/BuildElementVisitor.java | 373 ++-
.../querybuilder/rewriters/ElementRewriter.java | 341 ++-
.../arq/querybuilder/rewriters/ExprRewriter.java | 311 +-
.../querybuilder/rewriters/NodeValueRewriter.java | 124 +-
.../arq/querybuilder/rewriters/OpRewriter.java | 591 ++--
.../arq/querybuilder/rewriters/PathRewriter.java | 233 +-
.../arq/querybuilder/rewriters/package-info.java | 4 +-
.../updatebuilder/CollectionQuadHolder.java | 66 +-
.../updatebuilder/ModelQuadHolder.java | 13 +-
.../querybuilder/updatebuilder/PrefixHandler.java | 162 +-
.../querybuilder/updatebuilder/QBQuadHolder.java | 83 +-
.../updatebuilder/QuadCollectionHolder.java | 55 +-
.../arq/querybuilder/updatebuilder/QuadHolder.java | 28 +-
.../updatebuilder/QuadIteratorBuilder.java | 245 +-
.../updatebuilder/SingleQuadHolder.java | 129 +-
.../updatebuilder/WhereQuadHolder.java | 774 +++--
.../apache/jena/arq/AbstractRegexpBasedTest.java | 182 +-
.../arq/querybuilder/AbstractQueryBuilderTest.java | 205 +-
.../arq/querybuilder/AskBuilderContractTest.java | 34 +-
.../jena/arq/querybuilder/AskBuilderTest.java | 227 +-
.../querybuilder/ConstructBuilderContractTest.java | 34 +-
.../arq/querybuilder/ConstructBuilderTest.java | 233 +-
.../jena/arq/querybuilder/ConvertersTest.java | 561 ++--
.../querybuilder/DescribeBuilderContractTest.java | 34 +-
.../jena/arq/querybuilder/ExprFactoryTest.java | 1320 ++++----
.../querybuilder/SelectBuilderContractTest.java | 34 +-
.../jena/arq/querybuilder/SelectBuilderTest.java | 595 ++--
.../querybuilder/UpdateBuilderExampleTests.java | 996 +++---
.../jena/arq/querybuilder/UpdateBuilderTest.java | 1034 +++----
.../arq/querybuilder/WhereBuilderContractTest.java | 34 +-
.../jena/arq/querybuilder/WhereValidator.java | 338 +-
.../querybuilder/clauses/AbstractClauseTest.java | 45 +-
.../querybuilder/clauses/DatasetClauseTest.java | 224 +-
.../arq/querybuilder/clauses/PrologClauseTest.java | 254 +-
.../arq/querybuilder/clauses/SelectClauseTest.java | 226 +-
.../querybuilder/clauses/SolutionModifierTest.java | 664 ++--
.../arq/querybuilder/clauses/ValuesClauseTest.java | 446 +--
.../arq/querybuilder/clauses/WhereClauseTest.java | 2266 +++++++-------
.../querybuilder/handlers/AbstractHandlerTest.java | 30 +-
.../handlers/ConstructHandlerTest.java | 116 +-
.../querybuilder/handlers/DatasetHandlerTest.java | 164 +-
.../querybuilder/handlers/PrologHandlerTest.java | 142 +-
.../querybuilder/handlers/SelectHandlerTest.java | 350 +--
.../handlers/SolutionModifierHandlerTest.java | 398 +--
.../querybuilder/handlers/ValuesHandlerTest.java | 874 +++---
.../querybuilder/handlers/WhereHandlerTest.java | 132 +-
.../rewriters/NodeValueRewriterTest.java | 378 +--
.../updatebuilder/CollectionQuadHolderTest.java | 427 ++-
.../updatebuilder/ModelQuadHolderTest.java | 118 +-
.../updatebuilder/QBQuadHolderTest.java | 356 ++-
.../updatebuilder/SingleQuadHolderTest.java | 146 +-
.../updatebuilder/WhereQuadHolderTest.java | 349 ++-
83 files changed, 16416 insertions(+), 17003 deletions(-)
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
index 05f4b56..0430f02 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AbstractQueryBuilder.java
@@ -30,15 +30,15 @@ import org.apache.jena.arq.querybuilder.handlers.HandlerBlock;
import org.apache.jena.arq.querybuilder.handlers.PrologHandler;
import org.apache.jena.arq.querybuilder.handlers.ValuesHandler;
import org.apache.jena.arq.querybuilder.handlers.WhereHandler;
-import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Node;
import org.apache.jena.graph.Triple;
-import org.apache.jena.query.Query ;
+import org.apache.jena.query.Query;
import org.apache.jena.query.QueryParseException;
-import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.rdf.model.Resource;
import org.apache.jena.shared.PrefixMapping;
-import org.apache.jena.sparql.ARQInternalErrorException ;
+import org.apache.jena.sparql.ARQInternalErrorException;
import org.apache.jena.sparql.core.TriplePath;
-import org.apache.jena.sparql.core.Var ;
+import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.expr.Expr;
import org.apache.jena.sparql.path.Path;
import org.apache.jena.sparql.syntax.ElementGroup;
@@ -48,562 +48,540 @@ import org.apache.jena.sparql.util.ExprUtils;
/**
* Base class for all QueryBuilders.
*
- * @param <T>
- * The derived class type. Used for return types.
+ * @param <T> The derived class type. Used for return types.
*/
public abstract class AbstractQueryBuilder<T extends AbstractQueryBuilder<T>>
-implements Cloneable, PrologClause<T>, ValuesClause<T> {
-
- /**
- * the query this builder is building
- */
- protected Query query;
- /**
- * a map of vars to nodes for replacement during build.
- */
- private final Map<Var, Node> values;
-
- /**
- * Make a Node from an object.
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>Will call NodeFactoryExtra.parseNode() using the prefix mapping if the object is a String</li>
- * <li>Will create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- *
- * Uses the internal query prefix mapping to resolve prefixes.
- *
- * @param o
- * The object to convert. (may be null)
- * @return The Node value.
- */
- public Node makeNode(Object o) {
- return Converters.makeNode( o, query.getPrefixMapping() );
- }
-
- /**
- * Make a node or path from the object using the query prefix mapping.
- * @param o the object to make the node or path from.
- * @return A node or path.
- * @see Converters#makeNodeOrPath(Object, PrefixMapping)
- */
- private Object makeNodeOrPath(Object o)
- {
- return Converters.makeNodeOrPath(o, query.getPrefixMapping() );
- }
-
- /**
- * Creates a Path or Node as appropriate.
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the object if it is a Path
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>Will call PathParser.parse() using the prefix mapping if the object is a String</li>
- * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
- * prefixes if the object is a String and the PathParser.parse() fails.</li>
- * <li>Will create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- * @param o the object that should be interpreted as a path or a node.
- * @param pMapping the prefix mapping to resolve path or node with
- * @return the Path or Node
- * @deprecated use {@link Converters#makeNodeOrPath(Object, PrefixMapping)}
- */
- @Deprecated
- public static Object makeNodeOrPath(Object o, PrefixMapping pMapping)
- {
- return Converters.makeNodeOrPath(o, pMapping);
- }
-
- public ElementSubQuery asSubQuery() {
- return getWhereHandler().makeSubQuery( this );
- }
-
- /**
- * Make a triple path from the objects.
- *
- * For subject, predicate and objects nodes
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>If the object is a String
- * <ul>
- * <li>For <code>predicate</code> only will attempt to parse as a path</li>
- * <li>for subject, predicate and object will call NodeFactoryExtra.parseNode()
- * using the currently defined prefixes if the object is a String</li>
- * </ul></li>
- * <li>Will create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- *
- * @param s The subject object
- * @param p the predicate object
- * @param o the object object.
- * @return a TriplePath
- */
- public TriplePath makeTriplePath(Object s, Object p, Object o) {
- final Object po = makeNodeOrPath( p );
- if (po instanceof Path)
- {
- return new TriplePath(makeNode(s), (Path)po, makeNode(o));
- }
- return new TriplePath( new Triple( makeNode(s), (Node)po, makeNode(o)));
- }
-
-
- /**
- * A convenience method to make an expression from a string. Evaluates the
- * expression with respect to the current query.
- *
- * @param expression The expression to parse.
- * @return the Expr object.
- * @throws QueryParseException on error.
- */
- public Expr makeExpr(String expression) throws QueryParseException
- {
- return ExprUtils.parse(query, expression, true);
- }
-
- /**
- * A convenience method to quote a string.
- * @param q the string to quote.
- *
- * Will use single quotes if there are no single quotes in the string or if the
- * double quote is before the single quote in the string.
- *
- * Will use double quote otherwise.
- *
- * @return the quoted string.
- * @deprecated {@link Converters#quoted(String)}
- */
- @Deprecated
- public static String quote(String q) {
- return Converters.quoted(q);
- }
-
- /**
- * Verify that any Node_Variable nodes are returned as Var nodes.
- * @param n the node to check
- * @return the node n or a new Var if n is an instance of Node_Variable
- * @deprecated use {@link Converters#checkVar(Node)}
- */
- @Deprecated
- public static Node checkVar(Node n )
- {
- return Converters.checkVar(n);
- }
-
- /**
- * Make a node from an object while using the associated prefix mapping.
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
- * prefixes if the object is a String</li>
- * <li>Will create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- * @param o The object to convert (may be null).
- * @param pMapping The prefix mapping to use for prefix resolution.
- * @return The Node value.
- * @deprecated use {@link Converters#makeNode(Object, PrefixMapping)}
- */
- @Deprecated
- public static Node makeNode(Object o, PrefixMapping pMapping) {
- return Converters.makeNode(o, pMapping);
- }
-
- /**
- * Make a Var from an object.
- * <ul>
- * <li>Will return Var.ANON if object is null.</li>
- * <li>Will return null if the object is "*" or Node_RuleVariable.WILD</li>
- * <li>Will return the object if it is a Var</li>
- * <li>Will return resolve FrontsNode to Node and then resolve to Var</li>
- * <li>Will return resolve Node if the Node implements Node_Variable,
- * otherwise throws an NotAVariableException (instance of
- * ARQInternalErrorException)</li>
- * <li>Will return ?x if object is "?x"</li>
- * <li>Will return ?x if object is "x"</li>
- * <li>Will return the enclosed Var of a ExprVar</li>
- * <li>For all other objects will return the "?" prefixed to the toString()
- * value.</li>
- * </ul>
- *
- * @param o
- * The object to convert.
- * @return the Var value.
- * @throws ARQInternalErrorException
- * @deprecated use {@link Converters#makeVar(Object)}
- */
- @Deprecated
- public static Var makeVar(Object o) throws ARQInternalErrorException {
- return Converters.makeVar(o);
- }
-
- /**
- * Create a new query builder.
- */
- protected AbstractQueryBuilder() {
- query = new Query();
- values = new HashMap<Var, Node>();
- }
-
- /**
- * Get the HandlerBlock for this query builder.
- * @return The associated handler block.
- */
- public abstract HandlerBlock getHandlerBlock();
-
- @Override
- public final PrologHandler getPrologHandler() {
- return getHandlerBlock().getPrologHandler();
- }
-
- @Override
- public ValuesHandler getValuesHandler() {
- return getHandlerBlock().getValueHandler();
- }
-
- /**
- * Gets the where handler used by this QueryBuilder.
- * @return the where handler used by this QueryBuilder.
- */
- public final WhereHandler getWhereHandler() {
- return getHandlerBlock().getWhereHandler();
- }
-
- /**
- * Adds the contents of the whereClause to the where clause of this
- * builder.
- * @param whereClause the where clause to add.
- * @return this builder for chaining.
- */
- @SuppressWarnings("unchecked")
- public final T addWhere( AbstractQueryBuilder<?> whereClause) {
- getWhereHandler().addAll( whereClause.getWhereHandler());
- return (T) this;
- }
-
- @Override
- public final ExprFactory getExprFactory() {
- return getHandlerBlock().getPrologHandler().getExprFactory();
- }
-
- /**
- * 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.
- *
- * @param var
- * The variable to replace
- * @param value
- * The value to replace it with or null to remove the
- * replacement.
- */
- public void setVar(Var var, Node value) {
- if (value == null) {
- values.remove(var);
- } else {
- values.put(var, 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 {@link #makeVar} for conversion of the var param. See
- * {@link #makeNode} for conversion of the value param.
- *
- * @param var
- * The variable to replace.
- * @param value
- * The value to replace it with or null to remove the
- * replacement.
- */
- public void setVar(Object var, Object value) {
- if (value == null) {
- setVar(Converters.makeVar(var), null);
- } else {
- setVar(Converters.makeVar(var), makeNode(value));
- }
- }
-
- @Override
- public T addPrefix(String pfx, Resource uri) {
- return addPrefix(pfx, uri.getURI());
- }
-
- @Override
- public T addPrefix(String pfx, Node uri) {
- return addPrefix(pfx, uri.getURI());
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addPrefix(String pfx, String uri) {
- getPrologHandler().addPrefix(pfx, uri);
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addPrefixes(Map<String, String> prefixes) {
- getPrologHandler().addPrefixes(prefixes);
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addPrefixes(PrefixMapping prefixMapping) {
- getPrologHandler().addPrefixes( prefixMapping );
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T setBase(String base) {
- getPrologHandler().setBase(base);
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T setBase(Object base) {
- setBase(makeNode(base).getURI());
- return (T) this;
- }
-
- // --- VALUES
-
- /**
- * Creates a collection of nodes from an iterator of Objects.
- * @param iter the iterator of objects, may be null or empty.
- * @param prefixMapping the PrefixMapping to use when nodes are created.
- * @return a Collection of nodes or null if iter is null or empty.
- * @deprecated use {@link Converters#makeValueNodes(Iterator, PrefixMapping)}
- */
- @Deprecated
- public static Collection<Node> makeValueNodes( Iterator<?> iter, PrefixMapping prefixMapping )
- {
- return Converters.makeValueNodes(iter, prefixMapping);
- }
-
- /**
- * Creates a collection of nodes from an iterator of Objects.
- * Uses the prefix mapping from the PrologHandler.
- * @param iter the iterator of objects, may be null or empty.
- * @return a Collection of nodes or null if iter is null or empty.
- */
- public Collection<Node> makeValueNodes( Iterator<?> iter )
- {
- return Converters.makeValueNodes( iter, getPrologHandler().getPrefixes() );
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addValueVar(Object var) {
- if (var == null)
- {
- throw new IllegalArgumentException( "var must not be null.");
- }
- if (var instanceof Collection<?>)
- {
- final Collection<?> column = (Collection<?>)var;
- if (column.size() == 0)
- {
- throw new IllegalArgumentException( "column must have at least one entry.");
- }
- final Iterator<?> iter = column.iterator();
- final Var v = Converters.makeVar( iter.next() );
- getValuesHandler().addValueVar(v, makeValueNodes(iter));
- } else {
- getValuesHandler().addValueVar(Converters.makeVar(var), null );
- }
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addValueVar(Object var, Object... objects) {
-
- Collection<Node> values = null;
- if (objects != null)
- {
- values = makeValueNodes( Arrays.asList(objects).iterator());
- }
-
- getValuesHandler().addValueVar(Converters.makeVar(var), values );
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <K extends Collection<?>> T addValueVars(Map<?,K> dataTable) {
- final ValuesHandler hdlr = new ValuesHandler( null );
- for (final Map.Entry<?, K> entry : dataTable.entrySet())
- {
- Collection<Node> values = null;
- if (entry.getValue() != null)
- {
- values = makeValueNodes( entry.getValue().iterator() );
- }
- hdlr.addValueVar(Converters.makeVar(entry.getKey()), values );
- }
- getValuesHandler().addAll( hdlr );
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addValueRow(Object... values) {
- getValuesHandler().addValueRow( makeValueNodes( Arrays.asList(values).iterator()));
- return (T) this;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T addValueRow(Collection<?> values) {
- getValuesHandler().addValueRow( makeValueNodes( values.iterator()));
- return (T) this;
- }
-
- @Override
- public List<Var> getValuesVars() {
- return getValuesHandler().getValuesVars();
- }
-
- @Override
- public Map<Var,List<Node>> getValuesMap() {
- return getValuesHandler().getValuesMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T clearValues() {
- getValuesHandler().clear();
- return (T) this;
- }
-
- @Override
- public String toString() {
- return buildString();
- }
-
- /**
- * Build the query as a string.
- *
- * @return the string representation of the query.
- */
- public final String buildString() {
- return build().toString();
- }
-
- /**
- * Build the query. Performs the var replacements as specified by
- * setVar(var,node) calls.
- *
- * @return The query.
- */
- public final Query build() {
- final Query q = new Query();
-
- // set the query type
- switch (query.queryType())
- {
- case ASK:
- q.setQueryAskType();
- break;
- case CONSTRUCT:
- q.setQueryConstructType();
- break;
- case DESCRIBE:
- q.setQueryDescribeType();
- break;
- case SELECT:
- q.setQuerySelectType();
- break;
- case UNKNOWN:
- // do nothing
- break;
- default:
- throw new IllegalStateException( "Internal query is not a known type: "+q.queryType());
- }
-
- // use the HandlerBlock implementation to copy the data.
- final HandlerBlock handlerBlock = new HandlerBlock(q);
- handlerBlock.addAll( getHandlerBlock() );
-
- // set the vars
- handlerBlock.setVars(values);
-
- // make sure we have a query pattern before we start building.
- if (q.getQueryPattern() == null)
- {
- q.setQueryPattern( new ElementGroup() );
- }
-
- handlerBlock.build();
-
- q.resetResultVars();
- return q;
- }
-
- /**
- * Close the query.
- *
- * This can be used when the query would not normally parse as is required
- * by the Query.clone() method.
- *
- * @param q2
- * The query to clone
- * @return A clone of the q2 param.
- */
- public static Query clone(Query q2) {
- final Query retval = new Query();
-
- // set the query type
- if (q2.isSelectType())
- {
- retval.setQuerySelectType();
- } else if (q2.isAskType()) {
- retval.setQueryAskType();
- } else if (q2.isDescribeType())
- {
- retval.setQueryDescribeType();
- } else if (q2.isConstructType())
- {
- retval.setQueryConstructType();
- }
-
- // use the handler block to clone the data
- final HandlerBlock hb = new HandlerBlock( retval );
- final HandlerBlock hb2 = new HandlerBlock( q2 );
- hb.addAll(hb2);
- q2.resetResultVars();
- return retval;
- }
-
- /**
- * Rewrite a query replacing variables as specified in the values map.
- *
- * @param q2
- * The query to rewrite
- * @param values
- * a Mapping of var to node for replacement.
- * @return The new query with the specified vars replaced.
- */
- public static Query rewrite(Query q2, Map<Var, Node> values) {
- final HandlerBlock hb = new HandlerBlock(q2);
- hb.setVars(values);
- return q2;
- }
+ implements Cloneable, PrologClause<T>, ValuesClause<T> {
+
+ /**
+ * the query this builder is building
+ */
+ protected Query query;
+ /**
+ * a map of vars to nodes for replacement during build.
+ */
+ private final Map<Var, Node> values;
+
+ /**
+ * Make a Node from an object.
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>Will call NodeFactoryExtra.parseNode() using the prefix mapping if the
+ * object is a String</li>
+ * <li>Will create a literal representation if the parseNode() fails or for any
+ * other object type.</li>
+ * </ul>
+ *
+ * Uses the internal query prefix mapping to resolve prefixes.
+ *
+ * @param o The object to convert. (may be null)
+ * @return The Node value.
+ */
+ public Node makeNode(Object o) {
+ return Converters.makeNode(o, query.getPrefixMapping());
+ }
+
+ /**
+ * Make a node or path from the object using the query prefix mapping.
+ *
+ * @param o the object to make the node or path from.
+ * @return A node or path.
+ * @see Converters#makeNodeOrPath(Object, PrefixMapping)
+ */
+ private Object makeNodeOrPath(Object o) {
+ return Converters.makeNodeOrPath(o, query.getPrefixMapping());
+ }
+
+ /**
+ * Creates a Path or Node as appropriate.
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the object if it is a Path
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>Will call PathParser.parse() using the prefix mapping if the object is a
+ * String</li>
+ * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
+ * prefixes if the object is a String and the PathParser.parse() fails.</li>
+ * <li>Will create a literal representation if the parseNode() fails or for any
+ * other object type.</li>
+ * </ul>
+ *
+ * @param o the object that should be interpreted as a path or a node.
+ * @param pMapping the prefix mapping to resolve path or node with
+ * @return the Path or Node
+ * @deprecated use {@link Converters#makeNodeOrPath(Object, PrefixMapping)}
+ */
+ @Deprecated
+ public static Object makeNodeOrPath(Object o, PrefixMapping pMapping) {
+ return Converters.makeNodeOrPath(o, pMapping);
+ }
+
+ public ElementSubQuery asSubQuery() {
+ return getWhereHandler().makeSubQuery(this);
+ }
+
+ /**
+ * Make a triple path from the objects.
+ *
+ * For subject, predicate and objects nodes
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>If the object is a String
+ * <ul>
+ * <li>For <code>predicate</code> only will attempt to parse as a path</li>
+ * <li>for subject, predicate and object will call NodeFactoryExtra.parseNode()
+ * using the currently defined prefixes if the object is a String</li>
+ * </ul>
+ * </li>
+ * <li>Will create a literal representation if the parseNode() fails or for any
+ * other object type.</li>
+ * </ul>
+ *
+ * @param s The subject object
+ * @param p the predicate object
+ * @param o the object object.
+ * @return a TriplePath
+ */
+ public TriplePath makeTriplePath(Object s, Object p, Object o) {
+ final Object po = makeNodeOrPath(p);
+ if (po instanceof Path) {
+ return new TriplePath(makeNode(s), (Path) po, makeNode(o));
+ }
+ return new TriplePath(new Triple(makeNode(s), (Node) po, makeNode(o)));
+ }
+
+ /**
+ * A convenience method to make an expression from a string. Evaluates the
+ * expression with respect to the current query.
+ *
+ * @param expression The expression to parse.
+ * @return the Expr object.
+ * @throws QueryParseException on error.
+ */
+ public Expr makeExpr(String expression) throws QueryParseException {
+ return ExprUtils.parse(query, expression, true);
+ }
+
+ /**
+ * A convenience method to quote a string.
+ *
+ * @param q the string to quote.
+ *
+ * Will use single quotes if there are no single quotes in the string or if the
+ * double quote is before the single quote in the string.
+ *
+ * Will use double quote otherwise.
+ *
+ * @return the quoted string.
+ * @deprecated {@link Converters#quoted(String)}
+ */
+ @Deprecated
+ public static String quote(String q) {
+ return Converters.quoted(q);
+ }
+
+ /**
+ * Verify that any Node_Variable nodes are returned as Var nodes.
+ *
+ * @param n the node to check
+ * @return the node n or a new Var if n is an instance of Node_Variable
+ * @deprecated use {@link Converters#checkVar(Node)}
+ */
+ @Deprecated
+ public static Node checkVar(Node n) {
+ return Converters.checkVar(n);
+ }
+
+ /**
+ * Make a node from an object while using the associated prefix mapping.
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
+ * prefixes if the object is a String</li>
+ * <li>Will create a literal representation if the parseNode() fails or for any
+ * other object type.</li>
+ * </ul>
+ *
+ * @param o The object to convert (may be null).
+ * @param pMapping The prefix mapping to use for prefix resolution.
+ * @return The Node value.
+ * @deprecated use {@link Converters#makeNode(Object, PrefixMapping)}
+ */
+ @Deprecated
+ public static Node makeNode(Object o, PrefixMapping pMapping) {
+ return Converters.makeNode(o, pMapping);
+ }
+
+ /**
+ * Make a Var from an object.
+ * <ul>
+ * <li>Will return Var.ANON if object is null.</li>
+ * <li>Will return null if the object is "*" or Node_RuleVariable.WILD</li>
+ * <li>Will return the object if it is a Var</li>
+ * <li>Will return resolve FrontsNode to Node and then resolve to Var</li>
+ * <li>Will return resolve Node if the Node implements Node_Variable, otherwise
+ * throws an NotAVariableException (instance of ARQInternalErrorException)</li>
+ * <li>Will return ?x if object is "?x"</li>
+ * <li>Will return ?x if object is "x"</li>
+ * <li>Will return the enclosed Var of a ExprVar</li>
+ * <li>For all other objects will return the "?" prefixed to the toString()
+ * value.</li>
+ * </ul>
+ *
+ * @param o The object to convert.
+ * @return the Var value.
+ * @throws ARQInternalErrorException
+ * @deprecated use {@link Converters#makeVar(Object)}
+ */
+ @Deprecated
+ public static Var makeVar(Object o) throws ARQInternalErrorException {
+ return Converters.makeVar(o);
+ }
+
+ /**
+ * Create a new query builder.
+ */
+ protected AbstractQueryBuilder() {
+ query = new Query();
+ values = new HashMap<Var, Node>();
+ }
+
+ /**
+ * Get the HandlerBlock for this query builder.
+ *
+ * @return The associated handler block.
+ */
+ public abstract HandlerBlock getHandlerBlock();
+
+ @Override
+ public final PrologHandler getPrologHandler() {
+ return getHandlerBlock().getPrologHandler();
+ }
+
+ @Override
+ public ValuesHandler getValuesHandler() {
+ return getHandlerBlock().getValueHandler();
+ }
+
+ /**
+ * Gets the where handler used by this QueryBuilder.
+ *
+ * @return the where handler used by this QueryBuilder.
+ */
+ public final WhereHandler getWhereHandler() {
+ return getHandlerBlock().getWhereHandler();
+ }
+
+ /**
+ * Adds the contents of the whereClause to the where clause of this builder.
+ *
+ * @param whereClause the where clause to add.
+ * @return this builder for chaining.
+ */
+ @SuppressWarnings("unchecked")
+ public final T addWhere(AbstractQueryBuilder<?> whereClause) {
+ getWhereHandler().addAll(whereClause.getWhereHandler());
+ return (T) this;
+ }
+
+ @Override
+ public final ExprFactory getExprFactory() {
+ return getHandlerBlock().getPrologHandler().getExprFactory();
+ }
+
+ /**
+ * 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.
+ *
+ * @param var The variable to replace
+ * @param value The value to replace it with or null to remove the replacement.
+ */
+ public void setVar(Var var, Node value) {
+ if (value == null) {
+ values.remove(var);
+ } else {
+ values.put(var, 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 {@link #makeVar} for conversion of the var param. See {@link #makeNode}
+ * for conversion of the value param.
+ *
+ * @param var The variable to replace.
+ * @param value The value to replace it with or null to remove the replacement.
+ */
+ public void setVar(Object var, Object value) {
+ if (value == null) {
+ setVar(Converters.makeVar(var), null);
+ } else {
+ setVar(Converters.makeVar(var), makeNode(value));
+ }
+ }
+
+ @Override
+ public T addPrefix(String pfx, Resource uri) {
+ return addPrefix(pfx, uri.getURI());
+ }
+
+ @Override
+ public T addPrefix(String pfx, Node uri) {
+ return addPrefix(pfx, uri.getURI());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addPrefix(String pfx, String uri) {
+ getPrologHandler().addPrefix(pfx, uri);
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addPrefixes(Map<String, String> prefixes) {
+ getPrologHandler().addPrefixes(prefixes);
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addPrefixes(PrefixMapping prefixMapping) {
+ getPrologHandler().addPrefixes(prefixMapping);
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T setBase(String base) {
+ getPrologHandler().setBase(base);
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T setBase(Object base) {
+ setBase(makeNode(base).getURI());
+ return (T) this;
+ }
+
+ // --- VALUES
+
+ /**
+ * Creates a collection of nodes from an iterator of Objects.
+ *
+ * @param iter the iterator of objects, may be null or empty.
+ * @param prefixMapping the PrefixMapping to use when nodes are created.
+ * @return a Collection of nodes or null if iter is null or empty.
+ * @deprecated use {@link Converters#makeValueNodes(Iterator, PrefixMapping)}
+ */
+ @Deprecated
+ public static Collection<Node> makeValueNodes(Iterator<?> iter, PrefixMapping prefixMapping) {
+ return Converters.makeValueNodes(iter, prefixMapping);
+ }
+
+ /**
+ * Creates a collection of nodes from an iterator of Objects. Uses the prefix
+ * mapping from the PrologHandler.
+ *
+ * @param iter the iterator of objects, may be null or empty.
+ * @return a Collection of nodes or null if iter is null or empty.
+ */
+ public Collection<Node> makeValueNodes(Iterator<?> iter) {
+ return Converters.makeValueNodes(iter, getPrologHandler().getPrefixes());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addValueVar(Object var) {
+ if (var == null) {
+ throw new IllegalArgumentException("var must not be null.");
+ }
+ if (var instanceof Collection<?>) {
+ final Collection<?> column = (Collection<?>) var;
+ if (column.size() == 0) {
+ throw new IllegalArgumentException("column must have at least one entry.");
+ }
+ final Iterator<?> iter = column.iterator();
+ final Var v = Converters.makeVar(iter.next());
+ getValuesHandler().addValueVar(v, makeValueNodes(iter));
+ } else {
+ getValuesHandler().addValueVar(Converters.makeVar(var), null);
+ }
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addValueVar(Object var, Object... objects) {
+
+ Collection<Node> values = null;
+ if (objects != null) {
+ values = makeValueNodes(Arrays.asList(objects).iterator());
+ }
+
+ getValuesHandler().addValueVar(Converters.makeVar(var), values);
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <K extends Collection<?>> T addValueVars(Map<?, K> dataTable) {
+ final ValuesHandler hdlr = new ValuesHandler(null);
+ for (final Map.Entry<?, K> entry : dataTable.entrySet()) {
+ Collection<Node> values = null;
+ if (entry.getValue() != null) {
+ values = makeValueNodes(entry.getValue().iterator());
+ }
+ hdlr.addValueVar(Converters.makeVar(entry.getKey()), values);
+ }
+ getValuesHandler().addAll(hdlr);
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addValueRow(Object... values) {
+ getValuesHandler().addValueRow(makeValueNodes(Arrays.asList(values).iterator()));
+ return (T) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T addValueRow(Collection<?> values) {
+ getValuesHandler().addValueRow(makeValueNodes(values.iterator()));
+ return (T) this;
+ }
+
+ @Override
+ public List<Var> getValuesVars() {
+ return getValuesHandler().getValuesVars();
+ }
+
+ @Override
+ public Map<Var, List<Node>> getValuesMap() {
+ return getValuesHandler().getValuesMap();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public T clearValues() {
+ getValuesHandler().clear();
+ return (T) this;
+ }
+
+ @Override
+ public String toString() {
+ return buildString();
+ }
+
+ /**
+ * Build the query as a string.
+ *
+ * @return the string representation of the query.
+ */
+ public final String buildString() {
+ return build().toString();
+ }
+
+ /**
+ * Build the query. Performs the var replacements as specified by
+ * setVar(var,node) calls.
+ *
+ * @return The query.
+ */
+ public final Query build() {
+ final Query q = new Query();
+
+ // set the query type
+ switch (query.queryType()) {
+ case ASK:
+ q.setQueryAskType();
+ break;
+ case CONSTRUCT:
+ q.setQueryConstructType();
+ break;
+ case DESCRIBE:
+ q.setQueryDescribeType();
+ break;
+ case SELECT:
+ q.setQuerySelectType();
+ break;
+ case UNKNOWN:
+ // do nothing
+ break;
+ default:
+ throw new IllegalStateException("Internal query is not a known type: " + q.queryType());
+ }
+
+ // use the HandlerBlock implementation to copy the data.
+ final HandlerBlock handlerBlock = new HandlerBlock(q);
+ handlerBlock.addAll(getHandlerBlock());
+
+ // set the vars
+ handlerBlock.setVars(values);
+
+ // make sure we have a query pattern before we start building.
+ if (q.getQueryPattern() == null) {
+ q.setQueryPattern(new ElementGroup());
+ }
+
+ handlerBlock.build();
+
+ q.resetResultVars();
+ return q;
+ }
+
+ /**
+ * Close the query.
+ *
+ * This can be used when the query would not normally parse as is required by
+ * the Query.clone() method.
+ *
+ * @param q2 The query to clone
+ * @return A clone of the q2 param.
+ */
+ public static Query clone(Query q2) {
+ final Query retval = new Query();
+
+ // set the query type
+ if (q2.isSelectType()) {
+ retval.setQuerySelectType();
+ } else if (q2.isAskType()) {
+ retval.setQueryAskType();
+ } else if (q2.isDescribeType()) {
+ retval.setQueryDescribeType();
+ } else if (q2.isConstructType()) {
+ retval.setQueryConstructType();
+ }
+
+ // use the handler block to clone the data
+ final HandlerBlock hb = new HandlerBlock(retval);
+ final HandlerBlock hb2 = new HandlerBlock(q2);
+ hb.addAll(hb2);
+ q2.resetResultVars();
+ return retval;
+ }
+
+ /**
+ * Rewrite a query replacing variables as specified in the values map.
+ *
+ * @param q2 The query to rewrite
+ * @param values a Mapping of var to node for replacement.
+ * @return The new query with the specified vars replaced.
+ */
+ public static Query rewrite(Query q2, Map<Var, Node> values) {
+ final HandlerBlock hb = new HandlerBlock(q2);
+ hb.setVars(values);
+ return q2;
+ }
}
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AskBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AskBuilder.java
index 388bd87..02370de 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AskBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/AskBuilder.java
@@ -39,14 +39,17 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
/**
* Builder for SPARQL Ask Queries.
* <p>
- * The AskBuilder provides chainable methods to programmatically generate SPARQL Ask Queries.
- * The application order of the methods is not relevant for the resulting query.
- * An {@link ExprFactory} is intended for use along with the AskBuilder to generate needed {@link Expr} parameter values.
- * An {@link ExprFactory} that works with the same prefixes can be obtained with {@link AskBuilder#getExprFactory()}.
+ * The AskBuilder provides chainable methods to programmatically generate SPARQL
+ * Ask Queries. The application order of the methods is not relevant for the
+ * resulting query. An {@link ExprFactory} is intended for use along with the
+ * AskBuilder to generate needed {@link Expr} parameter values. An
+ * {@link ExprFactory} that works with the same prefixes can be obtained with
+ * {@link AskBuilder#getExprFactory()}.
* <p>
- * The AskBuilder can be used as <b>prepared query</b>.
- * Values for variables in the created query can be set with {@link AskBuilder#setVar(Object, Object)} and {@link AskBuilder#setVar(Var, Node)}.
- * The method {@link AskBuilder#clearWhereValues()} allows to clear the set values.
+ * The AskBuilder can be used as <b>prepared query</b>. Values for variables in
+ * the created query can be set with {@link AskBuilder#setVar(Object, Object)}
+ * and {@link AskBuilder#setVar(Var, Node)}. The method
+ * {@link AskBuilder#clearWhereValues()} allows to clear the set values.
*
* @see ConstructBuilder
* @see DescribeBuilder
@@ -54,323 +57,321 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
* @see UpdateBuilder
*/
public class AskBuilder extends AbstractQueryBuilder<AskBuilder>
- implements DatasetClause<AskBuilder>, WhereClause<AskBuilder>, SolutionModifierClause<AskBuilder> {
-
- private final HandlerBlock handlerBlock;
-
- public AskBuilder() {
- super();
- query.setQueryAskType();
- handlerBlock = new HandlerBlock(query);
- }
-
- @Override
- public HandlerBlock getHandlerBlock() {
- return handlerBlock;
- }
-
- @Override
- public DatasetHandler getDatasetHandler() {
- return handlerBlock.getDatasetHandler();
- }
-
- @Override
- public AskBuilder clone() {
- AskBuilder qb = new AskBuilder();
- qb.handlerBlock.addAll(handlerBlock);
- return qb;
- }
-
- @Override
- public AskBuilder fromNamed(String graphName) {
- getDatasetHandler().fromNamed(graphName);
- return this;
- }
-
- @Override
- public AskBuilder fromNamed(Collection<String> graphNames) {
- getDatasetHandler().fromNamed(graphNames);
- return this;
- }
-
- @Override
- public AskBuilder from(String graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public AskBuilder from(Collection<String> graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public AskBuilder addWhere(TriplePath t) {
- getWhereHandler().addWhere(t);
- return this;
- }
-
-
- @Override
- public AskBuilder addWhere(Triple t) {
- getWhereHandler().addWhere(new TriplePath(t));
- return this;
- }
-
- @Override
- public AskBuilder addWhere(FrontsTriple t) {
- getWhereHandler().addWhere(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public AskBuilder addWhere(Object s, Object p, Object o) {
- getWhereHandler().addWhere( makeTriplePath( s, p, o ));
- return this;
- }
-
- @Override
- public AskBuilder addWhereValueVar(Object var) {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
- return this;
- }
-
- @Override
- public AskBuilder addWhereValueVar(Object var, Object... values)
- {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
- return this;
- }
-
-
- @Override
- public <K extends Collection<?>> AskBuilder addWhereValueVars(Map<?,K> dataTable)
- {
- getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
- return this;
- }
-
- @Override
- public AskBuilder addWhereValueRow(Object... values)
- {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public AskBuilder addWhereValueRow(Collection<?> values) {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public List<Var> getWhereValuesVars() {
- return getWhereHandler().getValuesVars();
- }
-
- @Override
- public Map<Var, List<Node>> getWhereValuesMap() {
- return getWhereHandler().getValuesMap();
- }
-
- @Override
- public AskBuilder clearWhereValues() {
- getWhereHandler().clearValues();
- return this;
- }
-
- @Override
- public AskBuilder addOptional(TriplePath t) {
- getWhereHandler().addOptional(t);
- return this;
- }
-
-
- @Override
- public AskBuilder addOptional(Triple t) {
- getWhereHandler().addOptional(new TriplePath(t));
- return this;
- }
-
- @Override
- public AskBuilder addOptional(AbstractQueryBuilder<?> t) {
- getWhereHandler().addOptional(t.getWhereHandler());
- return this;
- }
-
- @Override
- public AskBuilder addOptional(FrontsTriple t) {
- getWhereHandler().addOptional(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public AskBuilder addOptional(Object s, Object p, Object o) {
- getWhereHandler().addOptional( makeTriplePath( s, p, o ));
- return this;
- }
-
- @Override
- public AskBuilder addFilter(Expr expr) {
- getWhereHandler().addFilter(expr);
- return this;
- }
-
- @Override
- public AskBuilder addFilter(String s) throws ParseException {
- getWhereHandler().addFilter(s);
- return this;
- }
-
- @Override
- public AskBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addSubQuery(subQuery);
- return this;
- }
-
- @Override
- public AskBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addUnion(subQuery);
- return this;
- }
-
- @Override
- public AskBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
- getPrologHandler().addAll(subQuery.getPrologHandler());
- getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
- return this;
- }
- @Override
- public AskBuilder addGraph(Object graph, FrontsTriple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
- return this;
- }
- @Override
- public AskBuilder addGraph(Object graph, Object subject, Object predicate, Object object)
- {
- getWhereHandler().addGraph(makeNode(graph), makeTriplePath( subject, predicate, object ));
- return this;
- }
- @Override
- public AskBuilder addGraph(Object graph, Triple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
- return this;
- }
- @Override
- public AskBuilder addGraph(Object graph, TriplePath triplePath) {
- getWhereHandler().addGraph(makeNode(graph), triplePath );
- return this;
- }
- @Override
- public AskBuilder addBind(Expr expression, Object var) {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public AskBuilder addBind(String expression, Object var) throws ParseException {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public AskBuilder addOrderBy(Expr orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public AskBuilder addOrderBy(Object orderBy) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
- return this;
- }
-
- @Override
- public AskBuilder addOrderBy(SortCondition orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public AskBuilder addOrderBy(Expr orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(orderBy, order);
- return this;
- }
-
- @Override
- public AskBuilder addOrderBy(Object orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
- return this;
- }
-
- @Override
- public AskBuilder addGroupBy(Object groupBy) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
- return this;
- }
-
- @Override
- public AskBuilder addGroupBy(Expr groupBy) {
- getSolutionModifierHandler().addGroupBy(groupBy);
- return this;
- }
-
- @Override
- public AskBuilder addGroupBy(Object var, Expr expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
- return this;
- }
-
- @Override
- public AskBuilder addGroupBy(Object var, String expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
- return this;
- }
-
- @Override
- public AskBuilder addHaving(String having) throws ParseException {
- getSolutionModifierHandler().addHaving(having);
- return this;
- }
-
- @Override
- public AskBuilder addHaving(Expr expression) throws ParseException {
- getSolutionModifierHandler().addHaving(expression);
- return this;
- }
-
- @Override
- public AskBuilder addHaving(Object var) throws ParseException {
- getSolutionModifierHandler().addHaving(Converters.makeVar(var));
- return this;
- }
-
- @Override
- public AskBuilder setLimit(int limit) {
- getSolutionModifierHandler().setLimit(limit);
- return this;
- }
-
- @Override
- public AskBuilder setOffset(int offset) {
- getSolutionModifierHandler().setOffset(offset);
- return this;
- }
-
- @Override
- public SolutionModifierHandler getSolutionModifierHandler() {
- return handlerBlock.getModifierHandler();
- }
-
- @Override
- public Node list(Object... objs) {
- return getWhereHandler().list(objs);
- }
-
- @Override
- public AskBuilder addMinus( AbstractQueryBuilder<?> t ) {
- getWhereHandler().addMinus( t );
- return this;
- }
+ implements DatasetClause<AskBuilder>, WhereClause<AskBuilder>, SolutionModifierClause<AskBuilder> {
+
+ private final HandlerBlock handlerBlock;
+
+ public AskBuilder() {
+ super();
+ query.setQueryAskType();
+ handlerBlock = new HandlerBlock(query);
+ }
+
+ @Override
+ public HandlerBlock getHandlerBlock() {
+ return handlerBlock;
+ }
+
+ @Override
+ public DatasetHandler getDatasetHandler() {
+ return handlerBlock.getDatasetHandler();
+ }
+
+ @Override
+ public AskBuilder clone() {
+ AskBuilder qb = new AskBuilder();
+ qb.handlerBlock.addAll(handlerBlock);
+ return qb;
+ }
+
+ @Override
+ public AskBuilder fromNamed(String graphName) {
+ getDatasetHandler().fromNamed(graphName);
+ return this;
+ }
+
+ @Override
+ public AskBuilder fromNamed(Collection<String> graphNames) {
+ getDatasetHandler().fromNamed(graphNames);
+ return this;
+ }
+
+ @Override
+ public AskBuilder from(String graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public AskBuilder from(Collection<String> graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhere(TriplePath t) {
+ getWhereHandler().addWhere(t);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhere(Triple t) {
+ getWhereHandler().addWhere(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhere(FrontsTriple t) {
+ getWhereHandler().addWhere(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhere(Object s, Object p, Object o) {
+ getWhereHandler().addWhere(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhereValueVar(Object var) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhereValueVar(Object var, Object... values) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
+ return this;
+ }
+
+ @Override
+ public <K extends Collection<?>> AskBuilder addWhereValueVars(Map<?, K> dataTable) {
+ getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhereValueRow(Object... values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addWhereValueRow(Collection<?> values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public List<Var> getWhereValuesVars() {
+ return getWhereHandler().getValuesVars();
+ }
+
+ @Override
+ public Map<Var, List<Node>> getWhereValuesMap() {
+ return getWhereHandler().getValuesMap();
+ }
+
+ @Override
+ public AskBuilder clearWhereValues() {
+ getWhereHandler().clearValues();
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOptional(TriplePath t) {
+ getWhereHandler().addOptional(t);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOptional(Triple t) {
+ getWhereHandler().addOptional(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOptional(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addOptional(t.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOptional(FrontsTriple t) {
+ getWhereHandler().addOptional(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOptional(Object s, Object p, Object o) {
+ getWhereHandler().addOptional(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addFilter(Expr expr) {
+ getWhereHandler().addFilter(expr);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addFilter(String s) throws ParseException {
+ getWhereHandler().addFilter(s);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addSubQuery(subQuery);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addUnion(subQuery);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
+ getPrologHandler().addAll(subQuery.getPrologHandler());
+ getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGraph(Object graph, FrontsTriple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGraph(Object graph, Object subject, Object predicate, Object object) {
+ getWhereHandler().addGraph(makeNode(graph), makeTriplePath(subject, predicate, object));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGraph(Object graph, Triple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGraph(Object graph, TriplePath triplePath) {
+ getWhereHandler().addGraph(makeNode(graph), triplePath);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addBind(Expr expression, Object var) {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addBind(String expression, Object var) throws ParseException {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOrderBy(Expr orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOrderBy(Object orderBy) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOrderBy(SortCondition orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOrderBy(Expr orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(orderBy, order);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addOrderBy(Object orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGroupBy(Object groupBy) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGroupBy(Expr groupBy) {
+ getSolutionModifierHandler().addGroupBy(groupBy);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGroupBy(Object var, Expr expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addGroupBy(Object var, String expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
+ return this;
+ }
+
+ @Override
+ public AskBuilder addHaving(String having) throws ParseException {
+ getSolutionModifierHandler().addHaving(having);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addHaving(Expr expression) throws ParseException {
+ getSolutionModifierHandler().addHaving(expression);
+ return this;
+ }
+
+ @Override
+ public AskBuilder addHaving(Object var) throws ParseException {
+ getSolutionModifierHandler().addHaving(Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public AskBuilder setLimit(int limit) {
+ getSolutionModifierHandler().setLimit(limit);
+ return this;
+ }
+
+ @Override
+ public AskBuilder setOffset(int offset) {
+ getSolutionModifierHandler().setOffset(offset);
+ return this;
+ }
+
+ @Override
+ public SolutionModifierHandler getSolutionModifierHandler() {
+ return handlerBlock.getModifierHandler();
+ }
+
+ @Override
+ public Node list(Object... objs) {
+ return getWhereHandler().list(objs);
+ }
+
+ @Override
+ public AskBuilder addMinus(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addMinus(t);
+ return this;
+ }
}
\ No newline at end of file
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ConstructBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ConstructBuilder.java
index 72b4c65..3955076 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ConstructBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ConstructBuilder.java
@@ -41,14 +41,18 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
/**
* Builder for SPARQL Construct Queries.
* <p>
- * The ConstructBuilder provides chainable methods to programmatically generate SPARQL Construct Queries.
- * The application order of the methods is not relevant for the resulting query.
- * An {@link ExprFactory} is intended for use along with the ConstructBuilder to generate needed {@link Expr} parameter values.
- * An {@link ExprFactory} that works with the same prefixes can be obtained with {@link ConstructBuilder#getExprFactory()}.
+ * The ConstructBuilder provides chainable methods to programmatically generate
+ * SPARQL Construct Queries. The application order of the methods is not
+ * relevant for the resulting query. An {@link ExprFactory} is intended for use
+ * along with the ConstructBuilder to generate needed {@link Expr} parameter
+ * values. An {@link ExprFactory} that works with the same prefixes can be
+ * obtained with {@link ConstructBuilder#getExprFactory()}.
* <p>
- * The ConstructBuilder can be used as<b>prepared query</b>.
- * Values for variables in the created query can be set with {@link ConstructBuilder#setVar(Object, Object)} and {@link ConstructBuilder#setVar(Var, Node)}.
- * The method {@link ConstructBuilder#clearWhereValues()} allows to clear the set values.
+ * The ConstructBuilder can be used as<b>prepared query</b>. Values for
+ * variables in the created query can be set with
+ * {@link ConstructBuilder#setVar(Object, Object)} and
+ * {@link ConstructBuilder#setVar(Var, Node)}. The method
+ * {@link ConstructBuilder#clearWhereValues()} allows to clear the set values.
*
* @see AskBuilder
* @see DescribeBuilder
@@ -56,344 +60,342 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
* @see UpdateBuilder
*/
public class ConstructBuilder extends AbstractQueryBuilder<ConstructBuilder> implements DatasetClause<ConstructBuilder>,
- WhereClause<ConstructBuilder>, SolutionModifierClause<ConstructBuilder>, ConstructClause<ConstructBuilder> {
-
- private final HandlerBlock handlerBlock;
-
- public ConstructBuilder() {
- super();
- query.setQueryConstructType();
- handlerBlock = new HandlerBlock(query);
- }
-
- @Override
- public DatasetHandler getDatasetHandler() {
- return handlerBlock.getDatasetHandler();
- }
-
- @Override
- public ConstructHandler getConstructHandler() {
- return handlerBlock.getConstructHandler();
- }
-
- @Override
- public SolutionModifierHandler getSolutionModifierHandler() {
- return handlerBlock.getModifierHandler();
- }
-
- @Override
- public HandlerBlock getHandlerBlock() {
- return handlerBlock;
- }
-
- @Override
- public ConstructBuilder clone() {
- ConstructBuilder qb = new ConstructBuilder();
- qb.handlerBlock.addAll(handlerBlock);
- return qb;
- }
-
- @Override
- public ConstructBuilder fromNamed(String graphName) {
- getDatasetHandler().fromNamed(graphName);
- return this;
- }
-
- @Override
- public ConstructBuilder fromNamed(Collection<String> graphNames) {
- getDatasetHandler().fromNamed(graphNames);
- return this;
- }
-
- @Override
- public ConstructBuilder from(String graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public ConstructBuilder from(Collection<String> graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public ConstructBuilder addOrderBy(Expr orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public ConstructBuilder addOrderBy(Object orderBy) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
- return this;
- }
-
- @Override
- public ConstructBuilder addOrderBy(SortCondition orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public ConstructBuilder addOrderBy(Expr orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(orderBy, order);
- return this;
- }
-
- @Override
- public ConstructBuilder addOrderBy(Object orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
- return this;
- }
-
- @Override
- public ConstructBuilder addGroupBy(Object groupBy) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
- return this;
- }
-
- @Override
- public ConstructBuilder addGroupBy(Expr groupBy) {
- getSolutionModifierHandler().addGroupBy(groupBy);
- return this;
- }
-
- @Override
- public ConstructBuilder addGroupBy(Object var, Expr expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
- return this;
- }
-
- @Override
- public ConstructBuilder addGroupBy(Object var, String expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
- return this;
- }
-
- @Override
- public ConstructBuilder addHaving(String having) throws ParseException {
- getSolutionModifierHandler().addHaving(having);
- return this;
- }
-
- @Override
- public ConstructBuilder addHaving(Expr expression) throws ParseException {
- getSolutionModifierHandler().addHaving(expression);
- return this;
- }
-
- @Override
- public ConstructBuilder addHaving(Object var) throws ParseException {
- getSolutionModifierHandler().addHaving(Converters.makeVar(var));
- return this;
- }
-
- @Override
- public ConstructBuilder setLimit(int limit) {
- getSolutionModifierHandler().setLimit(limit);
- return this;
- }
-
- @Override
- public ConstructBuilder setOffset(int offset) {
- getSolutionModifierHandler().setOffset(offset);
- return this;
- }
-
- @Override
- public ConstructBuilder addWhere(TriplePath t) {
- getWhereHandler().addWhere(t);
- return this;
- }
-
- @Override
- public ConstructBuilder addWhere(Triple t) {
- getWhereHandler().addWhere(new TriplePath(t));
- return this;
- }
-
- @Override
- public ConstructBuilder addWhere(FrontsTriple t) {
- getWhereHandler().addWhere(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public ConstructBuilder addWhere(Object s, Object p, Object o) {
- getWhereHandler().addWhere( makeTriplePath( s, p, o ));
- return this;
- }
-
-
- @Override
- public ConstructBuilder addWhereValueVar(Object var) {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
- return this;
- }
-
- @Override
- public ConstructBuilder addWhereValueVar(Object var, Object... values)
- {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
- return this;
- }
-
-
- @Override
- public <K extends Collection<?>> ConstructBuilder addWhereValueVars(Map<?,K> dataTable)
- {
- getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
- return this;
- }
-
- @Override
- public ConstructBuilder addWhereValueRow(Object... values)
- {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public ConstructBuilder addWhereValueRow(Collection<?> values) {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public List<Var> getWhereValuesVars() {
- return getWhereHandler().getValuesVars();
- }
-
- @Override
- public Map<Var, List<Node>> getWhereValuesMap() {
- return getWhereHandler().getValuesMap();
- }
-
- @Override
- public ConstructBuilder clearWhereValues() {
- getWhereHandler().clearValues();
- return this;
- }
-
- @Override
- public ConstructBuilder addOptional(TriplePath t) {
- getWhereHandler().addOptional(t);
- return this;
- }
-
- @Override
- public ConstructBuilder addOptional(Triple t) {
- getWhereHandler().addOptional(new TriplePath(t));
- return this;
- }
-
- @Override
- public ConstructBuilder addOptional(AbstractQueryBuilder<?> t) {
- getWhereHandler().addOptional(t.getWhereHandler());
- return this;
- }
-
- @Override
- public ConstructBuilder addOptional(FrontsTriple t) {
- getWhereHandler().addOptional(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public ConstructBuilder addOptional(Object s, Object p, Object o) {
- getWhereHandler().addOptional( makeTriplePath( s, p, o ));
- return this;
- }
-
- @Override
- public ConstructBuilder addFilter(Expr expr) {
- getWhereHandler().addFilter(expr);
- return this;
- }
-
- @Override
- public ConstructBuilder addFilter(String s) throws ParseException {
- getWhereHandler().addFilter(s);
- return this;
- }
-
- @Override
- public ConstructBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addSubQuery(subQuery);
- return this;
- }
-
- @Override
- public ConstructBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addUnion(subQuery);
- return this;
- }
-
- @Override
- public ConstructBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
- getPrologHandler().addAll(subQuery.getPrologHandler());
- getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
- return this;
- }
- @Override
- public ConstructBuilder addGraph(Object graph, FrontsTriple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
- return this;
- }
- @Override
- public ConstructBuilder addGraph(Object graph, Object subject, Object predicate, Object object)
- {
- getWhereHandler().addGraph(makeNode(graph), makeTriplePath( subject, predicate, object ));
- return this;
- }
- @Override
- public ConstructBuilder addGraph(Object graph, Triple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
- return this;
- }
- @Override
- public ConstructBuilder addGraph(Object graph, TriplePath triplePath) {
- getWhereHandler().addGraph(makeNode(graph), triplePath );
- return this;
- }
-
- @Override
- public ConstructBuilder addBind(Expr expression, Object var) {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public ConstructBuilder addBind(String expression, Object var) throws ParseException {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public ConstructBuilder addConstruct(Triple t) {
- getConstructHandler().addConstruct(t);
- return this;
- }
-
- @Override
- public ConstructBuilder addConstruct(FrontsTriple t) {
- return addConstruct(t.asTriple());
- }
-
- @Override
- public ConstructBuilder addConstruct(Object s, Object p, Object o) {
- return addConstruct(new Triple(makeNode(s), makeNode(p), makeNode(o)));
- }
-
- @Override
- public Node list(Object... objs) {
- return getWhereHandler().list(objs);
- }
-
- @Override
- public ConstructBuilder addMinus( AbstractQueryBuilder<?> t ) {
- getWhereHandler().addMinus( t );
- return this;
- }
+ WhereClause<ConstructBuilder>, SolutionModifierClause<ConstructBuilder>, ConstructClause<ConstructBuilder> {
+
+ private final HandlerBlock handlerBlock;
+
+ public ConstructBuilder() {
+ super();
+ query.setQueryConstructType();
+ handlerBlock = new HandlerBlock(query);
+ }
+
+ @Override
+ public DatasetHandler getDatasetHandler() {
+ return handlerBlock.getDatasetHandler();
+ }
+
+ @Override
+ public ConstructHandler getConstructHandler() {
+ return handlerBlock.getConstructHandler();
+ }
+
+ @Override
+ public SolutionModifierHandler getSolutionModifierHandler() {
+ return handlerBlock.getModifierHandler();
+ }
+
+ @Override
+ public HandlerBlock getHandlerBlock() {
+ return handlerBlock;
+ }
+
+ @Override
+ public ConstructBuilder clone() {
+ ConstructBuilder qb = new ConstructBuilder();
+ qb.handlerBlock.addAll(handlerBlock);
+ return qb;
+ }
+
+ @Override
+ public ConstructBuilder fromNamed(String graphName) {
+ getDatasetHandler().fromNamed(graphName);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder fromNamed(Collection<String> graphNames) {
+ getDatasetHandler().fromNamed(graphNames);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder from(String graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder from(Collection<String> graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOrderBy(Expr orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOrderBy(Object orderBy) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOrderBy(SortCondition orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOrderBy(Expr orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(orderBy, order);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOrderBy(Object orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGroupBy(Object groupBy) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGroupBy(Expr groupBy) {
+ getSolutionModifierHandler().addGroupBy(groupBy);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGroupBy(Object var, Expr expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGroupBy(Object var, String expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addHaving(String having) throws ParseException {
+ getSolutionModifierHandler().addHaving(having);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addHaving(Expr expression) throws ParseException {
+ getSolutionModifierHandler().addHaving(expression);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addHaving(Object var) throws ParseException {
+ getSolutionModifierHandler().addHaving(Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder setLimit(int limit) {
+ getSolutionModifierHandler().setLimit(limit);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder setOffset(int offset) {
+ getSolutionModifierHandler().setOffset(offset);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhere(TriplePath t) {
+ getWhereHandler().addWhere(t);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhere(Triple t) {
+ getWhereHandler().addWhere(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhere(FrontsTriple t) {
+ getWhereHandler().addWhere(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhere(Object s, Object p, Object o) {
+ getWhereHandler().addWhere(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhereValueVar(Object var) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhereValueVar(Object var, Object... values) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
+ return this;
+ }
+
+ @Override
+ public <K extends Collection<?>> ConstructBuilder addWhereValueVars(Map<?, K> dataTable) {
+ getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhereValueRow(Object... values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addWhereValueRow(Collection<?> values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public List<Var> getWhereValuesVars() {
+ return getWhereHandler().getValuesVars();
+ }
+
+ @Override
+ public Map<Var, List<Node>> getWhereValuesMap() {
+ return getWhereHandler().getValuesMap();
+ }
+
+ @Override
+ public ConstructBuilder clearWhereValues() {
+ getWhereHandler().clearValues();
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOptional(TriplePath t) {
+ getWhereHandler().addOptional(t);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOptional(Triple t) {
+ getWhereHandler().addOptional(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOptional(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addOptional(t.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOptional(FrontsTriple t) {
+ getWhereHandler().addOptional(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addOptional(Object s, Object p, Object o) {
+ getWhereHandler().addOptional(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addFilter(Expr expr) {
+ getWhereHandler().addFilter(expr);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addFilter(String s) throws ParseException {
+ getWhereHandler().addFilter(s);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addSubQuery(subQuery);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addUnion(subQuery);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
+ getPrologHandler().addAll(subQuery.getPrologHandler());
+ getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGraph(Object graph, FrontsTriple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGraph(Object graph, Object subject, Object predicate, Object object) {
+ getWhereHandler().addGraph(makeNode(graph), makeTriplePath(subject, predicate, object));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGraph(Object graph, Triple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addGraph(Object graph, TriplePath triplePath) {
+ getWhereHandler().addGraph(makeNode(graph), triplePath);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addBind(Expr expression, Object var) {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addBind(String expression, Object var) throws ParseException {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addConstruct(Triple t) {
+ getConstructHandler().addConstruct(t);
+ return this;
+ }
+
+ @Override
+ public ConstructBuilder addConstruct(FrontsTriple t) {
+ return addConstruct(t.asTriple());
+ }
+
+ @Override
+ public ConstructBuilder addConstruct(Object s, Object p, Object o) {
+ return addConstruct(new Triple(makeNode(s), makeNode(p), makeNode(o)));
+ }
+
+ @Override
+ public Node list(Object... objs) {
+ return getWhereHandler().list(objs);
+ }
+
+ @Override
+ public ConstructBuilder addMinus(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addMinus(t);
+ return this;
+ }
}
\ No newline at end of file
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Converters.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Converters.java
index 6565774..8df26c4 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Converters.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Converters.java
@@ -43,296 +43,283 @@ import org.apache.jena.sparql.path.PathParser;
import org.apache.jena.sparql.util.NodeFactoryExtra;
/**
- * A collection of static methods to convert from Objects to various
- * types used in Query and Update construction.
+ * A collection of static methods to convert from Objects to various types used
+ * in Query and Update construction.
*/
public class Converters {
- private Converters() {
- // do not make instance
- }
+ private Converters() {
+ // do not make instance
+ }
- /**
- * Converts any Node_Variable nodes into Var nodes.
- * @param n the node to check
- * @return the node n or a new Var if n is an instance of Node_Variable
- */
- public static Node checkVar(Node n )
- {
- if (n.isVariable())
- {
- return Var.alloc( n );
- }
- return n;
- }
+ /**
+ * Converts any Node_Variable nodes into Var nodes.
+ *
+ * @param n the node to check
+ * @return the node n or a new Var if n is an instance of Node_Variable
+ */
+ public static Node checkVar(Node n) {
+ if (n.isVariable()) {
+ return Var.alloc(n);
+ }
+ return n;
+ }
- /**
- * Creates a literal from an object.
- * If the object type is registered with the TypeMapper the associated literal
- * string is returned. If the object is not registered an IllegalArgumentException
- * is thrown.
- * @param o the object to convert.
- * @return the literal node.
- * @throws IllegalArgumentException if object type is not registered.
- */
- public static Node makeLiteral(Object o) {
+ /**
+ * Creates a literal from an object. If the object type is registered with the
+ * TypeMapper the associated literal string is returned. If the object is not
+ * registered an IllegalArgumentException is thrown.
+ *
+ * @param o the object to convert.
+ * @return the literal node.
+ * @throws IllegalArgumentException if object type is not registered.
+ */
+ public static Node makeLiteral(Object o) {
- RDFDatatype dt = TypeMapper.getInstance().getTypeByValue( o );
- if (dt == null) {
- String msg = "No TypeDef defined for %s. Use TypeMapper.getInstance().register() to "
- + "register one or use makeLiteral() method in query builder instance.";
- throw new IllegalArgumentException( String.format( msg, o.getClass()));
- }
- return NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(o));
+ RDFDatatype dt = TypeMapper.getInstance().getTypeByValue(o);
+ if (dt == null) {
+ String msg = "No TypeDef defined for %s. Use TypeMapper.getInstance().register() to "
+ + "register one or use makeLiteral() method in query builder instance.";
+ throw new IllegalArgumentException(String.format(msg, o.getClass()));
+ }
+ return NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(o));
- }
+ }
- /**
- * Creates a literal from the value and type URI.
- * There are several possible outcomes:
- * <ul>
- * <li>
- * If the URI is registered with TypeMapper and the value is the
- * proper lexical form for the type, the registered TypeMapper
- * is used and calling {@code getLiteralValue()} on the returned node
- * will return a proper object.
- * </li><li>
- * If the URI is unregistered a Datatype is created but not registered
- * with the TypeMapper. The resulting node is properly constructed for
- * used in output serialization, queries, or updates. Calling
- * {@code getLiteralValue()} on the returned node will throw DatatypeFormatException.
- * Note that if {@code JenaParameters.enableEagerLiteralValidation} is true the
- * DatatypeFormatException will be thrown by this method.
- * </li><li>
- * If the URI is registered but the value is not a proper lexical form
- * a DatatypeFormatException will be thrown by this method.
- * </li>
- * </ul>
- * @param value the value for the literal
- * @param typeUri the type URI for the literal node.
- * @return the literal node.
- * @throws DatatypeFormatException on errors noted above
- */
- public static Node makeLiteral(String value, String typeUri) {
- Object oValue = value;
- RDFDatatype dt = TypeMapper.getInstance().getTypeByName(typeUri);
- if (dt == null)
- {
- dt = new BaseDatatype(typeUri) {
+ /**
+ * Creates a literal from the value and type URI. There are several possible
+ * outcomes:
+ * <ul>
+ * <li>If the URI is registered with TypeMapper and the value is the proper
+ * lexical form for the type, the registered TypeMapper is used and calling
+ * {@code getLiteralValue()} on the returned node will return a proper object.
+ * </li>
+ * <li>If the URI is unregistered a Datatype is created but not registered with
+ * the TypeMapper. The resulting node is properly constructed for used in output
+ * serialization, queries, or updates. Calling {@code getLiteralValue()} on the
+ * returned node will throw DatatypeFormatException. Note that if
+ * {@code JenaParameters.enableEagerLiteralValidation} is true the
+ * DatatypeFormatException will be thrown by this method.</li>
+ * <li>If the URI is registered but the value is not a proper lexical form a
+ * DatatypeFormatException will be thrown by this method.</li>
+ * </ul>
+ *
+ * @param value the value for the literal
+ * @param typeUri the type URI for the literal node.
+ * @return the literal node.
+ * @throws DatatypeFormatException on errors noted above
+ */
+ public static Node makeLiteral(String value, String typeUri) {
+ Object oValue = value;
+ RDFDatatype dt = TypeMapper.getInstance().getTypeByName(typeUri);
+ if (dt == null) {
+ dt = new BaseDatatype(typeUri) {
- @Override
- public boolean isValidValue(Object valueForm) {
- return false;
- }
+ @Override
+ public boolean isValidValue(Object valueForm) {
+ return false;
+ }
- @Override
- public Object parse(String lexicalForm) throws DatatypeFormatException {
- RDFDatatype dt = TypeMapper.getInstance().getTypeByName(uri);
- if (dt == null)
- {
- throw new DatatypeFormatException("no registered Datatype for "+uri );
- }
- return dt.parse( lexicalForm );
- }
+ @Override
+ public Object parse(String lexicalForm) throws DatatypeFormatException {
+ RDFDatatype dt = TypeMapper.getInstance().getTypeByName(uri);
+ if (dt == null) {
+ throw new DatatypeFormatException("no registered Datatype for " + uri);
+ }
+ return dt.parse(lexicalForm);
+ }
- };
- } else {
- oValue = dt.parse( value );
- }
- LiteralLabel ll = LiteralLabelFactory.createByValue( oValue, null, dt );
- return NodeFactory.createLiteral(ll);
- }
+ };
+ } else {
+ oValue = dt.parse(value);
+ }
+ LiteralLabel ll = LiteralLabelFactory.createByValue(oValue, null, dt);
+ return NodeFactory.createLiteral(ll);
+ }
- /**
- * Makes a node from an object while using the associated prefix mapping.
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
- * prefixes if the object is a String</li>
- * <li>Will call makeLiteral() to create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- * @param o The object to convert (may be null).
- * @param pMapping The prefix mapping to use for prefix resolution.
- * @return The Node value.
- * @see #makeLiteral(Object)
- */
- public static Node makeNode(Object o, PrefixMapping pMapping) {
- if (o == null) {
- return Node.ANY;
- }
- if (o instanceof FrontsNode) {
- return checkVar(((FrontsNode) o).asNode());
- }
+ /**
+ * Makes a node from an object while using the associated prefix mapping.
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
+ * prefixes if the object is a String</li>
+ * <li>Will call makeLiteral() to create a literal representation if the
+ * parseNode() fails or for any other object type.</li>
+ * </ul>
+ *
+ * @param o The object to convert (may be null).
+ * @param pMapping The prefix mapping to use for prefix resolution.
+ * @return The Node value.
+ * @see #makeLiteral(Object)
+ */
+ public static Node makeNode(Object o, PrefixMapping pMapping) {
+ if (o == null) {
+ return Node.ANY;
+ }
+ if (o instanceof FrontsNode) {
+ return checkVar(((FrontsNode) o).asNode());
+ }
- if (o instanceof Node) {
- return checkVar( (Node) o );
- }
- if (o instanceof String) {
- try {
- return checkVar(NodeFactoryExtra.parseNode((String) o, PrefixMapFactory.create(pMapping)));
- } catch (final RiotException e) {
- // expected in some cases -- do nothing
- }
+ if (o instanceof Node) {
+ return checkVar((Node) o);
+ }
+ if (o instanceof String) {
+ try {
+ return checkVar(NodeFactoryExtra.parseNode((String) o, PrefixMapFactory.create(pMapping)));
+ } catch (final RiotException e) {
+ // expected in some cases -- do nothing
+ }
- }
- return makeLiteral( o );
- }
+ }
+ return makeLiteral(o);
+ }
- /**
- * Creates a Path or Node as appropriate.
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the object if it is a Path
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>Will call PathParser.parse() using the prefix mapping if the object is a String</li>
- * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
- * prefixes if the object is a String and the PathParser.parse() fails.</li>
- * <li>Will call makeLiteral() to create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- * @param o the object that should be interpreted as a path or a node.
- * @param pMapping the prefix mapping to resolve path or node with
- * @return the Path or Node
- * @see #makeLiteral(Object)
- */
- public static Object makeNodeOrPath(Object o, PrefixMapping pMapping)
- {
- if (o == null) {
- return Node.ANY;
- }
- if (o instanceof Path)
- {
- return o;
- }
- if (o instanceof FrontsNode) {
- return checkVar(((FrontsNode) o).asNode());
- }
+ /**
+ * Creates a Path or Node as appropriate.
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the object if it is a Path
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>Will call PathParser.parse() using the prefix mapping if the object is a
+ * String</li>
+ * <li>Will call NodeFactoryExtra.parseNode() using the currently defined
+ * prefixes if the object is a String and the PathParser.parse() fails.</li>
+ * <li>Will call makeLiteral() to create a literal representation if the
+ * parseNode() fails or for any other object type.</li>
+ * </ul>
+ *
+ * @param o the object that should be interpreted as a path or a node.
+ * @param pMapping the prefix mapping to resolve path or node with
+ * @return the Path or Node
+ * @see #makeLiteral(Object)
+ */
+ public static Object makeNodeOrPath(Object o, PrefixMapping pMapping) {
+ if (o == null) {
+ return Node.ANY;
+ }
+ if (o instanceof Path) {
+ return o;
+ }
+ if (o instanceof FrontsNode) {
+ return checkVar(((FrontsNode) o).asNode());
+ }
- if (o instanceof Node) {
- return checkVar((Node)o);
- }
- if (o instanceof String) {
- try {
- final Path p = PathParser.parse((String) o, pMapping);
- if (p instanceof P_Link)
- {
- return ((P_Link)p).getNode();
- }
- return p;
- }
+ if (o instanceof Node) {
+ return checkVar((Node) o);
+ }
+ if (o instanceof String) {
+ try {
+ final Path p = PathParser.parse((String) o, pMapping);
+ if (p instanceof P_Link) {
+ return ((P_Link) p).getNode();
+ }
+ return p;
+ }
- catch (final Exception e)
- {
- // expected in some cases -- do nothing
- }
+ catch (final Exception e) {
+ // expected in some cases -- do nothing
+ }
- }
- return makeNode( o, pMapping );
- }
+ }
+ return makeNode(o, pMapping);
+ }
- /**
- * Makes a Var from an object.
- * <ul>
- * <li>Will return Var.ANON if object is null.</li>
- * <li>Will return null if the object is "*" or Node_RuleVariable.WILD</li>
- * <li>Will return the object if it is a Var</li>
- * <li>Will return resolve FrontsNode to Node and then resolve to Var</li>
- * <li>Will return resolve Node if the Node implements Node_Variable,
- * otherwise throws an NotAVariableException (instance of
- * ARQInternalErrorException)</li>
- * <li>Will return ?x if object is "?x"</li>
- * <li>Will return ?x if object is "x"</li>
- * <li>Will return the enclosed Var of a ExprVar</li>
- * <li>For all other objects will return the "?" prefixed to the toString()
- * value.</li>
- * </ul>
- *
- * @param o
- * The object to convert.
- * @return the Var value.
- * @throws ARQInternalErrorException
- */
- public static Var makeVar(Object o) throws ARQInternalErrorException {
- if (o == null) {
- return Var.ANON;
- }
- if (o instanceof Var) {
- return (Var) o;
- }
- Var retval = null;
- if (o instanceof FrontsNode) {
- retval = Var.alloc(((FrontsNode) o).asNode());
- } else if (o instanceof Node) {
- retval = Var.alloc((Node) o);
- } else if (o instanceof ExprVar) {
- retval = Var.alloc((ExprVar) o);
- } else {
- retval = Var.alloc(Var.canonical(o.toString()));
- }
- if ("*".equals(Var.canonical(retval.toString()))) {
- return null;
- }
- return retval;
- }
+ /**
+ * Makes a Var from an object.
+ * <ul>
+ * <li>Will return Var.ANON if object is null.</li>
+ * <li>Will return null if the object is "*" or Node_RuleVariable.WILD</li>
+ * <li>Will return the object if it is a Var</li>
+ * <li>Will return resolve FrontsNode to Node and then resolve to Var</li>
+ * <li>Will return resolve Node if the Node implements Node_Variable, otherwise
+ * throws an NotAVariableException (instance of ARQInternalErrorException)</li>
+ * <li>Will return ?x if object is "?x"</li>
+ * <li>Will return ?x if object is "x"</li>
+ * <li>Will return the enclosed Var of a ExprVar</li>
+ * <li>For all other objects will return the "?" prefixed to the toString()
+ * value.</li>
+ * </ul>
+ *
+ * @param o The object to convert.
+ * @return the Var value.
+ * @throws ARQInternalErrorException
+ */
+ public static Var makeVar(Object o) throws ARQInternalErrorException {
+ if (o == null) {
+ return Var.ANON;
+ }
+ if (o instanceof Var) {
+ return (Var) o;
+ }
+ Var retval = null;
+ if (o instanceof FrontsNode) {
+ retval = Var.alloc(((FrontsNode) o).asNode());
+ } else if (o instanceof Node) {
+ retval = Var.alloc((Node) o);
+ } else if (o instanceof ExprVar) {
+ retval = Var.alloc((ExprVar) o);
+ } else {
+ retval = Var.alloc(Var.canonical(o.toString()));
+ }
+ if ("*".equals(Var.canonical(retval.toString()))) {
+ return null;
+ }
+ return retval;
+ }
- /**
- * A convenience method to quote a string.
- * @param q the string to quote.
- *
- * Will use single quotes if there are no single quotes in the string or if the
- * double quote is before the single quote in the string.
- *
- * Will use double quote otherwise.
- *
- * @return the quoted string.
- */
- public static String quoted(String q) {
- int qt = q.indexOf('"');
- int sqt = q.indexOf("'");
- if (qt == -1) {
- qt = Integer.MAX_VALUE;
- }
- if (sqt == -1) {
- sqt = Integer.MAX_VALUE;
- }
+ /**
+ * A convenience method to quote a string.
+ *
+ * @param q the string to quote.
+ *
+ * Will use single quotes if there are no single quotes in the string or if the
+ * double quote is before the single quote in the string.
+ *
+ * Will use double quote otherwise.
+ *
+ * @return the quoted string.
+ */
+ public static String quoted(String q) {
+ int qt = q.indexOf('"');
+ int sqt = q.indexOf("'");
+ if (qt == -1) {
+ qt = Integer.MAX_VALUE;
+ }
+ if (sqt == -1) {
+ sqt = Integer.MAX_VALUE;
+ }
- if (qt <= sqt)
- {
- return String.format( "'%s'", q);
- }
- return String.format( "\"%s\"", q);
- }
+ if (qt <= sqt) {
+ return String.format("'%s'", q);
+ }
+ return String.format("\"%s\"", q);
+ }
- /**
- * Creates a collection of nodes from an iterator of Objects.
- * @param iter the iterator of objects, may be null or empty.
- * @param prefixMapping the PrefixMapping to use when nodes are created.
- * @return a Collection of nodes or null if iter is null or empty.
- */
- public static Collection<Node> makeValueNodes( Iterator<?> iter, PrefixMapping prefixMapping )
- {
- if (iter == null || !iter.hasNext())
- {
- return null;
- }
- final List<Node> values = new ArrayList<Node>();
- while (iter.hasNext())
- {
- final Object o = iter.next();
- // handle null as UNDEF
- if (o == null)
- {
- values.add( null );
- } else
- {
- values.add( makeNode( o, prefixMapping ));
- }
- }
- return values;
- }
+ /**
+ * Creates a collection of nodes from an iterator of Objects.
+ *
+ * @param iter the iterator of objects, may be null or empty.
+ * @param prefixMapping the PrefixMapping to use when nodes are created.
+ * @return a Collection of nodes or null if iter is null or empty.
+ */
+ public static Collection<Node> makeValueNodes(Iterator<?> iter, PrefixMapping prefixMapping) {
+ if (iter == null || !iter.hasNext()) {
+ return null;
+ }
+ final List<Node> values = new ArrayList<Node>();
+ while (iter.hasNext()) {
+ final Object o = iter.next();
+ // handle null as UNDEF
+ if (o == null) {
+ values.add(null);
+ } else {
+ values.add(makeNode(o, prefixMapping));
+ }
+ }
+ return values;
+ }
}
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
index 1b2c2aa..5234f3e 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/DescribeBuilder.java
@@ -41,361 +41,362 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
/**
* Builder for SPARQL Describe Queries.
* <p>
- * The DescribeBuilder provides chainable methods to programmatically generate SPARQL Describe Queries.
- * The application order of the methods is not relevant for the resulting query.
- * An {@link ExprFactory} is intended for use along with the DescribeBuilder to generate needed {@link Expr} parameter values.
- * An {@link ExprFactory} that works with the same prefixes can be obtained with {@link DescribeBuilder#getExprFactory()}.
+ * The DescribeBuilder provides chainable methods to programmatically generate
+ * SPARQL Describe Queries. The application order of the methods is not relevant
+ * for the resulting query. An {@link ExprFactory} is intended for use along
+ * with the DescribeBuilder to generate needed {@link Expr} parameter values. An
+ * {@link ExprFactory} that works with the same prefixes can be obtained with
+ * {@link DescribeBuilder#getExprFactory()}.
* <p>
- * The DescribeBuilder can be used as <b>prepared query</b>.
- * Values for variables in the created query can be set with {@link DescribeBuilder#setVar(Object, Object)} and {@link DescribeBuilder#setVar(Var, Node)}.
- * The method {@link DescribeBuilder#clearWhereValues()} allows to clear the set values.
+ * The DescribeBuilder can be used as <b>prepared query</b>. Values for
+ * variables in the created query can be set with
+ * {@link DescribeBuilder#setVar(Object, Object)} and
+ * {@link DescribeBuilder#setVar(Var, Node)}. The method
+ * {@link DescribeBuilder#clearWhereValues()} allows to clear the set values.
*
* @see AskBuilder
* @see ConstructBuilder
* @see SelectBuilder
* @see UpdateBuilder
*/
-public class DescribeBuilder extends AbstractQueryBuilder<DescribeBuilder> implements
-DatasetClause<DescribeBuilder>,
- WhereClause<DescribeBuilder>, SolutionModifierClause<DescribeBuilder>, SelectClause<DescribeBuilder>{
-
- private final HandlerBlock handlerBlock;
-
- public DescribeBuilder() {
- super();
- query.setQueryDescribeType();
- handlerBlock = new HandlerBlock(query);
- }
-
- @Override
- public SelectHandler getSelectHandler() {
- return handlerBlock.getSelectHandler();
- }
-
- @Override
- public DescribeBuilder addVar(Object var) {
- getSelectHandler().addVar(Converters.makeVar(var));
- return this;
- }
-
- @Override
- public DescribeBuilder addVar(Expr expr, Object var) {
- getSelectHandler().addVar(expr, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public DescribeBuilder addVar(String expr, Object var) throws ParseException {
- getSelectHandler().addVar(expr, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public List<Var> getVars() {
- return getSelectHandler().getVars();
- }
-
- @Override
- public DescribeBuilder addOrderBy(Expr orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public DescribeBuilder addOrderBy(Object orderBy) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
- return this;
- }
-
- @Override
- public DescribeBuilder addOrderBy(SortCondition orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public DescribeBuilder addOrderBy(Expr orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(orderBy, order);
- return this;
- }
-
- @Override
- public DescribeBuilder addOrderBy(Object orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
- return this;
- }
-
- @Override
- public DescribeBuilder addGroupBy(Object groupBy) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
- return this;
- }
-
- @Override
- public DescribeBuilder addGroupBy(Expr groupBy) {
- getSolutionModifierHandler().addGroupBy(groupBy);
- return this;
- }
-
- @Override
- public DescribeBuilder addGroupBy(Object var, Expr expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
- return this;
- }
-
- @Override
- public DescribeBuilder addGroupBy(Object var, String expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
- return this;
- }
-
- @Override
- public DescribeBuilder addHaving(String expression) throws ParseException {
- getSolutionModifierHandler().addHaving(expression);
- return this;
- }
-
- @Override
- public DescribeBuilder addHaving(Expr expression) throws ParseException {
- getSolutionModifierHandler().addHaving(expression);
- return this;
- }
-
- @Override
- public DescribeBuilder addHaving(Object var) throws ParseException {
- getSolutionModifierHandler().addHaving(Converters.makeVar(var));
- return this;
- }
-
- @Override
- public DescribeBuilder setLimit(int limit) {
- getSolutionModifierHandler().setLimit(limit);
- return this;
- }
-
- @Override
- public DescribeBuilder setOffset(int offset) {
- getSolutionModifierHandler().setOffset(offset);
- return this;
- }
-
- @Override
- public SolutionModifierHandler getSolutionModifierHandler() {
- return handlerBlock.getModifierHandler();
- }
-
- @Override
- public DescribeBuilder addWhere(Triple t) {
- getWhereHandler().addWhere(new TriplePath(t));
- return this;
- }
-
- @Override
- public DescribeBuilder addWhere(TriplePath t) {
- getWhereHandler().addWhere(t);
- return this;
- }
-
- @Override
- public DescribeBuilder addWhere(FrontsTriple t) {
- getWhereHandler().addWhere(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public DescribeBuilder addWhere(Object s, Object p, Object o) {
- getWhereHandler().addWhere( makeTriplePath(s,p,o));
- return this;
- }
-
- @Override
- public DescribeBuilder addWhereValueVar(Object var) {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
- return this;
- }
-
- @Override
- public DescribeBuilder addWhereValueVar(Object var, Object... values)
- {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
- return this;
- }
-
- @Override
- public <K extends Collection<?>> DescribeBuilder addWhereValueVars(Map<?,K> dataTable)
- {
- getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
- return this;
- }
-
- @Override
- public DescribeBuilder addWhereValueRow(Object... values)
- {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public DescribeBuilder addWhereValueRow(Collection<?> values) {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public List<Var> getWhereValuesVars() {
- return getWhereHandler().getValuesVars();
- }
-
- @Override
- public Map<Var, List<Node>> getWhereValuesMap() {
- return getWhereHandler().getValuesMap();
- }
-
- @Override
- public DescribeBuilder clearWhereValues() {
- getWhereHandler().clearValues();
- return this;
- }
-
- @Override
- public DescribeBuilder addOptional(Triple t) {
- getWhereHandler().addOptional( new TriplePath( t ) );
- return this;
- }
-
- @Override
- public DescribeBuilder addOptional(TriplePath t) {
- getWhereHandler().addOptional( t );
- return this;
- }
-
- @Override
- public DescribeBuilder addOptional(FrontsTriple t) {
- getWhereHandler().addOptional( new TriplePath( t.asTriple() ) );
- return this;
- }
-
- @Override
- public DescribeBuilder addOptional(Object s, Object p, Object o) {
- getWhereHandler().addOptional( makeTriplePath( s, p, o ) );
- return this;
- }
-
- @Override
- public DescribeBuilder addOptional(AbstractQueryBuilder<?> t) {
- getWhereHandler().addOptional(t.getWhereHandler());
- return this;
- }
-
- @Override
- public DescribeBuilder addFilter(String expression) throws ParseException {
- getWhereHandler().addFilter(expression);
- return this;
- }
-
- @Override
- public DescribeBuilder addFilter(Expr expression) {
- getWhereHandler().addFilter(expression);
- return this;
- }
-
- @Override
- public DescribeBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addSubQuery(subQuery);
- return this;
- }
-
- @Override
- public DescribeBuilder addUnion(AbstractQueryBuilder<?> union) {
- getWhereHandler().addUnion(union);
- return this;
- }
-
- @Override
- public DescribeBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
- getPrologHandler().addAll(subQuery.getPrologHandler());
- getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
- return this;
- }
- @Override
- public DescribeBuilder addGraph(Object graph, FrontsTriple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
- return this;
- }
- @Override
- public DescribeBuilder addGraph(Object graph, Object subject, Object predicate, Object object)
- {
- getWhereHandler().addGraph(makeNode(graph), makeTriplePath( subject, predicate, object ));
- return this;
- }
- @Override
- public DescribeBuilder addGraph(Object graph, Triple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
- return this;
- }
- @Override
- public DescribeBuilder addGraph(Object graph, TriplePath triplePath) {
- getWhereHandler().addGraph(makeNode(graph), triplePath );
- return this;
- }
-
- @Override
- public DescribeBuilder addBind(Expr expression, Object var) {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public DescribeBuilder addBind(String expression, Object var) throws ParseException {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public Node list(Object... objs) {
- return getWhereHandler().list(objs);
- }
-
- @Override
- public DescribeBuilder addMinus(AbstractQueryBuilder<?> t) {
- getWhereHandler().addMinus( t );
- return this;
- }
-
- @Override
- public DescribeBuilder fromNamed(String graphName) {
- getDatasetHandler().fromNamed(graphName);
- return this;
- }
-
- @Override
- public DescribeBuilder fromNamed(Collection<String> graphNames) {
- getDatasetHandler().fromNamed(graphNames);
- return this;
- }
-
- @Override
- public DescribeBuilder from(String graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public DescribeBuilder from(Collection<String> graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public DatasetHandler getDatasetHandler() {
- return handlerBlock.getDatasetHandler();
- }
-
- @Override
- public HandlerBlock getHandlerBlock() {
- return handlerBlock;
- }
-
-
+public class DescribeBuilder extends AbstractQueryBuilder<DescribeBuilder> implements DatasetClause<DescribeBuilder>,
+ WhereClause<DescribeBuilder>, SolutionModifierClause<DescribeBuilder>, SelectClause<DescribeBuilder> {
+
+ private final HandlerBlock handlerBlock;
+
+ public DescribeBuilder() {
+ super();
+ query.setQueryDescribeType();
+ handlerBlock = new HandlerBlock(query);
+ }
+
+ @Override
+ public SelectHandler getSelectHandler() {
+ return handlerBlock.getSelectHandler();
+ }
+
+ @Override
+ public DescribeBuilder addVar(Object var) {
+ getSelectHandler().addVar(Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addVar(Expr expr, Object var) {
+ getSelectHandler().addVar(expr, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addVar(String expr, Object var) throws ParseException {
+ getSelectHandler().addVar(expr, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public List<Var> getVars() {
+ return getSelectHandler().getVars();
+ }
+
+ @Override
+ public DescribeBuilder addOrderBy(Expr orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOrderBy(Object orderBy) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOrderBy(SortCondition orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOrderBy(Expr orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(orderBy, order);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOrderBy(Object orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGroupBy(Object groupBy) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGroupBy(Expr groupBy) {
+ getSolutionModifierHandler().addGroupBy(groupBy);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGroupBy(Object var, Expr expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGroupBy(Object var, String expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addHaving(String expression) throws ParseException {
+ getSolutionModifierHandler().addHaving(expression);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addHaving(Expr expression) throws ParseException {
+ getSolutionModifierHandler().addHaving(expression);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addHaving(Object var) throws ParseException {
+ getSolutionModifierHandler().addHaving(Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder setLimit(int limit) {
+ getSolutionModifierHandler().setLimit(limit);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder setOffset(int offset) {
+ getSolutionModifierHandler().setOffset(offset);
+ return this;
+ }
+
+ @Override
+ public SolutionModifierHandler getSolutionModifierHandler() {
+ return handlerBlock.getModifierHandler();
+ }
+
+ @Override
+ public DescribeBuilder addWhere(Triple t) {
+ getWhereHandler().addWhere(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhere(TriplePath t) {
+ getWhereHandler().addWhere(t);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhere(FrontsTriple t) {
+ getWhereHandler().addWhere(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhere(Object s, Object p, Object o) {
+ getWhereHandler().addWhere(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhereValueVar(Object var) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhereValueVar(Object var, Object... values) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
+ return this;
+ }
+
+ @Override
+ public <K extends Collection<?>> DescribeBuilder addWhereValueVars(Map<?, K> dataTable) {
+ getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhereValueRow(Object... values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addWhereValueRow(Collection<?> values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public List<Var> getWhereValuesVars() {
+ return getWhereHandler().getValuesVars();
+ }
+
+ @Override
+ public Map<Var, List<Node>> getWhereValuesMap() {
+ return getWhereHandler().getValuesMap();
+ }
+
+ @Override
+ public DescribeBuilder clearWhereValues() {
+ getWhereHandler().clearValues();
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOptional(Triple t) {
+ getWhereHandler().addOptional(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOptional(TriplePath t) {
+ getWhereHandler().addOptional(t);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOptional(FrontsTriple t) {
+ getWhereHandler().addOptional(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOptional(Object s, Object p, Object o) {
+ getWhereHandler().addOptional(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addOptional(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addOptional(t.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addFilter(String expression) throws ParseException {
+ getWhereHandler().addFilter(expression);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addFilter(Expr expression) {
+ getWhereHandler().addFilter(expression);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addSubQuery(subQuery);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addUnion(AbstractQueryBuilder<?> union) {
+ getWhereHandler().addUnion(union);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
+ getPrologHandler().addAll(subQuery.getPrologHandler());
+ getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGraph(Object graph, FrontsTriple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGraph(Object graph, Object subject, Object predicate, Object object) {
+ getWhereHandler().addGraph(makeNode(graph), makeTriplePath(subject, predicate, object));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGraph(Object graph, Triple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addGraph(Object graph, TriplePath triplePath) {
+ getWhereHandler().addGraph(makeNode(graph), triplePath);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addBind(Expr expression, Object var) {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder addBind(String expression, Object var) throws ParseException {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public Node list(Object... objs) {
+ return getWhereHandler().list(objs);
+ }
+
+ @Override
+ public DescribeBuilder addMinus(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addMinus(t);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder fromNamed(String graphName) {
+ getDatasetHandler().fromNamed(graphName);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder fromNamed(Collection<String> graphNames) {
+ getDatasetHandler().fromNamed(graphNames);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder from(String graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public DescribeBuilder from(Collection<String> graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public DatasetHandler getDatasetHandler() {
+ return handlerBlock.getDatasetHandler();
+ }
+
+ @Override
+ public HandlerBlock getHandlerBlock() {
+ return handlerBlock;
+ }
}
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ExprFactory.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ExprFactory.java
index d1cdd61..9544502 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ExprFactory.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/ExprFactory.java
@@ -119,1676 +119,1555 @@ import org.apache.jena.sparql.expr.NodeValue;
*/
public class ExprFactory {
- private final PrefixMapping pMap;
-
- /**
- * Constructs an expression factor with the specified prefix definitions.
- * @param pMap the PrefixMapping to use in the expressions.
- */
- public ExprFactory(PrefixMapping pMap) {
- this.pMap = pMap;
- }
-
- /**
- * Constructs an expression factory with the prefix definitions found in
- * {@code PrefixMapping.Extended}
- * @see PrefixMapping#Extended
- */
- public ExprFactory() {
- this(PrefixMapping.Extended);
- }
-
- // expr 0 functions
-
- /**
- * implements rand() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-rand
- *
- * @see org.apache.jena.sparql.expr.E_Random
- * @return E_Random instance
- */
- public final E_Random rand() {
- return new E_Random();
- }
-
- /**
- * implements struuid() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-struuid
- *
- * @see org.apache.jena.sparql.expr.E_StrUUID
- * @return E_StrUUID instance
- */
- public final E_StrUUID struuid() {
- return new E_StrUUID();
- }
-
- /**
- * implements uuid() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-uuid
- *
- * @see org.apache.jena.sparql.expr.E_UUID
- * @return E_UUID instance
- */
- public final E_UUID uuid() {
- return new E_UUID();
- }
-
- /**
- * Returns the current ARQ name and version number as a string.
- *
- * @see org.apache.jena.sparql.expr.E_Version
- * @return E_Version instance
- */
- public final E_Version version() {
- return new E_Version();
- }
-
- /**
- * implements now() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-now
- *
- * @see org.apache.jena.sparql.expr.E_Now
- * @return E_Now instance
- */
- public final E_Now now() {
- return new E_Now();
- }
-
- // expr 1 functions
-
- /**
- * implements bound() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-bound
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Bound
- *
- * @param expr
- * the expression to check.
- * @return E_Bound instance
- */
- public final E_Bound bound(Object expr) {
- return new E_Bound(asExpr(expr));
- }
-
- /**
- * implements datatype() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-datatype
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Datatype
- *
- * @param expr
- * the expression to check.
- * @return E_Datatype instance
- */
- public final E_Datatype datatype(Object expr) {
- return new E_Datatype(asExpr(expr));
- }
-
- /**
- * implements day() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-day
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- *
- * @param expr
- * the expression to check.
- * @return E_Datatype instance
- */
- public final E_DateTimeDay day(Object expr) {
- return new E_DateTimeDay(asExpr(expr));
- }
-
- /**
- * implements hours() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-hours
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeHours
- *
- * @param expr
- * the expression to check.
- * @return E_DateTimeHours instance
- */
- public final E_DateTimeHours hours(Object expr) {
- return new E_DateTimeHours(asExpr(expr));
- }
-
- /**
- * implements minutes() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-minutes
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeMinutes
- *
- * @param expr
- * the expression to check.
- * @return E_DateTimeMinutes instance
- */
- public final E_DateTimeMinutes minutes(Object expr) {
- return new E_DateTimeMinutes(asExpr(expr));
- }
-
- /**
- * implements month() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-month
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeMonth
- *
- * @param expr
- * the expression to check.
- * @return E_DateTimeMonth instance
- */
- public final E_DateTimeMonth month(Object expr) {
- return new E_DateTimeMonth(asExpr(expr));
- }
-
- /**
- * implements seconds() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-seconds
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeSeconds
- *
- * @param expr
- * the expression to check.
- * @return E_DateTimeSeconds instance
- */
- public final E_DateTimeSeconds seconds(Object expr) {
- return new E_DateTimeSeconds(asExpr(expr));
- }
-
- /**
- * implements timezone() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-timezone
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeTimezone
- *
- * @param expr
- * the expression to check.
- * @return E_DateTypeTimezone instance
- */
- public final E_DateTimeTimezone timezone(Object expr) {
- return new E_DateTimeTimezone(asExpr(expr));
- }
-
- /**
- * implements tz() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-tz
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeTZ
- *
- * @param expr
- * the expression to check.
- * @return E_DateTimeTZ instance
- */
- public final E_DateTimeTZ tz(Object expr) {
- return new E_DateTimeTZ(asExpr(expr));
- }
-
- /**
- * implements year() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-year
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_DateTimeYear
- *
- * @param expr
- * the expression to check.
- * @return E_DateTimeYear instance
- */
- public final E_DateTimeYear year(Object expr) {
- return new E_DateTimeYear(asExpr(expr));
- }
-
- /**
- * implements iri() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-iri
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_IRI
- *
- * @param expr
- * the expression to check.
- * @return E_IRI instance
- */
- public final E_IRI iri(Object expr) {
- return new E_IRI(asExpr(expr));
- }
-
- /**
- * implements isBlank() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isBlank
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_IsBlank
- *
- * @param expr
- * the expression to check.
- * @return E_isBlank instance
- */
- public final E_IsBlank isBlank(Object expr) {
- return new E_IsBlank(asExpr(expr));
- }
-
- /**
- * implements isIRI() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isIRI
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_IsIRI
- *
- * @param expr
- * the expression to check.
- * @return E_IsIRI instance
- */
- public final E_IsIRI isIRI(Object expr) {
- return new E_IsIRI(asExpr(expr));
- }
-
- /**
- * implements isLiteral() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isLiteral
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_IsLiteral
- *
- * @param expr
- * the expression to check.
- * @return E_IsLiteral instance
- */
- public final E_IsLiteral isLiteral(Object expr) {
- return new E_IsLiteral(asExpr(expr));
- }
-
- /**
- * implements isNumeric() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isNumeric
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_IsNumeric
- *
- * @param expr
- * the expression to check.
- * @return E_IsNumeric instance
- */
- public final E_IsNumeric isNumeric(Object expr) {
- return new E_IsNumeric(asExpr(expr));
- }
-
- /**
- * implements lang() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-lang
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Lang
- *
- * @param expr
- * the expression to check.
- * @return E_Lang instance
- */
- public final E_Lang lang(Object expr) {
- return new E_Lang(asExpr(expr));
- }
-
- /**
- * implements not() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-not
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_LogicalNot
- *
- * @param expr
- * the expression to check.
- * @return E_LogicalNot instance
- */
- public final E_LogicalNot not(Object expr) {
- return new E_LogicalNot(asExpr(expr));
- }
-
- /**
- * implements abs() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-abs
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NumAbs
- *
- * @param expr
- * the expression to check.
- * @return E_NumAbs instance
- */
- public final E_NumAbs abs(Object expr) {
- return new E_NumAbs(asExpr(expr));
- }
-
- /**
- * implements ceil() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-ceil
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NumCeiling
- *
- * @param expr
- * the expression to check.
- * @return E_NumCeiling instance
- */
- public final E_NumCeiling ceil(Object expr) {
- return new E_NumCeiling(asExpr(expr));
- }
-
- /**
- * implements floor() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-floor
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NumFloor
- *
- * @param expr
- * the expression to check.
- * @return E_NumFloor instance
- */
- public final E_NumFloor floor(Object expr) {
- return new E_NumFloor(asExpr(expr));
- }
-
- /**
- * implements round() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-round
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NumRound
- *
- * @param expr
- * the expression to check.
- * @return E_Round instance
- */
- public final E_NumRound round(Object expr) {
- return new E_NumRound(asExpr(expr));
- }
-
- /**
- * implements str() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-str
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Str
- *
- * @param expr
- * the expression to check.
- * @return E_Str instance
- */
- public final E_Str str(Object expr) {
- return new E_Str(asExpr(expr));
- }
-
- /**
- * implements encode() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-encode
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrEncodeForURI
- *
- * @param expr
- * the expression to check.
- * @return E_StrEncodedForURI instance
- */
- public final E_StrEncodeForURI encode(Object expr) {
- return new E_StrEncodeForURI(asExpr(expr));
- }
-
- /**
- * implements strlen() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strlen
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrLength
- *
- * @param expr
- * the expression to check.
- * @return E_StrLength instance
- */
- public final E_StrLength strlen(Object expr) {
- return new E_StrLength(asExpr(expr));
- }
-
- /**
- * implements lcase() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-lcase
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrLowerCase
- *
- * @param expr
- * the expression to check.
- * @return E_StrLowerCase instance
- */
- public final E_StrLowerCase lcase(Object expr) {
- return new E_StrLowerCase(asExpr(expr));
- }
-
- /**
- * implements ucase() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-ucase
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrUpperCase
- *
- * @param expr
- * the expression to check.
- * @return E_StrUpperCase instance
- */
- public final E_StrUpperCase ucase(Object expr) {
- return new E_StrUpperCase(asExpr(expr));
- }
-
- /**
- * implements unary minus as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_UnaryMinus
- *
- * @param expr
- * the expression to check.
- * @return E_UnaryMinus instance
- */
- public final E_UnaryMinus minus(Object expr) {
- return new E_UnaryMinus(asExpr(expr));
- }
-
- /**
- * implements unary plus as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_UnaryPlus
- *
- * @param expr
- * the expression to check.
- * @return E_UnaryPlus instance
- */
- public final E_UnaryPlus plus(Object expr) {
- return new E_UnaryPlus(asExpr(expr));
- }
-
- /**
- * implements md5() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-md5
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_MD5
- *
- * @param expr
- * the expression to check.
- * @return E_MD5 instance
- */
- public final E_MD5 md5(Object expr) {
- return new E_MD5(asExpr(expr));
- }
-
- /**
- * implements sha1() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha1
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_SHA1
- *
- * @param expr
- * the expression to check.
- * @return E_SHA1 instance
- */
- public final E_SHA1 sha1(Object expr) {
- return new E_SHA1(asExpr(expr));
- }
-
- /**
- * implements sha224() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha224
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_SHA224
- *
- * @param expr
- * the expression to check.
- * @return E_SHA224 instance
- */
- public final E_SHA224 sha224(Object expr) {
- return new E_SHA224(asExpr(expr));
- }
-
- /**
- * implements sha256() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha256
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_SHA256
- *
- * @param expr
- * the expression to check.
- * @return E_SHA256 instance
- */
- public final E_SHA256 sha256(Object expr) {
- return new E_SHA256(asExpr(expr));
- }
-
- /**
- * implements sha384() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha384
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_SHA384
- *
- * @param expr
- * the expression to check.
- * @return E_SHA384 instance
- */
- public final E_SHA384 sha384(Object expr) {
- return new E_SHA384(asExpr(expr));
- }
-
- /**
- * implements sha512() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha512
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_SHA512
- *
- * @param expr
- * the expression to check.
- * @return E_SHA512 instance
- */
- public final E_SHA512 sha512(Object expr) {
- return new E_SHA512(asExpr(expr));
- }
-
- // expr2 functions
-
- /**
- * implements addition as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Add
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_Add instance
- */
- public final E_Add add(Object expr1, Object expr2) {
- return new E_Add(asExpr(expr1), asExpr(expr2));
- }
-
- // E_Cast has a private constructor and seems not to be used.
- // public final E_Cast cast( Expr expr1, Expr expr2 )
- // {
- // return new E_Cast( expr1, expr2 );
- // }
- /**
- * implements division as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Divide
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_Devide instance
- */
- public final E_Divide divide(Object expr1, Object expr2) {
- return new E_Divide(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements equality as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Equals
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_Equals instance
- */
- public final E_Equals eq(Object expr1, Object expr2) {
- return new E_Equals(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements greater than as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_GreaterThan
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_GreaterThan instance
- */
- public final E_GreaterThan gt(Object expr1, Object expr2) {
- return new E_GreaterThan(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements greater than or equal as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_GreaterThanOrEqual
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_GreaterThanOrEqual instance
- */
- public final E_GreaterThanOrEqual ge(Object expr1, Object expr2) {
- return new E_GreaterThanOrEqual(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements langMatches() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-langMatches
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_LangMatches
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_LangMatches instance
- */
- public final E_LangMatches langMatches(Object expr1, Object expr2) {
- return new E_LangMatches(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements less than as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_LessThan
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_LessThan instance
- */
- public final E_LessThan lt(Object expr1, Object expr2) {
- return new E_LessThan(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements less than or equal as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_LessThanOrEqual
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_LessThanOrEqual instance
- */
- public final E_LessThanOrEqual le(Object expr1, Object expr2) {
- return new E_LessThanOrEqual(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements logical and as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_LogicalAnd
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_LogicalAnd instance
- */
- public final E_LogicalAnd and(Object expr1, Object expr2) {
- return new E_LogicalAnd(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements logical or as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_LogicalOr
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_LogicalOr instance
- */
- public final E_LogicalOr or(Object expr1, Object expr2) {
- return new E_LogicalOr(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements multiplication s per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Multiply
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_Multiply instance
- */
- public final E_Multiply multiply(Object expr1, Object expr2) {
- return new E_Multiply(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements not equals as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NotEquals
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_NotEquals instance
- */
- public final E_NotEquals ne(Object expr1, Object expr2) {
- return new E_NotEquals(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements sameTerm() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sameTerm
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_SameTerm
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_SameTerm instance
- */
- public final E_SameTerm sameTerm(Object expr1, Object expr2) {
- return new E_SameTerm(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements strafter() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strafter
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrAfter
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrAfter instance
- */
- public final E_StrAfter strafter(Object expr1, Object expr2) {
- return new E_StrAfter(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements strbefore() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strbefore
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrBefore
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrBefore instance
- */
- public final E_StrBefore strbefore(Object expr1, Object expr2) {
- return new E_StrBefore(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements contains() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-contains
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrContains
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrContains instance
- */
- public final E_StrContains contains(Object expr1, Object expr2) {
- return new E_StrContains(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements strdt() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strdt
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrDatatype
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrDatatype instance
- */
- public final E_StrDatatype strdt(Object expr1, Object expr2) {
- return new E_StrDatatype(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements strends() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strends
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrEndsWith
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrEndsWith instance
- */
- public final E_StrEndsWith strends(Object expr1, Object expr2) {
- return new E_StrEndsWith(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements strlang() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strlang
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrLang
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrLang instance
- */
- public final E_StrLang strlang(Object expr1, Object expr2) {
- return new E_StrLang(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements strstarts() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strstarts
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrStartsWith
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_StrStartsWith instance
- */
- public final E_StrStartsWith strstarts(Object expr1, Object expr2) {
- return new E_StrStartsWith(asExpr(expr1), asExpr(expr2));
- }
-
- /**
- * implements subtraction as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Subtract
- *
- * @param expr1
- * the first expression.
- * @param expr2
- * the second expression.
- * @return E_Subtract instance
- */
-
- public final E_Subtract subtract(Object expr1, Object expr2) {
- return new E_Subtract(asExpr(expr1), asExpr(expr2));
- }
-
- // expr3 functions
-
- /**
- * implements if() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-if
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Conditional
- *
- * @param condition
- * the condition to check.
- * @param thenExpr
- * the expression to execute if condition is true.
- * @param elseExpr
- * the expression to execute if condition is false.
- * @return an E_Conditional instance.
- */
- public final E_Conditional cond(Expr condition, Expr thenExpr, Expr elseExpr) {
- return new E_Conditional(condition, thenExpr, elseExpr);
- }
-
- // exprN functions
- /**
- * implements bnode() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-bnode
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_BNode
- *
- * @param expr1
- * the blank node id.
- * @return an E_BNode instance
- */
- public final E_BNode bnode(Object expr1) {
- return new E_BNode(asExpr(expr1));
- }
-
- /**
- * implements bnode() as per SPARQL 1.1 spec
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-bnode
- *
- * @see org.apache.jena.sparql.expr.E_Random
- *
- * @return an E_BNode instance.
- */
- public final E_BNode bnode() {
- return new E_BNode();
- }
-
- /**
- * Creates a dynamic function call.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
- *
- * Converts function to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_FunctionDynamic
- *
- * @param function
- * The function to execute
- * @param args
- * the arguments to the function.
- * @return an E_FunctionDynamic instance.
- */
- public final E_FunctionDynamic call(Object function, ExprList args) {
- return new E_FunctionDynamic(asExpr(function), args);
- }
-
- /**
- * Creates a dynamic function call.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
- *
- * Converts function to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_FunctionDynamic
- *
- * @param function
- * The function to execute
- * @param args
- * the arguments to the function.
- * @return an E_FunctionDynamic instance.
- */
- public final E_FunctionDynamic call(Object function, Object... args) {
- return call(asExpr(function), asList(args));
- }
-
- /**
- * Creates a function call as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
- *
- * @see org.apache.jena.sparql.expr.E_Call
- *
- * The first argument is the function to call
- *
- * @param args
- * the arguments to the function.
- * @return an E_Call instance.
- */
- public final E_Call call(ExprList args) {
- return new E_Call(args);
- }
-
- /**
- * implements coalesce() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-coalesce
- *
- * @see org.apache.jena.sparql.expr.E_Coalesce
- *
- * @param args
- * the arguments to the function.
- * @return an E_Coalesce instance.
- */
- public final E_Coalesce coalesce(ExprList args) {
- return new E_Coalesce(args);
- }
-
- /**
- * implements coalesce() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-coalesce
- *
- * @see org.apache.jena.sparql.expr.E_Coalesce
- *
- * @param args
- * the arguments to the function.
- * @return an E_Coalesce instance.
- */
- public final E_Coalesce coalesce(Object... args) {
- return new E_Coalesce(asList(args));
- }
-
- /**
- * Creates a function call as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
- *
- * @see org.apache.jena.sparql.expr.E_Function
- *
- * @param name
- * the name of the function.
- * @param args
- * the arguments to the function.
- * @return an E_Function instance.
- */
- public final E_Function function(String name, ExprList args) {
- return new E_Function(name, args);
- }
-
- /**
- * implements "not in" as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-not-in
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NotOneOf
- *
- * @param expr
- * the expression that is not in the list
- * @param list
- * the list of expressions.
- * @return an E_NotOneOf instance.
- */
- public final E_NotOneOf notin(Object expr, ExprList list) {
- return new E_NotOneOf(asExpr(expr), list);
- }
-
- /**
- * implements "not in" as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-not-in
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_NotOneOf
- *
- * @param expr
- * the expression that is not in the list
- * @param list
- * the list of expressions.
- * @return an E_NotOneOf instance.
- */
- public final E_NotOneOf notin(Object expr, Object... list) {
- return new E_NotOneOf(asExpr(expr), asList(list));
- }
-
- /**
- * implements "in" as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-in
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_OneOf
- *
- * @param expr
- * the expression that is not in the list
- * @param list
- * the list of expressions.
- * @return an E_OneOf instance.
- */
- public final E_OneOf in(Object expr, ExprList list) {
- return new E_OneOf(asExpr(expr), list);
- }
-
- /**
- * implements "in" as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-in
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_OneOf
- *
- * @param expr
- * the expression that is not in the list
- * @param list
- * the list of expressions.
- * @return an E_OneOf instance.
- */
- public final E_OneOf in(Object expr, Object... list) {
- return new E_OneOf(asExpr(expr), asList(list));
- }
-
- /**
- * implements regex() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-regex
- *
- * Converts objects to an Expr objects via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Regex
- *
- * @param expr
- * string to match.
- * @param pattern
- * the pattern to match
- * @param flags
- * the regex flags
- * @return an E_Regex instance.
- */
- public final E_Regex regex(Object expr, Object pattern, Object flags) {
- return new E_Regex(asExpr(expr), asExpr(pattern), asExpr(flags));
- }
-
- /**
- * implements regex() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-regex
- *
- * Converts expr to an Expr object via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_Regex
- *
- * @param expr
- * string to match.
- * @param pattern
- * the pattern to match
- * @param flags
- * the regex flags
- * @return an E_Regex instance.
- */
- public final E_Regex regex(Object expr, String pattern, String flags) {
- return new E_Regex(asExpr(expr), pattern, flags);
- }
-
- /**
- * implements concat() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-concat
- *
- * @see org.apache.jena.sparql.expr.E_StrConcat
- *
- * @param list
- * the list of arguments to concatenate
- * @return an E_StrConcat instance
- */
- public final E_StrConcat concat(ExprList list) {
- return new E_StrConcat(list);
- }
-
- /**
- * implements concat() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-concat
- *
- * @see org.apache.jena.sparql.expr.E_StrConcat
- *
- * @param list
- * the list of arguments to concatenate
- * @return an E_StrConcat instance
- */
- public final E_StrConcat concat(Object... list) {
- return new E_StrConcat(asList(list));
- }
-
- /**
- * implements replace() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-replace
- *
- * Converts Objects to an Expr objects via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrReplace
- *
- * @param arg
- * the string literal to replace
- * @param pattern
- * the pattern to replace in the string literal.
- * @param replacement
- * the string literal to replace the pattern with.
- * @param flags the flags that control replacement options.
- * @return an E_StrReplace instance
- */
- public final E_StrReplace replace(Object arg, Object pattern, Object replacement, Object flags) {
- return new E_StrReplace(asExpr(arg), asExpr(pattern), asExpr(replacement), asExpr(flags));
- }
-
- /**
- * implements replace() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-replace
- *
- * Converts Objects to an Expr objects via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrReplace
- *
- * @param arg
- * the string literal to replace
- * @param pattern
- * the pattern to replace in the string literal.
- * @param replacement
- * the string literal to replace the pattern with.
- * @return an E_StrReplace instance
- */
- public final E_StrReplace replace(Object arg, Object pattern, Object replacement) {
- return new E_StrReplace(asExpr(arg), asExpr(pattern), asExpr(replacement), null);
- }
-
- /**
- * implements substr() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-substr
- *
- * Converts Objects to an Expr objects via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrSubstring
- *
- * @param src
- * the expression to extract the substring from.
- * @param loc
- * the location within the expression string to start
- * @param len
- * the length of the string to extract.
- *
- * @return an E_Substring instance.
- */
- public final E_StrSubstring substr(Object src, Object loc, Object len) {
- return new E_StrSubstring(asExpr(src), asExpr(loc), asExpr(len));
- }
-
- /**
- * implements substr() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-substr
- *
- * Converts Objects to an Expr objects via expr()
- *
- * @see #asExpr(Object)
- * @see org.apache.jena.sparql.expr.E_StrSubstring
- *
- * @param src
- * the expression to extract the substring from.
- * @param loc
- * the location within the expression string to start
- *
- * @return an E_Substring instance.
- */
- public final E_StrSubstring substr(Object src, Object loc) {
- return new E_StrSubstring(asExpr(src), asExpr(loc), null);
- }
- // expr op
-
- /**
- * implements exists() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-filter-exists
- *
- * @see org.apache.jena.sparql.expr.E_Exists
- *
- * @param whereClause
- * A WhereClause to check existence of.
- * @return an E_Exists instance,
- */
- public final E_Exists exists(WhereClause<?> whereClause) {
- return new E_Exists(whereClause.getWhereHandler().getClause());
- }
-
- /**
- * implements not exists() as per the SPARQL 11 query definition.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-filter-exists
- *
- * @see org.apache.jena.sparql.expr.E_NotExists
- *
- * @param whereClause
- * the argument to the function.
- * @return an E_NotExists instance.
- */
- public final E_NotExists notexists(WhereClause<?> whereClause) {
- return new E_NotExists(whereClause.getWhereHandler().getClause());
- }
-
- // exprnone
- /**
- * Should probably be called "null" but that is a reserved work. An
- * expression that can be used in place of null.
- *
- * @see org.apache.jena.sparql.expr.ExprNone
- *
- * @return an ExprNone instance
- */
- public final ExprNone none() {
- return (ExprNone) Expr.NONE;
- }
-
- /**
- * Converts the object to a ExprVar.
- * <ul>
- * <li>If the object is an ExprVar return it</li>
- * <li>Will return null if the object is "*" or Node_RuleVariable.WILD</li>
- * <li>otherwise create an ExprVar from {AbstractQuerybuilder.makeVar}
- * </ul>
- *
- * @see Converters#makeVar(Object)
- *
- * @param o
- * the object to convert.
- * @return an ExprVar
- */
- public final ExprVar asVar(Object o) {
- if (o instanceof ExprVar) {
- return (ExprVar) o;
- }
- Var v = Converters.makeVar(o);
- return v == null ? null : new ExprVar(v);
- }
-
- /**
- * Not really an Expr but a container of exprs.
- *
- * @param args
- * the list of expressons.
- * @return the expression list.
- */
- public final ExprList asList(Object... args) {
- // make sure the list is modifyable
- List<Expr> lst = Arrays.asList(args).stream().map(arg -> asExpr(arg)).collect(Collectors.toList());
- return new ExprList(lst);
- }
-
- /**
- * Not really an Expr but a container of exprs. creates an empty list.
- *
- * @return the empty expression list.
- */
- public final ExprList list() {
- return new ExprList();
- }
-
- /**
- * Convert the object into an expression using the query's PrefixMapping
- *
- * @param o
- * the object to convert.
- * @return the Expr.
- */
- public final Expr asExpr(Object o) {
- return asExpr(o, pMap);
- }
-
- /**
- * Convenience method to call AbstractQueryBuilder.quote
- *
- * @see Converters#quoted(String)
- * @param s
- * the string to quote
- * @return the quotes string.
- * @deprecated use {@link Converters#quoted(String)}
- */
- @Deprecated
- public final String quote(String s) {
- return Converters.quoted(s);
- }
-
- /**
- * Create an expression from an object.
- *
- * <b>this method does not parse strings to expressions.</b> to parse
- * strings to expressions see {AbstractQueryBuilder.makeExpr}
- *
- * <ul>
- * <li>If the object is null returns none()</li>
- * <li>If the object is an expression return it</li>
- * <li>If the object fronts a node and is not a var make a NodeVar</li>
- * <li>otherwise calls var()</li>
- * </ul>
- *
- * @see #asVar(Object)
- * @see Converters#makeVar(Object)
- *
- * @param o
- * the object to create the expression from
- * @return Expr
- */
- public static final Expr asExpr(Object o, PrefixMapping pMap) {
- if (o == null) {
- return Expr.NONE;
- }
- if (o instanceof Expr) {
- return (Expr) o;
- }
- Node n = Converters.makeNode(o, pMap);
-
- if (n.isVariable()) {
- return new ExprVar(Var.alloc(n));
- }
- return NodeValue.makeNode(n);
-
- }
+ private final PrefixMapping pMap;
+
+ /**
+ * Constructs an expression factor with the specified prefix definitions.
+ *
+ * @param pMap the PrefixMapping to use in the expressions.
+ */
+ public ExprFactory(PrefixMapping pMap) {
+ this.pMap = pMap;
+ }
+
+ /**
+ * Constructs an expression factory with the prefix definitions found in
+ * {@code PrefixMapping.Extended}
+ *
+ * @see PrefixMapping#Extended
+ */
+ public ExprFactory() {
+ this(PrefixMapping.Extended);
+ }
+
+ // expr 0 functions
+
+ /**
+ * implements rand() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-rand
+ *
+ * @see org.apache.jena.sparql.expr.E_Random
+ * @return E_Random instance
+ */
+ public final E_Random rand() {
+ return new E_Random();
+ }
+
+ /**
+ * implements struuid() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-struuid
+ *
+ * @see org.apache.jena.sparql.expr.E_StrUUID
+ * @return E_StrUUID instance
+ */
+ public final E_StrUUID struuid() {
+ return new E_StrUUID();
+ }
+
+ /**
+ * implements uuid() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-uuid
+ *
+ * @see org.apache.jena.sparql.expr.E_UUID
+ * @return E_UUID instance
+ */
+ public final E_UUID uuid() {
+ return new E_UUID();
+ }
+
+ /**
+ * Returns the current ARQ name and version number as a string.
+ *
+ * @see org.apache.jena.sparql.expr.E_Version
+ * @return E_Version instance
+ */
+ public final E_Version version() {
+ return new E_Version();
+ }
+
+ /**
+ * implements now() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-now
+ *
+ * @see org.apache.jena.sparql.expr.E_Now
+ * @return E_Now instance
+ */
+ public final E_Now now() {
+ return new E_Now();
+ }
+
+ // expr 1 functions
+
+ /**
+ * implements bound() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-bound
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Bound
+ *
+ * @param expr the expression to check.
+ * @return E_Bound instance
+ */
+ public final E_Bound bound(Object expr) {
+ return new E_Bound(asExpr(expr));
+ }
+
+ /**
+ * implements datatype() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-datatype
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Datatype
+ *
+ * @param expr the expression to check.
+ * @return E_Datatype instance
+ */
+ public final E_Datatype datatype(Object expr) {
+ return new E_Datatype(asExpr(expr));
+ }
+
+ /**
+ * implements day() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-day
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ *
+ * @param expr the expression to check.
+ * @return E_Datatype instance
+ */
+ public final E_DateTimeDay day(Object expr) {
+ return new E_DateTimeDay(asExpr(expr));
+ }
+
+ /**
+ * implements hours() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-hours
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeHours
+ *
+ * @param expr the expression to check.
+ * @return E_DateTimeHours instance
+ */
+ public final E_DateTimeHours hours(Object expr) {
+ return new E_DateTimeHours(asExpr(expr));
+ }
+
+ /**
+ * implements minutes() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-minutes
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeMinutes
+ *
+ * @param expr the expression to check.
+ * @return E_DateTimeMinutes instance
+ */
+ public final E_DateTimeMinutes minutes(Object expr) {
+ return new E_DateTimeMinutes(asExpr(expr));
+ }
+
+ /**
+ * implements month() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-month
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeMonth
+ *
+ * @param expr the expression to check.
+ * @return E_DateTimeMonth instance
+ */
+ public final E_DateTimeMonth month(Object expr) {
+ return new E_DateTimeMonth(asExpr(expr));
+ }
+
+ /**
+ * implements seconds() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-seconds
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeSeconds
+ *
+ * @param expr the expression to check.
+ * @return E_DateTimeSeconds instance
+ */
+ public final E_DateTimeSeconds seconds(Object expr) {
+ return new E_DateTimeSeconds(asExpr(expr));
+ }
+
+ /**
+ * implements timezone() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-timezone
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeTimezone
+ *
+ * @param expr the expression to check.
+ * @return E_DateTypeTimezone instance
+ */
+ public final E_DateTimeTimezone timezone(Object expr) {
+ return new E_DateTimeTimezone(asExpr(expr));
+ }
+
+ /**
+ * implements tz() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-tz
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeTZ
+ *
+ * @param expr the expression to check.
+ * @return E_DateTimeTZ instance
+ */
+ public final E_DateTimeTZ tz(Object expr) {
+ return new E_DateTimeTZ(asExpr(expr));
+ }
+
+ /**
+ * implements year() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-year
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_DateTimeYear
+ *
+ * @param expr the expression to check.
+ * @return E_DateTimeYear instance
+ */
+ public final E_DateTimeYear year(Object expr) {
+ return new E_DateTimeYear(asExpr(expr));
+ }
+
+ /**
+ * implements iri() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-iri
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_IRI
+ *
+ * @param expr the expression to check.
+ * @return E_IRI instance
+ */
+ public final E_IRI iri(Object expr) {
+ return new E_IRI(asExpr(expr));
+ }
+
+ /**
+ * implements isBlank() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isBlank
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_IsBlank
+ *
+ * @param expr the expression to check.
+ * @return E_isBlank instance
+ */
+ public final E_IsBlank isBlank(Object expr) {
+ return new E_IsBlank(asExpr(expr));
+ }
+
+ /**
+ * implements isIRI() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isIRI
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_IsIRI
+ *
+ * @param expr the expression to check.
+ * @return E_IsIRI instance
+ */
+ public final E_IsIRI isIRI(Object expr) {
+ return new E_IsIRI(asExpr(expr));
+ }
+
+ /**
+ * implements isLiteral() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isLiteral
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_IsLiteral
+ *
+ * @param expr the expression to check.
+ * @return E_IsLiteral instance
+ */
+ public final E_IsLiteral isLiteral(Object expr) {
+ return new E_IsLiteral(asExpr(expr));
+ }
+
+ /**
+ * implements isNumeric() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-isNumeric
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_IsNumeric
+ *
+ * @param expr the expression to check.
+ * @return E_IsNumeric instance
+ */
+ public final E_IsNumeric isNumeric(Object expr) {
+ return new E_IsNumeric(asExpr(expr));
+ }
+
+ /**
+ * implements lang() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-lang
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Lang
+ *
+ * @param expr the expression to check.
+ * @return E_Lang instance
+ */
+ public final E_Lang lang(Object expr) {
+ return new E_Lang(asExpr(expr));
+ }
+
+ /**
+ * implements not() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-not
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_LogicalNot
+ *
+ * @param expr the expression to check.
+ * @return E_LogicalNot instance
+ */
+ public final E_LogicalNot not(Object expr) {
+ return new E_LogicalNot(asExpr(expr));
+ }
+
+ /**
+ * implements abs() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-abs
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NumAbs
+ *
+ * @param expr the expression to check.
+ * @return E_NumAbs instance
+ */
+ public final E_NumAbs abs(Object expr) {
+ return new E_NumAbs(asExpr(expr));
+ }
+
+ /**
+ * implements ceil() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-ceil
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NumCeiling
+ *
+ * @param expr the expression to check.
+ * @return E_NumCeiling instance
+ */
+ public final E_NumCeiling ceil(Object expr) {
+ return new E_NumCeiling(asExpr(expr));
+ }
+
+ /**
+ * implements floor() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-floor
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NumFloor
+ *
+ * @param expr the expression to check.
+ * @return E_NumFloor instance
+ */
+ public final E_NumFloor floor(Object expr) {
+ return new E_NumFloor(asExpr(expr));
+ }
+
+ /**
+ * implements round() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-round
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NumRound
+ *
+ * @param expr the expression to check.
+ * @return E_Round instance
+ */
+ public final E_NumRound round(Object expr) {
+ return new E_NumRound(asExpr(expr));
+ }
+
+ /**
+ * implements str() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-str
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Str
+ *
+ * @param expr the expression to check.
+ * @return E_Str instance
+ */
+ public final E_Str str(Object expr) {
+ return new E_Str(asExpr(expr));
+ }
+
+ /**
+ * implements encode() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-encode
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrEncodeForURI
+ *
+ * @param expr the expression to check.
+ * @return E_StrEncodedForURI instance
+ */
+ public final E_StrEncodeForURI encode(Object expr) {
+ return new E_StrEncodeForURI(asExpr(expr));
+ }
+
+ /**
+ * implements strlen() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strlen
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrLength
+ *
+ * @param expr the expression to check.
+ * @return E_StrLength instance
+ */
+ public final E_StrLength strlen(Object expr) {
+ return new E_StrLength(asExpr(expr));
+ }
+
+ /**
+ * implements lcase() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-lcase
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrLowerCase
+ *
+ * @param expr the expression to check.
+ * @return E_StrLowerCase instance
+ */
+ public final E_StrLowerCase lcase(Object expr) {
+ return new E_StrLowerCase(asExpr(expr));
+ }
+
+ /**
+ * implements ucase() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-ucase
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrUpperCase
+ *
+ * @param expr the expression to check.
+ * @return E_StrUpperCase instance
+ */
+ public final E_StrUpperCase ucase(Object expr) {
+ return new E_StrUpperCase(asExpr(expr));
+ }
+
+ /**
+ * implements unary minus as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_UnaryMinus
+ *
+ * @param expr the expression to check.
+ * @return E_UnaryMinus instance
+ */
+ public final E_UnaryMinus minus(Object expr) {
+ return new E_UnaryMinus(asExpr(expr));
+ }
+
+ /**
+ * implements unary plus as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_UnaryPlus
+ *
+ * @param expr the expression to check.
+ * @return E_UnaryPlus instance
+ */
+ public final E_UnaryPlus plus(Object expr) {
+ return new E_UnaryPlus(asExpr(expr));
+ }
+
+ /**
+ * implements md5() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-md5
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_MD5
+ *
+ * @param expr the expression to check.
+ * @return E_MD5 instance
+ */
+ public final E_MD5 md5(Object expr) {
+ return new E_MD5(asExpr(expr));
+ }
+
+ /**
+ * implements sha1() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha1
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_SHA1
+ *
+ * @param expr the expression to check.
+ * @return E_SHA1 instance
+ */
+ public final E_SHA1 sha1(Object expr) {
+ return new E_SHA1(asExpr(expr));
+ }
+
+ /**
+ * implements sha224() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha224
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_SHA224
+ *
+ * @param expr the expression to check.
+ * @return E_SHA224 instance
+ */
+ public final E_SHA224 sha224(Object expr) {
+ return new E_SHA224(asExpr(expr));
+ }
+
+ /**
+ * implements sha256() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha256
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_SHA256
+ *
+ * @param expr the expression to check.
+ * @return E_SHA256 instance
+ */
+ public final E_SHA256 sha256(Object expr) {
+ return new E_SHA256(asExpr(expr));
+ }
+
+ /**
+ * implements sha384() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha384
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_SHA384
+ *
+ * @param expr the expression to check.
+ * @return E_SHA384 instance
+ */
+ public final E_SHA384 sha384(Object expr) {
+ return new E_SHA384(asExpr(expr));
+ }
+
+ /**
+ * implements sha512() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sha512
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_SHA512
+ *
+ * @param expr the expression to check.
+ * @return E_SHA512 instance
+ */
+ public final E_SHA512 sha512(Object expr) {
+ return new E_SHA512(asExpr(expr));
+ }
+
+ // expr2 functions
+
+ /**
+ * implements addition as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Add
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_Add instance
+ */
+ public final E_Add add(Object expr1, Object expr2) {
+ return new E_Add(asExpr(expr1), asExpr(expr2));
+ }
+
+ // E_Cast has a private constructor and seems not to be used.
+ // public final E_Cast cast( Expr expr1, Expr expr2 )
+ // {
+ // return new E_Cast( expr1, expr2 );
+ // }
+ /**
+ * implements division as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Divide
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_Devide instance
+ */
+ public final E_Divide divide(Object expr1, Object expr2) {
+ return new E_Divide(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements equality as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Equals
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_Equals instance
+ */
+ public final E_Equals eq(Object expr1, Object expr2) {
+ return new E_Equals(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements greater than as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_GreaterThan
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_GreaterThan instance
+ */
+ public final E_GreaterThan gt(Object expr1, Object expr2) {
+ return new E_GreaterThan(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements greater than or equal as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_GreaterThanOrEqual
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_GreaterThanOrEqual instance
+ */
+ public final E_GreaterThanOrEqual ge(Object expr1, Object expr2) {
+ return new E_GreaterThanOrEqual(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements langMatches() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-langMatches
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_LangMatches
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_LangMatches instance
+ */
+ public final E_LangMatches langMatches(Object expr1, Object expr2) {
+ return new E_LangMatches(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements less than as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_LessThan
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_LessThan instance
+ */
+ public final E_LessThan lt(Object expr1, Object expr2) {
+ return new E_LessThan(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements less than or equal as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_LessThanOrEqual
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_LessThanOrEqual instance
+ */
+ public final E_LessThanOrEqual le(Object expr1, Object expr2) {
+ return new E_LessThanOrEqual(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements logical and as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_LogicalAnd
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_LogicalAnd instance
+ */
+ public final E_LogicalAnd and(Object expr1, Object expr2) {
+ return new E_LogicalAnd(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements logical or as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_LogicalOr
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_LogicalOr instance
+ */
+ public final E_LogicalOr or(Object expr1, Object expr2) {
+ return new E_LogicalOr(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements multiplication s per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Multiply
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_Multiply instance
+ */
+ public final E_Multiply multiply(Object expr1, Object expr2) {
+ return new E_Multiply(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements not equals as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NotEquals
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_NotEquals instance
+ */
+ public final E_NotEquals ne(Object expr1, Object expr2) {
+ return new E_NotEquals(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements sameTerm() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-sameTerm
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_SameTerm
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_SameTerm instance
+ */
+ public final E_SameTerm sameTerm(Object expr1, Object expr2) {
+ return new E_SameTerm(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements strafter() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strafter
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrAfter
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrAfter instance
+ */
+ public final E_StrAfter strafter(Object expr1, Object expr2) {
+ return new E_StrAfter(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements strbefore() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strbefore
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrBefore
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrBefore instance
+ */
+ public final E_StrBefore strbefore(Object expr1, Object expr2) {
+ return new E_StrBefore(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements contains() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-contains
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrContains
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrContains instance
+ */
+ public final E_StrContains contains(Object expr1, Object expr2) {
+ return new E_StrContains(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements strdt() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strdt
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrDatatype
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrDatatype instance
+ */
+ public final E_StrDatatype strdt(Object expr1, Object expr2) {
+ return new E_StrDatatype(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements strends() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strends
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrEndsWith
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrEndsWith instance
+ */
+ public final E_StrEndsWith strends(Object expr1, Object expr2) {
+ return new E_StrEndsWith(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements strlang() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strlang
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrLang
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrLang instance
+ */
+ public final E_StrLang strlang(Object expr1, Object expr2) {
+ return new E_StrLang(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements strstarts() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-strstarts
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrStartsWith
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_StrStartsWith instance
+ */
+ public final E_StrStartsWith strstarts(Object expr1, Object expr2) {
+ return new E_StrStartsWith(asExpr(expr1), asExpr(expr2));
+ }
+
+ /**
+ * implements subtraction as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Subtract
+ *
+ * @param expr1 the first expression.
+ * @param expr2 the second expression.
+ * @return E_Subtract instance
+ */
+
+ public final E_Subtract subtract(Object expr1, Object expr2) {
+ return new E_Subtract(asExpr(expr1), asExpr(expr2));
+ }
+
+ // expr3 functions
+
+ /**
+ * implements if() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-if
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Conditional
+ *
+ * @param condition the condition to check.
+ * @param thenExpr the expression to execute if condition is true.
+ * @param elseExpr the expression to execute if condition is false.
+ * @return an E_Conditional instance.
+ */
+ public final E_Conditional cond(Expr condition, Expr thenExpr, Expr elseExpr) {
+ return new E_Conditional(condition, thenExpr, elseExpr);
+ }
+
+ // exprN functions
+ /**
+ * implements bnode() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-bnode
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_BNode
+ *
+ * @param expr1 the blank node id.
+ * @return an E_BNode instance
+ */
+ public final E_BNode bnode(Object expr1) {
+ return new E_BNode(asExpr(expr1));
+ }
+
+ /**
+ * implements bnode() as per SPARQL 1.1 spec
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-bnode
+ *
+ * @see org.apache.jena.sparql.expr.E_Random
+ *
+ * @return an E_BNode instance.
+ */
+ public final E_BNode bnode() {
+ return new E_BNode();
+ }
+
+ /**
+ * Creates a dynamic function call.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
+ *
+ * Converts function to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_FunctionDynamic
+ *
+ * @param function The function to execute
+ * @param args the arguments to the function.
+ * @return an E_FunctionDynamic instance.
+ */
+ public final E_FunctionDynamic call(Object function, ExprList args) {
+ return new E_FunctionDynamic(asExpr(function), args);
+ }
+
+ /**
+ * Creates a dynamic function call.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
+ *
+ * Converts function to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_FunctionDynamic
+ *
+ * @param function The function to execute
+ * @param args the arguments to the function.
+ * @return an E_FunctionDynamic instance.
+ */
+ public final E_FunctionDynamic call(Object function, Object... args) {
+ return call(asExpr(function), asList(args));
+ }
+
+ /**
+ * Creates a function call as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
+ *
+ * @see org.apache.jena.sparql.expr.E_Call
+ *
+ * The first argument is the function to call
+ *
+ * @param args the arguments to the function.
+ * @return an E_Call instance.
+ */
+ public final E_Call call(ExprList args) {
+ return new E_Call(args);
+ }
+
+ /**
+ * implements coalesce() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-coalesce
+ *
+ * @see org.apache.jena.sparql.expr.E_Coalesce
+ *
+ * @param args the arguments to the function.
+ * @return an E_Coalesce instance.
+ */
+ public final E_Coalesce coalesce(ExprList args) {
+ return new E_Coalesce(args);
+ }
+
+ /**
+ * implements coalesce() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-coalesce
+ *
+ * @see org.apache.jena.sparql.expr.E_Coalesce
+ *
+ * @param args the arguments to the function.
+ * @return an E_Coalesce instance.
+ */
+ public final E_Coalesce coalesce(Object... args) {
+ return new E_Coalesce(asList(args));
+ }
+
+ /**
+ * Creates a function call as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall
+ *
+ * @see org.apache.jena.sparql.expr.E_Function
+ *
+ * @param name the name of the function.
+ * @param args the arguments to the function.
+ * @return an E_Function instance.
+ */
+ public final E_Function function(String name, ExprList args) {
+ return new E_Function(name, args);
+ }
+
+ /**
+ * implements "not in" as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-not-in
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NotOneOf
+ *
+ * @param expr the expression that is not in the list
+ * @param list the list of expressions.
+ * @return an E_NotOneOf instance.
+ */
+ public final E_NotOneOf notin(Object expr, ExprList list) {
+ return new E_NotOneOf(asExpr(expr), list);
+ }
+
+ /**
+ * implements "not in" as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-not-in
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_NotOneOf
+ *
+ * @param expr the expression that is not in the list
+ * @param list the list of expressions.
+ * @return an E_NotOneOf instance.
+ */
+ public final E_NotOneOf notin(Object expr, Object... list) {
+ return new E_NotOneOf(asExpr(expr), asList(list));
+ }
+
+ /**
+ * implements "in" as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-in
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_OneOf
+ *
+ * @param expr the expression that is not in the list
+ * @param list the list of expressions.
+ * @return an E_OneOf instance.
+ */
+ public final E_OneOf in(Object expr, ExprList list) {
+ return new E_OneOf(asExpr(expr), list);
+ }
+
+ /**
+ * implements "in" as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-in
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_OneOf
+ *
+ * @param expr the expression that is not in the list
+ * @param list the list of expressions.
+ * @return an E_OneOf instance.
+ */
+ public final E_OneOf in(Object expr, Object... list) {
+ return new E_OneOf(asExpr(expr), asList(list));
+ }
+
+ /**
+ * implements regex() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-regex
+ *
+ * Converts objects to an Expr objects via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Regex
+ *
+ * @param expr string to match.
+ * @param pattern the pattern to match
+ * @param flags the regex flags
+ * @return an E_Regex instance.
+ */
+ public final E_Regex regex(Object expr, Object pattern, Object flags) {
+ return new E_Regex(asExpr(expr), asExpr(pattern), asExpr(flags));
+ }
+
+ /**
+ * implements regex() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-regex
+ *
+ * Converts expr to an Expr object via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_Regex
+ *
+ * @param expr string to match.
+ * @param pattern the pattern to match
+ * @param flags the regex flags
+ * @return an E_Regex instance.
+ */
+ public final E_Regex regex(Object expr, String pattern, String flags) {
+ return new E_Regex(asExpr(expr), pattern, flags);
+ }
+
+ /**
+ * implements concat() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-concat
+ *
+ * @see org.apache.jena.sparql.expr.E_StrConcat
+ *
+ * @param list the list of arguments to concatenate
+ * @return an E_StrConcat instance
+ */
+ public final E_StrConcat concat(ExprList list) {
+ return new E_StrConcat(list);
+ }
+
+ /**
+ * implements concat() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-concat
+ *
+ * @see org.apache.jena.sparql.expr.E_StrConcat
+ *
+ * @param list the list of arguments to concatenate
+ * @return an E_StrConcat instance
+ */
+ public final E_StrConcat concat(Object... list) {
+ return new E_StrConcat(asList(list));
+ }
+
+ /**
+ * implements replace() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-replace
+ *
+ * Converts Objects to an Expr objects via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrReplace
+ *
+ * @param arg the string literal to replace
+ * @param pattern the pattern to replace in the string literal.
+ * @param replacement the string literal to replace the pattern with.
+ * @param flags the flags that control replacement options.
+ * @return an E_StrReplace instance
+ */
+ public final E_StrReplace replace(Object arg, Object pattern, Object replacement, Object flags) {
+ return new E_StrReplace(asExpr(arg), asExpr(pattern), asExpr(replacement), asExpr(flags));
+ }
+
+ /**
+ * implements replace() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-replace
+ *
+ * Converts Objects to an Expr objects via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrReplace
+ *
+ * @param arg the string literal to replace
+ * @param pattern the pattern to replace in the string literal.
+ * @param replacement the string literal to replace the pattern with.
+ * @return an E_StrReplace instance
+ */
+ public final E_StrReplace replace(Object arg, Object pattern, Object replacement) {
+ return new E_StrReplace(asExpr(arg), asExpr(pattern), asExpr(replacement), null);
+ }
+
+ /**
+ * implements substr() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-substr
+ *
+ * Converts Objects to an Expr objects via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrSubstring
+ *
+ * @param src the expression to extract the substring from.
+ * @param loc the location within the expression string to start
+ * @param len the length of the string to extract.
+ *
+ * @return an E_Substring instance.
+ */
+ public final E_StrSubstring substr(Object src, Object loc, Object len) {
+ return new E_StrSubstring(asExpr(src), asExpr(loc), asExpr(len));
+ }
+
+ /**
+ * implements substr() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-substr
+ *
+ * Converts Objects to an Expr objects via expr()
+ *
+ * @see #asExpr(Object)
+ * @see org.apache.jena.sparql.expr.E_StrSubstring
+ *
+ * @param src the expression to extract the substring from.
+ * @param loc the location within the expression string to start
+ *
+ * @return an E_Substring instance.
+ */
+ public final E_StrSubstring substr(Object src, Object loc) {
+ return new E_StrSubstring(asExpr(src), asExpr(loc), null);
+ }
+ // expr op
+
+ /**
+ * implements exists() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-filter-exists
+ *
+ * @see org.apache.jena.sparql.expr.E_Exists
+ *
+ * @param whereClause A WhereClause to check existence of.
+ * @return an E_Exists instance,
+ */
+ public final E_Exists exists(WhereClause<?> whereClause) {
+ return new E_Exists(whereClause.getWhereHandler().getClause());
+ }
+
+ /**
+ * implements not exists() as per the SPARQL 11 query definition.
+ *
+ * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-filter-exists
+ *
+ * @see org.apache.jena.sparql.expr.E_NotExists
+ *
+ * @param whereClause the argument to the function.
+ * @return an E_NotExists instance.
+ */
+ public final E_NotExists notexists(WhereClause<?> whereClause) {
+ return new E_NotExists(whereClause.getWhereHandler().getClause());
+ }
+
+ // exprnone
+ /**
+ * Should probably be called "null" but that is a reserved work. An expression
+ * that can be used in place of null.
+ *
+ * @see org.apache.jena.sparql.expr.ExprNone
+ *
+ * @return an ExprNone instance
+ */
+ public final ExprNone none() {
+ return (ExprNone) Expr.NONE;
+ }
+
+ /**
+ * Converts the object to a ExprVar.
+ * <ul>
+ * <li>If the object is an ExprVar return it</li>
+ * <li>Will return null if the object is "*" or Node_RuleVariable.WILD</li>
+ * <li>otherwise create an ExprVar from {AbstractQuerybuilder.makeVar}
+ * </ul>
+ *
+ * @see Converters#makeVar(Object)
+ *
+ * @param o the object to convert.
+ * @return an ExprVar
+ */
+ public final ExprVar asVar(Object o) {
+ if (o instanceof ExprVar) {
+ return (ExprVar) o;
+ }
+ Var v = Converters.makeVar(o);
+ return v == null ? null : new ExprVar(v);
+ }
+
+ /**
+ * Not really an Expr but a container of exprs.
+ *
+ * @param args the list of expressons.
+ * @return the expression list.
+ */
+ public final ExprList asList(Object... args) {
+ // make sure the list is modifyable
+ List<Expr> lst = Arrays.asList(args).stream().map(arg -> asExpr(arg)).collect(Collectors.toList());
+ return new ExprList(lst);
+ }
+
+ /**
+ * Not really an Expr but a container of exprs. creates an empty list.
+ *
+ * @return the empty expression list.
+ */
+ public final ExprList list() {
+ return new ExprList();
+ }
+
+ /**
+ * Convert the object into an expression using the query's PrefixMapping
+ *
+ * @param o the object to convert.
+ * @return the Expr.
+ */
+ public final Expr asExpr(Object o) {
+ return asExpr(o, pMap);
+ }
+
+ /**
+ * Convenience method to call AbstractQueryBuilder.quote
+ *
+ * @see Converters#quoted(String)
+ * @param s the string to quote
+ * @return the quotes string.
+ * @deprecated use {@link Converters#quoted(String)}
+ */
+ @Deprecated
+ public final String quote(String s) {
+ return Converters.quoted(s);
+ }
+
+ /**
+ * Create an expression from an object.
+ *
+ * <b>this method does not parse strings to expressions.</b> to parse strings to
+ * expressions see {AbstractQueryBuilder.makeExpr}
+ *
+ * <ul>
+ * <li>If the object is null returns none()</li>
+ * <li>If the object is an expression return it</li>
+ * <li>If the object fronts a node and is not a var make a NodeVar</li>
+ * <li>otherwise calls var()</li>
+ * </ul>
+ *
+ * @see #asVar(Object)
+ * @see Converters#makeVar(Object)
+ *
+ * @param o the object to create the expression from
+ * @return Expr
+ */
+ public static final Expr asExpr(Object o, PrefixMapping pMap) {
+ if (o == null) {
+ return Expr.NONE;
+ }
+ if (o instanceof Expr) {
+ return (Expr) o;
+ }
+ Node n = Converters.makeNode(o, pMap);
+
+ if (n.isVariable()) {
+ return new ExprVar(Var.alloc(n));
+ }
+ return NodeValue.makeNode(n);
+
+ }
}
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Order.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Order.java
index 005a34e..77ee71d 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Order.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/Order.java
@@ -22,5 +22,5 @@ package org.apache.jena.arq.querybuilder;
* The order for the ORDER BY modifiers.
*/
public enum Order {
- ASCENDING, DESCENDING
+ ASCENDING, DESCENDING
}
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
index 6f3a278..5be834b 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/SelectBuilder.java
@@ -42,14 +42,18 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
/**
* Builder for SPARQL Select Queries.
* <p>
- * The SelectBuilder provides chainable methods to programmatically generate SPARQL Select Queries.
- * The application order of the methods is not relevant for the resulting query.
- * An {@link ExprFactory} is intended for use along with the SelectBuilder to generate needed {@link Expr} parameter values.
- * An {@link ExprFactory} that works with the same prefixes can be obtained with {@link SelectBuilder#getExprFactory()}.
+ * The SelectBuilder provides chainable methods to programmatically generate
+ * SPARQL Select Queries. The application order of the methods is not relevant
+ * for the resulting query. An {@link ExprFactory} is intended for use along
+ * with the SelectBuilder to generate needed {@link Expr} parameter values. An
+ * {@link ExprFactory} that works with the same prefixes can be obtained with
+ * {@link SelectBuilder#getExprFactory()}.
* <p>
- * The SelectBuilder can be used as <b>prepared query</b>.
- * Values for variables in the created query can be set with {@link SelectBuilder#setVar(Object, Object)} and {@link SelectBuilder#setVar(Var, Node)}.
- * The method {@link SelectBuilder#clearWhereValues()} allows to clear the set values.
+ * The SelectBuilder can be used as <b>prepared query</b>. Values for variables
+ * in the created query can be set with
+ * {@link SelectBuilder#setVar(Object, Object)} and
+ * {@link SelectBuilder#setVar(Var, Node)}. The method
+ * {@link SelectBuilder#clearWhereValues()} allows to clear the set values.
*
* @see AskBuilder
* @see ConstructBuilder
@@ -57,430 +61,423 @@ import org.apache.jena.sparql.lang.sparql_11.ParseException;
* @see UpdateBuilder
*/
public class SelectBuilder extends AbstractQueryBuilder<SelectBuilder> implements DatasetClause<SelectBuilder>,
- WhereClause<SelectBuilder>, SolutionModifierClause<SelectBuilder>, SelectClause<SelectBuilder> {
-
- private final HandlerBlock handlerBlock;
-
- public SelectBuilder() {
- super();
- query.setQuerySelectType();
- handlerBlock = new HandlerBlock(query);
- }
-
- @Override
- public DatasetHandler getDatasetHandler() {
- return handlerBlock.getDatasetHandler();
- }
-
- @Override
- public HandlerBlock getHandlerBlock() {
- return handlerBlock;
- }
-
- @Override
- public SelectBuilder clone() {
- SelectBuilder qb = new SelectBuilder();
- qb.handlerBlock.addAll(handlerBlock);
- return qb;
- }
-
- /**
- * Sets the distinct flag.
- *
- * Setting the select distinct will unset reduced if it was set.
- *
- * @param state
- * if true results will be distinct.
- * @return This builder for chaining.
- */
- public SelectBuilder setDistinct(boolean state) {
- getSelectHandler().setDistinct(state);
- return this;
- }
-
- /**
- * Sets the reduced flag.
- *
- * Setting the select reduced will unset distinct if it was set.
- *
- * @param state
- * if true results will be reduced.
- * @return This builder for chaining.
- */
- public SelectBuilder setReduced(boolean state) {
- getSelectHandler().setReduced(state);
- return this;
- }
-
- @Override
- public SelectBuilder addVar(Object var) {
- getSelectHandler().addVar(Converters.makeVar(var));
- return this;
- }
-
- @Override
- public SelectBuilder addVar(String expression, Object var) throws ParseException {
- getSelectHandler().addVar(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public SelectBuilder addVar(Expr expr, Object var) {
- getSelectHandler().addVar(expr, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public List<Var> getVars() {
- return getSelectHandler().getVars();
- }
-
- @Override
- public SelectBuilder fromNamed(String graphName) {
- getDatasetHandler().fromNamed(graphName);
- return this;
- }
-
- @Override
- public SelectBuilder fromNamed(Collection<String> graphNames) {
- getDatasetHandler().fromNamed(graphNames);
- return this;
- }
-
- @Override
- public SelectBuilder from(String graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public SelectBuilder from(Collection<String> graphName) {
- getDatasetHandler().from(graphName);
- return this;
- }
-
- @Override
- public SelectBuilder addOrderBy(Expr orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public SelectBuilder addOrderBy(Object orderBy) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
- return this;
- }
-
- @Override
- public SelectBuilder addOrderBy(SortCondition orderBy) {
- getSolutionModifierHandler().addOrderBy(orderBy);
- return this;
- }
-
- @Override
- public SelectBuilder addOrderBy(Expr orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(orderBy, order);
- return this;
- }
-
- @Override
- public SelectBuilder addOrderBy(Object orderBy, Order order) {
- getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
- return this;
- }
-
- @Override
- public SelectBuilder addGroupBy(Object groupBy) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
- return this;
- }
-
- @Override
- public SelectBuilder addGroupBy(Expr groupBy) {
- getSolutionModifierHandler().addGroupBy(groupBy);
- return this;
- }
-
- @Override
- public SelectBuilder addGroupBy(Object var, Expr expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
- return this;
- }
-
- @Override
- public SelectBuilder addGroupBy(Object var, String expr) {
- getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
- return this;
- }
-
- @Override
- public SolutionModifierHandler getSolutionModifierHandler() {
- return handlerBlock.getModifierHandler();
- }
-
- @Override
- public SelectBuilder addHaving(String having) throws ParseException {
- getSolutionModifierHandler().addHaving(having);
- return this;
- }
-
- @Override
- public SelectBuilder addHaving(Expr expression) throws ParseException {
- getSolutionModifierHandler().addHaving(expression);
- return this;
- }
-
- @Override
- public SelectBuilder addHaving(Object var) throws ParseException {
- getSolutionModifierHandler().addHaving(Converters.makeVar(var));
- return this;
- }
-
- @Override
- public SelectBuilder setLimit(int limit) {
- getSolutionModifierHandler().setLimit(limit);
- return this;
- }
-
- @Override
- public SelectBuilder setOffset(int offset) {
- getSolutionModifierHandler().setOffset(offset);
- return this;
- }
-
- /**
- * Converts a node to a string. If the node is a literal return the literal
- * value. If the node is a URI return the URI enclosed with < and > If
- * the node is a variable return the name preceded by '?'
- *
- * @param node
- * The node to convert.
- * @return A string representation of the node.
- */
- private static String toString(Node node) {
- if (node.isBlank()) {
- return node.getBlankNodeLabel();
- }
- if (node.isLiteral()) {
- return node.toString();
- }
- if (node.isURI()) {
- return String.format("<%s>", node.getURI());
- }
- if (node.isVariable()) {
- return String.format("?%s", node.getName());
- }
- return node.toString();
- }
-
- /**
- * Converts the object to a string. If the object is a node or fronts a node
- * then
- * <ul>
- * <li>If the node is a literal return the literal value.</li>
- * <li>If the node is a URI return the URI enclosed with < and ></li>
- * <li>If the node is a variable return the name preceded by '?'</li>
- * </ul>
- * otherwise return the toString() method of the object.
- *
- * @param o
- * the Object to convert.
- * @return The string representation of the object.
- */
- public static String makeString(Object o) {
- if (o instanceof FrontsNode) {
- return toString(((FrontsNode) o).asNode());
- }
- if (o instanceof Node) {
- return toString((Node) o);
- }
- return o.toString();
- }
-
- @Override
- public SelectBuilder addWhere(TriplePath t )
- {
- getWhereHandler().addWhere(t);
- return this;
- }
-
- @Override
- public SelectBuilder addWhere(Triple t) {
- getWhereHandler().addWhere(new TriplePath(t));
- return this;
- }
-
- @Override
- public SelectBuilder addWhere(FrontsTriple t) {
- getWhereHandler().addWhere(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public SelectBuilder addWhere(Object s, Object p, Object o) {
- getWhereHandler().addWhere( makeTriplePath( s, p, o ));
- return this;
- }
-
- @Override
- public SelectBuilder addWhereValueVar(Object var) {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
- return this;
- }
-
- @Override
- public SelectBuilder addWhereValueVar(Object var, Object... values)
- {
- getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
- return this;
- }
-
-
- @Override
- public <K extends Collection<?>> SelectBuilder addWhereValueVars(Map<?,K> dataTable)
- {
- getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
- return this;
- }
-
- @Override
- public SelectBuilder addWhereValueRow(Object... values)
- {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public SelectBuilder addWhereValueRow(Collection<?> values) {
- getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
- return this;
- }
-
- @Override
- public List<Var> getWhereValuesVars() {
- return getWhereHandler().getValuesVars();
- }
-
- @Override
- public Map<Var, List<Node>> getWhereValuesMap() {
- return getWhereHandler().getValuesMap();
- }
-
- @Override
- public SelectBuilder clearWhereValues() {
- getWhereHandler().clearValues();
- return this;
- }
-
- @Override
- public SelectBuilder addOptional(TriplePath t)
- {
- getWhereHandler().addOptional( t );
- return this;
- }
- @Override
- public SelectBuilder addOptional(Triple t) {
- getWhereHandler().addOptional(new TriplePath(t));
- return this;
- }
-
- @Override
- public SelectBuilder addOptional(FrontsTriple t) {
- getWhereHandler().addOptional(new TriplePath(t.asTriple()));
- return this;
- }
-
- @Override
- public SelectBuilder addOptional(Object s, Object p, Object o) {
- getWhereHandler().addOptional( makeTriplePath( s, p, o ));
- return this;
- }
-
- @Override
- public SelectBuilder addOptional(AbstractQueryBuilder<?> t) {
- getWhereHandler().addOptional(t.getWhereHandler());
- return this;
- }
-
- @Override
- public SelectBuilder addFilter(Expr expr) {
- getWhereHandler().addFilter(expr);
- return this;
- }
-
- @Override
- public SelectBuilder addFilter(String s) throws ParseException {
- getWhereHandler().addFilter(s);
- return this;
- }
-
- @Override
- public SelectBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addSubQuery(subQuery);
- return this;
- }
-
- @Override
- public SelectBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
- getWhereHandler().addUnion(subQuery);
- return this;
- }
-
- @Override
- public SelectBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
- getPrologHandler().addAll(subQuery.getPrologHandler());
- getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
- return this;
- }
- @Override
- public SelectBuilder addGraph(Object graph, FrontsTriple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
- return this;
- }
- @Override
- public SelectBuilder addGraph(Object graph, Object subject, Object predicate, Object object)
- {
- getWhereHandler().addGraph(makeNode(graph), makeTriplePath( subject, predicate, object ));
- return this;
- }
- @Override
- public SelectBuilder addGraph(Object graph, Triple triple) {
- getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
- return this;
- }
- @Override
- public SelectBuilder addGraph(Object graph, TriplePath triplePath) {
- getWhereHandler().addGraph(makeNode(graph), triplePath );
- return this;
- }
-
- @Override
- public SelectBuilder addBind(Expr expression, Object var) {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public SelectBuilder addBind(String expression, Object var) throws ParseException {
- getWhereHandler().addBind(expression, Converters.makeVar(var));
- return this;
- }
-
- @Override
- public SelectHandler getSelectHandler() {
- return handlerBlock.getSelectHandler();
- }
-
- @Override
- public Node list(Object... objs) {
- return getWhereHandler().list(objs);
- }
-
- @Override
- public SelectBuilder addMinus( AbstractQueryBuilder<?> t ) {
- getWhereHandler().addMinus( t );
- return this;
- }
-
-
+ WhereClause<SelectBuilder>, SolutionModifierClause<SelectBuilder>, SelectClause<SelectBuilder> {
+
+ private final HandlerBlock handlerBlock;
+
+ public SelectBuilder() {
+ super();
+ query.setQuerySelectType();
+ handlerBlock = new HandlerBlock(query);
+ }
+
+ @Override
+ public DatasetHandler getDatasetHandler() {
+ return handlerBlock.getDatasetHandler();
+ }
+
+ @Override
+ public HandlerBlock getHandlerBlock() {
+ return handlerBlock;
+ }
+
+ @Override
+ public SelectBuilder clone() {
+ SelectBuilder qb = new SelectBuilder();
+ qb.handlerBlock.addAll(handlerBlock);
+ return qb;
+ }
+
+ /**
+ * Sets the distinct flag.
+ *
+ * Setting the select distinct will unset reduced if it was set.
+ *
+ * @param state if true results will be distinct.
+ * @return This builder for chaining.
+ */
+ public SelectBuilder setDistinct(boolean state) {
+ getSelectHandler().setDistinct(state);
+ return this;
+ }
+
+ /**
+ * Sets the reduced flag.
+ *
+ * Setting the select reduced will unset distinct if it was set.
+ *
+ * @param state if true results will be reduced.
+ * @return This builder for chaining.
+ */
+ public SelectBuilder setReduced(boolean state) {
+ getSelectHandler().setReduced(state);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addVar(Object var) {
+ getSelectHandler().addVar(Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addVar(String expression, Object var) throws ParseException {
+ getSelectHandler().addVar(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addVar(Expr expr, Object var) {
+ getSelectHandler().addVar(expr, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public List<Var> getVars() {
+ return getSelectHandler().getVars();
+ }
+
+ @Override
+ public SelectBuilder fromNamed(String graphName) {
+ getDatasetHandler().fromNamed(graphName);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder fromNamed(Collection<String> graphNames) {
+ getDatasetHandler().fromNamed(graphNames);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder from(String graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder from(Collection<String> graphName) {
+ getDatasetHandler().from(graphName);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOrderBy(Expr orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOrderBy(Object orderBy) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOrderBy(SortCondition orderBy) {
+ getSolutionModifierHandler().addOrderBy(orderBy);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOrderBy(Expr orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(orderBy, order);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOrderBy(Object orderBy, Order order) {
+ getSolutionModifierHandler().addOrderBy(Converters.makeVar(orderBy), order);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGroupBy(Object groupBy) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(groupBy));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGroupBy(Expr groupBy) {
+ getSolutionModifierHandler().addGroupBy(groupBy);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGroupBy(Object var, Expr expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), expr);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGroupBy(Object var, String expr) {
+ getSolutionModifierHandler().addGroupBy(Converters.makeVar(var), makeExpr(expr));
+ return this;
+ }
+
+ @Override
+ public SolutionModifierHandler getSolutionModifierHandler() {
+ return handlerBlock.getModifierHandler();
+ }
+
+ @Override
+ public SelectBuilder addHaving(String having) throws ParseException {
+ getSolutionModifierHandler().addHaving(having);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addHaving(Expr expression) throws ParseException {
+ getSolutionModifierHandler().addHaving(expression);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addHaving(Object var) throws ParseException {
+ getSolutionModifierHandler().addHaving(Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder setLimit(int limit) {
+ getSolutionModifierHandler().setLimit(limit);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder setOffset(int offset) {
+ getSolutionModifierHandler().setOffset(offset);
+ return this;
+ }
+
+ /**
+ * Converts a node to a string. If the node is a literal return the literal
+ * value. If the node is a URI return the URI enclosed with < and > If the
+ * node is a variable return the name preceded by '?'
+ *
+ * @param node The node to convert.
+ * @return A string representation of the node.
+ */
+ private static String toString(Node node) {
+ if (node.isBlank()) {
+ return node.getBlankNodeLabel();
+ }
+ if (node.isLiteral()) {
+ return node.toString();
+ }
+ if (node.isURI()) {
+ return String.format("<%s>", node.getURI());
+ }
+ if (node.isVariable()) {
+ return String.format("?%s", node.getName());
+ }
+ return node.toString();
+ }
+
+ /**
+ * Converts the object to a string. If the object is a node or fronts a node
+ * then
+ * <ul>
+ * <li>If the node is a literal return the literal value.</li>
+ * <li>If the node is a URI return the URI enclosed with < and ></li>
+ * <li>If the node is a variable return the name preceded by '?'</li>
+ * </ul>
+ * otherwise return the toString() method of the object.
+ *
+ * @param o the Object to convert.
+ * @return The string representation of the object.
+ */
+ public static String makeString(Object o) {
+ if (o instanceof FrontsNode) {
+ return toString(((FrontsNode) o).asNode());
+ }
+ if (o instanceof Node) {
+ return toString((Node) o);
+ }
+ return o.toString();
+ }
+
+ @Override
+ public SelectBuilder addWhere(TriplePath t) {
+ getWhereHandler().addWhere(t);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhere(Triple t) {
+ getWhereHandler().addWhere(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhere(FrontsTriple t) {
+ getWhereHandler().addWhere(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhere(Object s, Object p, Object o) {
+ getWhereHandler().addWhere(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhereValueVar(Object var) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhereValueVar(Object var, Object... values) {
+ getWhereHandler().addValueVar(getPrologHandler().getPrefixes(), var, values);
+ return this;
+ }
+
+ @Override
+ public <K extends Collection<?>> SelectBuilder addWhereValueVars(Map<?, K> dataTable) {
+ getWhereHandler().addValueVars(getPrologHandler().getPrefixes(), dataTable);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhereValueRow(Object... values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addWhereValueRow(Collection<?> values) {
+ getWhereHandler().addValueRow(getPrologHandler().getPrefixes(), values);
+ return this;
+ }
+
+ @Override
+ public List<Var> getWhereValuesVars() {
+ return getWhereHandler().getValuesVars();
+ }
+
+ @Override
+ public Map<Var, List<Node>> getWhereValuesMap() {
+ return getWhereHandler().getValuesMap();
+ }
+
+ @Override
+ public SelectBuilder clearWhereValues() {
+ getWhereHandler().clearValues();
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOptional(TriplePath t) {
+ getWhereHandler().addOptional(t);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOptional(Triple t) {
+ getWhereHandler().addOptional(new TriplePath(t));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOptional(FrontsTriple t) {
+ getWhereHandler().addOptional(new TriplePath(t.asTriple()));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOptional(Object s, Object p, Object o) {
+ getWhereHandler().addOptional(makeTriplePath(s, p, o));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addOptional(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addOptional(t.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addFilter(Expr expr) {
+ getWhereHandler().addFilter(expr);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addFilter(String s) throws ParseException {
+ getWhereHandler().addFilter(s);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addSubQuery(subQuery);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
+ getWhereHandler().addUnion(subQuery);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
+ getPrologHandler().addAll(subQuery.getPrologHandler());
+ getWhereHandler().addGraph(makeNode(graph), subQuery.getWhereHandler());
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGraph(Object graph, FrontsTriple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple.asTriple()));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGraph(Object graph, Object subject, Object predicate, Object object) {
+ getWhereHandler().addGraph(makeNode(graph), makeTriplePath(subject, predicate, object));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGraph(Object graph, Triple triple) {
+ getWhereHandler().addGraph(makeNode(graph), new TriplePath(triple));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addGraph(Object graph, TriplePath triplePath) {
+ getWhereHandler().addGraph(makeNode(graph), triplePath);
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addBind(Expr expression, Object var) {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public SelectBuilder addBind(String expression, Object var) throws ParseException {
+ getWhereHandler().addBind(expression, Converters.makeVar(var));
+ return this;
+ }
+
+ @Override
+ public SelectHandler getSelectHandler() {
+ return handlerBlock.getSelectHandler();
+ }
+
+ @Override
+ public Node list(Object... objs) {
+ return getWhereHandler().list(objs);
+ }
+
+ @Override
+ public SelectBuilder addMinus(AbstractQueryBuilder<?> t) {
+ getWhereHandler().addMinus(t);
+ return this;
+ }
+
}
diff --git a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/UpdateBuilder.java b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/UpdateBuilder.java
index e2b82da..6ebdfcb 100644
--- a/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/UpdateBuilder.java
+++ b/jena-extras/jena-querybuilder/src/main/java/org/apache/jena/arq/querybuilder/UpdateBuilder.java
@@ -69,1190 +69,1092 @@ import org.apache.jena.vocabulary.RDF;
*/
public class UpdateBuilder {
- private final PrefixHandler prefixHandler;
- private final WhereQuadHolder whereProcessor;
- private List<QuadHolder> inserts = new ArrayList<QuadHolder>();
- private List<QuadHolder> deletes = new ArrayList<QuadHolder>();
- private Map<Var, Node> values;
- private Node with;
-
- /**
- * Creates an UpdateBuilder with an empty prefix mapping.
- */
- public UpdateBuilder() {
- this.prefixHandler = new PrefixHandler();
- this.whereProcessor = new WhereQuadHolder(prefixHandler);
- this.values = new HashMap<Var, Node>();
- this.with = null;
- }
-
- /**
- * Creates an UpdateBuilder with the prefixes defined in the prolog clause.
- * <b>May modify the
- * contents of the prefix mapping in the prolog handler</b>
- *
- * @param prologClause
- * the default prefixes for this builder.
- */
- public UpdateBuilder(PrologClause<?> prologClause) {
- this(prologClause.getPrologHandler().getPrefixes());
- }
-
- /**
- * Creates an UpdateBuilder with the specified PrefixMapping.
- * <b>May modify the contents of the prefix mapping</b>
- *
- * @param pMap
- * the prefix mapping to use.
- */
- public UpdateBuilder(PrefixMapping pMap) {
- this.prefixHandler = new PrefixHandler(pMap);
- this.whereProcessor = new WhereQuadHolder(prefixHandler);
- }
-
- /**
- * Convert a collection of QuadHolder to an iterator on Quads.
- * @param holders the Collection of QuadHolder objects
- * @return an iterator over the Quads.
- */
- private ExtendedIterator<Quad> getQuads(Collection<QuadHolder> holders) {
- ExtendedIterator<Quad> result = NiceIterator.emptyIterator();
- for (QuadHolder holder : holders) {
- result = result.andThen(holder.setValues(values).getQuads());
- }
- return result;
- }
-
- /**
- * Build the update.
- *
- * <b>Note: the update does not include the prefix statements</b> use
- * buildRequest() or appendTo() methods to include the prefix statements.
- *
- * @return the update.
- */
- public Update build() {
-
- if (deletes.isEmpty() && inserts.isEmpty()) {
- throw new IllegalStateException("At least one delete or insert must be specified");
- }
-
- if (whereProcessor.isEmpty()) {
- return buildNoWhere();
- }
- return buildWhere();
- }
-
- /**
- * Build as an UpdateRequest with prefix mapping set.
- *
- * @return a new UpdateRequest
- */
- public UpdateRequest buildRequest() {
- UpdateRequest req = new UpdateRequest(build());
- req.setPrefixMapping(prefixHandler.getPrefixes());
- return req;
- }
-
- /**
- * Appends the new Update to the UpdateRequest.
- *
- * @param req
- * the UpdateRequest to append this Update to.
- * @return the req parameter for chaining.
- */
- public UpdateRequest appendTo(UpdateRequest req) {
- req.add(build());
- for (Map.Entry<String, String> entry : prefixHandler.getPrefixes().getNsPrefixMap().entrySet()) {
- req.setPrefix(entry.getKey(), entry.getValue());
- }
- return req;
- }
-
- // build updates without where clauses
- private Update buildNoWhere() {
- if (inserts.isEmpty()) {
- QuadDataAcc quadData = new QuadDataAcc(getQuads(deletes).mapWith(new Function<Quad, Quad>() {
- @Override
- public Quad apply(Quad arg0) {
- return check(arg0);
- }
- }).toList());
- return new UpdateDataDelete(quadData);
- }
- if (deletes.isEmpty()) {
- QuadDataAcc quadData = new QuadDataAcc(getQuads(inserts).mapWith(new Function<Quad, Quad>() {
-
- @Override
- public Quad apply(Quad t) {
- return check(t);
- }
-
- }).toList());
- return new UpdateDataInsert(quadData);
- }
-
- throw new IllegalStateException("Can not have both insert and delete without a where clause");
- }
-
- // build updates with where clauses
- private Update buildWhere() {
-
- UpdateModify retval = new UpdateModify();
- if (with != null)
- {
- Node graph = values.get(with);
- if (graph == null) {
- graph = with;
- }
- retval.setWithIRI(graph);
- }
- QuadAcc acc;
- Iterator<Quad> iter;
-
- if (!inserts.isEmpty()) {
- retval.setHasInsertClause(true);
- acc = retval.getInsertAcc();
- iter = getQuads(inserts);
- while (iter.hasNext()) {
- acc.addQuad(iter.next());
- }
- }
- if (!deletes.isEmpty()) {
- retval.setHasDeleteClause(true);
- acc = retval.getDeleteAcc();
-
- iter = getQuads(deletes);
- while (iter.hasNext()) {
- acc.addQuad(iter.next());
- }
- }
-
- retval.setElement(whereProcessor.setVars(values).build());
-
- return retval;
-
- }
-
- /**
- * Make a triple path from the objects.
- *
- * For subject, predicate and objects nodes
- * <ul>
- * <li>Will return Node.ANY if object is null.</li>
- * <li>Will return the enclosed Node from a FrontsNode</li>
- * <li>Will return the object if it is a Node.</li>
- * <li>If the object is a String
- * <ul>
- * <li>For <code>predicate</code> only will attempt to parse as a path</li>
- * <li>for subject, predicate and object will call NodeFactoryExtra.parseNode()
- * using the currently defined prefixes if the object is a String</li>
- * </ul></li>
- * <li>Will create a literal representation if the parseNode() fails or for
- * any other object type.</li>
- * </ul>
- *
- * @param s The subject object
- * @param p the predicate object
- * @param o the object object.
- * @return a TriplePath
- */
- public TriplePath makeTriplePath(Object s, Object p, Object o) {
- final Object po = Converters.makeNodeOrPath( p, prefixHandler.getPrefixes() );
- if (po instanceof Path)
- {
- return new TriplePath(makeNode(s), (Path)po, makeNode(o));
- }
- return new TriplePath( new Triple( makeNode(s), (Node)po, makeNode(o)));
- }
-
- /**
- * Convert the object to a node.
- *
- * Shorthand for AbstractQueryBuilder.makeNode( o, prefixes )
- *
- * @see AbstractQueryBuilder#makeNode(Object)
- *
- * @param o
- * the object to convert to a node.
- * @return the Node.
- */
- public Node makeNode(Object o) {
- return Converters.makeNode(o, prefixHandler.getPrefixes());
- }
-
- /**
- * Convert the object to a node.
- *
- * Shorthand for AbstractQueryBuilder.makeVar( o )
- *
- * @see Converters#makeVar(Object)
- *
- * @param o
- * the object to convert to a var.
- * @return the Var.
- * @deprecated use {@link Converters#makeVar(Object)}
- */
- @Deprecated
- public Var makeVar(Object o) {
- return Converters.makeVar(o);
- }
-
- /**
- * Quote a string.
- *
- * Shorthand for AbstractQueryBuilder.quote( s )
- *
- * @see Converters#quoted(String)
- *
- * @deprecated Use quoted()
- * @param s
- * the string to quote.
- * @return the quoted string.
- * @deprecated use {@link Converters#quoted(String)}
- */
- @Deprecated
- public String quote(String s) {
- return Converters.quoted(s);
- }
-
- /**
- * Add a quad to the insert statement.
- *
- * Arguments are converted to nodes using the makeNode() method.
- *
- * @see #makeNode(Object)
- * @param g
- * the graph
- * @param s
- * the subject
- * @param p
- * the predicate
- * @param o
- * the object
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object g, Object s, Object p, Object o) {
- return addInsert(new Quad(makeNode(g), makeNode(s), makeNode(p), makeNode(o)));
- }
-
- /**
- * Add a quad to the insert statement.
- *
- *
- * @param quad
- * the quad to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Quad quad) {
- inserts.add(new SingleQuadHolder(quad));
- return this;
- }
-
- /**
- * Add a triple to the insert statement.
- *
- * Arguments are converted to nodes using the makeNode() method.
- *
- * @see #makeNode(Object)
- * @param s
- * the subject
- * @param p
- * the predicate
- * @param o
- * the object
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object s, Object p, Object o) {
- addInsert(new Triple(makeNode(s), makeNode(p), makeNode(o)));
- return this;
- }
-
- /**
- * Add a triple to the insert statement.
- *
- * @param t
- * the triple to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Triple t) {
- inserts.add(new SingleQuadHolder( t ));
- return this;
- }
-
- /**
- * Add a triple in a specified graph to the insert statement.
- *
- * The graph object is converted by a call to makeNode().
- *
- * @see #makeNode(Object)
- * @param g
- * the graph for the triple.
- * @param t
- * the triple to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object g, Triple t) {
- Quad q = new Quad(makeNode(g), t);
- inserts.add(new SingleQuadHolder(q));
- return this;
- }
-
- /**
- * Add all the statements in the model to the insert statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param model The model to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Model model) {
- inserts.add(new ModelQuadHolder( model ));
- return this;
- }
-
- /**
- * Add all the triples in the model to the insert statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param collection The triples to insert.
- * @return this builder for chaining.
- * @see Quad#defaultGraphNodeGenerated
- */
- public UpdateBuilder addInsert(Collection<Triple> collection) {
- inserts.add(new CollectionQuadHolder( collection ));
- return this;
- }
-
- /**
- * Add all the quads in the collection to the insert statement.
- *
- * @param collection The quads to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsertQuads(Collection<Quad> collection) {
- inserts.add(new QuadCollectionHolder( collection ));
- return this;
- }
-
- /**
- * Add all the triples to the insert statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param iter The iterator of triples to insert.
- * @return this builder for chaining.
- * @see Quad#defaultGraphNodeGenerated
- */
- public UpdateBuilder addInsert(Iterator<Triple> iter) {
- inserts.add(new CollectionQuadHolder( iter ));
- return this;
- }
-
- /**
- * Add all the statements in the model a specified graph to the insert statement.
- *
- * The graph object is converted by a call to makeNode().
- *
- * @see #makeNode(Object)
- * @param g
- * the graph for the triple.
- * @param model
- * the model to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object g, Model model) {
- inserts.add( new ModelQuadHolder( makeNode(g), model));
- return this;
- }
-
- /**
- * Add triples to the insert statement.
- *
- * @param g the name of the graph to add the triples to.
- * @param collection The triples to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object g, Collection<Triple> collection) {
- inserts.add(new CollectionQuadHolder( makeNode(g), collection ));
- return this;
- }
-
- /**
- * Add triples to the insert statement.
- * @param g the name of the graph to add the triples to.
- * @param iter The iterator of triples to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object g, Iterator<Triple> iter) {
- inserts.add(new CollectionQuadHolder( makeNode(g), iter ));
- return this;
- }
-
- /**
- * Add the statements from the where clause in the specified query builder
- * to the insert statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- * @see #makeNode(Object)
- * @see Quad#defaultGraphNodeGenerated
- * @param queryBuilder
- * The query builder to extract the where clause from.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(AbstractQueryBuilder<?> queryBuilder) {
- inserts.add(new QBQuadHolder( queryBuilder));
- return this;
- }
-
- /**
- * 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().
- *
- * @see #makeNode(Object)
- * @param graph
- * the graph to add the statements to.
- * @param queryBuilder
- * The query builder to extract the where clause from.
- * @return this builder for chaining.
- */
- public UpdateBuilder addInsert(Object graph, AbstractQueryBuilder<?> queryBuilder) {
- inserts.add(new QBQuadHolder(makeNode(graph), queryBuilder));
- return this;
- }
-
- /**
- * Add a quad to the delete statement.
- *
- * Arguments are converted to nodes using the makeNode() method.
- *
- * @see #makeNode(Object)
- * @param g
- * the graph
- * @param s
- * the subject
- * @param p
- * the predicate
- * @param o
- * the object
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object g, Object s, Object p, Object o) {
- return addDelete(new Quad(makeNode(g),
- makeNode(s),
- makeNode(p),
- makeNode(o)));
- }
-
- /**
- * Add a quad to the delete statement.
- *
- * @param quad
- * the quad to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Quad quad) {
- deletes.add(new SingleQuadHolder(quad));
- return this;
- }
-
- /**
- * Add all the quads collection to the delete statement.
- *
- * @param collection The quads to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDeleteQuads(Collection<Quad> collection) {
- deletes.add(new QuadCollectionHolder( collection ));
- return this;
- }
-
- /**
- * Add a triple to the delete statement.
- *
- * Arguments are converted to nodes using the makeNode() method.
- *
- * @see #makeNode(Object)
- * @param s
- * the subject
- * @param p
- * the predicate
- * @param o
- * the object
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object s, Object p, Object o) {
- addDelete(new Triple(makeNode(s), makeNode(p), makeNode(o)));
- return this;
- }
-
- /**
- * Add a triple to the delete statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param t
- * the triple to add.
- * @return this builder for chaining.
- * @see Quad#defaultGraphNodeGenerated
- */
- public UpdateBuilder addDelete(Triple t) {
- deletes.add(new SingleQuadHolder(t));
- return this;
- }
-
- /**
- * Add a triple to the delete statement.
- *
- * The graph object is converted by a call to makeNode().
- *
- * @see #makeNode(Object)
- * @param g
- * the graph for the triple.
- * @param t
- * the triple to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object g, Triple t) {
- Quad q = new Quad(makeNode(g), t);
- deletes.add(new SingleQuadHolder(q));
- return this;
- }
-
- /**
- * Add all the statements in the model to the delete statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param model The model to insert.
- * @return this builder for chaining.
- * @see Quad#defaultGraphNodeGenerated
- */
- public UpdateBuilder addDelete(Model model) {
- deletes.add(new ModelQuadHolder( model ));
- return this;
- }
-
- /**
- * Add all triples to the delete statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param collection The collection of triples to insert.
- * @return this builder for chaining.
- * @see Quad#defaultGraphNodeGenerated
- */
- public UpdateBuilder addDelete(Collection<Triple> collection) {
- deletes.add(new CollectionQuadHolder( collection ));
- return this;
- }
-
- /**
- * Add all the triples in the iterator to the delete statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @param iter The iterator of triples to insert.
- * @return this builder for chaining.
- * @see Quad#defaultGraphNodeGenerated
- */
- public UpdateBuilder addDelete(Iterator<Triple> iter) {
- deletes.add(new CollectionQuadHolder( iter ));
- return this;
- }
-
- /**
- * Add all the statements in the model a specified graph to the delete statement.
- *
- * The graph object is converted by a call to makeNode().
- *
- * @see #makeNode(Object)
- * @param g
- * the graph for the triples.
- * @param model
- * the model to add.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object g, Model model) {
- deletes.add( new ModelQuadHolder( makeNode(g), model));
- return this;
- }
-
-
- /**
- * Add all the statements in the model to the delete statement.
- *
- * @param g
- * the graph for the triples.
- * @param collection The collection of triples to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object g, Collection<Triple> collection) {
- deletes.add(new CollectionQuadHolder( makeNode(g), collection ));
- return this;
- }
-
- /**
- * Add all the statements in the model to the delete statement.
- *
- * @param g
- * the graph for the triples.
- * @param iter The iterator of triples to insert.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object g, Iterator<Triple> iter) {
- deletes.add(new CollectionQuadHolder( makeNode(g), iter ));
- return this;
- }
-
- /**
- * Add the statements from the where clause in the specified query builder
- * to the delete statement.
- * Uses Quad.defaultGraphNodeGenerated as the graph name.
- *
- * @see #makeNode(Object)
- * @see Quad#defaultGraphNodeGenerated
- * @param queryBuilder
- * The query builder to extract the where clause from.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(AbstractQueryBuilder<?> queryBuilder) {
- deletes.add(new QBQuadHolder( queryBuilder));
- return this;
- }
-
- /**
- * 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().
- *
- * @see #makeNode(Object)
- * @param graph
- * the graph to add the statements to.
- * @param queryBuilder
- * The query builder to extract the where clause from.
- * @return this builder for chaining.
- */
- public UpdateBuilder addDelete(Object graph, AbstractQueryBuilder<?> queryBuilder) {
- deletes.add(new QBQuadHolder(makeNode(graph), queryBuilder));
- return this;
- }
-
- /**
- * Add the prefix to the prefix mapping.
- *
- * @param pfx
- * the prefix to add.
- * @param uri
- * the uri for the prefix.
- * @return this builder for chaining
- */
- public UpdateBuilder addPrefix(String pfx, Resource uri) {
- return addPrefix(pfx, uri.getURI());
- }
-
- /**
- * Add the prefix to the prefix mapping.
- *
- * @param pfx
- * the prefix to add.
- * @param uri
- * the uri for the prefix.
- * @return this builder for chaining
- */
- public UpdateBuilder addPrefix(String pfx, Node uri) {
- return addPrefix(pfx, uri.getURI());
- }
-
- /**
- * Add the prefix to the prefix mapping.
- *
- * @param pfx
- * the prefix to add.
- * @param uri
- * the uri for the prefix.
- * @return this builder for chaining
- */
- public UpdateBuilder addPrefix(String pfx, String uri) {
- prefixHandler.addPrefix(pfx, uri);
- return this;
- }
-
- /**
- * Add the prefixes to the prefix mapping.
- *
- * @param prefixes
- * the prefixes to add.
- * @return this builder for chaining
- */
-
- public UpdateBuilder addPrefixes(Map<String, String> prefixes) {
- prefixHandler.addPrefixes(prefixes);
- return this;
- }
-
- /**
- * Add the prefixes to the prefix mapping.
- *
- * @param prefixes
- * the prefix mapping to add.
- * @return this builder for chaining
- */
-
- public UpdateBuilder addPrefixes(PrefixMapping prefixes) {
- prefixHandler.addPrefixes(prefixes);
- return this;
- }
-
- /**
- * Get an ExprFactory that uses the prefixes from this builder.
- *
- * @return the ExpressionFactory.
- */
- public ExprFactory getExprFactory() {
- return prefixHandler.getExprFactory();
- }
-
- /**
- * 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.
- *
- * @param var
- * The variable to replace
- * @param value
- * The value to replace it with or null to remove the
- * replacement.
- */
- public void setVar(Var var, Node value) {
- if (value == null) {
- values.remove(var);
- } else {
- values.put(var, 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 {@link #makeVar} for conversion of the var param. See
- * {@link #makeNode} for conversion of the value param.
- *
- * @param var
- * The variable to replace.
- * @param value
- * The value to replace it with or null to remove the
- * replacement.
- */
- public void setVar(Object var, Object value) {
- if (value == null) {
- setVar(Converters.makeVar(var), null);
- } else {
- setVar(Converters.makeVar(var), makeNode(value));
- }
- }
-
- private Quad check(Quad q) {
- if (Var.isVar(q.getGraph()))
- throw new QueryParseException("Variables not permitted in data quad", -1, -1);
- if (Var.isVar(q.getSubject()) || Var.isVar(q.getPredicate()) || Var.isVar(q.getObject()))
- throw new QueryParseException("Variables not permitted in data quad", -1, -1);
- if (q.getSubject().isLiteral())
- throw new QueryParseException("Literals not allowed as subjects in data", -1, -1);
- return q;
- }
-
- /**
- * Add all where attributes from the Where Handler argument.
- *
- * @param whereHandler
- * The Where Handler to copy from.
- */
- public UpdateBuilder addAll(WhereHandler whereHandler) {
- whereProcessor.addAll(whereHandler);
- return this;
- }
-
- /**
- * Add the triple path to the where clause
- *
- * @param t
- * The triple path to add.
- * @throws IllegalArgumentException
- * If the triple path is not a valid triple path for a where
- * clause.
- */
- public UpdateBuilder addWhere(TriplePath t) throws IllegalArgumentException {
- whereProcessor.addWhere(t);
- return this;
- }
-
- /**
- * Add the WhereClause
- *
- * @param whereClause
- * @throws IllegalArgumentException
- * If the triple path is not a valid triple path for a where
- * clause.
- */
- public UpdateBuilder addWhere(WhereClause<?> whereClause) throws IllegalArgumentException {
- whereProcessor.addAll(whereClause.getWhereHandler());
- return this;
- }
- /**
- * Add an optional triple to the where clause
- *
- * @param t
- * The triple path to add.
- * @return The Builder for chaining.
- * @throws IllegalArgumentException
- * If the triple is not a valid triple for a where clause.
- */
- public UpdateBuilder addOptional(TriplePath t) throws IllegalArgumentException {
- whereProcessor.addOptional(t);
- return this;
- }
-
- /**
- * Add the contents of a where handler as an optional statement.
- *
- * @param whereHandler
- * The where handler to use as the optional statement.
- */
- public UpdateBuilder addOptional(WhereHandler whereHandler) {
- whereProcessor.addOptional(whereHandler);
- return this;
- }
-
- /**
- * Add an expression string as a filter.
- *
- * @param expression
- * The expression string to add.
- * @return The Builder for chaining.
- * @throws ParseException
- * If the expression can not be parsed.
- */
- public UpdateBuilder addFilter(String expression) throws ParseException {
- whereProcessor.addFilter(expression);
- return this;
- }
-
- /**
- * Add a subquery to the where clause.
- *
- * @param subQuery
- * The sub query to add.
- * @return The Builder for chaining.
- */
- public UpdateBuilder addSubQuery(AbstractQueryBuilder<?> subQuery) {
- whereProcessor.addSubQuery(subQuery);
- return this;
- }
-
- /**
- * Add a union to the where clause.
- *
- * @param subQuery
- * The subquery to add as the union.
- * @return The Builder for chaining.
- */
- public UpdateBuilder addUnion(AbstractQueryBuilder<?> subQuery) {
- whereProcessor.addUnion(subQuery);
- return this;
- }
-
- /**
- * Add a graph to the where clause.
- *
- * @param graph
- * The name of the graph.
- * @param subQuery
- * The where handler that defines the graph.
- */
- public UpdateBuilder addGraph(Node graph, WhereHandler subQuery) {
- whereProcessor.addGraph(graph, subQuery);
- return this;
- }
-
- /**
- * Add a binding to the where clause.
- *
- * @param expr
- * The expression to bind.
- * @param var
- * The variable to bind it to.
- */
- public UpdateBuilder addBind(Expr expr, Var var) {
- whereProcessor.addBind(expr, var);
- return this;
- }
-
- /**
- * Add a binding to the where clause.
- *
- * @param expression
- * The expression to bind.
- * @param var
- * The variable to bind it to.
- * @throws ParseException
- */
- public UpdateBuilder addBind(String expression, Var var) throws ParseException {
- whereProcessor.addBind(expression, var);
- return this;
- }
-
- /**
- * 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 {@link AbstractQueryBuilder#makeNode} for conversion of the param
- * values.
- * <p>
- * usage:
- * <ul>
- * <li>list( param1, param2, param3, ... )</li>
- * <li>addWhere( list( param1, param2, param3, ... ), p, o )</li>
- * <li>addOptional( list( param1, param2, param3, ... ), p, o )</li>
- * </ul>
- * </p>
- *
- * @param objs
- * the list of objects for the list.
- * @return the first blank node in the list.
- */
- public Node list(Object... objs) {
- Node retval = NodeFactory.createBlankNode();
- Node lastObject = retval;
- for (int i = 0; i < objs.length; i++) {
- Node n = makeNode(objs[i]);
- addWhere(new TriplePath(new Triple(lastObject, RDF.first.asNode(), n)));
- if (i + 1 < objs.length) {
- Node nextObject = NodeFactory.createBlankNode();
- addWhere(new TriplePath(new Triple(lastObject, RDF.rest.asNode(), nextObject)));
- lastObject = nextObject;
- } else {
- addWhere(new TriplePath(new Triple(lastObject, RDF.rest.asNode(), RDF.nil.asNode())));
- }
-
- }
-
- return retval;
- }
-
- /**
- * Adds a triple to the where clause.
- *
- * @param t
- * The triple path to add
- * @return The Builder for chaining.
- */
- public UpdateBuilder addWhere(Triple t) {
- return addWhere(new TriplePath(t));
- }
-
- /**
- * Adds a triple to the where clause.
- *
- * @param t
- * The triple to add
- * @return The Builder for chaining.
- */
- public UpdateBuilder addWhere(FrontsTriple t) {
- return addWhere(t.asTriple());
- }
-
- /**
- * Adds a triple or triple path to the where clause.
- *
- * See {@link AbstractQueryBuilder#makeTriplePath} for conversion of the
- * param values.
- *
- * @param s
- * The subject.
- * @param p
- * The predicate.
- * @param o
- * The object.
- * @return The Builder for chaining.
- */
- public UpdateBuilder addWhere(Object s, Object p, Object o) {
- return addWhere(makeTriplePath(s, p, o));
- }
-
- /**
- * Adds an optional triple to the where clause.
- *
- * @param t
- * The triple to add
- * @return The Builder for chaining.
- */
- public UpdateBuilder addOptional(Triple t) {
- return addOptional(new TriplePath(t));
- }
-
- /**
- * Adds an optional triple as to the where clause.
- *
- * @param t
- * The triple to add
- * @return The Builder for chaining.
- */
- public UpdateBuilder addOptional(FrontsTriple t) {
- return addOptional(t.asTriple());
- }
-
- /**
- * Adds an optional triple or triple path to the where clause.
- *
- * See {@link AbstractQueryBuilder#makeTriplePath} for conversion of the
- * param values.
- *
- * @param s
- * The subject.
- * @param p
- * The predicate.
- * @param o
- * The object.
- * @return The Builder for chaining.
- */
- public UpdateBuilder addOptional(Object s, Object p, Object o) {
- return addOptional(makeTriplePath( s, p, o ));
- }
-
- /**
- * Adds an optional group pattern to the where clause.
- *
- * @param t
- * The select builder to add as an optional pattern
- * @return The Builder for chaining.
- */
- public UpdateBuilder addOptional(AbstractQueryBuilder<?> t) {
- whereProcessor.addOptional(t.getWhereHandler());
- return this;
- }
-
- /**
- * Adds a filter to the where clause
- *
- * Use ExprFactory or NodeValue static or the AbstractQueryBuilder.makeExpr
- * methods to create the expression.
- *
- * @see ExprFactory
- * @see org.apache.jena.sparql.expr.NodeValue
- * @see AbstractQueryBuilder#makeExpr(String)
- *
- * @param expression
- * the expression to evaluate for the filter.
- * @return @return The Builder for chaining.
- */
- public UpdateBuilder addFilter(Expr expression) {
- whereProcessor.addFilter(expression);
- return this;
- }
-
- /**
- * Add a graph statement to the query as per
- * http://www.w3.org/TR/2013/REC-sparql11
- * -query-20130321/#rGraphGraphPattern.
- *
- * See {@link AbstractQueryBuilder#makeNode} for conversion of the graph
- * param.
- *
- * @param graph
- * The iri or variable identifying the graph.
- * @param subQuery
- * The graph to add.
- * @return This builder for chaining.
- */
- public UpdateBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery) {
- whereProcessor.addGraph(makeNode(graph), subQuery.getWhereHandler());
- return this;
- }
-
- /**
- * Add a bind statement to the query *
- * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
- *
- * @param expression
- * The expression to bind to the var.
- * @param var
- * The variable to bind to.
- * @return This builder for chaining.
- */
- public UpdateBuilder addBind(Expr expression, Object var) {
- whereProcessor.addBind(expression, makeVar(var));
- return this;
- }
-
- /**
- * Add a bind statement to the query
- * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
- *
- * @param expression
- * The expression to bind to the var.
- * @param var
- * The variable to bind to.
- * @return This builder for chaining.
- * @throws ParseException
- */
- public UpdateBuilder addBind(String expression, Object var) throws ParseException {
- whereProcessor.addBind(expression, makeVar(var));
- return this;
- }
-
- /**
- * Add a minus clause to the query.
- *
- * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rMinusGraphPattern
- *
- * @param t
- * The select builder to add as a minus pattern
- * @return this builder for chaining
- */
- public UpdateBuilder addMinus(AbstractQueryBuilder<?> t) {
- whereProcessor.addMinus(t);
- return this;
- }
-
- /**
- * Specify the graph for all inserts and deletes.
- *
- *
- * @see Quad#defaultGraphNodeGenerated
- * @param iri
- * the IRI for the graph to use.
- * @return this builder for chaining.
- */
- public UpdateBuilder with(Object iri) {
- if (iri == null) {
- with = null;
- }
- Node n = makeNode(iri);
- if (n.isLiteral()) {
- throw new IllegalArgumentException(String.format("IRI '%s' must not be a literal", iri));
- }
- with = n;
- return this;
- }
-
- /**
- * Create a DeleteWhere from the where clause.
- * @return a DeleteWhere update.
- */
- public UpdateDeleteWhere buildDeleteWhere()
- {
- QuadAcc quadAcc = new QuadAcc( whereProcessor.getQuads().toList() );
- return new UpdateDeleteWhere( quadAcc );
- }
-
- /**
- * Create a DeleteWhere from the where clause.
- * @param queryBuilder the query builder to extract the where clause from.
- * @return a DeleteWhere update.
- */
- public UpdateDeleteWhere buildDeleteWhere( AbstractQueryBuilder<?> queryBuilder)
- {
- QuadAcc quadAcc = new QuadAcc( new QBQuadHolder( queryBuilder ).getQuads().toList() );
- return new UpdateDeleteWhere( quadAcc );
- }
+ private final PrefixHandler prefixHandler;
+ private final WhereQuadHolder whereProcessor;
+ private List<QuadHolder> inserts = new ArrayList<QuadHolder>();
+ private List<QuadHolder> deletes = new ArrayList<QuadHolder>();
+ private Map<Var, Node> values;
+ private Node with;
+
+ /**
+ * Creates an UpdateBuilder with an empty prefix mapping.
+ */
+ public UpdateBuilder() {
+ this.prefixHandler = new PrefixHandler();
+ this.whereProcessor = new WhereQuadHolder(prefixHandler);
+ this.values = new HashMap<Var, Node>();
+ this.with = null;
+ }
+
+ /**
+ * Creates an UpdateBuilder with the prefixes defined in the prolog clause.
+ * <b>May modify the contents of the prefix mapping in the prolog handler</b>
+ *
+ * @param prologClause the default prefixes for this builder.
+ */
+ public UpdateBuilder(PrologClause<?> prologClause) {
+ this(prologClause.getPrologHandler().getPrefixes());
+ }
+
+ /**
+ * Creates an UpdateBuilder with the specified PrefixMapping. <b>May modify the
+ * contents of the prefix mapping</b>
+ *
+ * @param pMap the prefix mapping to use.
+ */
+ public UpdateBuilder(PrefixMapping pMap) {
+ this.prefixHandler = new PrefixHandler(pMap);
+ this.whereProcessor = new WhereQuadHolder(prefixHandler);
+ }
+
+ /**
+ * Convert a collection of QuadHolder to an iterator on Quads.
+ *
+ * @param holders the Collection of QuadHolder objects
+ * @return an iterator over the Quads.
+ */
+ private ExtendedIterator<Quad> getQuads(Collection<QuadHolder> holders) {
+ ExtendedIterator<Quad> result = NiceIterator.emptyIterator();
+ for (QuadHolder holder : holders) {
+ result = result.andThen(holder.setValues(values).getQuads());
+ }
+ return result;
+ }
+
+ /**
+ * Build the update.
+ *
+ * <b>Note: the update does not include the prefix statements</b> use
+ * buildRequest() or appendTo() methods to include the prefix statements.
+ *
+ * @return the update.
+ */
+ public Update build() {
+
+ if (deletes.isEmpty() && inserts.isEmpty()) {
+ throw new IllegalStateException("At least one delete or insert must be specified");
+ }
+
+ if (whereProcessor.isEmpty()) {
+ return buildNoWhere();
+ }
+ return buildWhere();
+ }
+
+ /**
+ * Build as an UpdateRequest with prefix mapping set.
+ *
+ * @return a new UpdateRequest
+ */
+ public UpdateRequest buildRequest() {
+ UpdateRequest req = new UpdateRequest(build());
+ req.setPrefixMapping(prefixHandler.getPrefixes());
+ return req;
+ }
+
+ /**
+ * Appends the new Update to the UpdateRequest.
+ *
+ * @param req the UpdateRequest to append this Update to.
+ * @return the req parameter for chaining.
+ */
+ public UpdateRequest appendTo(UpdateRequest req) {
+ req.add(build());
+ for (Map.Entry<String, String> entry : prefixHandler.getPrefixes().getNsPrefixMap().entrySet()) {
+ req.setPrefix(entry.getKey(), entry.getValue());
+ }
+ return req;
+ }
+
+ // build updates without where clauses
+ private Update buildNoWhere() {
+ if (inserts.isEmpty()) {
+ QuadDataAcc quadData = new QuadDataAcc(getQuads(deletes).mapWith(new Function<Quad, Quad>() {
+ @Override
+ public Quad apply(Quad arg0) {
+ return check(arg0);
+ }
+ }).toList());
+ return new UpdateDataDelete(quadData);
+ }
+ if (deletes.isEmpty()) {
+ QuadDataAcc quadData = new QuadDataAcc(getQuads(inserts).mapWith(new Function<Quad, Quad>() {
+
+ @Override
+ public Quad apply(Quad t) {
+ return check(t);
+ }
+
+ }).toList());
+ return new UpdateDataInsert(quadData);
+ }
+
+ throw new IllegalStateException("Can not have both insert and delete without a where clause");
+ }
+
+ // build updates with where clauses
+ private Update buildWhere() {
+
+ UpdateModify retval = new UpdateModify();
+ if (with != null) {
+ Node graph = values.get(with);
+ if (graph == null) {
+ graph = with;
+ }
+ retval.setWithIRI(graph);
+ }
+ QuadAcc acc;
+ Iterator<Quad> iter;
+
+ if (!inserts.isEmpty()) {
+ retval.setHasInsertClause(true);
+ acc = retval.getInsertAcc();
+ iter = getQuads(inserts);
+ while (iter.hasNext()) {
+ acc.addQuad(iter.next());
+ }
+ }
+ if (!deletes.isEmpty()) {
+ retval.setHasDeleteClause(true);
+ acc = retval.getDeleteAcc();
+
+ iter = getQuads(deletes);
+ while (iter.hasNext()) {
+ acc.addQuad(iter.next());
+ }
+ }
+
+ retval.setElement(whereProcessor.setVars(values).build());
+
+ return retval;
+
+ }
+
+ /**
+ * Make a triple path from the objects.
+ *
+ * For subject, predicate and objects nodes
+ * <ul>
+ * <li>Will return Node.ANY if object is null.</li>
+ * <li>Will return the enclosed Node from a FrontsNode</li>
+ * <li>Will return the object if it is a Node.</li>
+ * <li>If the object is a String
+ * <ul>
+ * <li>For <code>predicate</code> only will attempt to parse as a path</li>
+ * <li>for subject, predicate and object will call NodeFactoryExtra.parseNode()
+ * using the currently defined prefixes if the object is a String</li>
+ * </ul>
+ * </li>
+ * <li>Will create a literal representation if the parseNode() fails or for any
+ * other object type.</li>
+ * </ul>
+ *
+ * @param s The subject object
+ * @param p the predicate object
+ * @param o the object object.
+ * @return a TriplePath
+ */
+ public TriplePath makeTriplePath(Object s, Object p, Object o) {
+ final Object po = Converters.makeNodeOrPath(p, prefixHandler.getPrefixes());
+ if (po instanceof Path) {
+ return new TriplePath(makeNode(s), (Path) po, makeNode(o));
+ }
+ return new TriplePath(new Triple(makeNode(s), (Node) po, makeNode(o)));
+ }
+
+ /**
+ * Convert the object to a node.
+ *
+ * Shorthand for AbstractQueryBuilder.makeNode( o, prefixes )
+ *
+ * @see AbstractQueryBuilder#makeNode(Object)
+ *
+ * @param o the object to convert to a node.
+ * @return the Node.
+ */
+ public Node makeNode(Object o) {
+ return Converters.makeNode(o, prefixHandler.getPrefixes());
+ }
+
+ /**
+ * Convert the object to a node.
+ *
+ * Shorthand for AbstractQueryBuilder.makeVar( o )
+ *
+ * @see Converters#makeVar(Object)
+ *
+ * @param o the object to convert to a var.
+ * @return the Var.
+ * @deprecated use {@link Converters#makeVar(Object)}
+ */
+ @Deprecated
+ public Var makeVar(Object o) {
+ return Converters.makeVar(o);
+ }
+
+ /**
+ * Quote a string.
+ *
+ * Shorthand for AbstractQueryBuilder.quote( s )
+ *
+ * @see Converters#quoted(String)
+ *
+ * @deprecated Use quoted()
+ * @param s the string to quote.
+ * @return the quoted string.
+ * @deprecated use {@link Converters#quoted(String)}
+ */
+ @Deprecated
+ public String quote(String s) {
+ return Converters.quoted(s);
+ }
+
+ /**
+ * Add a quad to the insert statement.
+ *
+ * Arguments are converted to nodes using the makeNode() method.
+ *
+ * @see #makeNode(Object)
+ * @param g the graph
+ * @param s the subject
+ * @param p the predicate
+ * @param o the object
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object g, Object s, Object p, Object o) {
+ return addInsert(new Quad(makeNode(g), makeNode(s), makeNode(p), makeNode(o)));
+ }
+
+ /**
+ * Add a quad to the insert statement.
+ *
+ *
+ * @param quad the quad to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Quad quad) {
+ inserts.add(new SingleQuadHolder(quad));
+ return this;
+ }
+
+ /**
+ * Add a triple to the insert statement.
+ *
+ * Arguments are converted to nodes using the makeNode() method.
+ *
+ * @see #makeNode(Object)
+ * @param s the subject
+ * @param p the predicate
+ * @param o the object
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object s, Object p, Object o) {
+ addInsert(new Triple(makeNode(s), makeNode(p), makeNode(o)));
+ return this;
+ }
+
+ /**
+ * Add a triple to the insert statement.
+ *
+ * @param t the triple to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Triple t) {
+ inserts.add(new SingleQuadHolder(t));
+ return this;
+ }
+
+ /**
+ * Add a triple in a specified graph to the insert statement.
+ *
+ * The graph object is converted by a call to makeNode().
+ *
+ * @see #makeNode(Object)
+ * @param g the graph for the triple.
+ * @param t the triple to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object g, Triple t) {
+ Quad q = new Quad(makeNode(g), t);
+ inserts.add(new SingleQuadHolder(q));
+ return this;
+ }
+
+ /**
+ * Add all the statements in the model to the insert statement. Uses
+ * Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @param model The model to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Model model) {
+ inserts.add(new ModelQuadHolder(model));
+ return this;
+ }
+
+ /**
+ * Add all the triples in the model to the insert statement. Uses
+ * Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @param collection The triples to insert.
+ * @return this builder for chaining.
+ * @see Quad#defaultGraphNodeGenerated
+ */
+ public UpdateBuilder addInsert(Collection<Triple> collection) {
+ inserts.add(new CollectionQuadHolder(collection));
+ return this;
+ }
+
+ /**
+ * Add all the quads in the collection to the insert statement.
+ *
+ * @param collection The quads to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsertQuads(Collection<Quad> collection) {
+ inserts.add(new QuadCollectionHolder(collection));
+ return this;
+ }
+
+ /**
+ * Add all the triples to the insert statement. Uses
+ * Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @param iter The iterator of triples to insert.
+ * @return this builder for chaining.
+ * @see Quad#defaultGraphNodeGenerated
+ */
+ public UpdateBuilder addInsert(Iterator<Triple> iter) {
+ inserts.add(new CollectionQuadHolder(iter));
+ return this;
+ }
+
+ /**
+ * Add all the statements in the model a specified graph to the insert
+ * statement.
+ *
+ * The graph object is converted by a call to makeNode().
+ *
+ * @see #makeNode(Object)
+ * @param g the graph for the triple.
+ * @param model the model to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object g, Model model) {
+ inserts.add(new ModelQuadHolder(makeNode(g), model));
+ return this;
+ }
+
+ /**
+ * Add triples to the insert statement.
+ *
+ * @param g the name of the graph to add the triples to.
+ * @param collection The triples to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object g, Collection<Triple> collection) {
+ inserts.add(new CollectionQuadHolder(makeNode(g), collection));
+ return this;
+ }
+
+ /**
+ * Add triples to the insert statement.
+ *
+ * @param g the name of the graph to add the triples to.
+ * @param iter The iterator of triples to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object g, Iterator<Triple> iter) {
+ inserts.add(new CollectionQuadHolder(makeNode(g), iter));
+ return this;
+ }
+
+ /**
+ * Add the statements from the where clause in the specified query builder to
+ * the insert statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @see #makeNode(Object)
+ * @see Quad#defaultGraphNodeGenerated
+ * @param queryBuilder The query builder to extract the where clause from.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(AbstractQueryBuilder<?> queryBuilder) {
+ inserts.add(new QBQuadHolder(queryBuilder));
+ return this;
+ }
+
+ /**
+ * 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().
+ *
+ * @see #makeNode(Object)
+ * @param graph the graph to add the statements to.
+ * @param queryBuilder The query builder to extract the where clause from.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addInsert(Object graph, AbstractQueryBuilder<?> queryBuilder) {
+ inserts.add(new QBQuadHolder(makeNode(graph), queryBuilder));
+ return this;
+ }
+
+ /**
+ * Add a quad to the delete statement.
+ *
+ * Arguments are converted to nodes using the makeNode() method.
+ *
+ * @see #makeNode(Object)
+ * @param g the graph
+ * @param s the subject
+ * @param p the predicate
+ * @param o the object
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object g, Object s, Object p, Object o) {
+ return addDelete(new Quad(makeNode(g), makeNode(s), makeNode(p), makeNode(o)));
+ }
+
+ /**
+ * Add a quad to the delete statement.
+ *
+ * @param quad the quad to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Quad quad) {
+ deletes.add(new SingleQuadHolder(quad));
+ return this;
+ }
+
+ /**
+ * Add all the quads collection to the delete statement.
+ *
+ * @param collection The quads to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDeleteQuads(Collection<Quad> collection) {
+ deletes.add(new QuadCollectionHolder(collection));
+ return this;
+ }
+
+ /**
+ * Add a triple to the delete statement.
+ *
+ * Arguments are converted to nodes using the makeNode() method.
+ *
+ * @see #makeNode(Object)
+ * @param s the subject
+ * @param p the predicate
+ * @param o the object
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object s, Object p, Object o) {
+ addDelete(new Triple(makeNode(s), makeNode(p), makeNode(o)));
+ return this;
+ }
+
+ /**
+ * Add a triple to the delete statement. Uses Quad.defaultGraphNodeGenerated as
+ * the graph name.
+ *
+ * @param t the triple to add.
+ * @return this builder for chaining.
+ * @see Quad#defaultGraphNodeGenerated
+ */
+ public UpdateBuilder addDelete(Triple t) {
+ deletes.add(new SingleQuadHolder(t));
+ return this;
+ }
+
+ /**
+ * Add a triple to the delete statement.
+ *
+ * The graph object is converted by a call to makeNode().
+ *
+ * @see #makeNode(Object)
+ * @param g the graph for the triple.
+ * @param t the triple to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object g, Triple t) {
+ Quad q = new Quad(makeNode(g), t);
+ deletes.add(new SingleQuadHolder(q));
+ return this;
+ }
+
+ /**
+ * Add all the statements in the model to the delete statement. Uses
+ * Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @param model The model to insert.
+ * @return this builder for chaining.
+ * @see Quad#defaultGraphNodeGenerated
+ */
+ public UpdateBuilder addDelete(Model model) {
+ deletes.add(new ModelQuadHolder(model));
+ return this;
+ }
+
+ /**
+ * Add all triples to the delete statement. Uses Quad.defaultGraphNodeGenerated
+ * as the graph name.
+ *
+ * @param collection The collection of triples to insert.
+ * @return this builder for chaining.
+ * @see Quad#defaultGraphNodeGenerated
+ */
+ public UpdateBuilder addDelete(Collection<Triple> collection) {
+ deletes.add(new CollectionQuadHolder(collection));
+ return this;
+ }
+
+ /**
+ * Add all the triples in the iterator to the delete statement. Uses
+ * Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @param iter The iterator of triples to insert.
+ * @return this builder for chaining.
+ * @see Quad#defaultGraphNodeGenerated
+ */
+ public UpdateBuilder addDelete(Iterator<Triple> iter) {
+ deletes.add(new CollectionQuadHolder(iter));
+ return this;
+ }
+
+ /**
+ * Add all the statements in the model a specified graph to the delete
+ * statement.
+ *
+ * The graph object is converted by a call to makeNode().
+ *
+ * @see #makeNode(Object)
+ * @param g the graph for the triples.
+ * @param model the model to add.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object g, Model model) {
+ deletes.add(new ModelQuadHolder(makeNode(g), model));
+ return this;
+ }
+
+ /**
+ * Add all the statements in the model to the delete statement.
+ *
+ * @param g the graph for the triples.
+ * @param collection The collection of triples to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object g, Collection<Triple> collection) {
+ deletes.add(new CollectionQuadHolder(makeNode(g), collection));
+ return this;
+ }
+
+ /**
+ * Add all the statements in the model to the delete statement.
+ *
+ * @param g the graph for the triples.
+ * @param iter The iterator of triples to insert.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object g, Iterator<Triple> iter) {
+ deletes.add(new CollectionQuadHolder(makeNode(g), iter));
+ return this;
+ }
+
+ /**
+ * Add the statements from the where clause in the specified query builder to
+ * the delete statement. Uses Quad.defaultGraphNodeGenerated as the graph name.
+ *
+ * @see #makeNode(Object)
+ * @see Quad#defaultGraphNodeGenerated
+ * @param queryBuilder The query builder to extract the where clause from.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(AbstractQueryBuilder<?> queryBuilder) {
+ deletes.add(new QBQuadHolder(queryBuilder));
+ return this;
+ }
+
+ /**
+ * 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().
+ *
+ * @see #makeNode(Object)
+ * @param graph the graph to add the statements to.
+ * @param queryBuilder The query builder to extract the where clause from.
+ * @return this builder for chaining.
+ */
+ public UpdateBuilder addDelete(Object graph, AbstractQueryBuilder<?> queryBuilder) {
+ deletes.add(new QBQuadHolder(makeNode(graph), queryBuilder));
+ return this;
+ }
+
+ /**
+ * Add the prefix to the prefix mapping.
+ *
+ * @param pfx the prefix to add.
+ * @param uri the uri for the prefix.
+ * @return this builder for chaining
+ */
+ public UpdateBuilder addPrefix(String pfx, Resource uri) {
+ return addPrefix(pfx, uri.getURI());
+ }
+
+ /**
+ * Add the prefix to the prefix mapping.
+ *
+ * @param pfx the prefix to add.
+ * @param uri the uri for the prefix.
+ * @return this builder for chaining
+ */
+ public UpdateBuilder addPrefix(String pfx, Node uri) {
+ return addPrefix(pfx, uri.getURI());
+ }
+
+ /**
+ * Add the prefix to the prefix mapping.
+ *
+ * @param pfx the prefix to add.
+ * @param uri the uri for the prefix.
+ * @return this builder for chaining
+ */
+ public UpdateBuilder addPrefix(String pfx, String uri) {
+ prefixHandler.addPrefix(pfx, uri);
+ return this;
+ }
+
+ /**
+ * Add the prefixes to the prefix mapping.
+ *
+ * @param prefixes the prefixes to add.
+ * @return this builder for chaining
+ */
+
+ public UpdateBuilder addPrefixes(Map<String, String> prefixes) {
+ prefixHandler.addPrefixes(prefixes);
+ return this;
+ }
+
+ /**
+ * Add the prefixes to the prefix mapping.
+ *
+ * @param prefixes the prefix mapping to add.
+ * @return this builder for chaining
+ */
+
+ public UpdateBuilder addPrefixes(PrefixMapping prefixes) {
+ prefixHandler.addPrefixes(prefixes);
+ return this;
+ }
+
+ /**
+ * Get an ExprFactory that uses the prefixes from this builder.
+ *
+ * @return the ExpressionFactory.
+ */
+ public ExprFactory getExprFactory() {
+ return prefixHandler.getExprFactory();
+ }
+
+ /**
+ * 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.
+ *
+ * @param var The variable to replace
+ * @param value The value to replace it with or null to remove the replacement.
+ */
+ public void setVar(Var var, Node value) {
+ if (value == null) {
+ values.remove(var);
+ } else {
+ values.put(var, 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 {@link #makeVar} for conversion of the var param. See {@link #makeNode}
+ * for conversion of the value param.
+ *
+ * @param var The variable to replace.
+ * @param value The value to replace it with or null to remove the replacement.
+ */
+ public void setVar(Object var, Object value) {
+ if (value == null) {
+ setVar(Converters.makeVar(var), null);
+ } else {
+ setVar(Converters.makeVar(var), makeNode(value));
+ }
+ }
+
+ private Quad check(Quad q) {
+ if (Var.isVar(q.getGraph()))
+ throw new QueryParseException("Variables not permitted in data quad", -1, -1);
+ if (Var.isVar(q.getSubject()) || Var.isVar(q.getPredicate()) || Var.isVar(q.getObject()))
+ throw new QueryParseException("Variables not permitted in data quad", -1, -1);
+ if (q.getSubject().isLiteral())
+ throw new QueryParseException("Literals not allowed as subjects in data", -1, -1);
+ return q;
+ }
+
+ /**
+ * Add all where attributes from the Where Handler argument.
+ *
+ * @param whereHandler The Where Handler to copy from.
+ */
+ public UpdateBuilder addAll(WhereHandler whereHandler) {
+ whereProcessor.addAll(whereHandler);
+ return this;
+ }
+
+ /**
+ * Add the triple path to the where clause
+ *
+ * @param t The triple path to add.
+ * @throws IllegalArgumentException If the triple path is not a valid triple
+ * path for a where clause.
+ */
+ public UpdateBuilder addWhere(TriplePath t) throws IllegalArgumentException {
+ whereProcessor.addWhere(t);
+ return this;
+ }
+
+ /**
+ * Add the WhereClause
+ *
+ * @param whereClause
+ * @throws IllegalArgumentException If the triple path is not a valid triple
+ * path for a where clause.
+ */
+ public UpdateBuilder addWhere(WhereClause<?> whereClause) throws IllegalArgumentException {
+ whereProcessor.addAll(whereClause.getWhereHandler());
+ return this;
+ }
+
+ /**
+ * Add an optional triple to the where clause
+ *
+ * @param t The triple path to add.
+ * @return The Builder for chaining.
+ * @throws IllegalArgumentException If the triple is not a valid triple for a
+ * where clause.
+ */
+ public UpdateBuilder addOptional(TriplePath t) throws IllegalArgumentException {
+ whereProcessor.addOptional(t);
+ return this;
+ }
+
+ /**
+ * Add the contents of a where handler as an optional statement.
+ *
+ * @param whereHandler The where handler to use as the optional statement.
+ */
+ public UpdateBuilder addOptional(WhereHandler whereHandler) {
+ whereProcessor.addOptional(whereHandler);
+ return this;
+ }
+
+ /**
+ * Add an expression string as a filter.
+ *
+ * @param expression The expression string to add.
+ * @return The Builder for chaining.
+ * @throws ParseException If the expression can not be parsed.
+ */
+ public UpdateBuilder addFilter(String expression) throws ParseException {
+ whereProcessor.addFilter(expression);
+ return this;
+ }
+
+ /**
+ * Add a subquery to the where clause.
+ *
+ * @param subQuery The sub query to add.
+ * @return The Builder for chaining.
... 25156 lines suppressed ...