Save This Page
Home » spring-framework-2.5.4 » org.springframework » jdbc » object » [javadoc | source]
org.springframework.jdbc.object
abstract public class: SqlQuery [javadoc | source]
java.lang.Object
   org.springframework.jdbc.object.RdbmsOperation
      org.springframework.jdbc.object.SqlOperation
         org.springframework.jdbc.object.SqlQuery

All Implemented Interfaces:
    InitializingBean

Direct Known Subclasses:
    UpdatableSqlQuery, SqlFunction, MappingSqlQuery, MappingSqlQueryWithParameters

Reusable operation object representing a SQL query.

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.

Fields inherited from org.springframework.jdbc.object.RdbmsOperation:
logger
Constructor:
 public SqlQuery() 
 public SqlQuery(DataSource ds,
    String sql) 
    Convenient constructor with a DataSource and SQL string.
    Parameters:
    ds - the DataSource to use to get connections
    sql - the SQL to execute; SQL can also be supplied at runtime by overriding the #getSql() method.
Method from org.springframework.jdbc.object.SqlQuery Summary:
execute,   execute,   execute,   execute,   execute,   execute,   execute,   execute,   execute,   execute,   execute,   execute,   executeByNamedParam,   executeByNamedParam,   findObject,   findObject,   findObject,   findObject,   findObject,   findObject,   findObject,   findObject,   findObject,   findObject,   findObjectByNamedParam,   findObjectByNamedParam,   getRowsExpected,   newRowMapper,   setRowsExpected
Methods from org.springframework.jdbc.object.SqlOperation:
compileInternal,   getParsedSql,   newPreparedStatementCreator,   newPreparedStatementCreator,   newPreparedStatementSetter,   onCompileInternal
Methods from org.springframework.jdbc.object.RdbmsOperation:
afterPropertiesSet,   allowsUnusedParameters,   checkCompiled,   compile,   compileInternal,   declareParameter,   getDeclaredParameters,   getGeneratedKeysColumnNames,   getJdbcTemplate,   getResultSetType,   getSql,   isCompiled,   isReturnGeneratedKeys,   isUpdatableResults,   setDataSource,   setFetchSize,   setGeneratedKeysColumnNames,   setJdbcTemplate,   setMaxRows,   setParameters,   setQueryTimeout,   setResultSetType,   setReturnGeneratedKeys,   setSql,   setTypes,   setUpdatableResults,   supportsLobParameters,   validateNamedParameters,   validateParameters
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.jdbc.object.SqlQuery Detail:
 public List execute() throws DataAccessException 
    Convenient method to execute without parameters nor context.
 public List execute(Object[] params) throws DataAccessException 
    Convenient method to execute without context.
 public List execute(Map context) throws DataAccessException 
    Convenient method to execute without parameters.
 public List execute(int p1) throws DataAccessException 
    Convenient method to execute with a single int parameter.
 public List execute(long p1) throws DataAccessException 
    Convenient method to execute with a single long parameter.
 public List execute(String p1) throws DataAccessException 
    Convenient method to execute with a single String parameter.
 public List execute(Object[] params,
    Map context) throws DataAccessException 
    Central execution method. All un-named parameter execution goes through this method.
 public List execute(int p1,
    Map context) throws DataAccessException 
    Convenient method to execute with a single int parameter and context.
 public List execute(int p1,
    int p2) throws DataAccessException 
    Convenient method to execute with two int parameters.
 public List execute(long p1,
    Map context) throws DataAccessException 
    Convenient method to execute with a single long parameter and context.
 public List execute(String p1,
    Map context) throws DataAccessException 
    Convenient method to execute with a single String parameter and context.
 public List execute(int p1,
    int p2,
    Map context) throws DataAccessException 
    Convenient method to execute with two int parameters and context.
 public List executeByNamedParam(Map paramMap) throws DataAccessException 
    Convenient method to execute without context.
 public List executeByNamedParam(Map paramMap,
    Map context) throws DataAccessException 
    Central execution method. All named parameter execution goes through this method.
 public Object findObject(Object[] params) throws DataAccessException 
    Convenient method to find a single object without context.
 public Object findObject(int p1) throws DataAccessException 
    Convenient method to find a single object given a single int parameter.
 public Object findObject(long p1) throws DataAccessException 
    Convenient method to find a single object given a single long parameter.
 public Object findObject(String p1) throws DataAccessException 
    Convenient method to find a single object given a single String parameter.
 public Object findObject(Object[] params,
    Map context) throws DataAccessException 
    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.
 public Object findObject(int p1,
    Map context) throws DataAccessException 
    Convenient method to find a single object given a single int parameter and a context.
 public Object findObject(int p1,
    int p2) throws DataAccessException 
    Convenient method to find a single object given two int parameters.
 public Object findObject(long p1,
    Map context) throws DataAccessException 
    Convenient method to find a single object given a single long parameter and a context.
 public Object findObject(String p1,
    Map context) throws DataAccessException 
    Convenient method to find a single object given a single String parameter and a context.
 public Object findObject(int p1,
    int p2,
    Map context) throws DataAccessException 
    Convenient method to find a single object given two int parameters and a context.
 public Object findObjectByNamedParam(Map paramMap) throws DataAccessException 
    Convenient method to execute without context.
 public Object findObjectByNamedParam(Map paramMap,
    Map context) throws DataAccessException 
    Generic object finder method for named parameters.
 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 .
 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.