Modifier and Type |
Method and Description |
static InParameter |
ARRAY(Object value) |
protected List<GroovyRowResult> |
asList(String sql,
ResultSet rs)
Hook to allow derived classes to override list of result collection behavior.
|
protected List<GroovyRowResult> |
asList(String sql,
ResultSet rs,
Closure metaClosure)
Hook to allow derived classes to override list of result collection behavior.
|
protected List<GroovyRowResult> |
asList(String sql,
ResultSet rs,
int offset,
int maxRows,
Closure metaClosure) |
protected String |
asSql(GString gstring,
List<Object> values)
Hook to allow derived classes to override sql generation from GStrings.
|
static InParameter |
BIGINT(Object value) |
static InParameter |
BINARY(Object value) |
static InParameter |
BIT(Object value) |
static InParameter |
BLOB(Object value) |
static InParameter |
BOOLEAN(Object value) |
protected SqlWithParams |
buildSqlWithIndexedProps(String sql)
Hook to allow derived classes to override behavior associated with the
parsing and indexing of parameters from a given sql statement.
|
void |
cacheConnection(Closure closure)
Caches the connection used while the closure is active.
|
void |
cacheStatements(Closure closure)
Caches every created preparedStatement in Closure closure
Every cached preparedStatement is closed after closure has been called.
|
int |
call(GString gstring)
Performs a stored procedure call with the given embedded parameters.
|
void |
call(GString gstring,
Closure closure)
Performs a stored procedure call with the given parameters,
calling the closure once with all result objects.
|
int |
call(String sql)
Performs a stored procedure call.
|
int |
call(String sql,
List<Object> params)
Performs a stored procedure call with the given parameters.
|
void |
call(String sql,
List<Object> params,
Closure closure)
Performs a stored procedure call with the given parameters.
|
int |
call(String sql,
Object[] params)
Performs a stored procedure call with the given parameters.
|
List<List<GroovyRowResult>> |
callWithAllRows(GString gstring,
Closure closure)
Performs a stored procedure call with the given parameters,
calling the closure once with all result objects,
and also returning a list of lists with the rows of the ResultSet(s).
|
List<List<GroovyRowResult>> |
callWithAllRows(String sql,
List<Object> params,
Closure closure)
Performs a stored procedure call with the given parameters,
calling the closure once with all result objects,
and also returning a list of lists with the rows of the ResultSet(s).
|
List<GroovyRowResult> |
callWithRows(GString gstring,
Closure closure)
Performs a stored procedure call with the given parameters,
calling the closure once with all result objects,
and also returning the rows of the ResultSet.
|
List<GroovyRowResult> |
callWithRows(String sql,
List<Object> params,
Closure closure)
Performs a stored procedure call with the given parameters,
calling the closure once with all result objects,
and also returning the rows of the ResultSet.
|
protected List<List<GroovyRowResult>> |
callWithRows(String sql,
List<Object> params,
int processResultsSets,
Closure closure)
Base internal method for call(), callWithRows(), and callWithAllRows() style of methods.
|
static InParameter |
CHAR(Object value) |
SqlWithParams |
checkForNamedParams(String sql,
List<Object> params) |
static InParameter |
CLOB(Object value) |
void |
close()
If this SQL object was created with a Connection then this method closes
the connection.
|
protected void |
closeResources(Connection connection)
An extension point allowing the behavior of resource closing to be
overridden in derived classes.
|
protected void |
closeResources(Connection connection,
Statement statement)
An extension point allowing the behavior of resource closing to be
overridden in derived classes.
|
protected void |
closeResources(Connection connection,
Statement statement,
ResultSet results)
An extension point allowing derived classes to change the behavior
of resource closing.
|
void |
commit()
If this SQL object was created with a Connection then this method commits
the connection.
|
protected void |
configure(Statement statement)
Provides a hook for derived classes to be able to configure JDBC statements.
|
protected Connection |
createConnection()
An extension point allowing derived classes to change the behavior of
connection creation.
|
protected Sql.AbstractQueryCommand |
createPreparedQueryCommand(String sql,
List<Object> queryParams)
Factory for the PreparedQueryCommand command pattern object allows subclass to supply implementations
of the command class.
|
protected Sql.AbstractQueryCommand |
createQueryCommand(String sql)
Factory for the QueryCommand command pattern object allows subclasses to
supply implementations of the command class.
|
static InParameter |
DATALINK(Object value) |
DataSet |
dataSet(Class<?> type) |
DataSet |
dataSet(String table) |
static InParameter |
DATE(Object value) |
static InParameter |
DECIMAL(Object value) |
static InParameter |
DISTINCT(Object value) |
static InParameter |
DOUBLE(Object value) |
void |
eachRow(GString gstring,
Closure closure)
Performs the given SQL query calling the given Closure with each row of the result set.
|
void |
eachRow(GString gstring,
Closure metaClosure,
Closure rowClosure)
Performs the given SQL query calling the given Closure with each row of the result set.
|
void |
eachRow(GString gstring,
Closure metaClosure,
int offset,
int maxRows,
Closure rowClosure)
Performs the given SQL query calling the given closure with each row of the result set starting at
the provided offset , and including up to maxRows number of rows.
|
void |
eachRow(GString gstring,
int offset,
int maxRows,
Closure closure)
Performs the given SQL query calling the given closure with each row of the result set starting at
the provided offset , and including up to maxRows number of rows.
|
void |
eachRow(Map params,
String sql,
Closure closure)
|
void |
eachRow(Map params,
String sql,
Closure metaClosure,
Closure rowClosure)
|
void |
eachRow(Map map,
String sql,
Closure metaClosure,
int offset,
int maxRows,
Closure rowClosure)
|
void |
eachRow(Map params,
String sql,
int offset,
int maxRows,
Closure closure)
|
void |
eachRow(String sql,
Closure closure)
Performs the given SQL query calling the given Closure with each row of the result set.
|
void |
eachRow(String sql,
Closure metaClosure,
Closure rowClosure)
Performs the given SQL query calling the given rowClosure with each row of the
result set.
|
void |
eachRow(String sql,
Closure metaClosure,
int offset,
int maxRows,
Closure rowClosure)
Performs the given SQL query calling the given rowClosure with each row of the result set starting at
the provided offset , and including up to maxRows number of rows.
|
void |
eachRow(String sql,
int offset,
int maxRows,
Closure closure)
Performs the given SQL query calling the given closure with each row of the result set starting at
the provided offset , and including up to maxRows number of rows.
|
void |
eachRow(String sql,
List<Object> params,
Closure closure)
Performs the given SQL query calling the given Closure with each row of the result set.
|
void |
eachRow(String sql,
List<Object> params,
Closure metaClosure,
Closure rowClosure)
Performs the given SQL query calling the given Closure with each row of the result set.
|
void |
eachRow(String sql,
List<Object> params,
Closure metaClosure,
int offset,
int maxRows,
Closure rowClosure)
Performs the given SQL query calling the given rowClosure with each row of the result set starting at
the provided offset , and including up to maxRows number of rows.
|
void |
eachRow(String sql,
List<Object> params,
int offset,
int maxRows,
Closure closure)
Performs the given SQL query calling the given closure with each row of the result set starting at
the provided offset , and including up to maxRows number of rows.
|
void |
eachRow(String sql,
Map params,
Closure closure)
|
void |
eachRow(String sql,
Map params,
Closure metaClosure,
Closure rowClosure)
|
void |
eachRow(String sql,
Map map,
Closure metaClosure,
int offset,
int maxRows,
Closure rowClosure)
|
void |
eachRow(String sql,
Map params,
int offset,
int maxRows,
Closure closure)
|
boolean |
execute(GString gstring)
Executes the given SQL with embedded expressions inside.
|
void |
execute(GString gstring,
Closure processResults)
Executes the given SQL with embedded expressions inside.
|
boolean |
execute(Map params,
String sql)
|
void |
execute(Map params,
String sql,
Closure processResults)
|
boolean |
execute(String sql)
Executes the given piece of SQL.
|
void |
execute(String sql,
Closure processResults)
Executes the given piece of SQL.
|
boolean |
execute(String sql,
List<Object> params)
Executes the given piece of SQL with parameters.
|
void |
execute(String sql,
List<Object> params,
Closure processResults)
Executes the given piece of SQL with parameters.
|
boolean |
execute(String sql,
Object[] params)
Executes the given piece of SQL with parameters.
|
void |
execute(String sql,
Object[] params,
Closure processResults)
Executes the given piece of SQL with parameters.
|
List<List<Object>> |
executeInsert(GString gstring)
Executes the given SQL statement (typically an INSERT statement).
|
List<GroovyRowResult> |
executeInsert(GString gstring,
List<String> keyColumnNames)
Executes the given SQL statement (typically an INSERT statement).
|
List<List<Object>> |
executeInsert(Map params,
String sql)
|
List<GroovyRowResult> |
executeInsert(Map params,
String sql,
List<String> keyColumnNames)
|
List<List<Object>> |
executeInsert(String sql)
Executes the given SQL statement (typically an INSERT statement).
|
List<List<Object>> |
executeInsert(String sql,
List<Object> params)
Executes the given SQL statement (typically an INSERT statement).
|
List<GroovyRowResult> |
executeInsert(String sql,
List<Object> params,
List<String> keyColumnNames)
Executes the given SQL statement (typically an INSERT statement).
|
List<List<Object>> |
executeInsert(String sql,
Object[] params)
Executes the given SQL statement (typically an INSERT statement).
|
List<GroovyRowResult> |
executeInsert(String sql,
String[] keyColumnNames)
Executes the given SQL statement (typically an INSERT statement).
|
List<GroovyRowResult> |
executeInsert(String sql,
String[] keyColumnNames,
Object[] params)
Executes the given SQL statement (typically an INSERT statement).
|
protected ResultSet |
executePreparedQuery(String sql,
List<Object> params)
Useful helper method which handles resource management when executing a
prepared query which returns a result set.
|
protected ResultSet |
executeQuery(String sql)
Useful helper method which handles resource management when executing a
query which returns a result set.
|
int |
executeUpdate(GString gstring)
Executes the given SQL update with embedded expressions inside.
|
int |
executeUpdate(Map params,
String sql)
|
int |
executeUpdate(String sql)
Executes the given SQL update.
|
int |
executeUpdate(String sql,
List<Object> params)
Executes the given SQL update with parameters.
|
int |
executeUpdate(String sql,
Object[] params)
Executes the given SQL update with parameters.
|
static ExpandedVariable |
expand(Object object)
When using GString SQL queries, allows a variable to be expanded
in the Sql string rather than representing an sql parameter.
|
protected int |
findWhereKeyword(String sql)
Hook to allow derived classes to override where clause sniffing.
|
GroovyRowResult |
firstRow(GString gstring)
Performs the given SQL query and return
the first row of the result set.
|
GroovyRowResult |
firstRow(Map params,
String sql)
|
GroovyRowResult |
firstRow(String sql)
Performs the given SQL query and return the first row of the result set.
|
GroovyRowResult |
firstRow(String sql,
List<Object> params)
Performs the given SQL query and return the first row of the result set.
|
GroovyRowResult |
firstRow(String sql,
Object[] params)
Performs the given SQL query and return the first row of the result set.
|
static InParameter |
FLOAT(Object value) |
Connection |
getConnection()
If this instance was created with a single Connection then the connection
is returned.
|
DataSource |
getDataSource() |
protected List<Object> |
getParameters(GString gstring)
Hook to allow derived classes to override behavior associated with
extracting params from a GString.
|
int |
getResultSetConcurrency()
Gets the resultSetConcurrency for statements created using the connection.
|
int |
getResultSetHoldability()
Gets the resultSetHoldability for statements created using the connection.
|
int |
getResultSetType()
Gets the resultSetType for statements created using the connection.
|
int |
getUpdateCount() |
List<Object> |
getUpdatedParams(List<Object> params,
List<Tuple> indexPropList) |
static InParameter |
in(int type,
Object value)
Create a new InParameter
|
static InOutParameter |
inout(InParameter in)
Create an inout parameter using this in parameter.
|
static InParameter |
INTEGER(Object value) |
boolean |
isCacheNamedQueries() |
boolean |
isCacheStatements() |
boolean |
isEnableNamedQueries() |
boolean |
isWithinBatch()
Returns true if the current Sql object is currently executing a withBatch
method call.
|
static InParameter |
JAVA_OBJECT(Object value) |
static void |
loadDriver(String driverClassName)
Attempts to load the JDBC driver on the thread, current or system class
loaders
|
static InParameter |
LONGVARBINARY(Object value) |
static InParameter |
LONGVARCHAR(Object value) |
static Sql |
newInstance(Map<String,Object> args)
Creates a new Sql instance given parameters in a Map.
|
static Sql |
newInstance(String url)
Creates a new Sql instance given a JDBC connection URL.
|
static Sql |
newInstance(String url,
Properties properties)
Creates a new Sql instance given a JDBC connection URL
and some properties.
|
static Sql |
newInstance(String url,
Properties properties,
String driverClassName)
Creates a new Sql instance given a JDBC connection URL,
some properties and a driver class name.
|
static Sql |
newInstance(String url,
String driverClassName)
Creates a new Sql instance given a JDBC connection URL
and a driver class name.
|
static Sql |
newInstance(String url,
String user,
String password)
Creates a new Sql instance given a JDBC connection URL,
a username and a password.
|
static Sql |
newInstance(String url,
String user,
String password,
String driverClassName)
Creates a new Sql instance given a JDBC connection URL,
a username, a password and a driver class name.
|
static InParameter |
NULL(Object value) |
protected String |
nullify(String sql)
Hook to allow derived classes to override null handling.
|
static InParameter |
NUMERIC(Object value) |
static InParameter |
OTHER(Object value) |
static OutParameter |
out(int type)
Create a new OutParameter
|
SqlWithParams |
preCheckForNamedParams(String sql)
|
void |
query(GString gstring,
Closure closure)
Performs the given SQL query, which should return a single
ResultSet object.
|
void |
query(Map map,
String sql,
Closure closure)
|
void |
query(String sql,
Closure closure)
Performs the given SQL query, which should return a single
ResultSet object.
|
void |
query(String sql,
List<Object> params,
Closure closure)
Performs the given SQL query, which should return a single
ResultSet object.
|
void |
query(String sql,
Map map,
Closure closure)
|
static InParameter |
REAL(Object value) |
static InParameter |
REF(Object value) |
static ResultSetOutParameter |
resultSet(int type)
Create a new ResultSetOutParameter
|
void |
rollback()
If this SQL object was created with a Connection then this method rolls back
the connection.
|
List<GroovyRowResult> |
rows(GString gstring)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(GString gstring,
Closure metaClosure)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(GString sql,
int offset,
int maxRows)
Performs the given SQL query and return a "page" of rows from the result set.
|
List<GroovyRowResult> |
rows(GString gstring,
int offset,
int maxRows,
Closure metaClosure)
Performs the given SQL query and return a "page" of rows from the result set.
|
List<GroovyRowResult> |
rows(Map params,
String sql)
|
List<GroovyRowResult> |
rows(Map params,
String sql,
Closure metaClosure)
|
List<GroovyRowResult> |
rows(Map params,
String sql,
int offset,
int maxRows)
|
List<GroovyRowResult> |
rows(Map params,
String sql,
int offset,
int maxRows,
Closure metaClosure)
|
List<GroovyRowResult> |
rows(String sql)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(String sql,
Closure metaClosure)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(String sql,
int offset,
int maxRows)
Performs the given SQL query and return a "page" of rows from the result set.
|
List<GroovyRowResult> |
rows(String sql,
int offset,
int maxRows,
Closure metaClosure)
Performs the given SQL query and return a "page" of rows from the result set.
|
List<GroovyRowResult> |
rows(String sql,
List<Object> params)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(String sql,
List<Object> params,
Closure metaClosure)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(String sql,
List<Object> params,
int offset,
int maxRows)
Performs the given SQL query and return a "page" of rows from the result set.
|
List<GroovyRowResult> |
rows(String sql,
List<Object> params,
int offset,
int maxRows,
Closure metaClosure)
Performs the given SQL query and return a "page" of rows from the result set.
|
List<GroovyRowResult> |
rows(String sql,
Map params,
Closure metaClosure)
|
List<GroovyRowResult> |
rows(String sql,
Map params,
int offset,
int maxRows)
|
List<GroovyRowResult> |
rows(String sql,
Map params,
int offset,
int maxRows,
Closure metaClosure)
|
List<GroovyRowResult> |
rows(String sql,
Object[] params)
Performs the given SQL query and return the rows of the result set.
|
List<GroovyRowResult> |
rows(String sql,
Object[] params,
int offset,
int maxRows)
Performs the given SQL query and return the rows of the result set.
|
void |
setCacheNamedQueries(boolean cacheNamedQueries)
Enables named query caching.
if cacheNamedQueries is true, cache is created and processed named queries will be cached.
|
void |
setCacheStatements(boolean cacheStatements)
Enables statement caching.
if cacheStatements is true, cache is created and all created prepared statements will be cached.
|
void |
setEnableNamedQueries(boolean enableNamedQueries)
Enables named query support:
if enableNamedQueries is true, queries with ':propname' and '?1.propname' style placeholders will be processed.
if enableNamedQueries is false, this feature will be turned off.
|
protected void |
setInternalConnection(Connection conn)
Stub needed for testing.
|
protected void |
setObject(PreparedStatement statement,
int i,
Object value)
Strategy method allowing derived classes to handle types differently
such as for CLOBs etc.
|
protected void |
setParameters(List<Object> params,
PreparedStatement statement)
Hook to allow derived classes to override behavior associated with
setting params for a prepared statement.
|
void |
setResultSetConcurrency(int resultSetConcurrency)
Sets the resultSetConcurrency for statements created using the connection.
|
void |
setResultSetHoldability(int resultSetHoldability)
Sets the resultSetHoldability for statements created using the connection.
|
void |
setResultSetType(int resultSetType)
Sets the resultSetType for statements created using the connection.
|
static InParameter |
SMALLINT(Object value) |
static InParameter |
STRUCT(Object value) |
static InParameter |
TIME(Object value) |
static InParameter |
TIMESTAMP(Object value) |
static InParameter |
TINYINT(Object value) |
static InParameter |
VARBINARY(Object value) |
static InParameter |
VARCHAR(Object value) |
int[] |
withBatch(Closure closure)
Performs the closure (containing batch operations) within a batch.
|
int[] |
withBatch(int batchSize,
Closure closure)
Performs the closure (containing batch operations) within a batch using a given batch size.
|
int[] |
withBatch(int batchSize,
String sql,
Closure closure)
Performs the closure (containing batch operations specific to an associated prepared statement)
within a batch using a given batch size.
|
int[] |
withBatch(String sql,
Closure closure)
Performs the closure (containing batch operations specific to an associated prepared statement)
within a batch.
|
static void |
withInstance(Map<String,Object> args,
Closure c)
Invokes a closure passing it a new Sql instance created from the given map of arguments.
|
static void |
withInstance(String url,
Closure c)
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL.
|
static void |
withInstance(String url,
Properties properties,
Closure c)
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL and properties.
|
static void |
withInstance(String url,
Properties properties,
String driverClassName,
Closure c)
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL,
properties and driver classname.
|
static void |
withInstance(String url,
String driverClassName,
Closure c)
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL.
|
static void |
withInstance(String url,
String user,
String password,
Closure c)
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL, user and password.
|
static void |
withInstance(String url,
String user,
String password,
String driverClassName,
Closure c)
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL.
|
void |
withStatement(Closure configureStatement)
Allows a closure to be passed in to configure the JDBC statements before they are executed.
|
void |
withTransaction(Closure closure)
Performs the closure within a transaction using a cached connection.
|