open class SqlFunction<T : Any> : MappingSqlQuery<T>
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 constructor 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 often 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. Subclasses are only supposed to add specialized run
methods for specific parameter and return types.
Like all RdbmsOperation objects, SqlFunction objects are thread-safe.
Author
Rod Johnson
Author
Juergen Hoeller
Author
Jean-Pierre Pawlak
See Also
StoredProcedure
SqlFunction()
Constructor to allow use as a JavaBean. A DataSource, SQL and any parameters must be supplied before invoking the SqlFunction(ds: DataSource, sql: String)
Create a new SqlFunction object with SQL, but without parameters. Must add parameters or settle with none. SqlFunction(ds: DataSource, sql: String, types: IntArray)
Create a new SqlFunction object with SQL and parameters. SqlFunction(ds: DataSource, sql: String, types: IntArray, resultType: Class<T>)
Create a new SqlFunction object with SQL, parameters and a result type. |
open fun run(): Int
Convenient method to run the function without arguments. open fun run(parameter: Int): Int
Convenient method to run the function with a single int argument. open fun run(vararg parameters: Any): Int
Analogous to the SqlQuery.execute([]) method. This is a generic method to execute a query, taken a number of arguments. |
|
open fun runGeneric(): Any
Convenient method to run the function without arguments, returning the value as an object. open fun runGeneric(parameter: Int): Any
Convenient method to run the function with a single int argument. open fun runGeneric(parameters: Array<Any>): Any
Analogous to the |
|
open fun setResultType(resultType: Class<T>): Unit
Specify the type that the result object is required to match. If not specified, the result value will be exposed as returned by the JDBC driver. |