Package org.sqlproc.engine.spring
Class SpringQuery
java.lang.Object
org.sqlproc.engine.spring.SpringQuery
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.sqlproc.engine.SqlQuery
SqlQuery.SqlQueryRowProcessor -
Field Summary
FieldsModifier and TypeFieldDescriptionThe collection of all parameters values for batch insert/update/delete.(package private) static final Pattern(package private) Integer- * The fetch size of rows to retrieve in one SQL(package private) IntegerThe first row to retrieveThe collection of all (auto-generated) identities.(package private) Map<String, IdentitySetter> The collection of all identities setters.The collection of all identities types.(package private) org.springframework.jdbc.core.JdbcTemplateThe Spring JdbcTemplate, the central class for all Spring database operations.(package private) booleanThe failed SQL command should be logged.(package private) final org.slf4j.LoggerThe internal slf4j logger.(package private) Integer- * The maximum number of rows to retrieveThe indicator there are no more data in ResultSet.(package private) booleanThe SQL output is sorted.(package private) Map<String, OutValueSetter> The collection of all parameters output value setters.The collection of all parameters, which have to be picked-up.The collection of all parameters types for output values.The collection of all parameters (input value declarations).The collection of all parameters types.The collection of all parameters values.(package private) StringThe SQL query/statement command.The collection of all scalars (output values declarations).The collection of all scalars types.(package private) SqlControlThe compound parameters controlling the META SQL execution.(package private) IntegerA timeout for the underlying query. -
Constructor Summary
ConstructorsConstructorDescriptionSpringQuery(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, String queryString) Creates a new instance of this adapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBatchParameterValues(Map<String, Object> parameterValues) int[]batch(SqlRuntimeContext runtimeCtx) callList(SqlRuntimeContext runtimeCtx) callUnique(SqlRuntimeContext runtimeCtx) intcallUpdate(SqlRuntimeContext runtimeCtx) private voiddoIdentitySelect(String identityName) Runs the select to obtain the value of auto-generated identity.int[]executeBatch(String[] statements) private voidgetGeneratedKeys(String identityName, Statement statement) Retrieves the value of auto-generated identity from executed prepared statement.Gets the value of the designated columns for one database row as the object in the Java programming language.getParameters(CallableStatement cs, boolean isFunction) Gets the value of the designated OUT parameters.getQuery()getResults(ResultSet rs) Gets the value of the designated columns as the objects in the Java programming language.private booleanlist(SqlRuntimeContext runtimeCtx) protected SqlProcessorExceptionnewSqlProcessorException(org.springframework.dao.DataAccessException ex, String query) intquery(SqlRuntimeContext runtimeCtx, SqlQuery.SqlQueryRowProcessor sqlQueryRowProcessor) protected intsetLimits(PreparedStatement ps, SqlFromToPlugin.LimitType limitType, int ix, boolean afterSql) Sets the limit related parameters.voidsetLogError(boolean logError) Sets an indicator the failed SQL command should be loggedsetOrdered(boolean ordered) setParameter(String name, Object val) setParameter(String name, Object val, Object type, Class<?>... moreTypes) setParameterList(String name, Object[] vals) setParameterList(String name, Object[] vals, Object type, Class<?>... moreTypes) protected voidsetParameters(Map<String, Object> parameterValues, PreparedStatement ps, SqlFromToPlugin.LimitType limitType, int start) Sets the value of the designated parameters.setSqlControl(SqlControl sqlControl) unique(SqlRuntimeContext runtimeCtx) intupdate(SqlRuntimeContext runtimeCtx) protected intupdateWithGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc, org.springframework.jdbc.core.PreparedStatementSetter pss, String identityName) This is a workaround, as this method is not visible in JdbcTemplate.protected int[]updateWithoutGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc, List<org.springframework.jdbc.core.PreparedStatementSetter> psss) This is a workaround, as this method is not visible in JdbcTemplate.protected intupdateWithoutGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc, org.springframework.jdbc.core.PreparedStatementSetter pss) This is a workaround, as this method is not visible in JdbcTemplate.
-
Field Details
-
logger
final org.slf4j.Logger loggerThe internal slf4j logger. -
jdbcTemplate
org.springframework.jdbc.core.JdbcTemplate jdbcTemplateThe Spring JdbcTemplate, the central class for all Spring database operations. -
queryString
String queryStringThe SQL query/statement command. -
scalars
The collection of all scalars (output values declarations). -
scalarTypes
The collection of all scalars types. -
parameters
The collection of all parameters (input value declarations). -
parameterValues
The collection of all parameters values. -
batchParameterValues
The collection of all parameters values for batch insert/update/delete. -
parameterTypes
The collection of all parameters types. -
parameterOutValueTypes
The collection of all parameters types for output values. -
parameterOutValueSetters
Map<String,OutValueSetter> parameterOutValueSettersThe collection of all parameters output value setters. -
parameterOutValuesToPickup
The collection of all parameters, which have to be picked-up. -
identities
The collection of all (auto-generated) identities. -
identitySetters
Map<String,IdentitySetter> identitySettersThe collection of all identities setters. -
identityTypes
The collection of all identities types. -
sqlControl
SqlControl sqlControlThe compound parameters controlling the META SQL execution. -
timeout
Integer timeoutA timeout for the underlying query. -
firstResult
Integer firstResultThe 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 orderedThe SQL output is sorted. -
logError
boolean logErrorThe failed SQL command should be logged. -
NO_MORE_DATA
The indicator there are no more data in ResultSet. -
CALL
-
-
Constructor Details
-
SpringQuery
Creates a new instance of this adapter.- Parameters:
jdbcTemplate- the Spring JdbcTemplate instancequeryString- the SQL query/statement command
-
-
Method Details
-
getQuery
-
setSqlControl
- Specified by:
setSqlControlin interfaceSqlQuery
-
setOrdered
- Specified by:
setOrderedin interfaceSqlQuery
-
getParameterValues
- Specified by:
getParameterValuesin interfaceSqlQuery
-
addBatchParameterValues
- Specified by:
addBatchParameterValuesin interfaceSqlQuery
-
list
- Specified by:
listin interfaceSqlQuery- Throws:
SqlProcessorException
-
unique
- Specified by:
uniquein interfaceSqlQuery- Throws:
SqlProcessorException
-
query
public int query(SqlRuntimeContext runtimeCtx, SqlQuery.SqlQueryRowProcessor sqlQueryRowProcessor) throws SqlProcessorException - Specified by:
queryin interfaceSqlQuery- Throws:
SqlProcessorException
-
update
- Specified by:
updatein interfaceSqlQuery- Throws:
SqlProcessorException
-
batch
- Specified by:
batchin interfaceSqlQuery- Throws:
SqlProcessorException
-
isSetJDBCIdentity
private boolean isSetJDBCIdentity() -
doIdentitySelect
Runs the select to obtain the value of auto-generated identity.- Parameters:
identityName- the identity name from the META SQL statement
-
getGeneratedKeys
Retrieves the value of auto-generated identity from executed prepared statement.- Parameters:
identityName- the identity name from the META SQL statementstatement- 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 ResultSetStatement.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
- Specified by:
callListin interfaceSqlQuery- Throws:
SqlProcessorException
-
callUnique
- Specified by:
callUniquein interfaceSqlQuery- Throws:
SqlProcessorException
-
callUpdate
- Specified by:
callUpdatein interfaceSqlQuery- Throws:
SqlProcessorException
-
callFunction
- Specified by:
callFunctionin interfaceSqlQuery- Throws:
SqlProcessorException
-
addScalar
-
addScalar
-
setParameter
- Specified by:
setParameterin interfaceSqlQuery- Throws:
SqlProcessorException
-
setParameter
public SqlQuery setParameter(String name, Object val, Object type, Class<?>... moreTypes) throws SqlProcessorException - Specified by:
setParameterin interfaceSqlQuery- Throws:
SqlProcessorException
-
setParameterList
- Specified by:
setParameterListin interfaceSqlQuery- Throws:
SqlProcessorException
-
setParameterList
public SqlQuery setParameterList(String name, Object[] vals, Object type, Class<?>... moreTypes) throws SqlProcessorException - Specified by:
setParameterListin interfaceSqlQuery- Throws:
SqlProcessorException
-
setParameters
protected void setParameters(Map<String, Object> parameterValues, PreparedStatement ps, SqlFromToPlugin.LimitType limitType, int start) throws SQLExceptionSets the value of the designated parameters.- Parameters:
ps- an instance of PreparedStatementlimitType- the limit type to restrict the number of rows in the result setstart- 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 closedPreparedStatement
-
setLimits
protected int setLimits(PreparedStatement ps, SqlFromToPlugin.LimitType limitType, int ix, boolean afterSql) throws SQLException Sets the limit related parameters.- Parameters:
ps- an instance of PreparedStatementlimitType- the limit type to restrict the number of rows in the result setix- a column indexafterSql- 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 closedPreparedStatement
-
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 closedCallableStatement
-
getResults
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 closedResultSet
-
getOneResult
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 closedResultSet
-
executeBatch
- Specified by:
executeBatchin interfaceSqlQuery- Throws:
SqlProcessorException
-
newSqlProcessorException
protected 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:
setLogErrorin interfaceSqlQuery- Parameters:
logError- an indicator the failed SQL command should be logged
-