public class SelectBuilder extends AbstractQueryBuilder<SelectBuilder> implements DatasetClause<SelectBuilder>, WhereClause<SelectBuilder>, SolutionModifierClause<SelectBuilder>, SelectClause<SelectBuilder>
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 ExprFactory is intended for use along with the SelectBuilder to generate needed Expr parameter values.
An ExprFactory that works with the same prefixes can be obtained with AbstractQueryBuilder.getExprFactory().
The SelectBuilder can be used as prepared query.
Values for variables in the created query can be set with AbstractQueryBuilder.setVar(Object, Object) and AbstractQueryBuilder.setVar(Var, Node).
The method clearWhereValues() allows to clear the set values.
AskBuilder,
ConstructBuilder,
DescribeBuilder,
UpdateBuilder| Constructor and Description |
|---|
SelectBuilder() |
| Modifier and Type | Method and Description |
|---|---|
SelectBuilder |
addBind(Expr expression,
Object var)
Add a bind statement to the query *
http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addBind(String expression,
Object var)
Add a bind statement to the query
http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addFilter(Expr expr)
Adds a filter to the where clause
Use ExprFactory or NodeValue static or the AbstractQueryBuilder.makeExpr
methods to create the expression.
|
SelectBuilder |
addFilter(String s)
Adds a filter to the where clause
|
SelectBuilder |
addGraph(Object graph,
AbstractQueryBuilder<?> subQuery)
Add a graph statement to the query as per
http://www.w3.org/TR/2013/REC-sparql11
-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addGraph(Object graph,
FrontsTriple triple)
Add a graph statement to the query as per
http://www.w3.org/TR/2013/REC-sparql11
-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addGraph(Object graph,
Object subject,
Object predicate,
Object object)
Add a graph statement to the query as per
http://www.w3.org/TR/2013/REC-sparql11
-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addGraph(Object graph,
Triple triple)
Add a graph statement to the query as per
http://www.w3.org/TR/2013/REC-sparql11
-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addGraph(Object graph,
TriplePath triplePath)
Add a graph statement to the query as per
http://www.w3.org/TR/2013/REC-sparql11
-query-20130321/#rGraphGraphPattern.
|
SelectBuilder |
addGroupBy(Expr groupBy)
Add an expression to the group by clause.
|
SelectBuilder |
addGroupBy(Object groupBy)
Add a variable to the group by clause.
|
SelectBuilder |
addGroupBy(Object var,
Expr expr)
Add var and expression to the group by clause.
|
SelectBuilder |
addGroupBy(Object var,
String expr)
Add var and expression to the group by clause.
|
SelectBuilder |
addHaving(Expr expression)
Add a having expression.
|
SelectBuilder |
addHaving(Object var)
Add a having expression.
|
SelectBuilder |
addHaving(String having)
Add a having expression.
|
SelectBuilder |
addMinus(AbstractQueryBuilder<?> t)
Add a minus clause to the query.
|
SelectBuilder |
addOptional(AbstractQueryBuilder<?> t)
Adds an optional group pattern to the where clause.
|
SelectBuilder |
addOptional(FrontsTriple t)
Adds an optional triple as to the where clause.
|
SelectBuilder |
addOptional(Object s,
Object p,
Object o)
Adds an optional triple or triple path to the where clause.
|
SelectBuilder |
addOptional(Triple t)
Adds an optional triple to the where clause.
|
SelectBuilder |
addOptional(TriplePath t)
Adds an optional triple path to the where clause.
|
SelectBuilder |
addOrderBy(Expr orderBy)
Add an ascending order by.
|
SelectBuilder |
addOrderBy(Expr orderBy,
Order order)
Add an order by with direction specified.
|
SelectBuilder |
addOrderBy(Object orderBy)
Add an ascending order by.
|
SelectBuilder |
addOrderBy(Object orderBy,
Order order)
Add an order by with direction specified.
|
SelectBuilder |
addOrderBy(SortCondition orderBy)
Add an ascending order by.
|
SelectBuilder |
addSubQuery(AbstractQueryBuilder<?> subQuery)
Add a sub query.
|
SelectBuilder |
addUnion(AbstractQueryBuilder<?> subQuery)
Add a union.
|
SelectBuilder |
addVar(Expr expr,
Object var)
Adds an expression as variable to the select statement.
|
SelectBuilder |
addVar(Object var)
Adds a variable to the select clause.
|
SelectBuilder |
addVar(String expression,
Object var)
Adds an expression as variable to the select statement.
|
SelectBuilder |
addWhere(FrontsTriple t)
Adds a triple to the where clause.
|
SelectBuilder |
addWhere(Object s,
Object p,
Object o)
Adds a triple or triple path to the where clause.
|
SelectBuilder |
addWhere(Triple t)
Adds a triple to the where clause.
|
SelectBuilder |
addWhere(TriplePath t)
Adds a triple path to the where clause.
|
SelectBuilder |
addWhereValueRow(Collection<?> values)
Add a collection of objects as row of values.
|
SelectBuilder |
addWhereValueRow(Object... values)
Add objects as a row of values.
|
SelectBuilder |
addWhereValueVar(Object var)
Add a variable or variable and values to the value statement.
|
SelectBuilder |
addWhereValueVar(Object var,
Object... values)
Add a variable and values to the value statement.
|
<K extends Collection<?>> |
addWhereValueVars(Map<?,K> dataTable)
Add a data table to the value statement.
|
SelectBuilder |
clearWhereValues()
Reset the values table in the where clause to the initial
undefined state.
|
SelectBuilder |
clone() |
SelectBuilder |
from(Collection<String> graphName)
Add several "FROM" graph names.
|
SelectBuilder |
from(String graphName)
Add the "FROM" graph name.
|
SelectBuilder |
fromNamed(Collection<String> graphNames)
Add several "FROM NAMED" graph names.
|
SelectBuilder |
fromNamed(String graphName)
Add the "FROM NAMED" graph name.
|
DatasetHandler |
getDatasetHandler()
Get the Dataset handler for this clause.
|
HandlerBlock |
getHandlerBlock()
Get the HandlerBlock for this query builder.
|
SelectHandler |
getSelectHandler()
Returns the select handler for this clause
|
SolutionModifierHandler |
getSolutionModifierHandler()
Get the Solution modifier for this clause.
|
List<Var> |
getVars() |
Map<Var,List<Node>> |
getWhereValuesMap()
Get an unmodifiable map of vars from the where clause values and their values.
|
List<Var> |
getWhereValuesVars()
Get an unmodifiable list of vars from the where clause values in the order that they appear
in the values table.
|
Node |
list(Object... objs)
Create a list node from a list of objects as per RDF Collections.
|
static String |
makeString(Object o)
Converts the object to a string.
|
SelectBuilder |
setDistinct(boolean state)
Sets the distinct flag.
|
SelectBuilder |
setLimit(int limit)
Set the limit.
|
SelectBuilder |
setOffset(int offset)
Set the offset.
|
SelectBuilder |
setReduced(boolean state)
Sets the reduced flag.
|
addPrefix, addPrefix, addPrefix, addPrefixes, addPrefixes, addValueRow, addValueRow, addValueVar, addValueVar, addValueVars, addWhere, asSubQuery, build, buildString, checkVar, clearValues, clone, getExprFactory, getPrologHandler, getValuesHandler, getValuesMap, getValuesVars, getWhereHandler, makeExpr, makeNode, makeNode, makeNodeOrPath, makeTriplePath, makeValueNodes, makeValueNodes, makeVar, quote, rewrite, setBase, setBase, setVar, setVar, toStringequals, getClass, hashCode, notify, notifyAll, wait, wait, waitaddWhere, getWhereHandlerpublic DatasetHandler getDatasetHandler()
DatasetClausegetDatasetHandler in interface DatasetClause<SelectBuilder>public HandlerBlock getHandlerBlock()
AbstractQueryBuildergetHandlerBlock in class AbstractQueryBuilder<SelectBuilder>public SelectBuilder clone()
public SelectBuilder setDistinct(boolean state)
state - if true results will be distinct.public SelectBuilder setReduced(boolean state)
state - if true results will be reduced.public SelectBuilder addVar(Object var)
SelectClauseaddVar in interface SelectClause<SelectBuilder>var - The variable to add.public SelectBuilder addVar(String expression, Object var) throws ParseException
SelectClauseaddVar in interface SelectClause<SelectBuilder>expression - The expression to be addedvar - The variable to add.ParseException - If the expression can not be parsed.public SelectBuilder addVar(Expr expr, Object var)
SelectClauseaddVar in interface SelectClause<SelectBuilder>expr - The expression to be addedvar - The variable to add.public List<Var> getVars()
getVars in interface SelectClause<SelectBuilder>public SelectBuilder fromNamed(String graphName)
DatasetClausefromNamed in interface DatasetClause<SelectBuilder>graphName - the graph name to add.public SelectBuilder fromNamed(Collection<String> graphNames)
DatasetClausefromNamed in interface DatasetClause<SelectBuilder>graphNames - the collection graph names to add.public SelectBuilder from(String graphName)
DatasetClausefrom in interface DatasetClause<SelectBuilder>graphName - the graph name to add.public SelectBuilder from(Collection<String> graphName)
DatasetClausefrom in interface DatasetClause<SelectBuilder>graphName - the collection graph names to add.public SelectBuilder addOrderBy(Expr orderBy)
SolutionModifierClauseaddOrderBy in interface SolutionModifierClause<SelectBuilder>orderBy - The expression to order by.ExprFactory,
NodeValue,
AbstractQueryBuilder.makeExpr(String)public SelectBuilder addOrderBy(Object orderBy)
SolutionModifierClauseaddOrderBy in interface SolutionModifierClause<SelectBuilder>orderBy - The object to order by.public SelectBuilder addOrderBy(SortCondition orderBy)
SolutionModifierClauseaddOrderBy in interface SolutionModifierClause<SelectBuilder>orderBy - The SortCondition to order by.public SelectBuilder addOrderBy(Expr orderBy, Order order)
SolutionModifierClauseaddOrderBy in interface SolutionModifierClause<SelectBuilder>orderBy - The expression to order by.order - The direction to order.public SelectBuilder addOrderBy(Object orderBy, Order order)
SolutionModifierClauseaddOrderBy in interface SolutionModifierClause<SelectBuilder>orderBy - The object to order by.order - The direction to order.public SelectBuilder addGroupBy(Object groupBy)
SolutionModifierClauseaddGroupBy in interface SolutionModifierClause<SelectBuilder>groupBy - The object to group by.public SelectBuilder addGroupBy(Expr groupBy)
SolutionModifierClauseaddGroupBy in interface SolutionModifierClause<SelectBuilder>groupBy - The expression to add.public SelectBuilder addGroupBy(Object var, Expr expr)
SolutionModifierClauseaddGroupBy in interface SolutionModifierClause<SelectBuilder>var - The variable to add.expr - The expression to add.public SelectBuilder addGroupBy(Object var, String expr)
SolutionModifierClauseaddGroupBy in interface SolutionModifierClause<SelectBuilder>var - The variable to add.expr - The expression to add.public SolutionModifierHandler getSolutionModifierHandler()
SolutionModifierClausegetSolutionModifierHandler in interface SolutionModifierClause<SelectBuilder>public SelectBuilder addHaving(String having) throws ParseException
SolutionModifierClauseaddHaving in interface SolutionModifierClause<SelectBuilder>having - Expression to evaluate for the having.ParseExceptionpublic SelectBuilder addHaving(Expr expression) throws ParseException
SolutionModifierClauseaddHaving in interface SolutionModifierClause<SelectBuilder>expression - Expression to evaluate for the having.ParseExceptionExprFactory,
NodeValue,
AbstractQueryBuilder.makeExpr(String)public SelectBuilder addHaving(Object var) throws ParseException
SolutionModifierClauseaddHaving in interface SolutionModifierClause<SelectBuilder>var - the variable to have.ParseExceptionpublic SelectBuilder setLimit(int limit)
SolutionModifierClausesetLimit in interface SolutionModifierClause<SelectBuilder>limit - the maximum number of results to return.public SelectBuilder setOffset(int offset)
SolutionModifierClausesetOffset in interface SolutionModifierClause<SelectBuilder>offset - the number of results to skip before returning results..public static String makeString(Object o)
o - the Object to convert.public SelectBuilder addWhere(TriplePath t)
WhereClauseaddWhere in interface WhereClause<SelectBuilder>t - The triple path to addpublic SelectBuilder addWhere(Triple t)
WhereClauseaddWhere in interface WhereClause<SelectBuilder>t - The triple path to addpublic SelectBuilder addWhere(FrontsTriple t)
WhereClauseaddWhere in interface WhereClause<SelectBuilder>t - The triple to addpublic SelectBuilder addWhere(Object s, Object p, Object o)
WhereClauseAbstractQueryBuilder.makeTriplePath(java.lang.Object, java.lang.Object, java.lang.Object) for conversion of the
param values.addWhere in interface WhereClause<SelectBuilder>s - The subject.p - The predicate.o - The object.public SelectBuilder addWhereValueVar(Object var)
WhereClauseaddWhereValueVar in interface WhereClause<SelectBuilder>var - The variable or collection to add.AbstractQueryBuilder.makeNode(Object),
Converters.makeVar(Object)public SelectBuilder addWhereValueVar(Object var, Object... values)
WhereClauseaddWhereValueVar in interface WhereClause<SelectBuilder>var - The variable to add.values - The values for the variableAbstractQueryBuilder.makeNode(Object),
Converters.makeVar(Object)public <K extends Collection<?>> SelectBuilder addWhereValueVars(Map<?,K> dataTable)
WhereClauseaddWhereValueVars in interface WhereClause<SelectBuilder>dataTable - The data table to add.Each item in the value collection is converted into a node using makeNode() strategy except that null values are converted
to UNDEF.
If there are already values in the value statement the data table is adds as follows:
- If the variable already exists in the table the map values are appended to the list of values
- If the variable does not exist in the table and there are other variables defined, an appropriate
number of nulls is added to the front of the map values to create UNDEF entries for the existing rows
- If there are variables in the value statement that are not specified in the map additional UNDEF
entries are appended to them to account for new rows that are added.
,
AbstractQueryBuilder.makeNode(Object),
Converters.makeVar(Object)public SelectBuilder addWhereValueRow(Object... values)
WhereClauseaddWhereValueRow in interface WhereClause<SelectBuilder>values - the collection of values to add.AbstractQueryBuilder.makeNode(Object)public SelectBuilder addWhereValueRow(Collection<?> values)
WhereClauseaddWhereValueRow in interface WhereClause<SelectBuilder>values - the collection of values to add.AbstractQueryBuilder.makeNode(Object)public List<Var> getWhereValuesVars()
WhereClausegetWhereValuesVars in interface WhereClause<SelectBuilder>public Map<Var,List<Node>> getWhereValuesMap()
WhereClausegetWhereValuesMap in interface WhereClause<SelectBuilder>public SelectBuilder clearWhereValues()
WhereClauseclearWhereValues in interface WhereClause<SelectBuilder>public SelectBuilder addOptional(TriplePath t)
WhereClauseaddOptional in interface WhereClause<SelectBuilder>t - The triple path to addpublic SelectBuilder addOptional(Triple t)
WhereClauseaddOptional in interface WhereClause<SelectBuilder>t - The triple to addpublic SelectBuilder addOptional(FrontsTriple t)
WhereClauseaddOptional in interface WhereClause<SelectBuilder>t - The triple to addpublic SelectBuilder addOptional(Object s, Object p, Object o)
WhereClauseAbstractQueryBuilder.makeTriplePath(java.lang.Object, java.lang.Object, java.lang.Object) for conversion of the
param values.addOptional in interface WhereClause<SelectBuilder>s - The subject.p - The predicate.o - The object.public SelectBuilder addOptional(AbstractQueryBuilder<?> t)
WhereClauseaddOptional in interface WhereClause<SelectBuilder>t - The select builder to add as an optional patternpublic SelectBuilder addFilter(Expr expr)
WhereClauseaddFilter in interface WhereClause<SelectBuilder>expr - the expression to evaluate for the filter.ExprFactory,
NodeValue,
AbstractQueryBuilder.makeExpr(String)public SelectBuilder addFilter(String s) throws ParseException
WhereClauseaddFilter in interface WhereClause<SelectBuilder>s - the expression to evaluate for the filter.ParseException - If the expression can not be parsed.public SelectBuilder addSubQuery(AbstractQueryBuilder<?> subQuery)
WhereClauseaddSubQuery in interface WhereClause<SelectBuilder>subQuery - The subquery as defined by a SelectBuilder.public SelectBuilder addUnion(AbstractQueryBuilder<?> subQuery)
WhereClauseaddUnion in interface WhereClause<SelectBuilder>subQuery - The union as defined by a SelectBuilder.public SelectBuilder addGraph(Object graph, AbstractQueryBuilder<?> subQuery)
WhereClauseAbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph
param.addGraph in interface WhereClause<SelectBuilder>graph - The iri or variable identifying the graph.subQuery - The graph to add.public SelectBuilder addGraph(Object graph, FrontsTriple triple)
WhereClauseAbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph
param.addGraph in interface WhereClause<SelectBuilder>graph - The iri or variable identifying the graph.triple - a single s, p, o triple for the query.public SelectBuilder addGraph(Object graph, Object subject, Object predicate, Object object)
WhereClauseAbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph
param.addGraph in interface WhereClause<SelectBuilder>graph - The iri or variable identifying the graph.subject - The subject for the graph querypredicate - The predicate for the graph query.object - The object for the graph query.public SelectBuilder addGraph(Object graph, Triple triple)
WhereClauseAbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph
param.addGraph in interface WhereClause<SelectBuilder>graph - The iri or variable identifying the graph.triple - a single triple for the query.public SelectBuilder addGraph(Object graph, TriplePath triplePath)
WhereClauseAbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph
param.addGraph in interface WhereClause<SelectBuilder>graph - The iri or variable identifying the graph.triplePath - a single triple path for the query.public SelectBuilder addBind(Expr expression, Object var)
WhereClauseaddBind in interface WhereClause<SelectBuilder>expression - The expression to bind to the var.var - The variable to bind to.public SelectBuilder addBind(String expression, Object var) throws ParseException
WhereClauseaddBind in interface WhereClause<SelectBuilder>expression - The expression to bind to the var.var - The variable to bind to.ParseExceptionpublic SelectHandler getSelectHandler()
SelectClausegetSelectHandler in interface SelectClause<SelectBuilder>public Node list(Object... objs)
WhereClauseAbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the param
values.
usage:
list in interface WhereClause<SelectBuilder>objs - the list of objects for the list.public SelectBuilder addMinus(AbstractQueryBuilder<?> t)
WhereClauseaddMinus in interface WhereClause<SelectBuilder>t - The select builder to add as a minus patternLicensed under the Apache License, Version 2.0