Class StoredProcedureQueryImpl

java.lang.Object
org.eclipse.persistence.internal.jpa.QueryImpl
org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl
All Implemented Interfaces:
Query, StoredProcedureQuery

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

    • hasMoreResults

      protected boolean hasMoreResults
    • executeCall

      protected DatabaseCall executeCall
    • executeStatement

      protected Statement executeStatement
    • executeResultSetIndex

      protected int executeResultSetIndex
    • outputCursorIndex

      protected int outputCursorIndex
    • isOutputCursorResultSet

      protected boolean isOutputCursorResultSet
  • Constructor Details

    • 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 Details

    • 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.
    • buildStoredProcedureQuery

      public static DatabaseQuery buildStoredProcedureQuery(Class<?> resultClass, StoredProcedureCall call, Map<String,Object> hints, ClassLoader classLoader, AbstractSession session)
      Build a ReadAllQuery from a class and stored procedure call.
    • buildStoredProcedureQuery

      public static DatabaseQuery buildStoredProcedureQuery(StoredProcedureCall call, Map<String,Object> hints, ClassLoader classLoader, AbstractSession session)
      Build a DataReadQuery with the stored procedure call given.
    • buildStoredProcedureQuery

      public static DatabaseQuery buildStoredProcedureQuery(String sqlResultSetMappingName, 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.
    • 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 StoredProcedureQuery
      Returns:
      true if first result corresponds to result set
      Throws:
      QueryTimeoutException - if the query execution exceeds the query timeout value set and only the statement is rolled back
      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 Query
      Specified by:
      executeUpdate in interface 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,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 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 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 Query
      Specified by:
      getResultList in interface 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 Query
      Specified by:
      getSingleResult in interface 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 StoredProcedureQuery
      Returns:
      update count or -1 if there is no pending result or if the next result is not an update count
      Throws:
      QueryTimeoutException - if the query execution exceeds the query timeout value set and only the statement is rolled back
      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 StoredProcedureQuery
      Returns:
      true if next result corresponds to result set
      Throws:
      QueryTimeoutException - if the query execution exceeds the query timeout value set and only the statement is rolled back
      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 StoredProcedureQuery registerStoredProcedureParameter(int position, Class type, ParameterMode mode)
      Register a positional parameter. All positional parameters must be registered.
      Specified by:
      registerStoredProcedureParameter in interface StoredProcedureQuery
      Parameters:
      position - parameter position
      type - type of the parameter
      mode - parameter mode
      Returns:
      the same query instance
    • registerStoredProcedureParameter

      public StoredProcedureQuery registerStoredProcedureParameter(String parameterName, Class type, 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 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 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(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 Query
      Specified by:
      setFlushMode in interface StoredProcedureQuery
      Overrides:
      setFlushMode in class QueryImpl
      Parameters:
      flushMode - flush mode
      Returns:
      the same query instance
    • setHint

      public 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 Query
      Specified by:
      setHint in interface 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(LockModeType lockMode)
      Set the lock mode type to be used for the query execution.
      Specified by:
      setLockMode in interface 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 Query
      Overrides:
      setMaxResults in class QueryImpl
      Returns:
      the same query instance
    • setParameter

      public StoredProcedureQuery setParameter(int position, Calendar value, TemporalType temporalType)
      Bind an instance of java.util.Calendar to a positional parameter.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface 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 StoredProcedureQuery setParameter(int position, Date value, TemporalType temporalType)
      Bind an instance of java.util.Date to a positional parameter.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface 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 StoredProcedureQuery setParameter(int position, Object value)
      Bind an argument to a positional parameter.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface 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 StoredProcedureQuery setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
      Bind an instance of java.util.Calendar to a Parameter object.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface StoredProcedureQuery
      Returns:
      the same query instance
      Throws:
      IllegalArgumentException - if the parameter does not correspond to a parameter of the query
    • setParameter

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

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

      public StoredProcedureQuery setParameter(String name, Calendar value, TemporalType temporalType)
      Bind an instance of java.util.Calendar to a named parameter.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface 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 StoredProcedureQuery setParameter(String name, Date value, TemporalType temporalType)
      Bind an instance of java.util.Date to a named parameter.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface 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 StoredProcedureQuery setParameter(String name, Object value)
      Bind an argument to a named parameter.
      Specified by:
      setParameter in interface Query
      Specified by:
      setParameter in interface 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