Class EJBQueryImpl<X>

  • All Implemented Interfaces:
    jakarta.persistence.Query, jakarta.persistence.TypedQuery<X>, JpaQuery<X>

    public class EJBQueryImpl<X>
    extends QueryImpl
    implements JpaQuery<X>
    Concrete JPA query class. The JPA query wraps a DatabaseQuery which is executed.
    • Constructor Detail

      • EJBQueryImpl

        protected EJBQueryImpl​(EntityManagerImpl entityManager)
        Base constructor for EJBQueryImpl. Initializes basic variables.
      • EJBQueryImpl

        public EJBQueryImpl​(String jpql,
                            EntityManagerImpl entityManager)
        Build an EJBQueryImpl based on the given jpql string.
      • EJBQueryImpl

        public EJBQueryImpl​(String queryDescription,
                            EntityManagerImpl entityManager,
                            boolean isNamedQuery)
        Create an EJBQueryImpl with either a query name or an jpql string.
        Parameters:
        isNamedQuery - determines whether to treat the queryDescription as jpql or a query name.
    • Method Detail

      • buildEJBQLDatabaseQuery

        public static DatabaseQuery buildEJBQLDatabaseQuery​(String jpql,
                                                            AbstractSession session)
        Build a DatabaseQuery from an jpql string.
        Parameters:
        session - the session to get the descriptors for this query for.
        Returns:
        a DatabaseQuery representing the given jpql.
      • buildEJBQLDatabaseQuery

        public static DatabaseQuery buildEJBQLDatabaseQuery​(String queryName,
                                                            String jpqlQuery,
                                                            AbstractSession session,
                                                            Enum lockMode,
                                                            Map<String,​Object> hints,
                                                            ClassLoader classLoader)
        Build a DatabaseQuery from an JPQL string.
        Parameters:
        jpqlQuery - the JPQL string.
        session - the session to get the descriptors for this query for.
        hints - a list of hints to be applied to the query.
        Returns:
        a DatabaseQuery representing the given jpql.
      • buildSQLDatabaseQuery

        public static DatabaseQuery buildSQLDatabaseQuery​(String sqlResultSetMappingName,
                                                          String sqlString,
                                                          ClassLoader classLoader,
                                                          AbstractSession session)
        Build a ResultSetMappingQuery from a sql result set mapping name and sql string.
      • buildSQLDatabaseQuery

        public static DatabaseQuery buildSQLDatabaseQuery​(String sqlResultSetMappingName,
                                                          String sqlString,
                                                          Map<String,​Object> hints,
                                                          ClassLoader classLoader,
                                                          AbstractSession session)
        Build a ResultSetMappingQuery from a sql result set mapping name and sql string.
        Parameters:
        hints - a list of hints to be applied to the query.
      • setHint

        public jakarta.persistence.TypedQuery<X> setHint​(String hintName,
                                                         Object value)
        Set an implementation-specific hint. If the hint name is not recognized, it is silently ignored.
        Specified by:
        setHint in interface jakarta.persistence.Query
        Specified by:
        setHint in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if the second argument is not valid for the implementation
      • setLockMode

        public EJBQueryImpl setLockMode​(jakarta.persistence.LockModeType lockMode)
        Set the lock mode type to be used for the query execution.
        Specified by:
        setLockMode in interface jakarta.persistence.Query
        Specified by:
        setLockMode in interface jakarta.persistence.TypedQuery<X>
        Overrides:
        setLockMode in class QueryImpl
        Throws:
        IllegalStateException - if not a Java Persistence query language SELECT query
      • getResultCollection

        public Collection getResultCollection()
        Non-standard method to return results of a ReadQuery that has a containerPolicy that returns objects as a collection rather than a List
        Specified by:
        getResultCollection in interface JpaQuery<X>
        Returns:
        Collection of results
      • getResultCursor

        public Cursor getResultCursor()
        Non-standard method to return results of a ReadQuery that uses a Cursor.
        Specified by:
        getResultCursor in interface JpaQuery<X>
        Returns:
        Cursor on results, either a CursoredStream, or ScrollableCursor
      • getSingleResult

        public X getSingleResult()
        Execute a query that returns a single result.
        Specified by:
        getSingleResult in interface jakarta.persistence.Query
        Specified by:
        getSingleResult in interface jakarta.persistence.TypedQuery<X>
        Overrides:
        getSingleResult in class QueryImpl
        Returns:
        the result
        Throws:
        jakarta.persistence.EntityNotFoundException - if there is no result
        jakarta.persistence.NonUniqueResultException - if more than one result
      • setFirstResult

        public EJBQueryImpl setFirstResult​(int startPosition)
        Set the position of the first result to retrieve.
        Specified by:
        setFirstResult in interface jakarta.persistence.Query
        Specified by:
        setFirstResult in interface jakarta.persistence.TypedQuery<X>
        Overrides:
        setFirstResult in class QueryImpl
        Parameters:
        startPosition - position of the first result, numbered from 0
        Returns:
        the same query instance
      • setFlushMode

        public EJBQueryImpl setFlushMode​(jakarta.persistence.FlushModeType flushMode)
        Set the flush mode type to be used for the query execution.
        Specified by:
        setFlushMode in interface jakarta.persistence.Query
        Specified by:
        setFlushMode in interface jakarta.persistence.TypedQuery<X>
        Overrides:
        setFlushMode in class QueryImpl
      • setMaxResults

        public EJBQueryImpl setMaxResults​(int maxResult)
        Set the maximum number of results to retrieve.
        Specified by:
        setMaxResults in interface jakarta.persistence.Query
        Specified by:
        setMaxResults in interface jakarta.persistence.TypedQuery<X>
        Overrides:
        setMaxResults in class QueryImpl
        Returns:
        the same query instance
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(int position,
                                                           Calendar value,
                                                           jakarta.persistence.TemporalType temporalType)
        Bind an instance of java.util.Calendar to a positional parameter.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(int position,
                                                           Date value,
                                                           jakarta.persistence.TemporalType temporalType)
        Bind an instance of java.util.Date to a positional parameter.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(int position,
                                                           Object value)
        Bind an argument to a positional parameter.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(jakarta.persistence.Parameter<Calendar> param,
                                                           Calendar value,
                                                           jakarta.persistence.TemporalType temporalType)
        Bind an instance of java.util.Calendar to a Parameter object.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if position does not correspond to a parameter of the query
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(jakarta.persistence.Parameter<Date> param,
                                                           Date value,
                                                           jakarta.persistence.TemporalType temporalType)
        Bind an instance of java.util.Date to a Parameter object.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Parameters:
        param - object
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if position does not correspond to a parameter of the query
      • setParameter

        public <T> jakarta.persistence.TypedQuery setParameter​(jakarta.persistence.Parameter<T> param,
                                                               T value)
        Set the value of a Parameter object.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Parameters:
        param - parameter to be set
        value - parameter value
        Returns:
        query instance
        Throws:
        IllegalArgumentException - if parameter does not correspond to a parameter of the query
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(String name,
                                                           Calendar value,
                                                           jakarta.persistence.TemporalType temporalType)
        Bind an instance of java.util.Calendar to a named parameter.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(String name,
                                                           Date value,
                                                           jakarta.persistence.TemporalType temporalType)
        Bind an instance of java.util.Date to a named parameter.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Returns:
        the same query instance
      • setParameter

        public jakarta.persistence.TypedQuery setParameter​(String name,
                                                           Object value)
        Bind an argument to a named parameter.
        Specified by:
        setParameter in interface jakarta.persistence.Query
        Specified by:
        setParameter in interface jakarta.persistence.TypedQuery<X>
        Parameters:
        name - the parameter name
        Returns:
        the same query instance