public class SpringQuery extends Object implements SqlQuery
For more info please see the Tutorials.
SqlQuery.SqlQueryRowProcessor| Modifier and Type | Field and Description |
|---|---|
(package private) static Pattern |
CALL |
(package private) Integer |
fetchSize
The fetch size of rows to retrieve in one SQL.
|
(package private) Integer |
firstResult
The first row to retrieve.
|
(package private) List<String> |
identities
The collection of all (auto-generated) identities.
|
(package private) Map<String,IdentitySetter> |
identitySetters
The collection of all identities setters.
|
(package private) Map<String,Object> |
identityTypes
The collection of all identities types.
|
(package private) org.springframework.jdbc.core.JdbcTemplate |
jdbcTemplate
The Spring JdbcTemplate, the central class for all Spring database operations.
|
(package private) boolean |
logError
The failed SQL command should be logged.
|
(package private) org.slf4j.Logger |
logger
The internal slf4j logger.
|
(package private) Integer |
maxResults
The maximum number of rows to retrieve.
|
private static Object |
NO_MORE_DATA
The indicator there are no more data in ResultSet.
|
(package private) boolean |
ordered
The SQL output is sorted.
|
(package private) Map<String,OutValueSetter> |
parameterOutValueSetters
The collection of all parameters output value setters.
|
(package private) Map<Integer,Integer> |
parameterOutValuesToPickup
The collection of all parameters, which have to be picked-up.
|
(package private) Map<String,Object> |
parameterOutValueTypes
The collection of all parameters types for output values.
|
(package private) List<String> |
parameters
The collection of all parameters (input value declarations).
|
(package private) Map<String,Object> |
parameterTypes
The collection of all parameters types.
|
(package private) Map<String,Object> |
parameterValues
The collection of all parameters values.
|
(package private) String |
queryString
The SQL query/statement command.
|
(package private) List<String> |
scalars
The collection of all scalars (output values declarations).
|
(package private) Map<String,Object> |
scalarTypes
The collection of all scalars types.
|
(package private) Integer |
timeout
A timeout for the underlying query.
|
| Constructor and Description |
|---|
SpringQuery(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String queryString)
Creates a new instance of this adapter.
|
| Modifier and Type | Method and Description |
|---|---|
SqlQuery |
addScalar(String columnAlias) |
SqlQuery |
addScalar(String columnAlias,
Object type) |
Object |
callFunction() |
List |
callList(SqlRuntimeContext runtimeCtx) |
Object |
callUnique(SqlRuntimeContext runtimeCtx) |
int |
callUpdate(SqlRuntimeContext runtimeCtx) |
private void |
doIdentitySelect(String identityName)
Runs the select to obtain the value of auto-generated identity.
|
int[] |
executeBatch(String[] statements) |
private void |
getGeneratedKeys(String identityName,
Statement statement)
Retrieves the value of auto-generated identity from executed prepared statement.
|
protected Object |
getOneResult(ResultSet rs)
Gets the value of the designated columns for one database row as the object in the Java programming language.
|
protected Object |
getParameters(CallableStatement cs,
boolean isFunction)
Gets the value of the designated OUT parameters.
|
Object |
getQuery() |
protected List |
getResults(ResultSet rs)
Gets the value of the designated columns as the objects in the Java programming language.
|
private boolean |
isSetJDBCIdentity() |
List |
list(SqlRuntimeContext runtimeCtx) |
protected SqlProcessorException |
newSqlProcessorException(org.springframework.dao.DataAccessException ex,
String query) |
int |
query(SqlRuntimeContext runtimeCtx,
SqlQuery.SqlQueryRowProcessor sqlQueryRowProcessor) |
SqlQuery |
setFetchSize(int fetchSize) |
SqlQuery |
setFirstResult(int firstResult) |
protected int |
setLimits(PreparedStatement ps,
SqlFromToPlugin.LimitType limitType,
int ix,
boolean afterSql)
Sets the limit related parameters.
|
void |
setLogError(boolean logError)
Sets an indicator the failed SQL command should be logged
|
SqlQuery |
setMaxResults(int maxResults) |
SqlQuery |
setOrdered(boolean ordered) |
SqlQuery |
setParameter(String name,
Object val) |
SqlQuery |
setParameter(String name,
Object val,
Object type) |
SqlQuery |
setParameterList(String name,
Object[] vals) |
SqlQuery |
setParameterList(String name,
Object[] vals,
Object type) |
protected void |
setParameters(PreparedStatement ps,
SqlFromToPlugin.LimitType limitType,
int start)
Sets the value of the designated parameters.
|
SqlQuery |
setTimeout(int timeout) |
Object |
unique(SqlRuntimeContext runtimeCtx) |
int |
update(SqlRuntimeContext runtimeCtx) |
protected int |
updateWithGenKeys(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,
org.springframework.jdbc.core.PreparedStatementSetter pss)
This is a workaround, as this method is not visible in JdbcTemplate.
|
final org.slf4j.Logger logger
org.springframework.jdbc.core.JdbcTemplate jdbcTemplate
String queryString
Map<String,Object> parameterOutValueTypes
Map<String,OutValueSetter> parameterOutValueSetters
Map<Integer,Integer> parameterOutValuesToPickup
Map<String,IdentitySetter> identitySetters
Integer timeout
Integer firstResult
Integer maxResults
Integer fetchSize
boolean ordered
boolean logError
private static final Object NO_MORE_DATA
static final Pattern CALL
public SpringQuery(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
String queryString)
jdbcTemplate - the Spring JdbcTemplate instancequeryString - the SQL query/statement commandpublic SqlQuery setTimeout(int timeout)
setTimeout in interface SqlQuerypublic SqlQuery setFirstResult(int firstResult)
setFirstResult in interface SqlQuerypublic SqlQuery setMaxResults(int maxResults)
setMaxResults in interface SqlQuerypublic SqlQuery setFetchSize(int fetchSize)
setFetchSize in interface SqlQuerypublic SqlQuery setOrdered(boolean ordered)
setOrdered in interface SqlQuerypublic List list(SqlRuntimeContext runtimeCtx) throws SqlProcessorException
list in interface SqlQuerySqlProcessorExceptionpublic Object unique(SqlRuntimeContext runtimeCtx) throws SqlProcessorException
unique in interface SqlQuerySqlProcessorExceptionpublic int query(SqlRuntimeContext runtimeCtx, SqlQuery.SqlQueryRowProcessor sqlQueryRowProcessor) throws SqlProcessorException
query in interface SqlQuerySqlProcessorExceptionpublic int update(SqlRuntimeContext runtimeCtx) throws SqlProcessorException
update in interface SqlQuerySqlProcessorExceptionprivate boolean isSetJDBCIdentity()
private void doIdentitySelect(String identityName)
identityName - the identity name from the META SQL statementprivate void getGeneratedKeys(String identityName, Statement statement)
identityName - the identity name from the META SQL statementstatement - statement to retrieve auto-generated keys fromprotected int updateWithGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc,
org.springframework.jdbc.core.PreparedStatementSetter pss,
String identityName)
throws org.springframework.dao.DataAccessException
Statement.getGeneratedKeys()
is closed after this method finishes.org.springframework.dao.DataAccessExceptionprotected int updateWithoutGenKeys(org.springframework.jdbc.core.PreparedStatementCreator psc,
org.springframework.jdbc.core.PreparedStatementSetter pss)
throws org.springframework.dao.DataAccessException
org.springframework.dao.DataAccessExceptionpublic List callList(SqlRuntimeContext runtimeCtx) throws SqlProcessorException
callList in interface SqlQuerySqlProcessorExceptionpublic Object callUnique(SqlRuntimeContext runtimeCtx) throws SqlProcessorException
callUnique in interface SqlQuerySqlProcessorExceptionpublic int callUpdate(SqlRuntimeContext runtimeCtx) throws SqlProcessorException
callUpdate in interface SqlQuerySqlProcessorExceptionpublic Object callFunction() throws SqlProcessorException
callFunction in interface SqlQuerySqlProcessorExceptionpublic SqlQuery setParameter(String name, Object val) throws SqlProcessorException
setParameter in interface SqlQuerySqlProcessorExceptionpublic SqlQuery setParameter(String name, Object val, Object type) throws SqlProcessorException
setParameter in interface SqlQuerySqlProcessorExceptionpublic SqlQuery setParameterList(String name, Object[] vals) throws SqlProcessorException
setParameterList in interface SqlQuerySqlProcessorExceptionpublic SqlQuery setParameterList(String name, Object[] vals, Object type) throws SqlProcessorException
setParameterList in interface SqlQuerySqlProcessorExceptionprotected void setParameters(PreparedStatement ps, SqlFromToPlugin.LimitType limitType, int start) throws SQLException
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 statementSQLException - if a database access error occurs or this method is called on a closed PreparedStatementprotected int setLimits(PreparedStatement ps, SqlFromToPlugin.LimitType limitType, int ix, boolean afterSql) throws SQLException
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 executionSQLException - if a database access error occurs or this method is called on a closed PreparedStatementprotected Object getParameters(CallableStatement cs, boolean isFunction) throws SQLException
cs - an instance of CallableStatementSQLException - if a database access error occurs or this method is called on a closed CallableStatementprotected List getResults(ResultSet rs) throws SQLException
rs - an instance of ResultSetSQLException - if a database access error occurs or this method is called on a closed ResultSetprotected Object getOneResult(ResultSet rs) throws SQLException
rs - an instance of ResultSetSQLException - if a database access error occurs or this method is called on a closed ResultSetpublic int[] executeBatch(String[] statements) throws SqlProcessorException
executeBatch in interface SqlQuerySqlProcessorExceptionprotected SqlProcessorException newSqlProcessorException(org.springframework.dao.DataAccessException ex, String query)
public void setLogError(boolean logError)
setLogError in interface SqlQuerylogError - an indicator the failed SQL command should be loggedCopyright © 2016. All rights reserved.