| java.lang.Object org.springframework.jdbc.object.RdbmsOperation org.springframework.jdbc.object.SqlOperation org.springframework.jdbc.object.SqlQuery
All known Subclasses: org.springframework.jdbc.object.UpdatableSqlQuery, org.springframework.jdbc.object.MappingSqlQueryWithParameters,
SqlQuery | abstract public class SqlQuery extends SqlOperation (Code) | | Reusable operation object representing a SQL query.
Subclasses must implement the
SqlQuery.newRowMapper method to provide
an object that can extract the results of iterating over the
ResultSet created during the execution of the query.
This class provides a number of public execute methods that are
analogous to the different convenient JDO query execute methods. Subclasses
can either rely on one of these inherited methods, or can add their own
custom execution methods, with meaningful names and typed parameters
(definitely a best practice). Each custom query method will invoke one of
this class's untyped query methods.
Like all RdbmsOperation classes that ship with the Spring
Framework, SqlQuery instances are thread-safe after their
initialization is complete. That is, after they are constructed and configured
via their setter methods, they can be used safely from multiple threads.
author: Rod Johnson author: Juergen Hoeller author: Thomas Risberg See Also: SqlUpdate |
Constructor Summary | |
public | SqlQuery() Constructor to allow use as a JavaBean. | public | SqlQuery(DataSource ds, String sql) Convenient constructor with a DataSource and SQL string. |
Method Summary | |
public List | execute(Object[] params, Map context) Central execution method. | public List | execute(Object[] params) Convenient method to execute without context.
Parameters: params - parameters for the query. | public List | execute(Map context) Convenient method to execute without parameters. | public List | execute() Convenient method to execute without parameters nor context. | public List | execute(int p1, Map context) Convenient method to execute with a single int parameter and context. | public List | execute(int p1) Convenient method to execute with a single int parameter. | public List | execute(int p1, int p2, Map context) Convenient method to execute with two int parameters and context. | public List | execute(int p1, int p2) Convenient method to execute with two int parameters. | public List | execute(long p1, Map context) Convenient method to execute with a single long parameter and context. | public List | execute(long p1) Convenient method to execute with a single long parameter. | public List | execute(String p1, Map context) Convenient method to execute with a single String parameter and context. | public List | execute(String p1) Convenient method to execute with a single String parameter. | public List | executeByNamedParam(Map paramMap, Map context) Central execution method. | public List | executeByNamedParam(Map paramMap) Convenient method to execute without context.
Parameters: paramMap - parameters associated with the name specified while declaringthe SqlParameters. | public Object | findObject(Object[] params, Map context) Generic object finder method, used by all other findObject methods.
Object finder methods are like EJB entity bean finders, in that it is
considered an error if they return more than one result.
the result object, or null if not found. | public Object | findObject(Object[] params) Convenient method to find a single object without context. | public Object | findObject(int p1, Map context) Convenient method to find a single object given a single int parameter
and a context. | public Object | findObject(int p1) Convenient method to find a single object given a single int parameter. | public Object | findObject(int p1, int p2, Map context) Convenient method to find a single object given two int parameters
and a context. | public Object | findObject(int p1, int p2) Convenient method to find a single object given two int parameters. | public Object | findObject(long p1, Map context) Convenient method to find a single object given a single long parameter
and a context. | public Object | findObject(long p1) Convenient method to find a single object given a single long parameter. | public Object | findObject(String p1, Map context) Convenient method to find a single object given a single String parameter
and a context. | public Object | findObject(String p1) Convenient method to find a single object given a single String parameter. | public Object | findObjectByNamedParam(Map paramMap, Map context) Generic object finder method for named parameters.
Parameters: paramMap - Map of parameter name to parameter object,matching named parameters specified in the SQL statement.Ordering is not significant. Parameters: context - contextual information passed to the mapRow callback method. | public Object | findObjectByNamedParam(Map paramMap) Convenient method to execute without context. | public int | getRowsExpected() Get the number of rows expected. | abstract protected RowMapper | newRowMapper(Object[] parameters, Map context) Subclasses must implement this method to extract an object per row, to be
returned by the execute method as an aggregated
List .
Parameters: parameters - the parameters to the execute() method,in case subclass is interested; may be null if therewere no parameters. Parameters: context - contextual information passed to the mapRow callback method. | public void | setRowsExpected(int rowsExpected) Set the number of rows expected.
This can be used to ensure efficient storage of results. |
SqlQuery | public SqlQuery()(Code) | | Constructor to allow use as a JavaBean.
The DataSource and SQL must be supplied before
compilation and use.
|
SqlQuery | public SqlQuery(DataSource ds, String sql)(Code) | | Convenient constructor with a DataSource and SQL string.
Parameters: ds - the DataSource to use to get connections Parameters: sql - the SQL to execute; SQL can also be supplied at runtimeby overriding the SqlQuery.getSql() method. |
execute | public List execute(Object[] params, Map context) throws DataAccessException(Code) | | Central execution method. All un-named parameter execution goes through this method.
Parameters: params - parameters, similar to JDO query parameters.Primitive parameters must be represented by their Object wrapper type.The ordering of parameters is significant. Parameters: context - contextual information passed to the mapRow callback method. The JDBC operation itself doesn't rely on this parameter,but it can be useful for creating the objects of the result list. a List of objects, one per row of the ResultSet. Normally all thesewill be of the same class, although it is possible to use different types. |
execute | public List execute(Object[] params) throws DataAccessException(Code) | | Convenient method to execute without context.
Parameters: params - parameters for the query. Primitive parameters mustbe represented by their Object wrapper type. The ordering of parameters issignificant. |
execute | public List execute(Map context) throws DataAccessException(Code) | | Convenient method to execute without parameters.
Parameters: context - the contextual information for object creation |
execute | public List execute(int p1, Map context) throws DataAccessException(Code) | | Convenient method to execute with a single int parameter and context.
Parameters: p1 - single int parameter Parameters: context - the contextual information for object creation |
execute | public List execute(int p1) throws DataAccessException(Code) | | Convenient method to execute with a single int parameter.
Parameters: p1 - single int parameter |
execute | public List execute(int p1, int p2, Map context) throws DataAccessException(Code) | | Convenient method to execute with two int parameters and context.
Parameters: p1 - first int parameter Parameters: p2 - second int parameter Parameters: context - the contextual information for object creation |
execute | public List execute(int p1, int p2) throws DataAccessException(Code) | | Convenient method to execute with two int parameters.
Parameters: p1 - first int parameter Parameters: p2 - second int parameter |
execute | public List execute(long p1, Map context) throws DataAccessException(Code) | | Convenient method to execute with a single long parameter and context.
Parameters: p1 - single long parameter Parameters: context - the contextual information for object creation |
execute | public List execute(long p1) throws DataAccessException(Code) | | Convenient method to execute with a single long parameter.
Parameters: p1 - single long parameter |
execute | public List execute(String p1, Map context) throws DataAccessException(Code) | | Convenient method to execute with a single String parameter and context.
Parameters: p1 - single String parameter Parameters: context - the contextual information for object creation |
executeByNamedParam | public List executeByNamedParam(Map paramMap, Map context) throws DataAccessException(Code) | | Central execution method. All named parameter execution goes through this method.
Parameters: paramMap - parameters associated with the name specified while declaringthe SqlParameters. Primitive parameters must be represented by their Object wrappertype. The ordering of parameters is not significant since they are supplied in aSqlParameterMap which is an implementation of the Map interface. Parameters: context - contextual information passed to the mapRow callback method. The JDBC operation itself doesn't rely on this parameter,but it can be useful for creating the objects of the result list. a List of objects, one per row of the ResultSet. Normally all thesewill be of the same class, although it is possible to use different types. |
executeByNamedParam | public List executeByNamedParam(Map paramMap) throws DataAccessException(Code) | | Convenient method to execute without context.
Parameters: paramMap - parameters associated with the name specified while declaringthe SqlParameters. Primitive parameters must be represented by their Object wrappertype. The ordering of parameters is not significant. |
findObject | public Object findObject(int p1, Map context) throws DataAccessException(Code) | | Convenient method to find a single object given a single int parameter
and a context.
|
findObject | public Object findObject(int p1, int p2, Map context) throws DataAccessException(Code) | | Convenient method to find a single object given two int parameters
and a context.
|
findObject | public Object findObject(long p1, Map context) throws DataAccessException(Code) | | Convenient method to find a single object given a single long parameter
and a context.
|
findObjectByNamedParam | public Object findObjectByNamedParam(Map paramMap, Map context) throws DataAccessException(Code) | | Generic object finder method for named parameters.
Parameters: paramMap - Map of parameter name to parameter object,matching named parameters specified in the SQL statement.Ordering is not significant. Parameters: context - contextual information passed to the mapRow callback method. The JDBC operation itself doesn't rely on this parameter,but it can be useful for creating the objects of the result list. a List of objects, one per row of the ResultSet. Normally all thesewill be of the same class, although it is possible to use different types. |
findObjectByNamedParam | public Object findObjectByNamedParam(Map paramMap) throws DataAccessException(Code) | | Convenient method to execute without context.
Parameters: paramMap - Map of parameter name to parameter object,matching named parameters specified in the SQL statement.Ordering is not significant. |
getRowsExpected | public int getRowsExpected()(Code) | | Get the number of rows expected.
|
newRowMapper | abstract protected RowMapper newRowMapper(Object[] parameters, Map context)(Code) | | Subclasses must implement this method to extract an object per row, to be
returned by the execute method as an aggregated
List .
Parameters: parameters - the parameters to the execute() method,in case subclass is interested; may be null if therewere no parameters. Parameters: context - contextual information passed to the mapRow callback method. The JDBC operation itself doesn't rely on this parameter,but it can be useful for creating the objects of the result list. See Also: SqlQuery.execute |
setRowsExpected | public void setRowsExpected(int rowsExpected)(Code) | | Set the number of rows expected.
This can be used to ensure efficient storage of results. The
default behavior is not to expect any specific number of rows.
|
Fields inherited from org.springframework.jdbc.object.RdbmsOperation | final protected Log logger(Code)(Java Doc)
|
|
|