Interface Stage.Query<R>

  • All Known Implementing Classes:
    StageQueryImpl
    Enclosing interface:
    Stage

    public static interface Stage.Query<R>
    A non-blocking counterpart to the Hibernate Query interface, allowing reactive execution of HQL and JPQL queries.

    The semantics of operations on this interface are identical to the semantics of the similarly-named operations of Query, except that the operations are performed asynchronously, returning a CompletionStage without blocking the calling thread.

    Note that TemporalType is not supported as an argument for parameter bindings, and so parameters of type Date or Calendar should not be used. Instead, datetime types from java.time should be used as parameters.

    See Also:
    Query
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletionStage<java.lang.Integer> executeUpdate()
      Asynchronously execute this delete, update, or insert query, returning the updated row count.
      org.hibernate.CacheMode getCacheMode()
      Obtain the CacheMode in effect for this query.
      java.lang.String getCacheRegion()  
      int getFirstResult()  
      org.hibernate.FlushMode getFlushMode()
      Obtain the FlushMode in effect for this query.
      int getMaxResults()  
      java.util.concurrent.CompletionStage<java.util.List<R>> getResultList()
      Asynchronously execute this query, returning the query results as a List, via a CompletionStage.
      java.util.concurrent.CompletionStage<R> getSingleResult()
      Asynchronously execute this query, returning a single row that matches the query, throwing an exception if the query returns zero rows or more than one matching row.
      java.util.concurrent.CompletionStage<R> getSingleResultOrNull()
      Asynchronously execute this query, returning a single row that matches the query, or null if the query returns no results, throwing an exception if the query returns more than one matching row.
      boolean isCacheable()  
      boolean isReadOnly()  
      Stage.Query<R> setCacheable​(boolean cacheable)
      Enable or disable caching of this query result set in the second-level query cache.
      Stage.Query<R> setCacheMode​(org.hibernate.CacheMode cacheMode)
      Set the current CacheMode in effect while this query is being executed.
      Stage.Query<R> setCacheRegion​(java.lang.String cacheRegion)
      Set the name of the cache region in which to store this query result set if caching is enabled.
      Stage.Query<R> setComment​(java.lang.String comment)
      Set the comment for this query.
      Stage.Query<R> setFirstResult​(int firstResult)
      Set the position of the first result that may be returned by this query when executed, where the results are numbered from 0.
      Stage.Query<R> setFlushMode​(org.hibernate.FlushMode flushMode)
      Set the current FlushMode in effect while this query is being executed.
      Stage.Query<R> setLockMode​(java.lang.String alias, org.hibernate.LockMode lockMode)
      Set the LockMode to use for specified alias (as defined in the query's from clause).
      Stage.Query<R> setLockMode​(org.hibernate.LockMode lockMode)
      Set the LockMode to use for the whole query.
      Stage.Query<R> setMaxResults​(int maxResults)
      Set the maximum number of results that may be returned by this query when executed.
      Stage.Query<R> setParameter​(int parameter, java.lang.Object argument)
      Set the value of an ordinal parameter.
      Stage.Query<R> setParameter​(java.lang.String parameter, java.lang.Object argument)
      Set the value of a named parameter.
      <T> Stage.Query<R> setParameter​(javax.persistence.Parameter<T> parameter, T argument)
      Set the value of a typed parameter.
      Stage.Query<R> setPlan​(javax.persistence.EntityGraph<R> entityGraph)
      Set the EntityGraph that will be used as a fetch plan for the root entity returned by this query.
      Stage.Query<R> setReadOnly​(boolean readOnly)
      Set the read-only/modifiable mode for entities and proxies loaded by this Query.
    • Method Detail

      • setParameter

        Stage.Query<R> setParameter​(int parameter,
                                    java.lang.Object argument)
        Set the value of an ordinal parameter. Ordinal parameters are numbered from 1, and are specified in the query using placeholder tokens of form ?1, ?2, etc.
        Parameters:
        parameter - an integer identifying the ordinal parameter
        argument - the argument to set
      • setParameter

        Stage.Query<R> setParameter​(java.lang.String parameter,
                                    java.lang.Object argument)
        Set the value of a named parameter. Named parameters are specified in the query using placeholder tokens of form :name.
        Parameters:
        parameter - the name of the parameter
        argument - the argument to set
      • setParameter

        <T> Stage.Query<R> setParameter​(javax.persistence.Parameter<T> parameter,
                                        T argument)
        Set the value of a typed parameter. Typed parameters are obtained from the JPA CriteriaBuilder, which may itself be obtained by calling Stage.SessionFactory.getCriteriaBuilder().
        Parameters:
        parameter - the parameter
        argument - the argument to set
        See Also:
        CriteriaBuilder.parameter(Class)
      • setMaxResults

        Stage.Query<R> setMaxResults​(int maxResults)
        Set the maximum number of results that may be returned by this query when executed.
      • setFirstResult

        Stage.Query<R> setFirstResult​(int firstResult)
        Set the position of the first result that may be returned by this query when executed, where the results are numbered from 0.
      • getMaxResults

        int getMaxResults()
        Returns:
        the maximum number results, or Integer.MAX_VALUE if not set
      • getFirstResult

        int getFirstResult()
        Returns:
        the first result, or 0 if not set
      • getSingleResult

        java.util.concurrent.CompletionStage<R> getSingleResult()
        Asynchronously execute this query, returning a single row that matches the query, throwing an exception if the query returns zero rows or more than one matching row. If the query has multiple results per row, the results are returned in an instance of Object[].
        Returns:
        the single resulting row
        Throws:
        javax.persistence.NoResultException - if there is no result
        javax.persistence.NonUniqueResultException - if there are multiple results
        See Also:
        Query.getSingleResult()
      • getSingleResultOrNull

        java.util.concurrent.CompletionStage<R> getSingleResultOrNull()
        Asynchronously execute this query, returning a single row that matches the query, or null if the query returns no results, throwing an exception if the query returns more than one matching row. If the query has multiple results per row, the results are returned in an instance of Object[].
        Returns:
        the single resulting row or null
        Throws:
        javax.persistence.NonUniqueResultException - if there are multiple results
        See Also:
        getSingleResult()
      • getResultList

        java.util.concurrent.CompletionStage<java.util.List<R>> getResultList()
        Asynchronously execute this query, returning the query results as a List, via a CompletionStage. If the query has multiple results per row, the results are returned in an instance of Object[].
        Returns:
        the resulting rows as a List
        See Also:
        Query.getResultList()
      • executeUpdate

        java.util.concurrent.CompletionStage<java.lang.Integer> executeUpdate()
        Asynchronously execute this delete, update, or insert query, returning the updated row count.
        Returns:
        the row count as an integer
        See Also:
        Query.executeUpdate()
      • setReadOnly

        Stage.Query<R> setReadOnly​(boolean readOnly)
        Set the read-only/modifiable mode for entities and proxies loaded by this Query. This setting overrides the default setting for the persistence context.
        See Also:
        Stage.Session.setDefaultReadOnly(boolean)
      • setComment

        Stage.Query<R> setComment​(java.lang.String comment)
        Set the comment for this query. This comment will be prepended to the SQL query sent to the database.
        Parameters:
        comment - The human-readable comment
      • setCacheable

        Stage.Query<R> setCacheable​(boolean cacheable)
        Enable or disable caching of this query result set in the second-level query cache.
        Parameters:
        cacheable - true if this query is cacheable
      • isCacheable

        boolean isCacheable()
        Returns:
        true if this query is cacheable
        See Also:
        setCacheable(boolean)
      • setCacheRegion

        Stage.Query<R> setCacheRegion​(java.lang.String cacheRegion)
        Set the name of the cache region in which to store this query result set if caching is enabled.
        Parameters:
        cacheRegion - the name of the cache region
      • getCacheRegion

        java.lang.String getCacheRegion()
        Returns:
        the name of the cache region
        See Also:
        setCacheRegion(String)
      • setCacheMode

        Stage.Query<R> setCacheMode​(org.hibernate.CacheMode cacheMode)
        Set the current CacheMode in effect while this query is being executed.
      • getCacheMode

        org.hibernate.CacheMode getCacheMode()
        Obtain the CacheMode in effect for this query. By default, the query inherits the CacheMode of the Stage.Session from which is originates.
        See Also:
        Stage.Session.getCacheMode()
      • setFlushMode

        Stage.Query<R> setFlushMode​(org.hibernate.FlushMode flushMode)
        Set the current FlushMode in effect while this query is being executed.
      • getFlushMode

        org.hibernate.FlushMode getFlushMode()
        Obtain the FlushMode in effect for this query. By default, the query inherits the FlushMode of the Stage.Session from which is originates.
        See Also:
        Stage.Session.getFlushMode()
      • setLockMode

        Stage.Query<R> setLockMode​(org.hibernate.LockMode lockMode)
        Set the LockMode to use for the whole query.
      • setLockMode

        Stage.Query<R> setLockMode​(java.lang.String alias,
                                   org.hibernate.LockMode lockMode)
        Set the LockMode to use for specified alias (as defined in the query's from clause).
        Parameters:
        alias - the from clause alias
        lockMode - the requested LockMode
        See Also:
        Query.setLockMode(String,LockMode)
      • setPlan

        Stage.Query<R> setPlan​(javax.persistence.EntityGraph<R> entityGraph)
        Set the EntityGraph that will be used as a fetch plan for the root entity returned by this query.