Package groovy.sql
Class GroovyResultSetExtension
- java.lang.Object
-
- groovy.lang.GroovyObjectSupport
-
- groovy.sql.GroovyResultSetExtension
-
- All Implemented Interfaces:
GroovyObject
public class GroovyResultSetExtension extends GroovyObjectSupport
GroovyResultSetExtension implements additional logic for ResultSet. Due to the version incompatibility between java6 and java5 this methods are moved here from the original GroovyResultSet class. The methods in this class are used by the proxy GroovyResultSetProxy, which will try to invoke methods on this class before invoking it on ResultSet.This class is not intended to be used directly. Should be used through GroovyResultSetProxy only!
- See Also:
GroovyResultSet,GroovyResultSetProxy
-
-
Constructor Summary
Constructors Constructor Description GroovyResultSetExtension(java.sql.ResultSet set)Creates a GroovyResultSet implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.util.Map values)Adds a new row to the result setvoideachRow(Closure closure)Call the closure once for each row in the result set.java.lang.ObjectgetAt(int index)Supports integer based subscript operators for accessing at numbered columns starting at zero.java.lang.ObjectgetProperty(java.lang.String columnName)Gets the value of the designated column in the current row of as anObject.protected java.sql.ResultSetgetResultSet()Gets the current result set.java.lang.ObjectinvokeMethod(java.lang.String name, java.lang.Object args)Invokes the given method.booleannext()Moves the cursor down one row from its current position.protected intnormalizeIndex(int index)Takes a zero based index and convert it into an SQL based 1 based index.booleanprevious()Moves the cursor to the previous row in thisgetResultSet()object.voidputAt(int index, java.lang.Object newValue)Supports integer based subscript operators for updating the values of numbered columns starting at zero.voidsetProperty(java.lang.String columnName, java.lang.Object newValue)Updates the designated column with anObjectvalue.java.lang.StringtoString()-
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
-
-
-
-
Method Detail
-
getResultSet
protected java.sql.ResultSet getResultSet() throws java.sql.SQLExceptionGets the current result set.- Returns:
- the result set
- Throws:
java.sql.SQLException- if the result set can not be returned
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args)Description copied from interface:GroovyObjectInvokes the given method.- Specified by:
invokeMethodin interfaceGroovyObject- Overrides:
invokeMethodin classGroovyObjectSupport- Parameters:
name- the name of the method to callargs- the arguments to use for the method call- Returns:
- the result of invoking the method
-
getProperty
public java.lang.Object getProperty(java.lang.String columnName)
Gets the value of the designated column in the current row of as anObject.- Specified by:
getPropertyin interfaceGroovyObject- Overrides:
getPropertyin classGroovyObjectSupport- Parameters:
columnName- the SQL name of the column- Returns:
- the returned column value
- Throws:
MissingPropertyException- if an SQLException happens while getting the object- See Also:
GroovyObject.getProperty(java.lang.String),ResultSet.getObject(java.lang.String)
-
setProperty
public void setProperty(java.lang.String columnName, java.lang.Object newValue)Updates the designated column with anObjectvalue.- Specified by:
setPropertyin interfaceGroovyObject- Overrides:
setPropertyin classGroovyObjectSupport- Parameters:
columnName- the SQL name of the columnnewValue- the updated value- Throws:
MissingPropertyException- if an SQLException happens while setting the new value- See Also:
GroovyObject.setProperty(java.lang.String, java.lang.Object),ResultSet.updateObject(java.lang.String, java.lang.Object)
-
getAt
public java.lang.Object getAt(int index) throws java.sql.SQLExceptionSupports integer based subscript operators for accessing at numbered columns starting at zero. Negative indices are supported, they will count from the last column backwards.- Parameters:
index- is the number of the column to look at starting at 1- Returns:
- the returned column value
- Throws:
java.sql.SQLException- if something goes wrong- See Also:
ResultSet.getObject(int)
-
putAt
public void putAt(int index, java.lang.Object newValue) throws java.sql.SQLExceptionSupports integer based subscript operators for updating the values of numbered columns starting at zero. Negative indices are supported, they will count from the last column backwards.- Parameters:
index- is the number of the column to look at starting at 1newValue- the updated value- Throws:
java.sql.SQLException- if something goes wrong- See Also:
ResultSet.updateObject(java.lang.String, java.lang.Object)
-
add
public void add(java.util.Map values) throws java.sql.SQLExceptionAdds a new row to the result set- Parameters:
values- a map containing the mappings for column names and values- Throws:
java.sql.SQLException- if something goes wrong- See Also:
ResultSet.insertRow(),ResultSet.updateObject(java.lang.String, java.lang.Object),ResultSet.moveToInsertRow()
-
normalizeIndex
protected int normalizeIndex(int index) throws java.sql.SQLExceptionTakes a zero based index and convert it into an SQL based 1 based index. A negative index will count backwards from the last column.- Parameters:
index- the raw requested index (may be negative)- Returns:
- a JDBC index
- Throws:
java.sql.SQLException- if some exception occurs finding out the column count
-
eachRow
public void eachRow(Closure closure) throws java.sql.SQLException
Call the closure once for each row in the result set.- Parameters:
closure- the closure to perform on each row- Throws:
java.sql.SQLException- if something goes wrong
-
next
public boolean next() throws java.sql.SQLExceptionMoves the cursor down one row from its current position. AgetResultSet()cursor is initially positioned before the first row; the first call to the methodnextmakes the first row the current row; the second call makes the second row the current row, and so on.If an input stream is open for the current row, a call to the method
nextwill implicitly close it. AgetResultSet()object's warning chain is cleared when a new row is read.- Returns:
trueif the new current row is valid;falseif there are no more rows- Throws:
java.sql.SQLException- if a database access error occurs
-
previous
public boolean previous() throws java.sql.SQLExceptionMoves the cursor to the previous row in thisgetResultSet()object.- Returns:
trueif the cursor is on a valid row;falseif it is off the result set- Throws:
java.sql.SQLException- if a database access error occurs or the result set type isTYPE_FORWARD_ONLY- Since:
- 1.2
-
-