[Java] Class GroovyResultSetExtension
- groovy.sql.GroovyResultSetExtension
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
Constructor and description |
---|
GroovyResultSetExtension
(ResultSet set) Creates a GroovyResultSet implementation. |
Methods Summary
Type Params | Return Type | Name and description |
---|---|---|
public void |
add(Map values) Adds a new row to the result set | |
public void |
eachRow(Closure closure) Call the closure once for each row in the result set. | |
public Object |
getAt(int index) Supports integer based subscript operators for accessing at numbered columns starting at zero. | |
public Object |
getProperty(String columnName) Gets the value of the designated column in the current row of as an Object . | |
protected ResultSet |
getResultSet() Gets the current result set. | |
public Object |
invokeMethod(String name, Object args) | |
public boolean |
next() Moves the cursor down one row from its current position. | |
protected int |
normalizeIndex(int index) Takes a zero based index and convert it into an SQL based 1 based index. | |
public boolean |
previous() Moves the cursor to the previous row in this getResultSet() object. | |
public void |
putAt(int index, Object newValue) Supports integer based subscript operators for updating the values of numbered columns starting at zero. | |
public void |
setProperty(String columnName, Object newValue) Updates the designated column with an Object value. | |
public String |
toString() |
Inherited Methods Summary
Methods inherited from class | Name |
---|---|
class GroovyObjectSupport | getMetaClass, setMetaClass |
Constructor Detail
public GroovyResultSetExtension(ResultSet set)
Creates a GroovyResultSet implementation.
- Parameters:
-
set
- the result set
Method Detail
public void add(Map values)
Adds a new row to the result set
- throws:
- java.sql.SQLException if something goes wrong
- Parameters:
-
values
- a map containing the mappings for column names and values
- See Also:
- ResultSet.insertRow
- ResultSet#updateObject(java.lang.String, java.lang.Object)
- ResultSet.moveToInsertRow
public void eachRow(Closure closure)
Call the closure once for each row in the result set.
- throws:
- SQLException if something goes wrong
- Parameters:
-
closure
- the closure to perform on each row
public Object getAt(int index)
Supports integer based subscript operators for accessing at numbered columns starting at zero. Negative indices are supported, they will count from the last column backwards.
- throws:
- java.sql.SQLException if something goes wrong
- Parameters:
-
index
- is the number of the column to look at starting at 1
- Returns:
- the returned column value
- See Also:
- ResultSet.getObject
public Object getProperty(String columnName)
Gets the value of the designated column in the current row of as an Object
.
- throws:
- MissingPropertyException if an SQLException happens while getting the object
- Parameters:
-
columnName
- the SQL name of the column
- Returns:
- the returned column value
- See Also:
- GroovyObject.getProperty
- ResultSet#getObject(java.lang.String)
protected ResultSet getResultSet()
Gets the current result set.
- throws:
- SQLException if the result set can not be returned
- Returns:
- the result set
public Object invokeMethod(String name, Object args)
public boolean next()
Moves the cursor down one row from its current position. A getResultSet()
cursor is initially positioned before the first row; the first call to the method next
makes 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 next
will implicitly close it. A getResultSet()
object's warning chain is cleared when a new row is read.
- throws:
- SQLException if a database access error occurs
- Returns:
-
true
if the new current row is valid;false
if there are no more rows
protected int normalizeIndex(int index)
Takes a zero based index and convert it into an SQL based 1 based index. A negative index will count backwards from the last column.
- throws:
- SQLException if some exception occurs finding out the column count
- Parameters:
-
index
- the raw requested index (may be negative)
- Returns:
- a JDBC index
public boolean previous()
Moves the cursor to the previous row in this getResultSet()
object.
- throws:
- SQLException if a database access error occurs or the result set type is
TYPE_FORWARD_ONLY
- Returns:
-
true
if the cursor is on a valid row;false
if it is off the result set
- Since:
- 1.2
public void putAt(int index, Object newValue)
Supports 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.
- throws:
- java.sql.SQLException if something goes wrong
- Parameters:
-
index
- is the number of the column to look at starting at 1 -
newValue
- the updated value
- See Also:
- ResultSet#updateObject(java.lang.String, java.lang.Object)
public void setProperty(String columnName, Object newValue)
Updates the designated column with an Object
value.
- throws:
- MissingPropertyException if an SQLException happens while setting the new value
- Parameters:
-
columnName
- the SQL name of the column -
newValue
- the updated value
- See Also:
- GroovyObject.setProperty
- ResultSet#updateObject(java.lang.String, java.lang.Object)
public String toString()
© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/3.0.7/html/gapi/groovy/sql/GroovyResultSetExtension.html