|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.object.RdbmsOperation org.springframework.jdbc.object.SqlOperation org.springframework.jdbc.object.SqlQuery org.springframework.jdbc.object.MappingSqlQueryWithParameters org.springframework.jdbc.object.MappingSqlQuery org.springframework.jdbc.object.SqlFunction
SQL "function" wrapper for a query that returns a single row of results. The default behavior is to return an int, but that can be overridden by using the methods with an extra return type parameter.
Intended to use to call SQL functions that return a single result using a query like "select user()" or "select sysdate from dual". It is not intended for calling more complex stored functions or for using a CallableStatement to invoke a stored procedure or stored function. Use StoredProcedure or SqlCall for this type of processing.
This is a concrete class, which there is normally no need to subclass. Code using this package can create an object of this type, declaring SQL and parameters, and then invoke the appropriate run method repeatedly to execute the function.
Like all RdbmsOperation objects, SqlFunction objects are threadsafe.
StoredProcedure
Nested Class Summary |
Nested classes inherited from class org.springframework.jdbc.object.MappingSqlQueryWithParameters |
MappingSqlQueryWithParameters.ResultReaderImpl |
Field Summary |
Fields inherited from class org.springframework.jdbc.object.RdbmsOperation |
logger |
Constructor Summary | |
SqlFunction()
Constructor to allow use as a JavaBean. |
|
SqlFunction(javax.sql.DataSource ds,
java.lang.String sql)
Create a new SQLFunction object with SQL, but without parameters. |
|
SqlFunction(javax.sql.DataSource ds,
java.lang.String sql,
int retType)
Create a new SQLFunction object with SQL and return type, but without parameters. |
|
SqlFunction(javax.sql.DataSource ds,
java.lang.String sql,
int[] types)
Create a new SQLFunction object with SQL and parameters. |
|
SqlFunction(javax.sql.DataSource ds,
java.lang.String sql,
int[] types,
int retType)
Create a new SQLFunction object with SQL, parameters and a return type |
Method Summary | |
protected java.lang.Object |
mapRow(java.sql.ResultSet rs,
int rowNum)
This implementation of this method extracts a single value from the single row returned by the function. |
int |
run()
Convenient method to run the function without arguments. |
int |
run(int p)
Convenient method to run the function with a single int argument. |
int |
run(java.lang.Object[] args)
Analogous to the SqlQuery.execute([]) method. |
java.lang.Object |
runGeneric()
Convenient method to run the function without arguments, returning the value as an object |
java.lang.Object |
runGeneric(int p)
Convenient method to run the function with a single int argument. |
java.lang.Object |
runGeneric(java.lang.Object[] args)
Analogous to the SqlQuery.execute([]) method. |
Methods inherited from class org.springframework.jdbc.object.MappingSqlQuery |
mapRow |
Methods inherited from class org.springframework.jdbc.object.MappingSqlQueryWithParameters |
newResultReader |
Methods inherited from class org.springframework.jdbc.object.SqlQuery |
execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, findObject, findObject, findObject, findObject, findObject, findObject, findObject, findObject, findObject, findObject, getRowsExpected, onCompileInternal, setRowsExpected |
Methods inherited from class org.springframework.jdbc.object.SqlOperation |
compileInternal, getResultSetType, isUpdatableResults, newPreparedStatementCreator, setResultSetType, setUpdatableResults |
Methods inherited from class org.springframework.jdbc.object.RdbmsOperation |
afterPropertiesSet, compile, declareParameter, getDeclaredParameters, getJdbcTemplate, getSql, isCompiled, setDataSource, setJdbcTemplate, setSql, setTypes, validateParameters |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SqlFunction()
public SqlFunction(javax.sql.DataSource ds, java.lang.String sql, int[] types)
ds
- DataSource to obtain connections fromsql
- SQL to executetypes
- SQL types of the parameters, as defined
in the java.sql.Types classpublic SqlFunction(javax.sql.DataSource ds, java.lang.String sql, int[] types, int retType) throws InvalidDataAccessApiUsageException
ds
- DataSource to obtain connections fromsql
- SQL to executetypes
- SQL types of the parameters, as defined
in the java.sql.Types classretType
- SQL type of the return value, as defined
in the java.sql.Types class
InvalidDataAccessApiUsageException
- is thrown if the return
type is not numeric or charpublic SqlFunction(javax.sql.DataSource ds, java.lang.String sql)
ds
- DataSource to obtain connections fromsql
- SQL to executepublic SqlFunction(javax.sql.DataSource ds, java.lang.String sql, int retType)
ds
- DataSource to obtain connections fromsql
- SQL to executeretType
- SQL type of the return value, as defined
in the java.sql.Types classMethod Detail |
protected java.lang.Object mapRow(java.sql.ResultSet rs, int rowNum) throws java.sql.SQLException, InvalidDataAccessApiUsageException
mapRow
in class MappingSqlQuery
rs
- ResultSet we're working throughrowNum
- row number (from 0) we're up to
java.sql.SQLException
- if there's an error extracting data.
Subclasses can simply fail to catch SQLExceptions.
InvalidDataAccessApiUsageException
public int run()
public int run(int p)
p
- single int argument
public int run(java.lang.Object[] args)
args
- array of arguments. These will be objects or
object wrapper types for primitives.
public java.lang.Object runGeneric()
public java.lang.Object runGeneric(int p)
p
- single int argument
public java.lang.Object runGeneric(java.lang.Object[] args)
args
- array of arguments. These will be objects or
object wrapper types for primitives.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |