Subclasses must implement the 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.
SqlUpdate
| Modifier and Type | Field and Description |
|---|---|
| private int | rowsExpected
The number of rows to expect; if 0, unknown. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | SqlQuery(DataSource
the ds, String DataSource to use to get connectionsthe SQL to execute; SQL can also be supplied at runtime
by overriding the sql)getSql() method.Convenient constructor with a |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: a List of objects, one per row of the ResultSet. Normally all these will be of the same class, although it is possible to use different types.parameters, similar to JDO query parameters.
Primitive parameters must be represented by their Object wrapper type.
The ordering of parameters is significant. params, Map<?, ?> the contextual information passed to the context)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.Central execution method. |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | execute(int
first int parameter p1, int second int parameter p2)Convenient method to execute with two int parameters. |
| public List | |
| public List | |
| public List | |
| public List | |
| public List | Returns: a List of objects, one per row of the ResultSet. Normally all these will be of the same class, although it is possible to use different types.parameters associated with the name specified while declaring
the SqlParameters. Primitive parameters must be represented by their Object wrapper
type. The ordering of parameters is not significant since they are supplied in a
SqlParameterMap which is an implementation of the Map interface. paramMap, Map<?, ?> the contextual information passed to the context)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.Central execution method. |
| public List | executeByNamedParam(Map<String, ?>
parameters associated with the name specified while declaring
the SqlParameters. Primitive parameters must be represented by their Object wrapper
type. The ordering of parameters is not significant. paramMap)Convenient method to execute without context. |
| public T | Returns: the result object, ornull if not found. Subclasses may
choose to treat this as an error and throw an exception.Generic object finder method, used by all other |
| public T | |
| public T | findObject(int p1, Map<?, ?> context)
Convenient method to find a single object given a single int parameter and a context. |
| public T | |
| public T | findObject(int p1, int p2, Map<?, ?> context)
Convenient method to find a single object given two int parameters and a context. |
| public T | |
| public T | findObject(long p1, Map<?, ?> context)
Convenient method to find a single object given a single long parameter and a context. |
| public T | |
| public T | findObject(String p1, Map<?, ?> context)
Convenient method to find a single object given a single String parameter and a context. |
| public T | |
| public T | Returns: a List of objects, one per row of the ResultSet. Normally all these will be of the same class, although it is possible to use different types.a Map of parameter name to parameter object,
matching named parameters specified in the SQL statement.
Ordering is not significant. paramMap, Map<?, ?> the contextual information passed to the context)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.Generic object finder method for named parameters. |
| public T | findObjectByNamedParam(Map<String, ?>
a Map of parameter name to parameter object,
matching named parameters specified in the SQL statement.
Ordering is not significant. paramMap)Convenient method to execute without context. |
| public int | |
| protected abstract RowMapper | newRowMapper(Object[]
the parameters to the parameters, Map<?, ?> execute() method,
in case subclass is interested; may be null if there
were no parameters.the contextual information passed to the context)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.Subclasses must implement this method to extract an object per row, to be
returned by the |
| public void |
| rowsExpected | back to summary |
|---|---|
| private int rowsExpected The number of rows to expect; if 0, unknown. | |
| SqlQuery | back to summary |
|---|---|
| public SqlQuery() Constructor to allow use as a JavaBean. The | |
| SqlQuery | back to summary |
|---|---|
| public SqlQuery(DataSource ds, String sql) Convenient constructor with a
| |
| execute | back to summary |
|---|---|
| public List Central execution method. All un-named parameter execution goes through this method.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute without context.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute without parameters.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute without parameters nor context. | |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with a single int parameter and context.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with a single int parameter.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with two int parameters and context.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with two int parameters.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with a single long parameter and context.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with a single long parameter.
| |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with a single String parameter and context. | |
| execute | back to summary |
|---|---|
| public List Convenient method to execute with a single String parameter.
| |
| executeByNamedParam | back to summary |
|---|---|
| public List Central execution method. All named parameter execution goes through this method.
| |
| executeByNamedParam | back to summary |
|---|---|
| public List Convenient method to execute without context. | |
| findObject | back to summary |
|---|---|
| public T findObject(Object[] params, Map<?, ?> context) throws DataAccessException Generic object finder method, used by all other
| |
| findObject | back to summary |
|---|---|
| public T findObject(Object... params) throws DataAccessException Convenient method to find a single object without context.
| |
| findObject | back to summary |
|---|---|
| public T findObject(int p1, Map<?, ?> context) throws DataAccessException Convenient method to find a single object given a single int parameter and a context.
| |
| findObject | back to summary |
|---|---|
| public T findObject(int p1) throws DataAccessException Convenient method to find a single object given a single int parameter.
| |
| findObject | back to summary |
|---|---|
| public T findObject(int p1, int p2, Map<?, ?> context) throws DataAccessException Convenient method to find a single object given two int parameters and a context.
| |
| findObject | back to summary |
|---|---|
| public T findObject(int p1, int p2) throws DataAccessException Convenient method to find a single object given two int parameters.
| |
| findObject | back to summary |
|---|---|
| public T findObject(long p1, Map<?, ?> context) throws DataAccessException Convenient method to find a single object given a single long parameter and a context.
| |
| findObject | back to summary |
|---|---|
| public T findObject(long p1) throws DataAccessException Convenient method to find a single object given a single long parameter.
| |
| findObject | back to summary |
|---|---|
| public T findObject(String p1, Map<?, ?> context) throws DataAccessException Convenient method to find a single object given a single String parameter and a context.
| |
| findObject | back to summary |
|---|---|
| public T findObject(String p1) throws DataAccessException Convenient method to find a single object given a single String parameter.
| |
| findObjectByNamedParam | back to summary |
|---|---|
| public T findObjectByNamedParam(Map<String, ?> paramMap, Map<?, ?> context) throws DataAccessException Generic object finder method for named parameters.
| |
| findObjectByNamedParam | back to summary |
|---|---|
| public T findObjectByNamedParam(Map<String, ?> paramMap) throws DataAccessException Convenient method to execute without context. | |
| getRowsExpected | back to summary |
|---|---|
| public int getRowsExpected() Get the number of rows expected. | |
| newRowMapper | back to summary |
|---|---|
| protected abstract RowMapper Subclasses must implement this method to extract an object per row, to be
returned by the
| |
| setRowsExpected | back to summary |
|---|---|
| public void setRowsExpected(int rowsExpected) 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. | |