Java Doc for Sql.java in  » Scripting » groovy-1.0 » groovy » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » groovy 1.0 » groovy.sql 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   groovy.sql.Sql

All known Subclasses:   groovy.sql.DataSet,
Sql
public class Sql (Code)
Represents an extent of objects
author:
   Chris Stevenson
author:
   James Strachan
version:
   $Revision: 4066 $


Field Summary
final public static  OutParameterARRAY
    
final public static  OutParameterBIGINT
    
final public static  OutParameterBINARY
    
final public static  OutParameterBIT
    
final public static  OutParameterBLOB
    
final public static  OutParameterBOOLEAN
    
final public static  OutParameterCHAR
    
final public static  OutParameterCLOB
    
final public static  OutParameterDATALINK
    
final public static  OutParameterDATE
    
final public static  OutParameterDECIMAL
    
final public static  OutParameterDISTINCT
    
final public static  OutParameterDOUBLE
    
final public static  OutParameterFLOAT
    
final public static  OutParameterINTEGER
    
final public static  OutParameterJAVA_OBJECT
    
final public static  OutParameterLONGVARBINARY
    
final public static  OutParameterLONGVARCHAR
    
final public static  OutParameterNULL
    
final public static  OutParameterNUMERIC
    
final public static  OutParameterOTHER
    
final public static  OutParameterREAL
    
final public static  OutParameterREF
    
final public static  OutParameterSMALLINT
    
final public static  OutParameterSTRUCT
    
final public static  OutParameterTIME
    
final public static  OutParameterTIMESTAMP
    
final public static  OutParameterTINYINT
    
final public static  OutParameterVARBINARY
    
final public static  OutParameterVARCHAR
    
protected  Loggerlog
    
 intupdateCount
    

Constructor Summary
public  Sql(DataSource dataSource)
     Constructs an SQL instance using the given DataSource.
public  Sql(Connection connection)
     Construts an SQL instance using the given Connection.
public  Sql(Sql parent)
    

Method Summary
public static  InParameterARRAY(Object value)
    
public static  InParameterBIGINT(Object value)
    
public static  InParameterBINARY(Object value)
    
public static  InParameterBIT(Object value)
    
public static  InParameterBLOB(Object value)
    
public static  InParameterBOOLEAN(Object value)
    
public static  InParameterCHAR(Object value)
    
public static  InParameterCLOB(Object value)
    
public static  InParameterDATALINK(Object value)
    
public static  InParameterDATE(Object value)
    
public static  InParameterDECIMAL(Object value)
    
public static  InParameterDISTINCT(Object value)
    
public static  InParameterDOUBLE(Object value)
    
public static  InParameterFLOAT(Object value)
    
public static  InParameterINTEGER(Object value)
    
public static  InParameterJAVA_OBJECT(Object value)
    
public static  InParameterLONGVARBINARY(Object value)
    
public static  InParameterLONGVARCHAR(Object value)
    
public static  InParameterNULL(Object value)
    
public static  InParameterNUMERIC(Object value)
    
public static  InParameterOTHER(Object value)
    
public static  InParameterREAL(Object value)
    
public static  InParameterREF(Object value)
    
public static  InParameterSMALLINT(Object value)
    
public static  InParameterSTRUCT(Object value)
    
public static  InParameterTIME(Object value)
    
public static  InParameterTIMESTAMP(Object value)
    
public static  InParameterTINYINT(Object value)
    
public static  InParameterVARBINARY(Object value)
    
public static  InParameterVARCHAR(Object value)
    
protected  StringasSql(GString gstring, List values)
    
public  intcall(String sql)
    
public  intcall(String sql, List params)
    
public  voidcall(String sql, List params, Closure closure)
     Performs a stored procedure call with the given parameters.
public  intcall(GString gstring)
    
public  voidcall(GString gstring, Closure closure)
     Performs a stored procedure call with the given parameters, calling the closure once with all result objects.
public  voidclose()
     If this SQL object was created with a Connection then this method closes the connection.
protected  voidcloseResources(Connection connection, Statement statement, ResultSet results)
    
protected  voidcloseResources(Connection connection, Statement statement)
    
public  voidcommit()
    
protected  voidconfigure(Statement statement)
    
protected  ConnectioncreateConnection()
    
public  DataSetdataSet(String table)
    
public  DataSetdataSet(Class type)
    
public  voideachRow(String sql, Closure closure)
    
public  voideachRow(String sql, List params, Closure closure)
    
public  voideachRow(GString gstring, Closure closure)
    
public  booleanexecute(String sql)
    
public  booleanexecute(String sql, List params)
    
public  booleanexecute(GString gstring)
    
public  ListexecuteInsert(String sql)
     Executes the given SQL statement.
public  ListexecuteInsert(String sql, List params)
     Executes the given SQL statement with a particular list of parameter values.
public  ListexecuteInsert(GString gstring)
    

Executes the given SQL with embedded expressions inside, and returns the values of any auto-generated colums, such as an autoincrement ID field.

public  intexecuteUpdate(String sql)
    
public  intexecuteUpdate(String sql, List params)
    
public  intexecuteUpdate(GString gstring)
    
public static  ExpandedVariableexpand(Object object)
     Creates a variable to be expanded in the Sql string rather than representing an sql parameter.
protected  intfindWhereKeyword(String sql)
     Find the first 'where' keyword in the sql.
public  ObjectfirstRow(String sql)
    
public  ObjectfirstRow(String sql, List params)
    
public  ConnectiongetConnection()
     If this instance was created with a single Connection then the connection is returned.
public  DataSourcegetDataSource()
    
protected  ListgetParameters(GString gstring)
    
public  intgetUpdateCount()
    
public static  InParameterin(int type, Object value)
    
public static  InOutParameterinout(InParameter in)
     Create an inout parameter using this in parameter.
public static  voidloadDriver(String driverClassName)
    
public static  SqlnewInstance(String url)
    
public static  SqlnewInstance(String url, Properties properties)
    
public static  SqlnewInstance(String url, Properties properties, String driverClassName)
    
public static  SqlnewInstance(String url, String user, String password)
    
public static  SqlnewInstance(String url, String user, String password, String driverClassName)
    
public static  SqlnewInstance(String url, String driverClassName)
    
protected  Stringnullify(String sql)
    
public static  OutParameterout(int type)
     Create a new OutParameter
Parameters:
  type - the JDBC data type.
public  voidquery(String sql, Closure closure)
    
public  voidquery(String sql, List params, Closure closure)
    
public  voidquery(GString gstring, Closure closure)
    
public  voidqueryEach(String sql, Closure closure)
    
public  voidqueryEach(String sql, List params, Closure closure)
    
public  voidqueryEach(GString gstring, Closure closure)
    
public static  ResultSetOutParameterresultSet(int type)
     Create a new ResultSetOutParameter
Parameters:
  type - the JDBC data type.
public  voidrollback()
    
public  Listrows(String sql)
    
public  Listrows(String sql, List params)
    
protected  voidsetObject(PreparedStatement statement, int i, Object value)
     Strategy method allowing derived classes to handle types differently such as for CLOBs etc.
protected  voidsetParameters(List params, PreparedStatement statement)
    
public  voidwithStatement(Closure configureStatement)
     Allows a closure to be passed in to configure the JDBC statements before they are executed to do things like set the query size etc.

Field Detail
ARRAY
final public static OutParameter ARRAY(Code)



BIGINT
final public static OutParameter BIGINT(Code)



BINARY
final public static OutParameter BINARY(Code)



BIT
final public static OutParameter BIT(Code)



BLOB
final public static OutParameter BLOB(Code)



BOOLEAN
final public static OutParameter BOOLEAN(Code)



CHAR
final public static OutParameter CHAR(Code)



CLOB
final public static OutParameter CLOB(Code)



DATALINK
final public static OutParameter DATALINK(Code)



DATE
final public static OutParameter DATE(Code)



DECIMAL
final public static OutParameter DECIMAL(Code)



DISTINCT
final public static OutParameter DISTINCT(Code)



DOUBLE
final public static OutParameter DOUBLE(Code)



FLOAT
final public static OutParameter FLOAT(Code)



INTEGER
final public static OutParameter INTEGER(Code)



JAVA_OBJECT
final public static OutParameter JAVA_OBJECT(Code)



LONGVARBINARY
final public static OutParameter LONGVARBINARY(Code)



LONGVARCHAR
final public static OutParameter LONGVARCHAR(Code)



NULL
final public static OutParameter NULL(Code)



NUMERIC
final public static OutParameter NUMERIC(Code)



OTHER
final public static OutParameter OTHER(Code)



REAL
final public static OutParameter REAL(Code)



REF
final public static OutParameter REF(Code)



SMALLINT
final public static OutParameter SMALLINT(Code)



STRUCT
final public static OutParameter STRUCT(Code)



TIME
final public static OutParameter TIME(Code)



TIMESTAMP
final public static OutParameter TIMESTAMP(Code)



TINYINT
final public static OutParameter TINYINT(Code)



VARBINARY
final public static OutParameter VARBINARY(Code)



VARCHAR
final public static OutParameter VARCHAR(Code)



log
protected Logger log(Code)



updateCount
int updateCount(Code)




Constructor Detail
Sql
public Sql(DataSource dataSource)(Code)
Constructs an SQL instance using the given DataSource. Each operation will use a Connection from the DataSource pool and close it when the operation is completed putting it back into the pool.
Parameters:
  dataSource -



Sql
public Sql(Connection connection)(Code)
Construts an SQL instance using the given Connection. It is the callers responsibility to close the Connection after the Sql instance has been used. You can do this on the connection object directly or by calling the java.sql.Connection.close method.
Parameters:
  connection -



Sql
public Sql(Sql parent)(Code)




Method Detail
ARRAY
public static InParameter ARRAY(Object value)(Code)



BIGINT
public static InParameter BIGINT(Object value)(Code)



BINARY
public static InParameter BINARY(Object value)(Code)



BIT
public static InParameter BIT(Object value)(Code)



BLOB
public static InParameter BLOB(Object value)(Code)



BOOLEAN
public static InParameter BOOLEAN(Object value)(Code)



CHAR
public static InParameter CHAR(Object value)(Code)



CLOB
public static InParameter CLOB(Object value)(Code)



DATALINK
public static InParameter DATALINK(Object value)(Code)



DATE
public static InParameter DATE(Object value)(Code)



DECIMAL
public static InParameter DECIMAL(Object value)(Code)



DISTINCT
public static InParameter DISTINCT(Object value)(Code)



DOUBLE
public static InParameter DOUBLE(Object value)(Code)



FLOAT
public static InParameter FLOAT(Object value)(Code)



INTEGER
public static InParameter INTEGER(Object value)(Code)



JAVA_OBJECT
public static InParameter JAVA_OBJECT(Object value)(Code)



LONGVARBINARY
public static InParameter LONGVARBINARY(Object value)(Code)



LONGVARCHAR
public static InParameter LONGVARCHAR(Object value)(Code)



NULL
public static InParameter NULL(Object value)(Code)



NUMERIC
public static InParameter NUMERIC(Object value)(Code)



OTHER
public static InParameter OTHER(Object value)(Code)



REAL
public static InParameter REAL(Object value)(Code)



REF
public static InParameter REF(Object value)(Code)



SMALLINT
public static InParameter SMALLINT(Object value)(Code)



STRUCT
public static InParameter STRUCT(Object value)(Code)



TIME
public static InParameter TIME(Object value)(Code)



TIMESTAMP
public static InParameter TIMESTAMP(Object value)(Code)



TINYINT
public static InParameter TINYINT(Object value)(Code)



VARBINARY
public static InParameter VARBINARY(Object value)(Code)



VARCHAR
public static InParameter VARCHAR(Object value)(Code)



asSql
protected String asSql(GString gstring, List values)(Code)
the SQL version of the given query using ? instead of anyparameter



call
public int call(String sql) throws Exception(Code)
Performs a stored procedure call



call
public int call(String sql, List params) throws Exception(Code)
Performs a stored procedure call with the given parameters



call
public void call(String sql, List params, Closure closure) throws Exception(Code)
Performs a stored procedure call with the given parameters. The closure is called once with all the out parameters.



call
public int call(GString gstring) throws Exception(Code)
Performs a stored procedure call with the given parameters



call
public void call(GString gstring, Closure closure) throws Exception(Code)
Performs a stored procedure call with the given parameters, calling the closure once with all result objects.



close
public void close() throws SQLException(Code)
If this SQL object was created with a Connection then this method closes the connection. If this SQL object was created from a DataSource then this method does nothing.
throws:
  SQLException -



closeResources
protected void closeResources(Connection connection, Statement statement, ResultSet results)(Code)



closeResources
protected void closeResources(Connection connection, Statement statement)(Code)



commit
public void commit()(Code)



configure
protected void configure(Statement statement)(Code)
Provides a hook to be able to configure JDBC statements, such as to configure
Parameters:
  statement -



createConnection
protected Connection createConnection() throws SQLException(Code)



dataSet
public DataSet dataSet(String table)(Code)



dataSet
public DataSet dataSet(Class type)(Code)



eachRow
public void eachRow(String sql, Closure closure) throws SQLException(Code)
Performs the given SQL query calling the closure with each row of the result set



eachRow
public void eachRow(String sql, List params, Closure closure) throws SQLException(Code)
Performs the given SQL query calling the closure with the result set



eachRow
public void eachRow(GString gstring, Closure closure) throws SQLException(Code)
Performs the given SQL query calling the closure with the result set



execute
public boolean execute(String sql) throws SQLException(Code)
Executes the given piece of SQL



execute
public boolean execute(String sql, List params) throws SQLException(Code)
Executes the given piece of SQL with parameters



execute
public boolean execute(GString gstring) throws SQLException(Code)
Executes the given SQL with embedded expressions inside



executeInsert
public List executeInsert(String sql) throws SQLException(Code)
Executes the given SQL statement. See Sql.executeInsert(GString) for more details.
Parameters:
  sql - The SQL statement to execute. A list of the auto-generated column values for eachinserted row.



executeInsert
public List executeInsert(String sql, List params) throws SQLException(Code)
Executes the given SQL statement with a particular list of parameter values. See Sql.executeInsert(GString) for more details.
Parameters:
  sql - The SQL statement to execute.
Parameters:
  params - The parameter values that will be substitutedinto the SQL statement's parameter slots. A list of the auto-generated column values for eachinserted row.



executeInsert
public List executeInsert(GString gstring) throws SQLException(Code)

Executes the given SQL with embedded expressions inside, and returns the values of any auto-generated colums, such as an autoincrement ID field. These values can be accessed using array notation. For example, to return the second auto-generated column value of the third row, use keys[3][1]. The method is designed to be used with SQL INSERT statements, but is not limited to them.

The standard use for this method is when a table has an autoincrement ID column and you want to know what the ID is for a newly inserted row. In this example, we insert a single row into a table in which the first column contains the autoincrement ID:

 def sql = Sql.newInstance("jdbc:mysql://localhost:3306/groovy",
 "user", 
 "password",
 "com.mysql.jdbc.Driver")
 def keys = sql.insert("insert into test_table (INT_DATA, STRING_DATA) "
 + "VALUES (1, 'Key Largo')")
 def id = keys[0][0]
 // 'id' now contains the value of the new row's ID column.
 // It can be used to update an object representation's
 // id attribute for example.
 ...
 
A list of column values representing each row'sauto-generated keys.



executeUpdate
public int executeUpdate(String sql) throws SQLException(Code)
Executes the given SQL update the number of rows updated



executeUpdate
public int executeUpdate(String sql, List params) throws SQLException(Code)
Executes the given SQL update with parameters the number of rows updated



executeUpdate
public int executeUpdate(GString gstring) throws SQLException(Code)
Executes the given SQL update with embedded expressions inside the number of rows updated



expand
public static ExpandedVariable expand(Object object)(Code)
Creates a variable to be expanded in the Sql string rather than representing an sql parameter.
Parameters:
  object -



findWhereKeyword
protected int findWhereKeyword(String sql)(Code)
Find the first 'where' keyword in the sql.
Parameters:
  sql -



firstRow
public Object firstRow(String sql) throws SQLException(Code)
Performs the given SQL query and return the first row of the result set



firstRow
public Object firstRow(String sql, List params) throws SQLException(Code)
Performs the given SQL query with the list of params and return the first row of the result set



getConnection
public Connection getConnection()(Code)
If this instance was created with a single Connection then the connection is returned. Otherwise if this instance was created with a DataSource then this method returns null the connection wired into this object, or null if this objectuses a DataSource



getDataSource
public DataSource getDataSource()(Code)



getParameters
protected List getParameters(GString gstring)(Code)
extracts the parameters from the expression as a List



getUpdateCount
public int getUpdateCount()(Code)
Returns the updateCount.



in
public static InParameter in(int type, Object value)(Code)
Create a new InParameter
Parameters:
  type - the JDBC data type
Parameters:
  value - the object value an InParameter



inout
public static InOutParameter inout(InParameter in)(Code)
Create an inout parameter using this in parameter.
Parameters:
  in -



loadDriver
public static void loadDriver(String driverClassName) throws ClassNotFoundException(Code)
Attempts to load the JDBC driver on the thread, current or system class loaders
Parameters:
  driverClassName -
throws:
  ClassNotFoundException -



newInstance
public static Sql newInstance(String url) throws SQLException(Code)
A helper method which creates a new Sql instance from a JDBC connection URL
Parameters:
  url - a new Sql instance with a connection



newInstance
public static Sql newInstance(String url, Properties properties) throws SQLException(Code)
A helper method which creates a new Sql instance from a JDBC connection URL
Parameters:
  url - a new Sql instance with a connection



newInstance
public static Sql newInstance(String url, Properties properties, String driverClassName) throws SQLException, ClassNotFoundException(Code)
A helper method which creates a new Sql instance from a JDBC connection URL and driver class name
Parameters:
  url - a new Sql instance with a connection



newInstance
public static Sql newInstance(String url, String user, String password) throws SQLException(Code)
A helper method which creates a new Sql instance from a JDBC connection URL, username and password
Parameters:
  url - a new Sql instance with a connection



newInstance
public static Sql newInstance(String url, String user, String password, String driverClassName) throws SQLException, ClassNotFoundException(Code)
A helper method which creates a new Sql instance from a JDBC connection URL, username, password and driver class name
Parameters:
  url - a new Sql instance with a connection



newInstance
public static Sql newInstance(String url, String driverClassName) throws SQLException, ClassNotFoundException(Code)
A helper method which creates a new Sql instance from a JDBC connection URL and driver class name
Parameters:
  url -
Parameters:
  driverClassName - the class name of the driver a new Sql instance with a connection



nullify
protected String nullify(String sql)(Code)
replace ?'"? references with NULLish
Parameters:
  sql -



out
public static OutParameter out(int type)(Code)
Create a new OutParameter
Parameters:
  type - the JDBC data type. an OutParameter



query
public void query(String sql, Closure closure) throws SQLException(Code)
Performs the given SQL query calling the closure with the result set



query
public void query(String sql, List params, Closure closure) throws SQLException(Code)
Performs the given SQL query with parameters calling the closure with the result set



query
public void query(GString gstring, Closure closure) throws SQLException(Code)
Performs the given SQL query calling the closure with the result set



queryEach
public void queryEach(String sql, Closure closure) throws SQLException(Code)



queryEach
public void queryEach(String sql, List params, Closure closure) throws SQLException(Code)



queryEach
public void queryEach(GString gstring, Closure closure) throws SQLException(Code)



resultSet
public static ResultSetOutParameter resultSet(int type)(Code)
Create a new ResultSetOutParameter
Parameters:
  type - the JDBC data type. a ResultSetOutParameter



rollback
public void rollback()(Code)



rows
public List rows(String sql) throws SQLException(Code)
Performs the given SQL query and return the rows of the result set



rows
public List rows(String sql, List params) throws SQLException(Code)
Performs the given SQL query with the list of params and return the rows of the result set



setObject
protected void setObject(PreparedStatement statement, int i, Object value) throws SQLException(Code)
Strategy method allowing derived classes to handle types differently such as for CLOBs etc.



setParameters
protected void setParameters(List params, PreparedStatement statement) throws SQLException(Code)
Appends the parameters to the given statement



withStatement
public void withStatement(Closure configureStatement)(Code)
Allows a closure to be passed in to configure the JDBC statements before they are executed to do things like set the query size etc.
Parameters:
  configureStatement -



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.