groovy.sql
Class DataSet

java.lang.Object
  extended by groovy.sql.Sql
      extended by groovy.sql.DataSet

public class DataSet
extends Sql

Represents an extent of objects

Version:
$Revision: 16362 $
Author:
Chris Stevenson, Paul King, James Strachan

Field Summary
private  Sql delegate
           
private  java.util.List params
           
private  DataSet parent
           
private  boolean reversed
           
private  Closure sort
           
private  SqlOrderByVisitor sortVisitor
           
private  java.lang.String sql
           
private  java.lang.String table
           
private  SqlWhereVisitor visitor
           
private  Closure where
           
 
Fields inherited from class groovy.sql.Sql
ARRAY, BIGINT, BINARY, BIT, BLOB, BOOLEAN, CHAR, CLOB, DATALINK, DATE, DECIMAL, DISTINCT, DOUBLE, FLOAT, INTEGER, JAVA_OBJECT, log, LONGVARBINARY, LONGVARCHAR, NULL, NUMERIC, OTHER, REAL, REF, SMALLINT, STRUCT, TIME, TIMESTAMP, TINYINT, VARBINARY, VARCHAR
 
Constructor Summary
private DataSet(DataSet parent)
           
private DataSet(DataSet parent, Closure where)
           
private DataSet(DataSet parent, Closure where, Closure sort)
           
  DataSet(Sql sql, java.lang.Class type)
           
  DataSet(Sql sql, java.lang.String table)
           
 
Method Summary
 void add(java.util.Map<java.lang.String,java.lang.Object> map)
           
 void cacheConnection(Closure closure)
          Caches the connection used while the closure is active.
protected  void closeResources(java.sql.Connection connection, java.sql.Statement statement)
          An extension point allowing the behavior of resource closing to be overriden in derived classes.
protected  void closeResources(java.sql.Connection connection, java.sql.Statement statement, java.sql.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  java.sql.Connection createConnection()
          An extension point allowing derived classes to change the behavior of connection creation.
 DataSet createView(Closure criteria)
           
 void each(Closure closure)
           
 DataSet findAll(Closure where)
           
 java.lang.Object firstRow()
          Returns the first row from a DataSet's underlying table
 java.util.List getParameters()
           
 java.lang.String getSql()
           
private  java.lang.String getSqlOrderBy()
           
protected  SqlOrderByVisitor getSqlOrderByVisitor()
           
private  java.lang.String getSqlWhere()
           
protected  SqlWhereVisitor getSqlWhereVisitor()
           
 DataSet reverse()
           
 void rollback()
          If this SQL object was created with a Connection then this method rolls back the connection.
 java.util.List rows()
          Returns a List of all of the rows from the table a DataSet represents
 DataSet sort(Closure sort)
           
private  void visit(Closure closure, CodeVisitorSupport visitor)
           
 void withTransaction(Closure closure)
          Performs the closure within a transaction using a cached connection.
 
Methods inherited from class groovy.sql.Sql
ARRAY, asSql, BIGINT, BINARY, BIT, BLOB, BOOLEAN, cacheStatements, call, call, call, call, call, CHAR, CLOB, close, configure, DATALINK, dataSet, dataSet, DATE, DECIMAL, DISTINCT, DOUBLE, eachRow, eachRow, eachRow, eachRow, execute, execute, execute, executeInsert, executeInsert, executeInsert, executeUpdate, executeUpdate, executeUpdate, expand, findWhereKeyword, firstRow, firstRow, firstRow, FLOAT, getConnection, getDataSource, getParameters, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, in, inout, INTEGER, isCacheStatements, JAVA_OBJECT, loadDriver, LONGVARBINARY, LONGVARCHAR, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, NULL, nullify, NUMERIC, OTHER, out, query, query, query, REAL, REF, resultSet, rows, rows, rows, rows, setCacheStatements, setObject, setParameters, setResultSetConcurrency, setResultSetHoldability, setResultSetType, SMALLINT, STRUCT, TIME, TIMESTAMP, TINYINT, VARBINARY, VARCHAR, withStatement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

where

private Closure where

sort

private Closure sort

reversed

private boolean reversed

parent

private DataSet parent

table

private java.lang.String table

visitor

private SqlWhereVisitor visitor

sortVisitor

private SqlOrderByVisitor sortVisitor

sql

private java.lang.String sql

params

private java.util.List params

delegate

private Sql delegate
Constructor Detail

DataSet

public DataSet(Sql sql,
               java.lang.Class type)

DataSet

public DataSet(Sql sql,
               java.lang.String table)

DataSet

private DataSet(DataSet parent,
                Closure where)

DataSet

private DataSet(DataSet parent,
                Closure where,
                Closure sort)

DataSet

private DataSet(DataSet parent)
Method Detail

createConnection

protected java.sql.Connection createConnection()
                                        throws java.sql.SQLException
Description copied from class: Sql
An extension point allowing derived classes to change the behavior of connection creation. The default behavior is to either use the supplied connection or obtain it from the supplied datasource.

Overrides:
createConnection in class Sql
Returns:
the connection associated with this Sql
Throws:
java.sql.SQLException - if a SQL error occurs

closeResources

protected void closeResources(java.sql.Connection connection,
                              java.sql.Statement statement,
                              java.sql.ResultSet results)
Description copied from class: Sql
An extension point allowing derived classes to change the behavior of resource closing.

Overrides:
closeResources in class Sql
Parameters:
connection - the connection to close
statement - the statement to close
results - the results to close

closeResources

protected void closeResources(java.sql.Connection connection,
                              java.sql.Statement statement)
Description copied from class: Sql
An extension point allowing the behavior of resource closing to be overriden in derived classes.

Overrides:
closeResources in class Sql
Parameters:
connection - the connection to close
statement - the statement to close

cacheConnection

public void cacheConnection(Closure closure)
                     throws java.sql.SQLException
Description copied from class: Sql
Caches the connection used while the closure is active. If the closure takes a single argument, it will be called with the connection, otherwise it will be called with no arguments.

Overrides:
cacheConnection in class Sql
Parameters:
closure - the given closure
Throws:
java.sql.SQLException - if a database error occurs

withTransaction

public void withTransaction(Closure closure)
                     throws java.sql.SQLException
Description copied from class: Sql
Performs the closure within a transaction using a cached connection. If the closure takes a single argument, it will be called with the connection, otherwise it will be called with no arguments.

Overrides:
withTransaction in class Sql
Parameters:
closure - the given closure
Throws:
java.sql.SQLException - if a database error occurs

commit

public void commit()
            throws java.sql.SQLException
Description copied from class: Sql
If this SQL object was created with a Connection then this method commits the connection. If this SQL object was created from a DataSource then this method does nothing.

Overrides:
commit in class Sql
Throws:
java.sql.SQLException - if a database access error occurs

rollback

public void rollback()
              throws java.sql.SQLException
Description copied from class: Sql
If this SQL object was created with a Connection then this method rolls back the connection. If this SQL object was created from a DataSource then this method does nothing.

Overrides:
rollback in class Sql
Throws:
java.sql.SQLException - if a database access error occurs

add

public void add(java.util.Map<java.lang.String,java.lang.Object> map)
         throws java.sql.SQLException
Throws:
java.sql.SQLException

findAll

public DataSet findAll(Closure where)

sort

public DataSet sort(Closure sort)

reverse

public DataSet reverse()

each

public void each(Closure closure)
          throws java.sql.SQLException
Throws:
java.sql.SQLException

getSqlWhere

private java.lang.String getSqlWhere()

getSqlOrderBy

private java.lang.String getSqlOrderBy()

getSql

public java.lang.String getSql()

getParameters

public java.util.List getParameters()

getSqlWhereVisitor

protected SqlWhereVisitor getSqlWhereVisitor()

getSqlOrderByVisitor

protected SqlOrderByVisitor getSqlOrderByVisitor()

visit

private void visit(Closure closure,
                   CodeVisitorSupport visitor)

createView

public DataSet createView(Closure criteria)

rows

public java.util.List rows()
                    throws java.sql.SQLException
Returns a List of all of the rows from the table a DataSet represents

Returns:
Returns a list of GroovyRowResult objects from the dataset
Throws:
java.sql.SQLException - if a database error occurs

firstRow

public java.lang.Object firstRow()
                          throws java.sql.SQLException
Returns the first row from a DataSet's underlying table

Returns:
Returns the first GroovyRowResult object from the dataset
Throws:
java.sql.SQLException - if a database error occurs


Copyright © ${year} The Codehaus. All Rights Reserved.