|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.sql.Sql
Represents an extent of objects
Field Summary | |
protected Logger |
log
|
Constructor Summary | |
Sql(Connection connection)
Construts an SQL instance using the given Connection. |
|
Sql(DataSource dataSource)
Constructs an SQL instance using the given DataSource. |
|
Sql(Sql parent)
|
Method Summary | |
protected String |
asSql(GString gstring)
|
int |
call(GString gstring)
Performs a stored procedure call with the given parameters |
int |
call(String sql)
Performs a stored procedure call |
int |
call(String sql,
List params)
Performs a stored procedure call with the given parameters |
void |
close()
If this SQL object was created with a Connection then this method closes the connection. |
protected void |
closeResources(Connection connection,
Statement statement)
|
protected void |
closeResources(Connection connection,
Statement statement,
ResultSet results)
|
protected Connection |
createConnection()
|
DataSet |
dataSet(Class type)
|
DataSet |
dataSet(String table)
|
void |
eachRow(GString gstring,
Closure closure)
Performs the given SQL query calling the closure with the result set |
void |
eachRow(String sql,
Closure closure)
Performs the given SQL query calling the closure with each row of the result set |
void |
eachRow(String sql,
List params,
Closure closure)
Performs the given SQL query calling the closure with the result set |
boolean |
execute(GString gstring)
Executes the given SQL with embedded expressions inside |
boolean |
execute(String sql)
Executes the given piece of SQL |
boolean |
execute(String sql,
List params)
Executes the given piece of SQL with parameters |
int |
executeUpdate(GString gstring)
Executes the given SQL update with embedded expressions inside |
int |
executeUpdate(String sql)
Executes the given SQL update |
int |
executeUpdate(String sql,
List params)
Executes the given SQL update with parameters |
protected int |
findWhereKeyword(String sql)
Find the first 'where' keyword in the sql. |
DataSource |
getDataSource()
|
protected List |
getParameters(GString gstring)
|
static void |
loadDriver(String driverClassName)
Attempts to load the JDBC driver on the thread, current or system class loaders |
static Sql |
newInstance(String url)
A helper method which creates a new Sql instance from a JDBC connection URL |
static Sql |
newInstance(String url,
Properties properties)
A helper method which creates a new Sql instance from a JDBC connection URL |
static Sql |
newInstance(String url,
Properties properties,
String driverClassName)
A helper method which creates a new Sql instance from a JDBC connection URL and driver class name |
static Sql |
newInstance(String url,
String driverClassName)
A helper method which creates a new Sql instance from a JDBC connection URL and driver class name |
static Sql |
newInstance(String url,
String user,
String password)
A helper method which creates a new Sql instance from a JDBC connection URL, username and password |
static Sql |
newInstance(String url,
String user,
String password,
String driverClassName)
A helper method which creates a new Sql instance from a JDBC connection URL, username, password and driver class name |
protected String |
nullify(String sql)
replace ?'"? references with NULLish |
void |
query(GString gstring,
Closure closure)
Performs the given SQL query calling the closure with the result set |
void |
query(String sql,
Closure closure)
Performs the given SQL query calling the closure with the result set |
void |
query(String sql,
List params,
Closure closure)
Performs the given SQL query with parameters calling the closure with the result set |
void |
queryEach(GString gstring,
Closure closure)
Deprecated. please use eachRow instead |
void |
queryEach(String sql,
Closure closure)
Deprecated. please use eachRow instead |
void |
queryEach(String sql,
List params,
Closure closure)
Deprecated. please use eachRow instead |
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 params,
PreparedStatement statement)
Appends the parameters to the given statement |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Logger log
Constructor Detail |
public Sql(DataSource dataSource)
dataSource
- public Sql(Connection connection)
close()
method.
connection
- public Sql(Sql parent)
Method Detail |
public static Sql newInstance(String url) throws SQLException
url
-
SQLException
public static Sql newInstance(String url, Properties properties) throws SQLException
url
-
SQLException
public static Sql newInstance(String url, Properties properties, String driverClassName) throws SQLException, ClassNotFoundException
url
-
SQLException
ClassNotFoundException
public static Sql newInstance(String url, String user, String password) throws SQLException
url
-
SQLException
public static Sql newInstance(String url, String user, String password, String driverClassName) throws SQLException, ClassNotFoundException
url
-
SQLException
ClassNotFoundException
public static Sql newInstance(String url, String driverClassName) throws SQLException, ClassNotFoundException
url
- driverClassName
- the class name of the driver
SQLException
ClassNotFoundException
public static void loadDriver(String driverClassName) throws ClassNotFoundException
driverClassName
-
ClassNotFoundException
public DataSet dataSet(String table)
public DataSet dataSet(Class type)
public void query(String sql, Closure closure) throws SQLException
SQLException
public void query(String sql, List params, Closure closure) throws SQLException
SQLException
public void query(GString gstring, Closure closure) throws SQLException
SQLException
public void queryEach(String sql, Closure closure) throws SQLException
SQLException
public void eachRow(String sql, Closure closure) throws SQLException
SQLException
public void queryEach(String sql, List params, Closure closure) throws SQLException
SQLException
public void eachRow(String sql, List params, Closure closure) throws SQLException
SQLException
public void eachRow(GString gstring, Closure closure) throws SQLException
SQLException
public void queryEach(GString gstring, Closure closure) throws SQLException
SQLException
public boolean execute(String sql) throws SQLException
SQLException
public int executeUpdate(String sql) throws SQLException
SQLException
public boolean execute(String sql, List params) throws SQLException
SQLException
public int executeUpdate(String sql, List params) throws SQLException
SQLException
public boolean execute(GString gstring) throws SQLException
SQLException
public int executeUpdate(GString gstring) throws SQLException
SQLException
public int call(String sql) throws Exception
Exception
public int call(String sql, List params) throws Exception
Exception
public int call(GString gstring) throws Exception
Exception
public void close() throws SQLException
SQLException
public DataSource getDataSource()
protected String asSql(GString gstring)
protected String nullify(String sql)
sql
-
protected int findWhereKeyword(String sql)
sql
-
protected List getParameters(GString gstring)
protected void setParameters(List params, PreparedStatement statement) throws SQLException
SQLException
protected void setObject(PreparedStatement statement, int i, Object value) throws SQLException
SQLException
protected Connection createConnection() throws SQLException
SQLException
protected void closeResources(Connection connection, Statement statement, ResultSet results)
protected void closeResources(Connection connection, Statement statement)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |