1 46 package groovy.sql; 47 48 import groovy.lang.GroovyObjectSupport; 49 import groovy.lang.MissingPropertyException; 50 51 import java.math.BigDecimal ; 52 import java.sql.Array ; 53 import java.sql.Blob ; 54 import java.sql.Clob ; 55 import java.sql.Ref ; 56 import java.sql.ResultSet ; 57 import java.sql.ResultSetMetaData ; 58 import java.sql.SQLException ; 59 import java.sql.SQLWarning ; 60 import java.sql.Statement ; 61 import java.util.Calendar ; 62 import java.util.Iterator ; 63 import java.util.Map ; 64 65 73 public class GroovyResultSet extends GroovyObjectSupport implements ResultSet { 74 75 private ResultSet resultSet; 76 private boolean updated; 77 78 public GroovyResultSet(ResultSet resultSet) { 79 this.resultSet = resultSet; 80 } 81 82 public Object getProperty(String property) { 83 try { 84 return resultSet.getObject(property); 85 } 86 catch (SQLException e) { 87 throw new MissingPropertyException(property, GroovyResultSet.class, e); 88 } 89 } 90 91 public void setProperty(String property, Object newValue) { 92 try { 93 resultSet.updateObject(property, newValue); 94 updated = true; 95 } 96 catch (SQLException e) { 97 throw new MissingPropertyException(property, GroovyResultSet.class, e); 98 } 99 } 100 101 108 public Object getAt(int index) throws SQLException { 109 index = normalizeIndex(index); 110 return resultSet.getObject(index); 111 } 112 113 120 public void putAt(int index, Object newValue) throws SQLException { 121 index = normalizeIndex(index); 122 resultSet.updateObject(index, newValue); 123 } 124 125 129 public void add(Map values) throws SQLException { 130 resultSet.moveToInsertRow(); 131 for (Iterator iter = values.entrySet().iterator(); iter.hasNext();) { 132 Map.Entry entry = (Map.Entry ) iter.next(); 133 resultSet.updateObject(entry.getKey().toString(), entry.getValue()); 134 } 135 resultSet.insertRow(); 136 } 137 138 146 protected int normalizeIndex(int index) throws SQLException { 147 if (index < 0) { 148 int columnCount = resultSet.getMetaData().getColumnCount(); 149 do { 150 index += columnCount; 151 } 152 while (index < 0); 153 } 154 return index + 1; 155 } 156 157 160 176 public boolean next() throws SQLException { 177 if (updated) { 178 resultSet.updateRow(); 179 updated = false; 180 } 181 return resultSet.next(); 182 } 183 184 185 200 public void close() throws SQLException { 201 resultSet.close(); 202 } 203 204 216 public boolean wasNull() throws SQLException { 217 return resultSet.wasNull(); 218 } 219 220 224 234 public String getString(int columnIndex) throws SQLException { 235 return resultSet.getString(columnIndex); 236 } 237 238 248 public boolean getBoolean(int columnIndex) throws SQLException { 249 return resultSet.getBoolean(columnIndex); 250 } 251 252 262 public byte getByte(int columnIndex) throws SQLException { 263 return resultSet.getByte(columnIndex); 264 } 265 266 276 public short getShort(int columnIndex) throws SQLException { 277 return resultSet.getShort(columnIndex); 278 } 279 280 290 public int getInt(int columnIndex) throws SQLException { 291 return resultSet.getInt(columnIndex); 292 } 293 294 304 public long getLong(int columnIndex) throws SQLException { 305 return resultSet.getLong(columnIndex); 306 } 307 308 318 public float getFloat(int columnIndex) throws SQLException { 319 return resultSet.getFloat(columnIndex); 320 } 321 322 332 public double getDouble(int columnIndex) throws SQLException { 333 return resultSet.getDouble(columnIndex); 334 } 335 336 348 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { 349 return resultSet.getBigDecimal(columnIndex, scale); 350 } 351 352 363 public byte[] getBytes(int columnIndex) throws SQLException { 364 return resultSet.getBytes(columnIndex); 365 } 366 367 377 public java.sql.Date getDate(int columnIndex) throws SQLException { 378 return resultSet.getDate(columnIndex); 379 } 380 381 391 public java.sql.Time getTime(int columnIndex) throws SQLException { 392 return resultSet.getTime(columnIndex); 393 } 394 395 405 public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException { 406 return resultSet.getTimestamp(columnIndex); 407 } 408 409 432 public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException { 433 return resultSet.getAsciiStream(columnIndex); 434 } 435 436 465 public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException { 466 return resultSet.getUnicodeStream(columnIndex); 467 } 468 469 490 public java.io.InputStream getBinaryStream(int columnIndex) 491 throws SQLException { 492 493 return resultSet.getBinaryStream(columnIndex); 494 } 495 496 497 501 511 public String getString(String columnName) throws SQLException { 512 return resultSet.getString(columnName); 513 } 514 515 525 public boolean getBoolean(String columnName) throws SQLException { 526 return resultSet.getBoolean(columnName); 527 } 528 529 539 public byte getByte(String columnName) throws SQLException { 540 return resultSet.getByte(columnName); 541 } 542 543 553 public short getShort(String columnName) throws SQLException { 554 return resultSet.getShort(columnName); 555 } 556 557 567 public int getInt(String columnName) throws SQLException { 568 return resultSet.getInt(columnName); 569 } 570 571 581 public long getLong(String columnName) throws SQLException { 582 return resultSet.getLong(columnName); 583 } 584 585 595 public float getFloat(String columnName) throws SQLException { 596 return resultSet.getFloat(columnName); 597 } 598 599 609 public double getDouble(String columnName) throws SQLException { 610 return resultSet.getDouble(columnName); 611 } 612 613 625 public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { 626 return resultSet.getBigDecimal(columnName, scale); 627 } 628 629 640 public byte[] getBytes(String columnName) throws SQLException { 641 return resultSet.getBytes(columnName); 642 } 643 644 654 public java.sql.Date getDate(String columnName) throws SQLException { 655 return resultSet.getDate(columnName); 656 } 657 658 669 public java.sql.Time getTime(String columnName) throws SQLException { 670 return resultSet.getTime(columnName); 671 } 672 673 683 public java.sql.Timestamp getTimestamp(String columnName) throws SQLException { 684 return resultSet.getTimestamp(columnName); 685 } 686 687 709 public java.io.InputStream getAsciiStream(String columnName) throws SQLException { 710 return resultSet.getAsciiStream(columnName); 711 } 712 713 740 public java.io.InputStream getUnicodeStream(String columnName) throws SQLException { 741 return resultSet.getUnicodeStream(columnName); 742 } 743 744 765 public java.io.InputStream getBinaryStream(String columnName) 766 throws SQLException { 767 768 return resultSet.getBinaryStream(columnName); 769 } 770 771 772 776 799 public SQLWarning getWarnings() throws SQLException { 800 return resultSet.getWarnings(); 801 } 802 803 811 public void clearWarnings() throws SQLException { 812 resultSet.clearWarnings(); 813 } 814 815 838 public String getCursorName() throws SQLException { 839 return resultSet.getCursorName(); 840 } 841 842 849 public ResultSetMetaData getMetaData() throws SQLException { 850 return resultSet.getMetaData(); 851 } 852 853 879 public Object getObject(int columnIndex) throws SQLException { 880 return resultSet.getObject(columnIndex); 881 } 882 883 909 public Object getObject(String columnName) throws SQLException { 910 return resultSet.getObject(columnName); 911 } 912 913 915 924 public int findColumn(String columnName) throws SQLException { 925 return resultSet.findColumn(columnName); 926 } 927 928 929 931 935 946 public java.io.Reader getCharacterStream(int columnIndex) throws SQLException { 947 return resultSet.getCharacterStream(columnIndex); 948 } 949 950 962 public java.io.Reader getCharacterStream(String columnName) throws SQLException { 963 return resultSet.getCharacterStream(columnName); 964 } 965 966 978 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 979 return resultSet.getBigDecimal(columnIndex); 980 } 981 982 995 public BigDecimal getBigDecimal(String columnName) throws SQLException { 996 return resultSet.getBigDecimal(columnName); 997 } 998 999 1003 1013 public boolean isBeforeFirst() throws SQLException { 1014 return resultSet.isBeforeFirst(); 1015 } 1016 1017 1027 public boolean isAfterLast() throws SQLException { 1028 return resultSet.isAfterLast(); 1029 } 1030 1031 1040 public boolean isFirst() throws SQLException { 1041 return resultSet.isFirst(); 1042 } 1043 1044 1057 public boolean isLast() throws SQLException { 1058 return resultSet.isLast(); 1059 } 1060 1061 1070 public void beforeFirst() throws SQLException { 1071 resultSet.beforeFirst(); 1072 } 1073 1074 1082 public void afterLast() throws SQLException { 1083 resultSet.afterLast(); 1084 } 1085 1086 1096 public boolean first() throws SQLException { 1097 return resultSet.first(); 1098 } 1099 1100 1110 public boolean last() throws SQLException { 1111 return resultSet.last(); 1112 } 1113 1114 1122 public int getRow() throws SQLException { 1123 return resultSet.getRow(); 1124 } 1125 1126 1160 public boolean absolute( int row ) throws SQLException { 1161 return resultSet.absolute(row); 1162 } 1163 1164 1186 public boolean relative( int rows ) throws SQLException { 1187 return resultSet.relative(rows); 1188 } 1189 1190 1200 public boolean previous() throws SQLException { 1201 if (updated) { 1202 resultSet.updateRow(); 1203 updated = false; 1204 } 1205 return resultSet.previous(); 1206 } 1207 1208 1227 public void setFetchDirection(int direction) throws SQLException { 1228 resultSet.setFetchDirection(direction); 1229 } 1230 1231 1240 public int getFetchDirection() throws SQLException { 1241 return resultSet.getFetchDirection(); 1242 } 1243 1244 1260 public void setFetchSize(int rows) throws SQLException { 1261 resultSet.setFetchSize(rows); 1262 } 1263 1264 1273 public int getFetchSize() throws SQLException { 1274 return resultSet.getFetchSize(); 1275 } 1276 1277 1288 public int getType() throws SQLException { 1289 return resultSet.getType(); 1290 } 1291 1292 1303 public int getConcurrency() throws SQLException { 1304 return resultSet.getConcurrency(); 1305 } 1306 1307 1311 1321 public boolean rowUpdated() throws SQLException { 1322 return resultSet.rowUpdated(); 1323 } 1324 1325 1337 public boolean rowInserted() throws SQLException { 1338 return resultSet.rowInserted(); 1339 } 1340 1341 1354 public boolean rowDeleted() throws SQLException { 1355 return resultSet.rowDeleted(); 1356 } 1357 1358 1370 public void updateNull(int columnIndex) throws SQLException { 1371 resultSet.updateNull(columnIndex); 1372 } 1373 1374 1386 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 1387 resultSet.updateBoolean(columnIndex, x); 1388 } 1389 1390 1403 public void updateByte(int columnIndex, byte x) throws SQLException { 1404 resultSet.updateByte(columnIndex, x); 1405 } 1406 1407 1419 public void updateShort(int columnIndex, short x) throws SQLException { 1420 resultSet.updateShort(columnIndex, x); 1421 } 1422 1423 1435 public void updateInt(int columnIndex, int x) throws SQLException { 1436 resultSet.updateInt(columnIndex, x); 1437 } 1438 1439 1451 public void updateLong(int columnIndex, long x) throws SQLException { 1452 resultSet.updateLong(columnIndex, x); 1453 } 1454 1455 1467 public void updateFloat(int columnIndex, float x) throws SQLException { 1468 resultSet.updateFloat(columnIndex, x); 1469 } 1470 1471 1483 public void updateDouble(int columnIndex, double x) throws SQLException { 1484 resultSet.updateDouble(columnIndex, x); 1485 } 1486 1487 1500 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { 1501 resultSet.updateBigDecimal(columnIndex, x); 1502 } 1503 1504 1516 public void updateString(int columnIndex, String x) throws SQLException { 1517 resultSet.updateString(columnIndex, x); 1518 } 1519 1520 1532 public void updateBytes(int columnIndex, byte x[]) throws SQLException { 1533 resultSet.updateBytes(columnIndex, x); 1534 } 1535 1536 1548 public void updateDate(int columnIndex, java.sql.Date x) throws SQLException { 1549 resultSet.updateDate(columnIndex, x); 1550 } 1551 1552 1564 public void updateTime(int columnIndex, java.sql.Time x) throws SQLException { 1565 resultSet.updateTime(columnIndex, x); 1566 } 1567 1568 1581 public void updateTimestamp(int columnIndex, java.sql.Timestamp x) 1582 throws SQLException { 1583 resultSet.updateTimestamp(columnIndex, x); 1584 } 1585 1586 1599 public void updateAsciiStream(int columnIndex, 1600 java.io.InputStream x, 1601 int length) throws SQLException { 1602 resultSet.updateAsciiStream(columnIndex, x, length); 1603 } 1604 1605 1618 public void updateBinaryStream(int columnIndex, 1619 java.io.InputStream x, 1620 int length) throws SQLException { 1621 resultSet.updateBinaryStream(columnIndex, x, length); 1622 } 1623 1624 1637 public void updateCharacterStream(int columnIndex, 1638 java.io.Reader x, 1639 int length) throws SQLException { 1640 resultSet.updateCharacterStream(columnIndex, x, length); 1641 } 1642 1643 1659 public void updateObject(int columnIndex, Object x, int scale) 1660 throws SQLException { 1661 resultSet.updateObject(columnIndex, x, scale); 1662 } 1663 1664 1676 public void updateObject(int columnIndex, Object x) throws SQLException { 1677 resultSet.updateObject(columnIndex, x); 1678 } 1679 1680 1691 public void updateNull(String columnName) throws SQLException { 1692 resultSet.updateNull(columnName); 1693 } 1694 1695 1707 public void updateBoolean(String columnName, boolean x) throws SQLException { 1708 resultSet.updateBoolean(columnName, x); 1709 } 1710 1711 1723 public void updateByte(String columnName, byte x) throws SQLException { 1724 resultSet.updateByte(columnName, x); 1725 } 1726 1727 1739 public void updateShort(String columnName, short x) throws SQLException { 1740 resultSet.updateShort(columnName, x); 1741 } 1742 1743 1755 public void updateInt(String columnName, int x) throws SQLException { 1756 resultSet.updateInt(columnName, x); 1757 } 1758 1759 1771 public void updateLong(String columnName, long x) throws SQLException { 1772 resultSet.updateLong(columnName, x); 1773 } 1774 1775 1787 public void updateFloat(String columnName, float x) throws SQLException { 1788 resultSet.updateFloat(columnName, x); 1789 } 1790 1791 1803 public void updateDouble(String columnName, double x) throws SQLException { 1804 resultSet.updateDouble(columnName, x); 1805 } 1806 1807 1820 public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { 1821 resultSet.updateBigDecimal(columnName, x); 1822 } 1823 1824 1836 public void updateString(String columnName, String x) throws SQLException { 1837 resultSet.updateString(columnName, x); 1838 } 1839 1840 1853 public void updateBytes(String columnName, byte x[]) throws SQLException { 1854 resultSet.updateBytes(columnName, x); 1855 } 1856 1857 1869 public void updateDate(String columnName, java.sql.Date x) throws SQLException { 1870 resultSet.updateDate(columnName, x); 1871 } 1872 1873 1885 public void updateTime(String columnName, java.sql.Time x) throws SQLException { 1886 resultSet.updateTime(columnName, x); 1887 } 1888 1889 1902 public void updateTimestamp(String columnName, java.sql.Timestamp x) 1903 throws SQLException { 1904 resultSet.updateTimestamp(columnName, x); 1905 } 1906 1907 1920 public void updateAsciiStream(String columnName, 1921 java.io.InputStream x, 1922 int length) throws SQLException { 1923 resultSet.updateAsciiStream(columnName, x, length); 1924 } 1925 1926 1939 public void updateBinaryStream(String columnName, 1940 java.io.InputStream x, 1941 int length) throws SQLException { 1942 resultSet.updateBinaryStream(columnName, x, length); 1943 } 1944 1945 1959 public void updateCharacterStream(String columnName, 1960 java.io.Reader reader, 1961 int length) throws SQLException { 1962 resultSet.updateCharacterStream(columnName, reader, length); 1963 } 1964 1965 1981 public void updateObject(String columnName, Object x, int scale) 1982 throws SQLException { 1983 resultSet.updateObject(columnName, x, scale); 1984 } 1985 1986 1998 public void updateObject(String columnName, Object x) throws SQLException { 1999 resultSet.updateObject(columnName, x); 2000 } 2001 2002 2013 public void insertRow() throws SQLException { 2014 resultSet.insertRow(); 2015 } 2016 2017 2026 public void updateRow() throws SQLException { 2027 resultSet.updateRow(); 2028 } 2029 2030 2039 public void deleteRow() throws SQLException { 2040 resultSet.deleteRow(); 2041 } 2042 2043 2068 public void refreshRow() throws SQLException { 2069 resultSet.refreshRow(); 2070 } 2071 2072 2087 public void cancelRowUpdates() throws SQLException { 2088 resultSet.cancelRowUpdates(); 2089 } 2090 2091 2112 public void moveToInsertRow() throws SQLException { 2113 resultSet.moveToInsertRow(); 2114 } 2115 2116 2125 public void moveToCurrentRow() throws SQLException { 2126 resultSet.moveToCurrentRow(); 2127 } 2128 2129 2142 public Statement getStatement() throws SQLException { 2143 return resultSet.getStatement(); 2144 } 2145 2146 2164 public Object getObject(int i, java.util.Map map) throws SQLException { 2165 return resultSet.getObject(i, map); 2166 } 2167 2168 2179 public Ref getRef(int i) throws SQLException { 2180 return resultSet.getRef(i); 2181 } 2182 2183 2194 public Blob getBlob(int i) throws SQLException { 2195 return resultSet.getBlob(i); 2196 } 2197 2198 2209 public Clob getClob(int i) throws SQLException { 2210 return resultSet.getClob(i); 2211 } 2212 2213 2224 public Array getArray(int i) throws SQLException { 2225 return resultSet.getArray(i); 2226 } 2227 2228 2245 public Object getObject(String colName, java.util.Map map) throws SQLException { 2246 return resultSet.getObject(colName, map); 2247 } 2248 2249 2260 public Ref getRef(String colName) throws SQLException { 2261 return resultSet.getRef(colName); 2262 } 2263 2264 2275 public Blob getBlob(String colName) throws SQLException { 2276 return resultSet.getBlob(colName); 2277 } 2278 2279 2290 public Clob getClob(String colName) throws SQLException { 2291 return resultSet.getClob(colName); 2292 } 2293 2294 2305 public Array getArray(String colName) throws SQLException { 2306 return resultSet.getArray(colName); 2307 } 2308 2309 2326 public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { 2327 return resultSet.getDate(columnIndex, cal); 2328 } 2329 2330 2347 public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { 2348 return resultSet.getDate(columnName, cal); 2349 } 2350 2351 2368 public java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLException { 2369 return resultSet.getTime(columnIndex, cal); 2370 } 2371 2372 2389 public java.sql.Time getTime(String columnName, Calendar cal) throws SQLException { 2390 return resultSet.getTime(columnName, cal); 2391 } 2392 2393 2410 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) 2411 throws SQLException { 2412 return resultSet.getTimestamp(columnIndex, cal); 2413 } 2414 2415 2432 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) 2433 throws SQLException { 2434 return resultSet.getTimestamp(columnName, cal); 2435 } 2436 2437 2439 2452 public java.net.URL getURL(int columnIndex) throws SQLException { 2453 return resultSet.getURL(columnIndex); 2454 } 2455 2456 2469 public java.net.URL getURL(String columnName) throws SQLException { 2470 return resultSet.getURL(columnName); 2471 } 2472 2473 2485 public void updateRef(int columnIndex, java.sql.Ref x) throws SQLException { 2486 resultSet.updateRef(columnIndex, x); 2487 } 2488 2489 2501 public void updateRef(String columnName, java.sql.Ref x) throws SQLException { 2502 resultSet.updateRef(columnName, x); 2503 } 2504 2505 2517 public void updateBlob(int columnIndex, java.sql.Blob x) throws SQLException { 2518 resultSet.updateBlob(columnIndex, x); 2519 } 2520 2521 2533 public void updateBlob(String columnName, java.sql.Blob x) throws SQLException { 2534 resultSet.updateBlob(columnName, x); 2535 } 2536 2537 2549 public void updateClob(int columnIndex, java.sql.Clob x) throws SQLException { 2550 resultSet.updateClob(columnIndex, x); 2551 } 2552 2553 2565 public void updateClob(String columnName, java.sql.Clob x) throws SQLException { 2566 resultSet.updateClob(columnName, x); 2567 } 2568 2569 2581 public void updateArray(int columnIndex, java.sql.Array x) throws SQLException { 2582 resultSet.updateArray(columnIndex, x); 2583 } 2584 2585 2597 public void updateArray(String columnName, java.sql.Array x) throws SQLException { 2598 resultSet.updateArray(columnName, x); 2599 } 2600} 2601 | Popular Tags |