Interface QueryHolder

All Known Implementing Classes:
TokenStreamSparqlQueryHolder

public interface QueryHolder
Represents a caretaker of a query, enabling parameter setting and final assembly of the query.
  • Method Details

    • getQuery

      String getQuery()
      Gets the original query string.
      Returns:
      Gets the original unparsed query
    • getParameters

      Set<Parameter<?>> getParameters()
      Gets a collection of parameters in the query.
      Returns:
      Parameter objects
    • getQueryParameters

      Set<? extends QueryParameter<?>> getQueryParameters()
      Gets a collection of parameters in the query.

      This returns the same set as getParameters(), but it returns more specific type QueryParameter.

      Returns:
      Parameter objects
    • getProjectedQueryParameters

      default List<? extends QueryParameter<?>> getProjectedQueryParameters()
      Gets the list of query parameters that appear in the SELECT projection clause (in the order in which they are declared).
      Returns:
      Projected query parameters
    • hasParameter

      boolean hasParameter(String name)
      Checks whether the query has a parameter with the specified name.
      Parameters:
      name - Parameter name
      Returns:
      true if the query has a matching parameter, false otherwise
    • hasParameter

      boolean hasParameter(int position)
      Checks whether the query has a parameter at the specified position.
      Parameters:
      position - Parameter position
      Returns:
      true if the query has a matching parameter, false otherwise
    • getParameter

      Parameter<?> getParameter(String name)
      Gets a parameter with the specified name.
      Parameters:
      name - Parameter name
      Returns:
      Parameter object
      Throws:
      IllegalArgumentException - If the parameter of the specified name does not exist
    • getParameter

      Parameter<?> getParameter(int position)
      Gets a parameter with the specified position.
      Parameters:
      position - Parameter position
      Returns:
      Parameter object
      Throws:
      IllegalArgumentException - If the parameter at the specified position does not exist
    • getParameterValue

      Object getParameterValue(Parameter<?> parameter)
      Gets value bound to the specified parameter.
      Parameters:
      parameter - Parameter
      Returns:
      parameter value
      Throws:
      IllegalArgumentException - If there is no parameter with the specified name
    • setParameter

      <T> void setParameter(Parameter<T> parameter, Object value)
      Sets value of the specified parameter in the query.

      If a value was already specified for the parameter, it is overwritten by the new one. This version expresses the value type information using XSD datatype in the query string.

      Type Parameters:
      T - Type of the parameter
      Parameters:
      parameter - Parameter object
      value - Value to use
      Throws:
      IllegalArgumentException - If there is no such parameter in the query
      See Also:
    • setParameter

      <T> void setParameter(Parameter<T> parameter, String value, String language)
      Sets value of the specified parameter in the query.

      If a value was already specified for the parameter, it is overwritten by the new one.

      Type Parameters:
      T - Type of the parameter
      Parameters:
      parameter - Parameter object
      value - String value to use
      language - Parameter language
      Throws:
      IllegalArgumentException - If there is no such parameter in the query
    • setUntypedParameter

      <T> void setUntypedParameter(Parameter<T> parameter, Object value)
      Sets value of the specified parameter in the query.

      If a value was already specified for the parameter, it is overwritten by the new one. This version inserts the string representation of the value directly into the query, without any type information.

      Parameters:
      parameter - Parameter object
      value - Value to use
      Throws:
      IllegalArgumentException - If there is no such parameter in the query
      See Also:
    • setFirstResult

      void setFirstResult(int startPosition)
      Sets the position of the first result to retrieve.
      Parameters:
      startPosition - The position to set, starting at 0
    • getFirstResult

      int getFirstResult()
      Gets the currently set first result position.
      Returns:
      the first result position, 0 if none was set
    • setMaxResults

      void setMaxResults(int maxResults)
      Sets the maximum number of results the query should retrieve.
      Parameters:
      maxResults - The maximum number of results
    • getMaxResults

      int getMaxResults()
      Gets the currently set maximum number of results to retrieve
      Returns:
      Maximum results value, Integer.MAX_VALUE when none was set
    • clearParameter

      void clearParameter(Parameter<?> parameter)
      Clears any previously set value of the specified parameter.
      Parameters:
      parameter - Parameter object
      Throws:
      IllegalArgumentException - If there is no such parameter in the query
    • clearParameters

      void clearParameters()
      Clears any previously set parameter values in this query.
    • assembleQuery

      String assembleQuery()
      Assembles the query, using any parameter values specified, and returns it as a string.
      Returns:
      Assembled query
    • getQueryType

      QueryType getQueryType()
      Gets the type of this query.
      Returns:
      Query type