Class QueryImpl

java.lang.Object
cz.cvut.kbss.jopa.model.QueryImpl
All Implemented Interfaces:
Query
Direct Known Subclasses:
ResultSetMappingQuery

public class QueryImpl extends Object implements Query
  • Constructor Details

  • Method Details

    • getResultList

      public List getResultList()
      Description copied from interface: Query
      Execute a SELECT query and return the query results as an untyped List.
      Specified by:
      getResultList in interface Query
      Returns:
      a list of the results
    • getSingleResult

      public Object getSingleResult()
      Description copied from interface: Query
      Execute a SELECT query that returns a single result.
      Specified by:
      getSingleResult in interface Query
      Returns:
      Query result
    • getResultStream

      public Stream getResultStream()
      Description copied from interface: Query
      Execute a SELECT query and return the query results as an untyped java.util.stream.Stream.

      By default this method delegates to getResultList().stream(), however persistence provider may choose to override this method to provide additional capabilities.

      Specified by:
      getResultStream in interface Query
      Returns:
      a stream of the results
    • setMaxResults

      public Query setMaxResults(int maxResults)
      Description copied from interface: Query
      Set the maximum number of results to retrieve.
      Specified by:
      setMaxResults in interface Query
      Parameters:
      maxResults - maximum number of results
      Returns:
      the same query instance
    • setFirstResult

      public Query setFirstResult(int startPosition)
      Description copied from interface: Query
      Set the position of the first result to retrieve.
      Specified by:
      setFirstResult in interface Query
      Parameters:
      startPosition - position of the first result, numbered from 0
      Returns:
      the same query instance
    • executeUpdate

      public void executeUpdate()
      Description copied from interface: Query
      Execute an update or delete statement.
      Specified by:
      executeUpdate in interface Query
    • hasParameter

      public boolean hasParameter(String name)
    • hasParameter

      public boolean hasParameter(int position)
    • getParameter

      public Parameter<?> getParameter(int position)
      Description copied from interface: Query
      Gets the parameter object corresponding to the declared positional parameter with the given position. This method is not required to be supported for native queries.
      Specified by:
      getParameter in interface Query
      Parameters:
      position - position
      Returns:
      parameter object
    • getParameter

      public Parameter<?> getParameter(String name)
      Description copied from interface: Query
      Gets the parameter object corresponding to the declared parameter of the given name. This method is not required to be supported for native queries.
      Specified by:
      getParameter in interface Query
      Parameters:
      name - Parameter name
      Returns:
      parameter object
    • getParameters

      public Set<Parameter<?>> getParameters()
      Description copied from interface: Query
      Gets the parameter objects corresponding to the declared parameters of the query. Returns empty set if the query has no parameters. This method is not required to be supported for native queries.
      Specified by:
      getParameters in interface Query
      Returns:
      set of parameter objects
    • isBound

      public boolean isBound(Parameter<?> parameter)
      Description copied from interface: Query
      Returns a boolean indicating whether a value has been bound to the parameter.
      Specified by:
      isBound in interface Query
      Parameters:
      parameter - parameter object
      Returns:
      boolean indicating whether parameter has been bound
    • getParameterValue

      public Object getParameterValue(String name)
      Description copied from interface: Query
      Returns the input value bound to the named parameter.
      Specified by:
      getParameterValue in interface Query
      Parameters:
      name - parameter name
      Returns:
      parameter value
    • getParameterValue

      public Object getParameterValue(int position)
      Description copied from interface: Query
      Returns the input value bound to the positional parameter.
      Specified by:
      getParameterValue in interface Query
      Parameters:
      position - position
      Returns:
      parameter value
    • getParameterValue

      public <T> T getParameterValue(Parameter<T> parameter)
      Description copied from interface: Query
      Returns the input value bound to the parameter.
      Specified by:
      getParameterValue in interface Query
      Parameters:
      parameter - parameter object
      Returns:
      parameter value
    • setParameter

      public Query setParameter(int position, Object value)
      Description copied from interface: Query
      Binds an argument value to a positional parameter.

      This version exploits the type of the parameter value and maps it to the corresponding XSD datatype (if it exists).

      Specified by:
      setParameter in interface Query
      Parameters:
      position - position
      value - parameter value
      Returns:
      this query instance
      See Also:
    • setParameter

      public Query setParameter(int position, String value, String language)
      Description copied from interface: Query
      Binds a String argument value to a positional parameter.
      Specified by:
      setParameter in interface Query
      Parameters:
      position - position
      value - parameter value
      language - language tag for the parameter value
      Returns:
      this query instance
    • setParameter

      public Query setParameter(String name, Object value)
      Description copied from interface: Query
      Binds an argument value to a named parameter.

      This version exploits the type of the parameter value and maps it to the corresponding XSD datatype (if it exists).

      Specified by:
      setParameter in interface Query
      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      this query instance
      See Also:
    • setParameter

      public Query setParameter(String name, String value, String language)
      Description copied from interface: Query
      Binds a String argument value to a named parameter.
      Specified by:
      setParameter in interface Query
      Parameters:
      name - parameter name
      value - parameter value
      language - language tag for the parameter value
      Returns:
      this query instance
    • setUntypedParameter

      public Query setUntypedParameter(int position, Object value)
      Description copied from interface: Query
      Binds an argument value to a positional parameter.

      This version does not express the type of the value in the query. Instead, it inserts the value directly into the query string. It can be useful, e.g., for specifying values in filters.

      Do not use this method to set query limit and offset, use the Query.setFirstResult(int) and Query.setMaxResults(int) methods instead.

      Specified by:
      setUntypedParameter in interface Query
      Parameters:
      position - position
      value - parameter value
      Returns:
      this query instance
    • setUntypedParameter

      public Query setUntypedParameter(String name, Object value)
      Description copied from interface: Query
      Binds an argument value to a named parameter.

      This version does not express the type of the value in the query. Instead, it inserts the value directly into the query string. It can be useful, e.g., for specifying values in filters.

      Do not use this method to set query limit and offset, use the Query.setFirstResult(int) and Query.setMaxResults(int) methods instead.

      Specified by:
      setUntypedParameter in interface Query
      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      this query instance
    • getMaxResults

      public int getMaxResults()
      Description copied from interface: Query
      The maximum number of results the query object was set to retrieve.

      Returns Integer.MAX_VALUE if Query.setMaxResults(int) was not applied to the query object.

      Specified by:
      getMaxResults in interface Query
      Returns:
      maximum number of results
    • getFirstResult

      public int getFirstResult()
      Description copied from interface: Query
      The position of the first result the query object was set to retrieve.

      Returns 0 if setFirstResult was not applied to the query object.

      Specified by:
      getFirstResult in interface Query
      Returns:
      position of the first result
    • setParameter

      public <T> Query setParameter(Parameter<T> parameter, T value)
      Description copied from interface: Query
      Binds the value of a Parameter object.

      This version exploits the type of the parameter value and maps it to the corresponding XSD datatype (if it exists).

      Specified by:
      setParameter in interface Query
      Parameters:
      parameter - parameter object
      value - parameter value
      Returns:
      this query instance
      See Also:
    • setParameter

      public Query setParameter(Parameter<String> parameter, String value, String language)
      Description copied from interface: Query
      Binds the value of a String Parameter.
      Specified by:
      setParameter in interface Query
      Parameters:
      parameter - parameter object
      value - parameter value
      language - language tag for the parameter value
      Returns:
      this query instance
    • setUntypedParameter

      public <T> Query setUntypedParameter(Parameter<T> parameter, T value)
      Description copied from interface: Query
      Binds the value of a Parameter object.

      This version does not express the type of the value in the query. Instead, it inserts the value directly into the query string. It can be useful, e.g., for specifying values in filters.

      Do not use this method to set query limit and offset, use the Query.setFirstResult(int) and Query.setMaxResults(int) methods instead.

      Specified by:
      setUntypedParameter in interface Query
      Parameters:
      parameter - parameter object
      value - parameter value
      Returns:
      this query instance
    • setHint

      public Query setHint(String hintName, Object value)
      Description copied from interface: Query
      Sets a query hint.

      The hint elements may be used to specify query properties and hints. Vendor-specific hints that are not recognized by a provider are silently ignored.

      Specified by:
      setHint in interface Query
      Parameters:
      hintName - Name of the query hint
      value - Value of the query hint
      Returns:
      this query instance
    • getHints

      public Map<String,Object> getHints()
      Description copied from interface: Query
      Gets the hints and associated values that are in effect for this query instance.
      Specified by:
      getHints in interface Query
      Returns:
      Map of query hints with values