Class SelectBuilder

    • Constructor Detail

      • SelectBuilder

        public SelectBuilder()
    • Method Detail

      • setDistinct

        public SelectBuilder setDistinct​(boolean state)
        Sets the distinct flag. Setting the select distinct will unset reduced if it was set.
        Parameters:
        state - if true results will be distinct.
        Returns:
        This builder for chaining.
      • setReduced

        public SelectBuilder setReduced​(boolean state)
        Sets the reduced flag. Setting the select reduced will unset distinct if it was set.
        Parameters:
        state - if true results will be reduced.
        Returns:
        This builder for chaining.
      • addVar

        public SelectBuilder addVar​(java.lang.Object var)
        Description copied from interface: SelectClause
        Adds a variable to the select clause. A variable may only be added once. Attempting to add the same variable multiple times will be silently ignored.
        Specified by:
        addVar in interface SelectClause<SelectBuilder>
        Parameters:
        var - The variable to add.
        Returns:
        This builder for chaining.
      • addVar

        public SelectBuilder addVar​(java.lang.String expression,
                                    java.lang.Object var)
                             throws ParseException
        Description copied from interface: SelectClause
        Adds an expression as variable to the select statement. Creates an '(Expression as Var)' to the select statement. A variable may only be added once. Attempting to add the same variable multiple times will be silently ignored.
        Specified by:
        addVar in interface SelectClause<SelectBuilder>
        Parameters:
        expression - The expression to be added
        var - The variable to add.
        Returns:
        This builder for chaining.
        Throws:
        ParseException - If the expression can not be parsed.
      • addVar

        public SelectBuilder addVar​(Expr expr,
                                    java.lang.Object var)
        Description copied from interface: SelectClause
        Adds an expression as variable to the select statement. Creates an '(Expression as Var)' to the select statement. A variable may only be added once. Attempting to add the same variable multiple times will be silently ignored.
        Specified by:
        addVar in interface SelectClause<SelectBuilder>
        Parameters:
        expr - The expression to be added
        var - The variable to add.
        Returns:
        This builder for chaining.
      • fromNamed

        public SelectBuilder fromNamed​(java.lang.String graphName)
        Description copied from interface: DatasetClause
        Add the "FROM NAMED" graph name.
        Specified by:
        fromNamed in interface DatasetClause<SelectBuilder>
        Parameters:
        graphName - the graph name to add.
        Returns:
        This builder for chaining.
      • fromNamed

        public SelectBuilder fromNamed​(java.util.Collection<java.lang.String> graphNames)
        Description copied from interface: DatasetClause
        Add several "FROM NAMED" graph names.
        Specified by:
        fromNamed in interface DatasetClause<SelectBuilder>
        Parameters:
        graphNames - the collection graph names to add.
        Returns:
        This builder for chaining.
      • from

        public SelectBuilder from​(java.lang.String graphName)
        Description copied from interface: DatasetClause
        Add the "FROM" graph name.
        Specified by:
        from in interface DatasetClause<SelectBuilder>
        Parameters:
        graphName - the graph name to add.
        Returns:
        This builder for chaining.
      • from

        public SelectBuilder from​(java.util.Collection<java.lang.String> graphName)
        Description copied from interface: DatasetClause
        Add several "FROM" graph names.
        Specified by:
        from in interface DatasetClause<SelectBuilder>
        Parameters:
        graphName - the collection graph names to add.
        Returns:
        This builder for chaining.
      • makeString

        public static java.lang.String makeString​(java.lang.Object o)
        Converts the object to a string. If the object is a node or fronts a node then
        • 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 '?'
        otherwise return the toString() method of the object.
        Parameters:
        o - the Object to convert.
        Returns:
        The string representation of the object.
      • addWhereValueVar

        public SelectBuilder addWhereValueVar​(java.lang.Object var)
        Description copied from interface: WhereClause
        Add a variable or variable and values to the value statement. The first var (or first item in a collection) is converted to a variable using the makeVar strategy. A variable may be added multiple times, doing so will append values to the list of variable values. The order in which variables are added to the values table is preserved. Adding a collection as the var will use the first object in the collection as the var and the remaining objects as values. Values are created using makeNode() strategy except that null values are converted to UNDEF.
        Specified by:
        addWhereValueVar in interface WhereClause<SelectBuilder>
        Parameters:
        var - The variable or collection to add.
        Returns:
        The builder for chaining.
        See Also:
        AbstractQueryBuilder.makeNode(Object), Converters.makeVar(Object)
      • addWhereValueVar

        public SelectBuilder addWhereValueVar​(java.lang.Object var,
                                              java.lang.Object... values)
        Description copied from interface: WhereClause
        Add a variable and values to the value statement. The var is converted to a variable using the makeVar strategy. A variable may be added multiple times, doing so will append values to the list of variable values. The order in which variables are added to the values table is preserved. Values are created using makeNode() strategy except that null values are converted to UNDEF.
        Specified by:
        addWhereValueVar in interface WhereClause<SelectBuilder>
        Parameters:
        var - The variable to add.
        values - The values for the variable
        Returns:
        The builder for chaining.
        See Also:
        AbstractQueryBuilder.makeNode(Object), Converters.makeVar(Object)
      • addWhereValueVars

        public <K extends java.util.Collection<?>> SelectBuilder addWhereValueVars​(java.util.Map<?,​K> dataTable)
        Description copied from interface: WhereClause
        Add a data table to the value statement. Each key in the map is used converted into a variable using the makeVar strategy. The order in which variables are added to the values table is preserved. Variables are added in the iteration order for the map. It may be advisable to use a LinkedHashMap to preserver the insert order.
        Specified by:
        addWhereValueVars in interface WhereClause<SelectBuilder>
        Parameters:
        dataTable - The data table to add.
        Returns:
        The builder for chaining.
        See Also:
        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)
      • addWhereValueRow

        public SelectBuilder addWhereValueRow​(java.lang.Object... values)
        Description copied from interface: WhereClause
        Add objects as a row of values. This method is different from the other methods in that the values are appended to each of the variables in the clause. There must be sufficient entries in the list to provide data for each variable in the table. Values objects are converted to nodes using the makeNode strategy. Variables will always be in the order added to the values table.
        Specified by:
        addWhereValueRow in interface WhereClause<SelectBuilder>
        Parameters:
        values - the collection of values to add.
        Returns:
        The builder for chaining.
        See Also:
        AbstractQueryBuilder.makeNode(Object)
      • addWhereValueRow

        public SelectBuilder addWhereValueRow​(java.util.Collection<?> values)
        Description copied from interface: WhereClause
        Add a collection of objects as row of values. This method is different from the other methods in that the values are appended to each of the variables in the clause. There must be sufficient entries in the list to provide data for each variable in the table. Values objects are converted to nodes using the makeNode strategy. Variables will always be in the order added to the values table.
        Specified by:
        addWhereValueRow in interface WhereClause<SelectBuilder>
        Parameters:
        values - the collection of values to add.
        Returns:
        The builder for chaining.
        See Also:
        AbstractQueryBuilder.makeNode(Object)
      • getWhereValuesVars

        public java.util.List<Var> getWhereValuesVars()
        Description copied from interface: WhereClause
        Get an unmodifiable list of vars from the where clause values in the order that they appear in the values table.
        Specified by:
        getWhereValuesVars in interface WhereClause<SelectBuilder>
        Returns:
        an unmodifiable list of vars.
      • getWhereValuesMap

        public java.util.Map<Var,​java.util.List<Node>> getWhereValuesMap()
        Description copied from interface: WhereClause
        Get an unmodifiable map of vars from the where clause values and their values. Null values are considered as UNDEF values.
        Specified by:
        getWhereValuesMap in interface WhereClause<SelectBuilder>
        Returns:
        an unmodifiable map of vars and their values.
      • clearWhereValues

        public SelectBuilder clearWhereValues()
        Description copied from interface: WhereClause
        Reset the values table in the where clause to the initial undefined state. Used primarily to reset the builder values table to a known state.
        Specified by:
        clearWhereValues in interface WhereClause<SelectBuilder>
      • addGraph

        public SelectBuilder addGraph​(java.lang.Object graph,
                                      java.lang.Object subject,
                                      java.lang.Object predicate,
                                      java.lang.Object object)
        Description copied from interface: WhereClause
        Add a graph statement to the query as per http://www.w3.org/TR/2013/REC-sparql11 -query-20130321/#rGraphGraphPattern. See AbstractQueryBuilder.makeNode(java.lang.Object) for conversion of the graph param.
        Specified by:
        addGraph in interface WhereClause<SelectBuilder>
        Parameters:
        graph - The iri or variable identifying the graph.
        subject - The subject for the graph query
        predicate - The predicate for the graph query.
        object - The object for the graph query.
        Returns:
        This builder for chaining.
      • addBind

        public SelectBuilder addBind​(Expr expression,
                                     java.lang.Object var)
        Description copied from interface: WhereClause
        Add a bind statement to the query * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
        Specified by:
        addBind in interface WhereClause<SelectBuilder>
        Parameters:
        expression - The expression to bind to the var.
        var - The variable to bind to.
        Returns:
        This builder for chaining.
      • addBind

        public SelectBuilder addBind​(java.lang.String expression,
                                     java.lang.Object var)
                              throws ParseException
        Description copied from interface: WhereClause
        Add a bind statement to the query http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rGraphGraphPattern.
        Specified by:
        addBind in interface WhereClause<SelectBuilder>
        Parameters:
        expression - The expression to bind to the var.
        var - The variable to bind to.
        Returns:
        This builder for chaining.
        Throws:
        ParseException
      • list

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

        usage:

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

        Specified by:
        list in interface WhereClause<SelectBuilder>
        Parameters:
        objs - the list of objects for the list.
        Returns:
        the first blank node in the list.
      • addMinus

        public SelectBuilder addMinus​(AbstractQueryBuilder<?> t)
        Description copied from interface: WhereClause
        Add a minus clause to the query. https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rMinusGraphPattern
        Specified by:
        addMinus in interface WhereClause<SelectBuilder>
        Parameters:
        t - The select builder to add as a minus pattern
        Returns:
        this builder for chaining