Class StoredProcedureQueryImpl

  • All Implemented Interfaces:
    jakarta.persistence.Query, jakarta.persistence.StoredProcedureQuery

    public class StoredProcedureQueryImpl
    extends QueryImpl
    implements jakarta.persistence.StoredProcedureQuery
    Concrete JPA query class. The JPA query wraps a StoredProcesureQuery which is executed.
    • Field Detail

      • hasMoreResults

        protected boolean hasMoreResults
      • executeStatement

        protected Statement executeStatement
      • executeResultSetIndex

        protected int executeResultSetIndex
      • outputCursorIndex

        protected int outputCursorIndex
      • isOutputCursorResultSet

        protected boolean isOutputCursorResultSet
    • Constructor Detail

      • StoredProcedureQueryImpl

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

        public StoredProcedureQueryImpl​(DatabaseQuery query,
                                        EntityManagerImpl entityManager)
        Create an StoredProcedureQueryImpl with a DatabaseQuery.
      • StoredProcedureQueryImpl

        public StoredProcedureQueryImpl​(String name,
                                        EntityManagerImpl entityManager)
        Create an StoredProcedureQueryImpl with a query name.
    • Method Detail

      • buildResultRecords

        protected List buildResultRecords​(ResultSet resultSet)
        Build the given result set into a list objects. Assumes there is an execute call available and therefore should not be called unless an execute statement was issued by the user.
      • buildResultSetMappingNameQuery

        public static DatabaseQuery buildResultSetMappingNameQuery​(List<String> resultSetMappingNames,
                                                                   StoredProcedureCall call)
        Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call. This is called from a named stored procedure that employs result set mapping name(s) which should be available from the session.
      • buildResultSetMappingNameQuery

        public static DatabaseQuery buildResultSetMappingNameQuery​(List<String> resultSetMappingNames,
                                                                   StoredProcedureCall call,
                                                                   Map<String,​Object> hints,
                                                                   ClassLoader classLoader,
                                                                   AbstractSession session)
        Build a ResultSetMappingQuery from a sql result set mapping name and a stored procedure call. This is called from a named stored procedure that employs result set mapping name(s) which should be available from the session.
      • buildResultSetMappingQuery

        public static DatabaseQuery buildResultSetMappingQuery​(List<SQLResultSetMapping> resultSetMappings,
                                                               StoredProcedureCall call)
        Build a ResultSetMappingQuery from the sql result set mappings given a stored procedure call. This is called from a named stored procedure query that employs result class name(s). The resultSetMappings are build from these class name(s) and are not available from the session.
      • buildResultSetMappingQuery

        public static DatabaseQuery buildResultSetMappingQuery​(List<SQLResultSetMapping> resultSetMappings,
                                                               StoredProcedureCall call,
                                                               Map<String,​Object> hints,
                                                               ClassLoader classLoader,
                                                               AbstractSession session)
        Build a ResultSetMappingQuery from the sql result set mappings given a stored procedure call. This is called from a named stored procedure query that employs result class name(s). The resultSetMappings are build from these class name(s) and are not available from the session.
      • close

        public void close()
        Call this method to close any open connections to the database.
        Overrides:
        close in class QueryImpl
      • execute

        public boolean execute()
        Returns true if the first result corresponds to a result set, and false if it is an update count or if there are no results other than through INOUT and OUT parameters, if any.
        Specified by:
        execute in interface jakarta.persistence.StoredProcedureQuery
        Returns:
        true if first result corresponds to result set
        Throws:
        jakarta.persistence.QueryTimeoutException - if the query execution exceeds the query timeout value set and only the statement is rolled back
        jakarta.persistence.PersistenceException - if the query execution exceeds the query timeout value set and the transaction is rolled back
      • executeUpdate

        public int executeUpdate()
        Execute an update or delete statement (from a stored procedure query).
        Specified by:
        executeUpdate in interface jakarta.persistence.Query
        Specified by:
        executeUpdate in interface jakarta.persistence.StoredProcedureQuery
        Overrides:
        executeUpdate in class QueryImpl
        Returns:
        the number of entities updated or deleted
      • finalize

        public void finalize()
        Finalize method in case the query is not closed.
        Overrides:
        finalize in class Object
      • getCall

        protected StoredProcedureCall getCall()
        Return the stored procedure call associated with this query.
      • getInternalParameters

        protected Map<String,​jakarta.persistence.Parameter<?>> getInternalParameters()
        Return the internal map of parameters.
        Overrides:
        getInternalParameters in class QueryImpl
      • getOutputParameterValue

        public Object getOutputParameterValue​(int position)
        Used to retrieve the values passed back from the procedure through INOUT and OUT parameters. For portability, all results corresponding to result sets and update counts must be retrieved before the values of output parameters.
        Specified by:
        getOutputParameterValue in interface jakarta.persistence.StoredProcedureQuery
        Parameters:
        position - parameter position
        Returns:
        the result that is passed back through the parameter
        Throws:
        IllegalArgumentException - if the position does not correspond to a parameter of the query or is not an INOUT or OUT parameter
      • getOutputParameterValue

        public Object getOutputParameterValue​(String parameterName)
        Used to retrieve the values passed back from the procedure through INOUT and OUT parameters. For portability, all results corresponding to result sets and update counts must be retrieved before the values of output parameters.
        Specified by:
        getOutputParameterValue in interface jakarta.persistence.StoredProcedureQuery
        Parameters:
        parameterName - name of the parameter as registered or specified in metadata
        Returns:
        the result that is passed back through the parameter
        Throws:
        IllegalArgumentException - if the parameter name does not correspond to a parameter of the query or is not an INOUT or OUT parameter
      • getResultList

        public List getResultList()
        Execute the query and return the query results as a List.
        Specified by:
        getResultList in interface jakarta.persistence.Query
        Specified by:
        getResultList in interface jakarta.persistence.StoredProcedureQuery
        Overrides:
        getResultList in class QueryImpl
        Returns:
        a list of the results
      • getResultSetMappingQuery

        protected ResultSetMappingQuery getResultSetMappingQuery()
        Return the ResultSetMappingQuery for this stored procedure query. NOTE: Methods assumes associated database query is a ResultSetMappingQuery.
      • getSingleResult

        public Object getSingleResult()
        Execute the query and return the single query result.
        Specified by:
        getSingleResult in interface jakarta.persistence.Query
        Specified by:
        getSingleResult in interface jakarta.persistence.StoredProcedureQuery
        Overrides:
        getSingleResult in class QueryImpl
        Returns:
        a single result object.
      • getUpdateCount

        public int getUpdateCount()
        Returns the update count or -1 if there is no pending result or if the next result is not an update count.
        Specified by:
        getUpdateCount in interface jakarta.persistence.StoredProcedureQuery
        Returns:
        update count or -1 if there is no pending result or if the next result is not an update count
        Throws:
        jakarta.persistence.QueryTimeoutException - if the query execution exceeds the query timeout value set and only the statement is rolled back
        jakarta.persistence.PersistenceException - if the query execution exceeds the query timeout value set and the transaction is rolled back
      • hasMoreResults

        public boolean hasMoreResults()
        Returns true if the next result corresponds to a result set, and false if it is an update count or if there are no results other than through INOUT and OUT parameters, if any.
        Specified by:
        hasMoreResults in interface jakarta.persistence.StoredProcedureQuery
        Returns:
        true if next result corresponds to result set
        Throws:
        jakarta.persistence.QueryTimeoutException - if the query execution exceeds the query timeout value set and only the statement is rolled back
        jakarta.persistence.PersistenceException - if the query execution exceeds the query timeout value set and the transaction is rolled back
      • isValidCallableStatement

        protected boolean isValidCallableStatement()
        Returns true if the execute statement for this query is 1) not null (i.e. query has been executed and 2) is an instance of callable statement, meaning there are out parameters associated with it.
      • registerStoredProcedureParameter

        public jakarta.persistence.StoredProcedureQuery registerStoredProcedureParameter​(int position,
                                                                                         Class type,
                                                                                         jakarta.persistence.ParameterMode mode)
        Register a positional parameter. All positional parameters must be registered.
        Specified by:
        registerStoredProcedureParameter in interface jakarta.persistence.StoredProcedureQuery
        Parameters:
        position - parameter position
        type - type of the parameter
        mode - parameter mode
        Returns:
        the same query instance
      • registerStoredProcedureParameter

        public jakarta.persistence.StoredProcedureQuery registerStoredProcedureParameter​(String parameterName,
                                                                                         Class type,
                                                                                         jakarta.persistence.ParameterMode mode)
        Register a named parameter. When using parameter names, all parameters must be registered in the order in which they occur in the parameter list of the stored procedure.
        Specified by:
        registerStoredProcedureParameter in interface jakarta.persistence.StoredProcedureQuery
        Parameters:
        parameterName - name of the parameter as registered or specified in metadata
        type - type of the parameter
        mode - parameter mode
        Returns:
        the same query instance
      • setFirstResult

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

        public StoredProcedureQueryImpl setFlushMode​(jakarta.persistence.FlushModeType flushMode)
        Set the flush mode type to be used for the query execution. The flush mode type applies to the query regardless of the flush mode type in use for the entity manager.
        Specified by:
        setFlushMode in interface jakarta.persistence.Query
        Specified by:
        setFlushMode in interface jakarta.persistence.StoredProcedureQuery
        Overrides:
        setFlushMode in class QueryImpl
        Parameters:
        flushMode - flush mode
        Returns:
        the same query instance
      • setHint

        public jakarta.persistence.StoredProcedureQuery setHint​(String hintName,
                                                                Object value)
        Set a query property or hint. The hints elements may be used to specify query properties and hints. Properties defined by this specification must be observed by the provider. Vendor-specific hints that are not recognized by a provider must be silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use, this hint may or may not be observed.
        Specified by:
        setHint in interface jakarta.persistence.Query
        Specified by:
        setHint in interface jakarta.persistence.StoredProcedureQuery
        Parameters:
        hintName - name of the property or hint
        value - value for the property or hint
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if the second argument is not valid for the implementation
      • setLockMode

        public StoredProcedureQueryImpl 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
        Overrides:
        setLockMode in class QueryImpl
        Throws:
        IllegalStateException - if not a Java Persistence query language SELECT query
      • setMaxResults

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

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
      • setParameter

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if position does not correspond to a positional parameter of the query or if the value argument is of incorrect type
      • setParameter

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same 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

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if the parameter does not correspond to a parameter of the query
      • setParameter

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if the parameter does not correspond to a parameter of the query
      • setParameter

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

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type
      • setParameter

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same query instance
        Throws:
        IllegalArgumentException - if the parameter name does not correspond to a parameter of the query or if the value argument is of incorrect type
      • setParameter

        public jakarta.persistence.StoredProcedureQuery 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.StoredProcedureQuery
        Returns:
        the same 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
      • setParameterInternal

        protected void setParameterInternal​(String name,
                                            Object value,
                                            boolean isIndex)
        Bind an argument to a named or indexed parameter.
        Overrides:
        setParameterInternal in class QueryImpl
        Parameters:
        name - the parameter name
        value - to bind
        isIndex - defines if index or named