Class SpringQuery

java.lang.Object
org.sqlproc.engine.spring.SpringQuery
All Implemented Interfaces:
org.sqlproc.engine.SqlQuery

public class SpringQuery extends Object implements org.sqlproc.engine.SqlQuery
The Spring stack implementation of the SQL Engine query contract. In fact it's an adapter the internal Spring stuff.

For more info please see the Tutorials.

Author:
Vladimir Hudec
  • Field Details

    • logger

      final org.slf4j.Logger logger
      The internal slf4j logger.
    • jdbcTemplate

      org.springframework.jdbc.core.JdbcTemplate jdbcTemplate
      The Spring JdbcTemplate, the central class for all Spring database operations.
    • queryString

      String queryString
      The SQL query/statement command.
    • scalars

      List<String> scalars
      The collection of all scalars (output values declarations).
    • scalarTypes

      Map<String,Object> scalarTypes
      The collection of all scalars types.
    • parameters

      List<String> parameters
      The collection of all parameters (input value declarations).
    • parameterValues

      Map<String,Object> parameterValues
      The collection of all parameters values.
    • batchParameterValues

      List<Map<String,Object>> batchParameterValues
      The collection of all parameters values for batch insert/update/delete.
    • parameterTypes

      Map<String,Object> parameterTypes
      The collection of all parameters types.
    • parameterOutValueTypes

      Map<String,Object> parameterOutValueTypes
      The collection of all parameters types for output values.
    • parameterOutValueSetters

      Map<String, org.sqlproc.engine.type.OutValueSetter> parameterOutValueSetters
      The collection of all parameters output value setters.
    • parameterOutValuesToPickup

      Map<Integer,Integer> parameterOutValuesToPickup
      The collection of all parameters, which have to be picked-up.
    • identities

      List<String> identities
      The collection of all (auto-generated) identities.
    • identitySetters

      Map<String, org.sqlproc.engine.type.IdentitySetter> identitySetters
      The collection of all identities setters.
    • identityTypes

      Map<String,Object> identityTypes
      The collection of all identities types.
    • sqlControl

      org.sqlproc.engine.SqlControl sqlControl
      The compound parameters controlling the META SQL execution.
    • timeout

      Integer timeout
      A timeout for the underlying query.
    • firstResult

      Integer firstResult
      The first row to retrieve. -
    • maxResults

      Integer maxResults
      - * The maximum number of rows to retrieve. -
    • fetchSize

      Integer fetchSize
      - * The fetch size of rows to retrieve in one SQL. -
    • ordered

      boolean ordered
      The SQL output is sorted.
    • logError

      boolean logError
      The failed SQL command should be logged.
    • NO_MORE_DATA

      private static final Map<String,Object> NO_MORE_DATA
      The indicator there are no more data in ResultSet.
    • CALL

      static final Pattern CALL
  • Constructor Details

    • SpringQuery

      public SpringQuery(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, String queryString)
      Creates a new instance of this adapter.
      Parameters:
      jdbcTemplate - the Spring JdbcTemplate instance
      queryString - the SQL query/statement command
  • Method Details

    • getQuery

      public Object getQuery()
      Specified by:
      getQuery in interface org.sqlproc.engine.SqlQuery
    • setSqlControl

      public org.sqlproc.engine.SqlQuery setSqlControl(org.sqlproc.engine.SqlControl sqlControl)
      Specified by:
      setSqlControl in interface org.sqlproc.engine.SqlQuery
    • setOrdered

      public org.sqlproc.engine.SqlQuery setOrdered(boolean ordered)
      Specified by:
      setOrdered in interface org.sqlproc.engine.SqlQuery
    • getParameterValues

      public Map<String,Object> getParameterValues()
      Specified by:
      getParameterValues in interface org.sqlproc.engine.SqlQuery
    • addBatchParameterValues

      public void addBatchParameterValues(Map<String,Object> parameterValues)
      Specified by:
      addBatchParameterValues in interface org.sqlproc.engine.SqlQuery
    • list

      public List<Map<String,Object>> list(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      list in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • unique

      public Map<String,Object> unique(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      unique in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • query

      public int query(org.sqlproc.engine.SqlRuntimeContext runtimeCtx, org.sqlproc.engine.SqlQuery.SqlQueryRowProcessor sqlQueryRowProcessor) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      query in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • update

      public int update(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      update in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • batch

      public int[] batch(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      batch in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • isSetJDBCIdentity

      private boolean isSetJDBCIdentity()
    • doIdentitySelect

      private void doIdentitySelect(String identityName)
      Runs the select to obtain the value of auto-generated identity.
      Parameters:
      identityName - the identity name from the META SQL statement
    • getGeneratedKeys

      private void getGeneratedKeys(String identityName, Statement statement)
      Retrieves the value of auto-generated identity from executed prepared statement.
      Parameters:
      identityName - the identity name from the META SQL statement
      statement - statement to retrieve auto-generated keys from
    • updateWithGenKeys

      protected int updateWithGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc, org.springframework.jdbc.core.PreparedStatementSetter pss, String identityName) throws org.springframework.dao.DataAccessException
      This is a workaround, as this method is not visible in JdbcTemplate. It executes the prepared SQL statement and retrieves the values of generated identities from the statement. The generated identities cannot be obtained later because the ResultSet Statement.getGeneratedKeys() is closed after this method finishes.
      Throws:
      org.springframework.dao.DataAccessException
    • updateWithoutGenKeys

      protected int updateWithoutGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc, org.springframework.jdbc.core.PreparedStatementSetter pss) throws org.springframework.dao.DataAccessException
      This is a workaround, as this method is not visible in JdbcTemplate.
      Throws:
      org.springframework.dao.DataAccessException
    • updateWithoutGenKeys

      protected int[] updateWithoutGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc, List<org.springframework.jdbc.core.PreparedStatementSetter> psss) throws org.springframework.dao.DataAccessException
      This is a workaround, as this method is not visible in JdbcTemplate.
      Throws:
      org.springframework.dao.DataAccessException
    • callList

      public List<Map<String,Object>> callList(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      callList in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • callUnique

      public Map<String,Object> callUnique(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      callUnique in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • callUpdate

      public int callUpdate(org.sqlproc.engine.SqlRuntimeContext runtimeCtx) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      callUpdate in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • callFunction

      public Map<String,Object> callFunction() throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      callFunction in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • addScalar

      public org.sqlproc.engine.SqlQuery addScalar(String columnAlias)
      Specified by:
      addScalar in interface org.sqlproc.engine.SqlQuery
    • addScalar

      public org.sqlproc.engine.SqlQuery addScalar(String columnAlias, Object type, Class<?>... moreTypes)
      Specified by:
      addScalar in interface org.sqlproc.engine.SqlQuery
    • setParameter

      public org.sqlproc.engine.SqlQuery setParameter(String name, Object val) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      setParameter in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • setParameter

      public org.sqlproc.engine.SqlQuery setParameter(String name, Object val, Object type, Class<?>... moreTypes) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      setParameter in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • setParameterList

      public org.sqlproc.engine.SqlQuery setParameterList(String name, Object[] vals) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      setParameterList in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • setParameterList

      public org.sqlproc.engine.SqlQuery setParameterList(String name, Object[] vals, Object type, Class<?>... moreTypes) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      setParameterList in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • setParameters

      protected void setParameters(Map<String,Object> parameterValues, PreparedStatement ps, org.sqlproc.engine.plugin.SqlFromToPlugin.LimitType limitType, int start) throws SQLException
      Sets the value of the designated parameters.
      Parameters:
      ps - an instance of PreparedStatement
      limitType - the limit type to restrict the number of rows in the result set
      start - the index of the first parameter to bind to prepared statement
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed PreparedStatement
    • setLimits

      protected int setLimits(PreparedStatement ps, org.sqlproc.engine.plugin.SqlFromToPlugin.LimitType limitType, int ix, boolean afterSql) throws SQLException
      Sets the limit related parameters.
      Parameters:
      ps - an instance of PreparedStatement
      limitType - the limit type to restrict the number of rows in the result set
      ix - a column index
      afterSql - an indicator it's done after the main SQL statement execution
      Returns:
      the updated column index
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed PreparedStatement
    • getParameters

      protected Map<String,Object> getParameters(CallableStatement cs, boolean isFunction) throws SQLException
      Gets the value of the designated OUT parameters.
      Parameters:
      cs - an instance of CallableStatement
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed CallableStatement
    • getResults

      protected List<Map<String,Object>> getResults(ResultSet rs) throws SQLException
      Gets the value of the designated columns as the objects in the Java programming language.
      Parameters:
      rs - an instance of ResultSet
      Returns:
      the result list
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed ResultSet
    • getOneResult

      protected Map<String,Object> getOneResult(ResultSet rs) throws SQLException
      Gets the value of the designated columns for one database row as the object in the Java programming language.
      Parameters:
      rs - an instance of ResultSet
      Returns:
      the result object for one row
      Throws:
      SQLException - if a database access error occurs or this method is called on a closed ResultSet
    • executeBatch

      public int[] executeBatch(String[] statements) throws org.sqlproc.engine.SqlProcessorException
      Specified by:
      executeBatch in interface org.sqlproc.engine.SqlQuery
      Throws:
      org.sqlproc.engine.SqlProcessorException
    • newSqlProcessorException

      protected org.sqlproc.engine.SqlProcessorException newSqlProcessorException(org.springframework.dao.DataAccessException ex, String query)
    • setLogError

      public void setLogError(boolean logError)
      Sets an indicator the failed SQL command should be logged
      Specified by:
      setLogError in interface org.sqlproc.engine.SqlQuery
      Parameters:
      logError - an indicator the failed SQL command should be logged