Interface Query

All Known Subinterfaces:
TypedQuery<X>
All Known Implementing Classes:
QueryImpl, ResultSetMappingQuery, TypedQueryImpl

public interface Query
  • Method Details

    • executeUpdate

      void executeUpdate()
      Execute an update or delete statement.
      Throws:
      IllegalStateException - if called for a SELECT statement or for a criteria query
      TransactionRequiredException - if there is no transaction or the persistence context has not been joined to the transaction
      OWLPersistenceException - if the query execution exceeds the query timeout value set and the transaction is rolled back
    • getResultList

      List getResultList()
      Execute a SELECT query and return the query results as an untyped List.
      Returns:
      a list of the results
      Throws:
      IllegalStateException - if called for a Java Persistence query language UPDATE or DELETE statement
      TransactionRequiredException - if a lock mode has been set and there is no transaction
      OWLPersistenceException - if the query execution exceeds the query timeout value set and the transaction is rolled back
    • getResultStream

      default Stream getResultStream()
      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.

      Returns:
      a stream of the results
      Throws:
      IllegalStateException - if called for a SELECT statement or for a criteria query
      TransactionRequiredException - if there is no transaction or the persistence context has not been joined to the transaction
      OWLPersistenceException - if the query execution exceeds the query timeout value set and the transaction is rolled back
    • getSingleResult

      Object getSingleResult()
      Execute a SELECT query that returns a single result.
      Returns:
      Query result
      Throws:
      NoResultException - There is no result
      NoUniqueResultException - There are more than one results
    • setMaxResults

      Query setMaxResults(int maxResult)
      Set the maximum number of results to retrieve.
      Parameters:
      maxResult - maximum number of results
      Returns:
      the same query instance
      Throws:
      IllegalArgumentException - if the argument is negative
    • getMaxResults

      int getMaxResults()
      The maximum number of results the query object was set to retrieve.

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

      Returns:
      maximum number of results
    • setFirstResult

      Query setFirstResult(int startPosition)
      Set the position of the first result to retrieve.
      Parameters:
      startPosition - position of the first result, numbered from 0
      Returns:
      the same query instance
      Throws:
      IllegalArgumentException - If the argument is negative
    • getFirstResult

      int getFirstResult()
      The position of the first result the query object was set to retrieve.

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

      Returns:
      position of the first result
    • getParameter

      Parameter<?> getParameter(int position)
      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.
      Parameters:
      position - position
      Returns:
      parameter object
      Throws:
      IllegalArgumentException - If the parameter with the specified position does not exist
    • getParameter

      Parameter<?> getParameter(String name)
      Gets the parameter object corresponding to the declared parameter of the given name. This method is not required to be supported for native queries.
      Parameters:
      name - Parameter name
      Returns:
      parameter object
      Throws:
      IllegalArgumentException - If the parameter of the specified name does not exist
    • getParameters

      Set<Parameter<?>> getParameters()
      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.
      Returns:
      set of parameter objects
    • isBound

      boolean isBound(Parameter<?> parameter)
      Returns a boolean indicating whether a value has been bound to the parameter.
      Parameters:
      parameter - parameter object
      Returns:
      boolean indicating whether parameter has been bound
    • getParameterValue

      Object getParameterValue(int position)
      Returns the input value bound to the positional parameter.
      Parameters:
      position - position
      Returns:
      parameter value
      Throws:
      IllegalStateException - If the parameter has not been bound
      IllegalArgumentException - If the parameter with the specified position does not exist
    • getParameterValue

      Object getParameterValue(String name)
      Returns the input value bound to the named parameter.
      Parameters:
      name - parameter name
      Returns:
      parameter value
      Throws:
      IllegalStateException - If the parameter has not been bound
      IllegalArgumentException - If the parameter with the specified name does not exist
    • getParameterValue

      <T> T getParameterValue(Parameter<T> parameter)
      Returns the input value bound to the parameter.
      Parameters:
      parameter - parameter object
      Returns:
      parameter value
      Throws:
      IllegalStateException - If the parameter has not been bound
      IllegalArgumentException - If the parameter is not a parameter of the query
    • setParameter

      Query setParameter(int position, Object value)
      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).

      Parameters:
      position - position
      value - parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If position does not correspond to a positional parameter of the query or if the argument is of incorrect type
      See Also:
    • setParameter

      Query setParameter(int position, String value, String language)
      Binds a String argument value to a positional parameter.
      Parameters:
      position - position
      value - parameter value
      language - language tag for the parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If position does not correspond to a positional parameter of the query or if the argument is of incorrect type
    • setParameter

      Query setParameter(String name, Object value)
      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).

      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
      See Also:
    • setParameter

      Query setParameter(String name, String value, String language)
      Binds a String argument value to a named parameter.
      Parameters:
      name - parameter name
      value - parameter value
      language - language tag for the parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If the parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
    • setParameter

      <T> Query setParameter(Parameter<T> parameter, T value)
      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).

      Parameters:
      parameter - parameter object
      value - parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If the parameter does not correspond to a parameter of the query
      See Also:
    • setParameter

      Query setParameter(Parameter<String> parameter, String value, String language)
      Binds the value of a String Parameter.
      Parameters:
      parameter - parameter object
      value - parameter value
      language - language tag for the parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If the parameter does not correspond to a parameter of the query
    • setUntypedParameter

      Query setUntypedParameter(int position, Object value)
      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. Can be useful e.g. for specifying OFFSET or LIMIT values.

      Parameters:
      position - position
      value - parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If position does not correspond to a positional parameter of the query or if the argument is of incorrect type
    • setUntypedParameter

      Query setUntypedParameter(String name, Object value)
      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. Can be useful e.g. for specifying OFFSET or LIMIT values.

      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If parameter name does not correspond to a parameter of the query or if the argument is of incorrect type
    • setUntypedParameter

      <T> Query setUntypedParameter(Parameter<T> parameter, T value)
      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. Can be useful e.g. for specifying OFFSET or LIMIT values.

      Parameters:
      parameter - parameter object
      value - parameter value
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If the parameter does not correspond to a parameter of the query
    • setHint

      Query setHint(String hintName, Object value)
      Sets a query hint.

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

      Parameters:
      hintName - Name of the query hint
      value - Value of the query hint
      Returns:
      this query instance
      Throws:
      IllegalArgumentException - If the value is not valid for the hint implementation
    • getHints

      Map<String,Object> getHints()
      Gets the hints and associated values that are in effect for this query instance.
      Returns:
      Map of query hints with values