00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.driver;
00026
00027 import java.io.ByteArrayInputStream;
00028 import java.io.IOException;
00029 import java.io.InputStream;
00030 import java.io.ObjectInputStream;
00031 import java.math.BigDecimal;
00032 import java.math.BigInteger;
00033 import java.sql.PreparedStatement;
00034 import java.sql.ResultSet;
00035 import java.sql.SQLException;
00036 import java.sql.SQLWarning;
00037 import java.sql.Time;
00038 import java.sql.Timestamp;
00039 import java.util.ArrayList;
00040 import java.util.Calendar;
00041 import java.util.Hashtable;
00042
00043 import org.objectweb.cjdbc.common.sql.NotImplementedException;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 public class DriverResultSet
00098 implements
00099 java.sql.ResultSet,
00100 java.io.Serializable,
00101 java.lang.Cloneable
00102 {
00103
00104 protected int currentRow = -1;
00105
00106 protected int nbOfRows = -1;
00107
00108 protected int nbOfColumns = -1;
00109
00110 protected ArrayList data;
00111
00112 private boolean hasMoreData;
00113
00114 protected int fetchDirection = FETCH_FORWARD;
00115
00116 protected int fetchSize = 0;
00117
00118 private String cursorName;
00119
00120
00121 protected Field[] fields;
00122
00123 protected boolean wasNullFlag = false;
00124
00125 protected transient Hashtable columnNameToIndex = null;
00126
00127 protected transient Hashtable fullColumnNameToIndex = null;
00128
00129
00130 protected int resultSetType = 0;
00131
00132 protected int resultSetConcurrency = 0;
00133
00134 protected SQLWarning warnings = null;
00135
00136 protected transient Statement owningStatement;
00137
00138 private boolean isClosed = true;
00139
00140
00141 private transient PreparedStatement deleteStatement = null;
00142
00143 private transient PreparedStatement insertStatement = null;
00144
00145 private transient PreparedStatement refreshStatement = null;
00146
00147 private transient PreparedStatement updateStatement = null;
00148
00149 private transient boolean inserting = false;
00150
00151 private transient boolean updating = false;
00152
00153 private transient Object[] tempRow = null;
00154
00155 private transient String[] primaryKeyColumns = null;
00156
00157 private static final String UPDATEABLE_MESSAGE = "ResultSet not updateable. The "
00158 + "query that generated this result set must select only one table, and must "
00159 + "select all primary keys from that table. See the JDBC 2.1 API Specification, "
00160 + "section 5.6 for more details.";
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 public boolean next() throws java.sql.SQLException
00179 {
00180 checkIfClosed();
00181
00182 if (inserting)
00183 {
00184 insertStatement.clearParameters();
00185 tempRow = null;
00186 inserting = false;
00187 }
00188
00189 if (updating)
00190 cancelRowUpdates();
00191
00192 if (nbOfRows == 0)
00193 return false;
00194
00195 if (currentRow + 1 >= nbOfRows)
00196 {
00197 if (hasMoreData)
00198 {
00199 owningStatement.connection.fetchNextData(cursorName, fetchSize, this);
00200 currentRow = 0;
00201 if (data == null)
00202 {
00203 nbOfRows = 0;
00204 return false;
00205 }
00206 else
00207 {
00208 nbOfRows = data.size();
00209 return true;
00210 }
00211 }
00212
00213
00214 currentRow = nbOfRows;
00215 return false;
00216 }
00217
00218 clearWarnings();
00219 currentRow++;
00220 return true;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 public boolean prev() throws SQLException
00236 {
00237 checkIfClosed();
00238
00239 if (inserting)
00240 {
00241 insertStatement.clearParameters();
00242 tempRow = null;
00243 inserting = false;
00244 }
00245
00246 if (updating)
00247 cancelRowUpdates();
00248
00249 if (currentRow - 1 >= 0)
00250 {
00251 currentRow--;
00252 return true;
00253 }
00254
00255 return false;
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 public boolean isBeforeFirst() throws SQLException
00269 {
00270 checkIfClosed();
00271 if (nbOfRows == 0)
00272 return false;
00273 else
00274 return (currentRow == -1);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 public boolean isAfterLast() throws SQLException
00288 {
00289 checkIfClosed();
00290 if (nbOfRows == 0)
00291 return false;
00292 else
00293 return (currentRow >= nbOfRows);
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 public boolean isFirst() throws SQLException
00306 {
00307 checkIfClosed();
00308 if (nbOfRows == 0)
00309 return false;
00310 else
00311 return (currentRow == 0);
00312 }
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 public boolean isLast() throws SQLException
00327 {
00328 checkIfClosed();
00329 if (nbOfRows == 0)
00330 return false;
00331 else
00332 return (currentRow == nbOfRows - 1);
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 public void beforeFirst() throws SQLException
00345 {
00346 checkIfClosed();
00347
00348 if (inserting)
00349 {
00350 insertStatement.clearParameters();
00351 tempRow = null;
00352 inserting = false;
00353 }
00354
00355 if (updating)
00356 cancelRowUpdates();
00357
00358 currentRow = -1;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 public void afterLast() throws SQLException
00371 {
00372 checkIfClosed();
00373
00374 if (inserting)
00375 {
00376 insertStatement.clearParameters();
00377 tempRow = null;
00378 inserting = false;
00379 }
00380
00381 if (updating)
00382 cancelRowUpdates();
00383
00384 if (nbOfRows != 0)
00385 currentRow = nbOfRows;
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 public boolean first() throws SQLException
00399 {
00400 checkIfClosed();
00401
00402 if (inserting)
00403 {
00404 insertStatement.clearParameters();
00405 tempRow = null;
00406 inserting = false;
00407 }
00408
00409 if (updating)
00410 cancelRowUpdates();
00411
00412 if (nbOfRows == 0)
00413 return false;
00414
00415 currentRow = 0;
00416 return true;
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 public boolean last() throws SQLException
00430 {
00431 checkIfClosed();
00432
00433 if (inserting)
00434 {
00435 insertStatement.clearParameters();
00436 tempRow = null;
00437 inserting = false;
00438 }
00439
00440 if (updating)
00441 cancelRowUpdates();
00442
00443 if (nbOfRows == 0)
00444 return false;
00445
00446 currentRow = nbOfRows - 1;
00447 return true;
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 public int getRow() throws SQLException
00460 {
00461 checkIfClosed();
00462 if (currentRow < 0 || currentRow >= nbOfRows || nbOfRows == 0)
00463 return 0;
00464 else
00465 return currentRow + 1;
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 public boolean absolute(int row) throws SQLException
00492 {
00493 checkIfClosed();
00494
00495 if (inserting)
00496 {
00497 insertStatement.clearParameters();
00498 tempRow = null;
00499 inserting = false;
00500 }
00501
00502 if (updating)
00503 cancelRowUpdates();
00504
00505 if (nbOfRows == 0)
00506 return false;
00507
00508 if (row == 0)
00509 throw new SQLException("Cannot absolute position to row 0");
00510
00511 if (row == 1)
00512 return first();
00513
00514 if (row == -1)
00515 return last();
00516
00517 if (row > nbOfRows)
00518 {
00519 afterLast();
00520 return false;
00521 }
00522
00523 if (row < 0)
00524 {
00525 int newRowPosition = nbOfRows + row + 1;
00526
00527 if (newRowPosition <= 0)
00528 {
00529 beforeFirst();
00530 return false;
00531 }
00532
00533 return absolute(newRowPosition);
00534 }
00535 else
00536 {
00537 row--;
00538 currentRow = row;
00539 return true;
00540 }
00541 }
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561 public boolean relative(int rows) throws SQLException
00562 {
00563 checkIfClosed();
00564
00565 if (inserting)
00566 {
00567 insertStatement.clearParameters();
00568 tempRow = null;
00569 inserting = false;
00570 }
00571
00572 if (updating)
00573 cancelRowUpdates();
00574
00575 if (nbOfRows == 0)
00576 return false;
00577
00578 return absolute(currentRow + rows + 1);
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593 public boolean previous() throws SQLException
00594 {
00595 return prev();
00596 }
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 public void setFetchDirection(int direction) throws SQLException
00611 {
00612 if (direction != FETCH_FORWARD && direction != FETCH_REVERSE)
00613 throw new SQLException("Illegal value for fetch direction");
00614 else
00615 fetchDirection = direction;
00616 }
00617
00618
00619
00620
00621
00622
00623
00624 public int getFetchDirection() throws SQLException
00625 {
00626 return fetchDirection;
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642 public void setFetchSize(int rows) throws SQLException
00643 {
00644 if (rows < 0 || rows > nbOfRows)
00645 throw new SQLException("Value must be between 0 and getMaxRows()");
00646 fetchSize = rows;
00647 }
00648
00649
00650
00651
00652
00653
00654
00655 public int getFetchSize() throws SQLException
00656 {
00657 return fetchSize;
00658 }
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 public String getString(int columnIndex) throws SQLException
00674 {
00675 checkRowAndColPosAndSetNullFlag(columnIndex);
00676
00677 if (wasNullFlag)
00678 return null;
00679
00680 if (inserting || updating)
00681 return tempRow[columnIndex - 1].toString();
00682 else
00683 return (((Object[]) data.get(currentRow))[columnIndex - 1]).toString();
00684 }
00685
00686
00687
00688
00689
00690
00691
00692
00693 public boolean getBoolean(int columnIndex) throws SQLException
00694 {
00695 checkRowAndColPosAndSetNullFlag(columnIndex);
00696
00697 if (wasNullFlag)
00698 return false;
00699
00700 Object object;
00701 if (inserting || updating)
00702 object = tempRow[columnIndex - 1];
00703 else
00704 object = (((Object[]) data.get(currentRow))[columnIndex - 1]);
00705
00706 String stringVal = object.toString();
00707 if ((stringVal != null) && (stringVal.length() > 0))
00708 {
00709 stringVal = stringVal.toLowerCase();
00710
00711
00712 if (owningStatement.connection.getPreparedStatementBooleanTrue().equals(
00713 stringVal))
00714 {
00715 return true;
00716 }
00717 else if (owningStatement.connection.getPreparedStatementBooleanFalse()
00718 .equals(stringVal))
00719 {
00720 return false;
00721 }
00722
00723
00724 else if ("t".equals(stringVal))
00725 {
00726 return true;
00727 }
00728 else if ("f".equals(stringVal))
00729 {
00730 return false;
00731 }
00732 else if ("true".equals(stringVal))
00733 {
00734 return true;
00735 }
00736 else if ("false".equals(stringVal))
00737 {
00738 return false;
00739 }
00740 else if ("1".equals(stringVal))
00741 {
00742 return true;
00743 }
00744 else if ("0".equals(stringVal))
00745 {
00746 return false;
00747 }
00748 else if ("y".equals(stringVal))
00749 {
00750 return true;
00751 }
00752 else if ("n".equals(stringVal))
00753 {
00754 return false;
00755 }
00756 else if ("yes".equals(stringVal))
00757 {
00758 return true;
00759 }
00760 else if ("no".equals(stringVal))
00761 {
00762 return false;
00763 }
00764
00765
00766 throw new SQLException("column value " + stringVal
00767 + " could not be converted to boolean");
00768 }
00769 else
00770 {
00771 return false;
00772 }
00773 }
00774
00775
00776
00777
00778
00779
00780
00781
00782 public short getShort(int columnIndex) throws SQLException
00783 {
00784 checkRowAndColPosAndSetNullFlag(columnIndex);
00785
00786 if (wasNullFlag)
00787 return 0;
00788
00789 Object obj;
00790 if (inserting || updating)
00791 obj = tempRow[columnIndex - 1];
00792 else
00793 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
00794
00795 if (obj instanceof Number)
00796 {
00797 return ((Number) obj).shortValue();
00798 }
00799
00800
00801 try
00802 {
00803 String string = obj.toString();
00804 string = string.trim();
00805 return Short.parseShort(string);
00806 }
00807 catch (NumberFormatException e)
00808 {
00809 throw new SQLException("the value " + obj.toString()
00810 + " is not a valid short number");
00811 }
00812 }
00813
00814
00815
00816
00817
00818
00819
00820
00821 public int getInt(int columnIndex) throws SQLException
00822 {
00823 checkRowAndColPosAndSetNullFlag(columnIndex);
00824
00825 if (wasNullFlag)
00826 return 0;
00827
00828 Object obj;
00829 if (inserting || updating)
00830 obj = tempRow[columnIndex - 1];
00831 else
00832 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
00833
00834 if (obj instanceof Number)
00835 {
00836 return ((Number) obj).intValue();
00837 }
00838
00839
00840 try
00841 {
00842 String string = obj.toString();
00843 string = string.trim();
00844 return Integer.parseInt(string);
00845 }
00846 catch (NumberFormatException e)
00847 {
00848 throw new SQLException("the value " + obj.toString()
00849 + " is not a valid int number");
00850 }
00851 }
00852
00853
00854
00855
00856
00857
00858
00859
00860 public long getLong(int columnIndex) throws SQLException
00861 {
00862 checkRowAndColPosAndSetNullFlag(columnIndex);
00863
00864 if (wasNullFlag)
00865 return 0;
00866
00867 Object obj;
00868 if (inserting || updating)
00869 obj = tempRow[columnIndex - 1];
00870 else
00871 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
00872
00873 if (obj instanceof Number)
00874 {
00875 return ((Number) obj).longValue();
00876 }
00877
00878
00879 try
00880 {
00881 String string = obj.toString();
00882 string = string.trim();
00883 return Long.parseLong(string);
00884 }
00885 catch (NumberFormatException e)
00886 {
00887 throw new SQLException("the value " + obj.toString()
00888 + " is not a valid long number");
00889 }
00890 }
00891
00892
00893
00894
00895
00896
00897
00898
00899 public float getFloat(int columnIndex) throws SQLException
00900 {
00901 checkRowAndColPosAndSetNullFlag(columnIndex);
00902
00903 if (wasNullFlag)
00904 return 0;
00905
00906 Object obj;
00907 if (inserting || updating)
00908 obj = tempRow[columnIndex - 1];
00909 else
00910 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
00911
00912 if (obj instanceof Number)
00913 {
00914 return ((Number) obj).floatValue();
00915 }
00916
00917
00918 try
00919 {
00920 String string = obj.toString();
00921 string = string.trim();
00922 return Float.parseFloat(string);
00923 }
00924 catch (NumberFormatException e)
00925 {
00926 throw new SQLException("the value " + obj.toString()
00927 + " is not a valid float number");
00928 }
00929 }
00930
00931
00932
00933
00934
00935
00936
00937
00938 public double getDouble(int columnIndex) throws SQLException
00939 {
00940 checkRowAndColPosAndSetNullFlag(columnIndex);
00941
00942 if (wasNullFlag)
00943 return 0;
00944
00945 Object obj;
00946 if (inserting || updating)
00947 obj = tempRow[columnIndex - 1];
00948 else
00949 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
00950
00951 if (obj instanceof Number)
00952 {
00953 return ((Number) obj).doubleValue();
00954 }
00955
00956
00957 try
00958 {
00959 String string = obj.toString();
00960 string = string.trim();
00961 return Double.parseDouble(string);
00962 }
00963 catch (NumberFormatException e)
00964 {
00965 throw new SQLException("the value " + obj.toString()
00966 + " is not a valid double number");
00967 }
00968 }
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980 public BigDecimal getBigDecimal(int columnIndex, int scale)
00981 throws SQLException
00982 {
00983 BigDecimal bigDecimal = getBigDecimal(columnIndex);
00984 if (bigDecimal == null)
00985 return null;
00986 else
00987 return bigDecimal.setScale(scale);
00988 }
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999 public byte[] getBytes(int columnIndex) throws SQLException
01000 {
01001 checkRowAndColPosAndSetNullFlag(columnIndex);
01002
01003 if (wasNullFlag)
01004 return null;
01005
01006 Object o;
01007 if (inserting || updating)
01008 o = tempRow[columnIndex - 1];
01009 else
01010 o = ((Object[]) data.get(currentRow))[columnIndex - 1];
01011
01012 byte[] tmp;
01013 if (o instanceof java.lang.String)
01014 {
01015 tmp = ((String) o).getBytes();
01016 }
01017 else
01018 {
01019 tmp = (byte[]) o;
01020 }
01021
01022 if (((Connection) owningStatement.getConnection()).isDriverProcessed())
01023 return owningStatement.connection.getBlobFilter().decode(tmp);
01024 else
01025 return tmp;
01026 }
01027
01028
01029
01030
01031
01032
01033
01034
01035 public java.sql.Date getDate(int columnIndex) throws SQLException
01036 {
01037 checkRowAndColPosAndSetNullFlag(columnIndex);
01038
01039 if (wasNullFlag)
01040 return null;
01041
01042
01043
01044
01045 String dateString;
01046 if (inserting || updating)
01047 dateString = tempRow[columnIndex - 1].toString();
01048 else
01049 dateString = ((Object[]) data.get(currentRow))[columnIndex - 1]
01050 .toString();
01051
01052 if (dateString.length() == 10)
01053 return java.sql.Date.valueOf(dateString);
01054 else
01055 return java.sql.Date.valueOf(dateString.substring(0, 10));
01056 }
01057
01058
01059
01060
01061
01062
01063
01064
01065 public Time getTime(int columnIndex) throws SQLException
01066 {
01067 checkRowAndColPosAndSetNullFlag(columnIndex);
01068
01069 if (wasNullFlag)
01070 return null;
01071
01072 Object obj;
01073 if (inserting || updating)
01074 obj = tempRow[columnIndex - 1];
01075 else
01076 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
01077
01078 if (obj instanceof java.util.Date)
01079 {
01080 java.util.Date time = (java.util.Date) obj;
01081
01082
01083 String timeString = time.toString();
01084 if (timeString.length() == 8)
01085 {
01086
01087
01088 return new Time(time.getTime());
01089 }
01090
01091
01092
01093 Calendar cal = Calendar.getInstance();
01094 cal.setTime(time);
01095 cal.clear(Calendar.YEAR);
01096 cal.clear(Calendar.MONTH);
01097 cal.clear(Calendar.DATE);
01098 cal.clear(Calendar.MILLISECOND);
01099 return new Time(cal.getTimeInMillis());
01100 }
01101
01102
01103 try
01104 {
01105 String string = obj.toString();
01106 string = string.trim();
01107 return Time.valueOf(string);
01108 }
01109 catch (IllegalArgumentException e)
01110 {
01111 throw new SQLException("the value " + obj.toString()
01112 + " is not a valid time");
01113 }
01114 }
01115
01116
01117
01118
01119
01120
01121
01122
01123 public Timestamp getTimestamp(int columnIndex) throws SQLException
01124 {
01125 checkRowAndColPosAndSetNullFlag(columnIndex);
01126
01127 if (wasNullFlag)
01128 return null;
01129
01130 Object obj;
01131 if (inserting || updating)
01132 obj = tempRow[columnIndex - 1];
01133 else
01134 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
01135
01136 if (obj instanceof java.util.Date)
01137 {
01138 return new Timestamp(((java.util.Date) obj).getTime());
01139 }
01140
01141
01142 try
01143 {
01144 String string = obj.toString();
01145 string = string.trim();
01146 return Timestamp.valueOf(string);
01147 }
01148 catch (IllegalArgumentException e)
01149 {
01150 throw new SQLException("the value " + obj.toString()
01151 + " is not a valid timestamp");
01152 }
01153 }
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173 public InputStream getAsciiStream(int columnIndex) throws SQLException
01174 {
01175 checkRowAndColPosAndSetNullFlag(columnIndex);
01176
01177 return getBinaryStream(columnIndex);
01178 }
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 public InputStream getUnicodeStream(int columnIndex) throws SQLException
01194 {
01195 checkRowAndColPosAndSetNullFlag(columnIndex);
01196
01197 return getBinaryStream(columnIndex);
01198 }
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212 public InputStream getBinaryStream(int columnIndex) throws SQLException
01213 {
01214 checkRowAndColPosAndSetNullFlag(columnIndex);
01215
01216 byte b[] = getBytes(columnIndex);
01217 if (b != null)
01218 return new ByteArrayInputStream(b);
01219 else
01220 return null;
01221 }
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231 public String getString(String columnName) throws SQLException
01232 {
01233 return this.getString(findColumn(columnName));
01234 }
01235
01236
01237
01238
01239 public boolean getBoolean(String columnName) throws SQLException
01240 {
01241 return getBoolean(findColumn(columnName));
01242 }
01243
01244
01245
01246
01247 public byte getByte(String columnName) throws SQLException
01248 {
01249 return getByte(findColumn(columnName));
01250 }
01251
01252
01253
01254
01255 public short getShort(String columnName) throws SQLException
01256 {
01257 return getShort(findColumn(columnName));
01258 }
01259
01260
01261
01262
01263 public int getInt(String columnName) throws SQLException
01264 {
01265 return getInt(findColumn(columnName));
01266 }
01267
01268
01269
01270
01271 public long getLong(String columnName) throws SQLException
01272 {
01273 return getLong(findColumn(columnName));
01274 }
01275
01276
01277
01278
01279 public float getFloat(String columnName) throws SQLException
01280 {
01281 return getFloat(findColumn(columnName));
01282 }
01283
01284
01285
01286
01287 public double getDouble(String columnName) throws SQLException
01288 {
01289 return getDouble(findColumn(columnName));
01290 }
01291
01292
01293
01294
01295
01296 public BigDecimal getBigDecimal(String columnName, int scale)
01297 throws SQLException
01298 {
01299 return getBigDecimal(findColumn(columnName), scale);
01300 }
01301
01302
01303
01304
01305 public byte[] getBytes(String columnName) throws SQLException
01306 {
01307 return getBytes(findColumn(columnName));
01308 }
01309
01310
01311
01312
01313 public java.sql.Date getDate(String columnName) throws SQLException
01314 {
01315 return getDate(findColumn(columnName));
01316 }
01317
01318
01319
01320
01321 public Time getTime(String columnName) throws SQLException
01322 {
01323 return getTime(findColumn(columnName));
01324 }
01325
01326
01327
01328
01329 public Timestamp getTimestamp(String columnName) throws SQLException
01330 {
01331 return getTimestamp(findColumn(columnName));
01332 }
01333
01334
01335
01336
01337 public InputStream getAsciiStream(String columnName) throws SQLException
01338 {
01339 return getAsciiStream(findColumn(columnName));
01340 }
01341
01342
01343
01344
01345
01346 public InputStream getUnicodeStream(String columnName) throws SQLException
01347 {
01348 return getUnicodeStream(findColumn(columnName));
01349 }
01350
01351
01352
01353
01354 public InputStream getBinaryStream(String columnName) throws SQLException
01355 {
01356 return getBinaryStream(findColumn(columnName));
01357 }
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372 public java.sql.SQLWarning getWarnings() throws SQLException
01373 {
01374 return warnings;
01375 }
01376
01377
01378
01379
01380
01381
01382
01383
01384 public void clearWarnings() throws SQLException
01385 {
01386 warnings = null;
01387 }
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406 public String getCursorName() throws SQLException
01407 {
01408 throw new NotImplementedException("getCursorName()");
01409 }
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425 public Object getObject(int columnIndex) throws SQLException
01426 {
01427 checkRowAndColPosAndSetNullFlag(columnIndex);
01428
01429 if (wasNullFlag)
01430 return null;
01431
01432 Object o;
01433 if (inserting || updating)
01434 o = tempRow[columnIndex];
01435 else
01436 o = ((Object[]) data.get(currentRow))[columnIndex - 1];
01437
01438 if (o instanceof byte[])
01439 {
01440 try
01441 {
01442 byte[] b = owningStatement.connection.getBlobFilter()
01443 .decode((byte[]) o);
01444 return new ObjectInputStream(new ByteArrayInputStream(b)).readObject();
01445 }
01446 catch (ClassNotFoundException e)
01447 {
01448 e.printStackTrace();
01449 throw new SQLException("Missing class while deserializing Blob" + e);
01450 }
01451 catch (IOException e)
01452 {
01453 e.printStackTrace();
01454 throw new SQLException("IOException while deserializing Blob" + e);
01455 }
01456 }
01457 else
01458 {
01459 return o;
01460 }
01461 }
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477 public Object getObject(String columnName) throws SQLException
01478 {
01479 return getObject(findColumn(columnName));
01480 }
01481
01482
01483
01484
01485
01486
01487 public java.io.Reader getCharacterStream(int columnIndex) throws SQLException
01488 {
01489 String s = getString(columnIndex);
01490 if (s == null)
01491 return null;
01492 char[] data = s.toCharArray();
01493 return new java.io.CharArrayReader(data);
01494 }
01495
01496
01497
01498
01499 public java.io.Reader getCharacterStream(String columnName)
01500 throws SQLException
01501 {
01502 return getCharacterStream(findColumn(columnName));
01503 }
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514 public BigDecimal getBigDecimal(int columnIndex) throws SQLException
01515 {
01516 checkRowAndColPosAndSetNullFlag(columnIndex);
01517
01518 if (wasNullFlag)
01519 return null;
01520
01521 Object obj;
01522 if (inserting || updating)
01523 obj = tempRow[columnIndex - 1];
01524 else
01525 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
01526
01527 if (obj instanceof BigDecimal)
01528 return (BigDecimal) obj;
01529 else if (obj instanceof Long)
01530 {
01531 return new BigDecimal(((Long) obj).longValue());
01532 }
01533 else if (obj instanceof BigInteger)
01534 {
01535 return new BigDecimal(((BigInteger) obj));
01536 }
01537 else if (obj instanceof Short)
01538 {
01539 return new BigDecimal(((Short) obj).shortValue());
01540 }
01541 else if (obj instanceof Integer)
01542 {
01543 return new BigDecimal(((Integer) obj).intValue());
01544 }
01545 else if (obj instanceof String)
01546 {
01547 return new BigDecimal((String) obj);
01548 }
01549 else if (obj instanceof Number)
01550 {
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567 return new BigDecimal(obj.toString());
01568 }
01569 else
01570 {
01571 throw new SQLException("Type " + obj.getClass().getName()
01572 + " is not compatible with BigDecimal");
01573 }
01574 }
01575
01576
01577
01578
01579 public BigDecimal getBigDecimal(String columnName) throws SQLException
01580 {
01581 return getBigDecimal(findColumn(columnName));
01582 }
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594 public Object getObject(int i, java.util.Map map) throws SQLException
01595 {
01596 throw new NotImplementedException("getObject(int, java.util.Map)");
01597 }
01598
01599
01600
01601
01602
01603
01604
01605
01606 public java.sql.Ref getRef(int i) throws SQLException
01607 {
01608 throw new NotImplementedException("getRef");
01609 }
01610
01611
01612
01613
01614
01615
01616
01617
01618 public java.sql.Blob getBlob(int columnIndex) throws SQLException
01619 {
01620 checkRowAndColPosAndSetNullFlag(columnIndex);
01621
01622 if (wasNullFlag)
01623 return null;
01624
01625 Object o;
01626 if (inserting || updating)
01627 o = tempRow[columnIndex - 1];
01628 else
01629 o = (((Object[]) data.get(currentRow))[columnIndex - 1]);
01630
01631
01632
01633 if (o instanceof Blob)
01634 return (java.sql.Blob) o;
01635 else
01636 return new Blob(getBytes(columnIndex));
01637 }
01638
01639
01640
01641
01642
01643
01644
01645
01646 public java.sql.Clob getClob(int columnIndex) throws SQLException
01647 {
01648 checkRowAndColPosAndSetNullFlag(columnIndex);
01649
01650 if (wasNullFlag)
01651 return null;
01652
01653 Object o;
01654 if (inserting || updating)
01655 o = tempRow[columnIndex - 1];
01656 else
01657 o = (((Object[]) data.get(currentRow))[columnIndex - 1]);
01658
01659
01660
01661 if (o instanceof String)
01662 return new Clob((String) o);
01663 else if (o instanceof Clob)
01664 return (java.sql.Clob) o;
01665 else
01666 return new Clob(new String(o.toString()));
01667 }
01668
01669
01670
01671
01672
01673
01674
01675
01676 public java.sql.Array getArray(int columnIndex) throws SQLException
01677 {
01678 checkRowAndColPosAndSetNullFlag(columnIndex);
01679
01680 if (wasNullFlag)
01681 return null;
01682
01683 if (inserting || updating)
01684 return (java.sql.Array) tempRow[columnIndex - 1];
01685 else
01686 return (java.sql.Array) (((Object[]) data.get(currentRow))[columnIndex - 1]);
01687 }
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699 public Object getObject(String colName, java.util.Map map)
01700 throws SQLException
01701 {
01702 throw new NotImplementedException("getObject(String, java.util.Map)");
01703 }
01704
01705
01706
01707
01708
01709
01710
01711
01712 public java.sql.Ref getRef(String colName) throws SQLException
01713 {
01714 throw new NotImplementedException("getRef(String)");
01715 }
01716
01717
01718
01719
01720
01721
01722
01723
01724 public java.sql.Blob getBlob(String colName) throws SQLException
01725 {
01726 return getBlob(findColumn(colName));
01727 }
01728
01729
01730
01731
01732
01733
01734
01735
01736 public java.sql.Clob getClob(String colName) throws SQLException
01737 {
01738 return getClob(findColumn(colName));
01739 }
01740
01741
01742
01743
01744
01745
01746
01747
01748 public java.sql.Array getArray(String colName) throws SQLException
01749 {
01750 return getArray(findColumn(colName));
01751 }
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763 public java.sql.Date getDate(int columnIndex, Calendar cal)
01764 throws SQLException
01765 {
01766 throw new NotImplementedException("getDate(int, Calendar)");
01767 }
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779 public java.sql.Date getDate(String columnName, Calendar cal)
01780 throws SQLException
01781 {
01782 throw new NotImplementedException("getDate(String, Calendar)");
01783 }
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795 public java.sql.Time getTime(int columnIndex, Calendar cal)
01796 throws SQLException
01797 {
01798 throw new NotImplementedException("getTime(int, Calendar)");
01799 }
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811 public java.sql.Time getTime(String columnName, Calendar cal)
01812 throws SQLException
01813 {
01814 throw new NotImplementedException("getTime(String, Calendar)");
01815 }
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal)
01829 throws SQLException
01830 {
01831 throw new NotImplementedException("getTimestamp(int, Calendar)");
01832 }
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal)
01846 throws SQLException
01847 {
01848 throw new NotImplementedException("getTimestamp(String, Calendar)");
01849 }
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863
01864 public boolean rowUpdated() throws SQLException
01865 {
01866 throw new NotImplementedException("rowUpdated");
01867 }
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877 public boolean rowInserted() throws SQLException
01878 {
01879 throw new NotImplementedException("rowInserted");
01880 }
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892 public boolean rowDeleted() throws SQLException
01893 {
01894 throw new NotImplementedException("rowDeleted");
01895 }
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906 public void updateNull(int columnIndex) throws SQLException
01907 {
01908 checkIfClosed();
01909
01910 if (inserting)
01911 insertStatement
01912 .setNull(columnIndex, fields[columnIndex - 1].getSqlType());
01913 else
01914 {
01915 checkUpdateFlagAndPrepareUpdateIfNeeded();
01916 updateStatement
01917 .setNull(columnIndex, fields[columnIndex - 1].getSqlType());
01918 }
01919
01920 tempRow[columnIndex - 1] = null;
01921 }
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934 public void updateBoolean(int columnIndex, boolean x) throws SQLException
01935 {
01936 checkIfClosed();
01937
01938 if (inserting)
01939 insertStatement.setBoolean(columnIndex, x);
01940 else
01941 {
01942 checkUpdateFlagAndPrepareUpdateIfNeeded();
01943 updateStatement.setBoolean(columnIndex, x);
01944 }
01945
01946 tempRow[columnIndex - 1] = Boolean.valueOf(x);
01947 }
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959 public void updateByte(int columnIndex, byte x) throws SQLException
01960 {
01961 checkIfClosed();
01962
01963 if (inserting)
01964 insertStatement.setByte(columnIndex, x);
01965 else
01966 {
01967 checkUpdateFlagAndPrepareUpdateIfNeeded();
01968 updateStatement.setByte(columnIndex, x);
01969 }
01970
01971 tempRow[columnIndex - 1] = new Byte(x);
01972 }
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984 public void updateShort(int columnIndex, short x) throws SQLException
01985 {
01986 checkIfClosed();
01987
01988 if (inserting)
01989 insertStatement.setShort(columnIndex, x);
01990 else
01991 {
01992 checkUpdateFlagAndPrepareUpdateIfNeeded();
01993 updateStatement.setShort(columnIndex, x);
01994 }
01995
01996 tempRow[columnIndex - 1] = new Short(x);
01997 }
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009 public void updateInt(int columnIndex, int x) throws SQLException
02010 {
02011 checkIfClosed();
02012
02013 if (inserting)
02014 insertStatement.setInt(columnIndex, x);
02015 else
02016 {
02017 checkUpdateFlagAndPrepareUpdateIfNeeded();
02018 updateStatement.setInt(columnIndex, x);
02019 }
02020
02021 tempRow[columnIndex - 1] = new Integer(x);
02022 }
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034 public void updateLong(int columnIndex, long x) throws SQLException
02035 {
02036 checkIfClosed();
02037
02038 if (inserting)
02039 insertStatement.setLong(columnIndex, x);
02040 else
02041 {
02042 checkUpdateFlagAndPrepareUpdateIfNeeded();
02043 updateStatement.setLong(columnIndex, x);
02044 }
02045
02046 tempRow[columnIndex - 1] = new Long(x);
02047 }
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059 public void updateFloat(int columnIndex, float x) throws SQLException
02060 {
02061 checkIfClosed();
02062
02063 if (inserting)
02064 insertStatement.setFloat(columnIndex, x);
02065 else
02066 {
02067 checkUpdateFlagAndPrepareUpdateIfNeeded();
02068 updateStatement.setFloat(columnIndex, x);
02069 }
02070
02071 tempRow[columnIndex - 1] = new Float(x);
02072 }
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084 public void updateDouble(int columnIndex, double x) throws SQLException
02085 {
02086 checkIfClosed();
02087
02088 if (inserting)
02089 insertStatement.setDouble(columnIndex, x);
02090 else
02091 {
02092 checkUpdateFlagAndPrepareUpdateIfNeeded();
02093 updateStatement.setDouble(columnIndex, x);
02094 }
02095
02096 tempRow[columnIndex - 1] = new Double(x);
02097 }
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109 public void updateBigDecimal(int columnIndex, BigDecimal x)
02110 throws SQLException
02111 {
02112 checkIfClosed();
02113
02114 if (inserting)
02115 insertStatement.setBigDecimal(columnIndex, x);
02116 else
02117 {
02118 checkUpdateFlagAndPrepareUpdateIfNeeded();
02119 updateStatement.setBigDecimal(columnIndex, x);
02120 }
02121
02122 tempRow[columnIndex - 1] = x;
02123 }
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135 public void updateString(int columnIndex, String x) throws SQLException
02136 {
02137 checkIfClosed();
02138
02139 if (inserting)
02140 insertStatement.setString(columnIndex, x);
02141 else
02142 {
02143 checkUpdateFlagAndPrepareUpdateIfNeeded();
02144 updateStatement.setString(columnIndex, x);
02145 }
02146
02147 tempRow[columnIndex - 1] = x;
02148 }
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160 public void updateBytes(int columnIndex, byte x[]) throws SQLException
02161 {
02162 checkIfClosed();
02163
02164 if (inserting)
02165 insertStatement.setBytes(columnIndex, x);
02166 else
02167 {
02168 checkUpdateFlagAndPrepareUpdateIfNeeded();
02169 updateStatement.setBytes(columnIndex, x);
02170 }
02171
02172 tempRow[columnIndex - 1] = x;
02173 }
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185 public void updateDate(int columnIndex, java.sql.Date x) throws SQLException
02186 {
02187 checkIfClosed();
02188
02189 if (inserting)
02190 insertStatement.setDate(columnIndex, x);
02191 else
02192 {
02193 checkUpdateFlagAndPrepareUpdateIfNeeded();
02194 updateStatement.setDate(columnIndex, x);
02195 }
02196
02197 tempRow[columnIndex - 1] = x;
02198 }
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210 public void updateTime(int columnIndex, java.sql.Time x) throws SQLException
02211 {
02212 checkIfClosed();
02213
02214 if (inserting)
02215 insertStatement.setTime(columnIndex, x);
02216 else
02217 {
02218 checkUpdateFlagAndPrepareUpdateIfNeeded();
02219 updateStatement.setTime(columnIndex, x);
02220 }
02221
02222 tempRow[columnIndex - 1] = x;
02223 }
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235 public void updateTimestamp(int columnIndex, java.sql.Timestamp x)
02236 throws SQLException
02237 {
02238 checkIfClosed();
02239
02240 if (inserting)
02241 insertStatement.setTimestamp(columnIndex, x);
02242 else
02243 {
02244 checkUpdateFlagAndPrepareUpdateIfNeeded();
02245 updateStatement.setTimestamp(columnIndex, x);
02246 }
02247
02248 tempRow[columnIndex - 1] = x;
02249 }
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262 public void updateAsciiStream(int columnIndex, java.io.InputStream x,
02263 int length) throws SQLException
02264 {
02265 this.updateBinaryStream(columnIndex, x, length);
02266 }
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279 public void updateBinaryStream(int columnIndex, java.io.InputStream x,
02280 int length) throws SQLException
02281 {
02282 checkIfClosed();
02283
02284 byte[] data = new byte[length];
02285 try
02286 {
02287 x.read(data, 0, length);
02288 }
02289 catch (Exception ioe)
02290 {
02291 throw new SQLException("Problem with streaming of data");
02292 }
02293
02294 this.updateBytes(columnIndex, data);
02295 }
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308 public void updateCharacterStream(int columnIndex, java.io.Reader x,
02309 int length) throws SQLException
02310 {
02311 checkIfClosed();
02312
02313 char[] data = new char[length];
02314 try
02315 {
02316 x.read(data, 0, length);
02317 }
02318 catch (Exception ioe)
02319 {
02320 throw new SQLException("Problem with streaming of data");
02321 }
02322
02323 this.updateString(columnIndex, new String(data));
02324 }
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339 public void updateObject(int columnIndex, Object x, int scale)
02340 throws SQLException
02341 {
02342 checkIfClosed();
02343
02344 if (inserting)
02345 insertStatement.setObject(columnIndex, x, scale);
02346 else
02347 {
02348 checkUpdateFlagAndPrepareUpdateIfNeeded();
02349 updateStatement.setObject(columnIndex, x, scale);
02350 }
02351
02352 tempRow[columnIndex - 1] = x;
02353 }
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365 public void updateObject(int columnIndex, Object x) throws SQLException
02366 {
02367 checkIfClosed();
02368
02369 if (inserting)
02370 insertStatement.setObject(columnIndex, x);
02371 else
02372 {
02373 checkUpdateFlagAndPrepareUpdateIfNeeded();
02374 updateStatement.setObject(columnIndex, x);
02375 }
02376
02377 tempRow[columnIndex - 1] = x;
02378 }
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390 public void updateNull(String columnName) throws SQLException
02391 {
02392 this.updateNull(findColumn(columnName));
02393 }
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405 public void updateBoolean(String columnName, boolean x) throws SQLException
02406 {
02407 this.updateBoolean(findColumn(columnName), x);
02408 }
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420 public void updateByte(String columnName, byte x) throws SQLException
02421 {
02422 this.updateByte(findColumn(columnName), x);
02423 }
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435 public void updateShort(String columnName, short x) throws SQLException
02436 {
02437 this.updateShort(findColumn(columnName), x);
02438 }
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450 public void updateInt(String columnName, int x) throws SQLException
02451 {
02452 this.updateInt(findColumn(columnName), x);
02453 }
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465 public void updateLong(String columnName, long x) throws SQLException
02466 {
02467 this.updateLong(findColumn(columnName), x);
02468 }
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480 public void updateFloat(String columnName, float x) throws SQLException
02481 {
02482 this.updateFloat(findColumn(columnName), x);
02483 }
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495 public void updateDouble(String columnName, double x) throws SQLException
02496 {
02497 this.updateDouble(findColumn(columnName), x);
02498 }
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510 public void updateBigDecimal(String columnName, BigDecimal x)
02511 throws SQLException
02512 {
02513 this.updateBigDecimal(findColumn(columnName), x);
02514 }
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526 public void updateString(String columnName, String x) throws SQLException
02527 {
02528 this.updateString(findColumn(columnName), x);
02529 }
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541 public void updateBytes(String columnName, byte x[]) throws SQLException
02542 {
02543 this.updateBytes(findColumn(columnName), x);
02544 }
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556 public void updateDate(String columnName, java.sql.Date x)
02557 throws SQLException
02558 {
02559 this.updateDate(findColumn(columnName), x);
02560 }
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572 public void updateTime(String columnName, java.sql.Time x)
02573 throws SQLException
02574 {
02575 this.updateTime(findColumn(columnName), x);
02576 }
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588 public void updateTimestamp(String columnName, java.sql.Timestamp x)
02589 throws SQLException
02590 {
02591 this.updateTimestamp(findColumn(columnName), x);
02592 }
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605 public void updateAsciiStream(String columnName, java.io.InputStream x,
02606 int length) throws SQLException
02607 {
02608 this.updateAsciiStream(findColumn(columnName), x, length);
02609 }
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622 public void updateBinaryStream(String columnName, java.io.InputStream x,
02623 int length) throws SQLException
02624 {
02625 this.updateBinaryStream(findColumn(columnName), x, length);
02626 }
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639 public void updateCharacterStream(String columnName, java.io.Reader reader,
02640 int length) throws SQLException
02641 {
02642 this.updateCharacterStream(findColumn(columnName), reader, length);
02643 }
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658 public void updateObject(String columnName, Object x, int scale)
02659 throws SQLException
02660 {
02661 this.updateObject(findColumn(columnName), x, scale);
02662 }
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674 public void updateObject(String columnName, Object x) throws SQLException
02675 {
02676 this.updateObject(findColumn(columnName), x);
02677 }
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687 public void insertRow() throws SQLException
02688 {
02689 checkIfClosed();
02690
02691 if (!inserting)
02692 throw new SQLException("insertRow cannot be called "
02693 + "when the cursor is not on the insert row");
02694
02695
02696 try
02697 {
02698 insertStatement.executeUpdate();
02699 }
02700 finally
02701 {
02702
02703 insertStatement.clearParameters();
02704 }
02705
02706
02707 if (data == null)
02708 data = new ArrayList();
02709 data.add(tempRow);
02710 nbOfRows++;
02711
02712
02713 tempRow = new Object[nbOfColumns];
02714 }
02715
02716
02717
02718
02719
02720
02721
02722
02723 public void updateRow() throws SQLException
02724 {
02725 checkIfClosed();
02726
02727 if (inserting)
02728 throw new SQLException("updateRow cannot be called "
02729 + "when the cursor is on the insert row");
02730
02731 if (!updating)
02732 return;
02733
02734
02735 for (int i = 0; i < primaryKeyColumns.length; ++i)
02736 updateStatement.setObject(nbOfColumns + i + 1, ((Object[]) data
02737 .get(currentRow))[findColumn(primaryKeyColumns[i]) - 1]);
02738
02739
02740 try
02741 {
02742 updateStatement.executeUpdate();
02743 }
02744 finally
02745 {
02746
02747 updateStatement.clearParameters();
02748 }
02749
02750
02751 data.set(currentRow, tempRow);
02752
02753
02754 tempRow = null;
02755 updating = false;
02756 }
02757
02758
02759
02760
02761
02762
02763
02764
02765 public void deleteRow() throws SQLException
02766 {
02767 checkIfClosed();
02768
02769 if (inserting)
02770 throw new SQLException("deleteRow cannot be called "
02771 + "when the cursor is on the insert row");
02772
02773 this.checkRowPos();
02774
02775 if (deleteStatement == null)
02776 this.buildDeleteStatement();
02777
02778
02779 for (int i = 0; i < primaryKeyColumns.length; ++i)
02780 deleteStatement
02781 .setObject(
02782 i + 1,
02783 ((Object[]) data.get(currentRow))[findColumn(primaryKeyColumns[i]) - 1]);
02784
02785
02786 try
02787 {
02788 deleteStatement.executeUpdate();
02789 }
02790 finally
02791 {
02792
02793 deleteStatement.clearParameters();
02794 }
02795
02796
02797 data.remove(currentRow);
02798 nbOfRows--;
02799
02800
02801 if (updating)
02802 this.cancelRowUpdates();
02803 }
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821 public void refreshRow() throws SQLException
02822 {
02823 checkIfClosed();
02824
02825 if (inserting)
02826 throw new SQLException("refreshRow cannot be called "
02827 + "when the cursor is on the insert row");
02828
02829 this.checkRowPos();
02830
02831 if (refreshStatement == null)
02832 this.buildRefreshStatement();
02833
02834
02835 for (int i = 0; i < primaryKeyColumns.length; ++i)
02836 refreshStatement
02837 .setObject(
02838 i + 1,
02839 ((Object[]) data.get(currentRow))[findColumn(primaryKeyColumns[i]) - 1]);
02840
02841
02842 DriverResultSet res;
02843 try
02844 {
02845 res = (DriverResultSet) refreshStatement.executeQuery();
02846 }
02847 finally
02848 {
02849
02850 refreshStatement.clearParameters();
02851 }
02852
02853
02854 try
02855 {
02856 data.set(currentRow, res.data.get(0));
02857 }
02858 catch (NullPointerException e)
02859 {
02860 throw new SQLException("The current row has been "
02861 + "removed from the database");
02862 }
02863 finally
02864 {
02865
02866 res.close();
02867 }
02868
02869
02870 if (updating)
02871 this.cancelRowUpdates();
02872 }
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882
02883 public void cancelRowUpdates() throws SQLException
02884 {
02885 checkIfClosed();
02886
02887 if (inserting)
02888 throw new SQLException("cancelRowUpdates cannot be "
02889 + "called when the cursor is on the insert row");
02890
02891 if (!updating)
02892 return;
02893
02894 updateStatement.clearParameters();
02895 tempRow = null;
02896 updating = false;
02897 }
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913 public void moveToInsertRow() throws SQLException
02914 {
02915 checkIfClosed();
02916
02917 if (inserting)
02918 return;
02919
02920 if (insertStatement == null)
02921 this.buildInsertStatement();
02922
02923 tempRow = new Object[nbOfColumns];
02924 inserting = true;
02925 }
02926
02927
02928
02929
02930
02931
02932
02933
02934 public void moveToCurrentRow() throws SQLException
02935 {
02936 checkIfClosed();
02937
02938 if (!inserting)
02939 return;
02940
02941 insertStatement.clearParameters();
02942 tempRow = null;
02943 inserting = false;
02944 }
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960 public int getType() throws SQLException
02961 {
02962 return resultSetType;
02963 }
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973 public int getConcurrency() throws SQLException
02974 {
02975 return resultSetConcurrency;
02976 }
02977
02978
02979
02980
02981
02982
02983
02984 public void close() throws SQLException
02985 {
02986 if (hasMoreData)
02987 owningStatement.connection.closeRemoteResultSet(cursorName);
02988 isClosed = true;
02989 }
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001 public boolean wasNull() throws SQLException
03002 {
03003 return wasNullFlag;
03004 }
03005
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015 public java.sql.Statement getStatement() throws SQLException
03016 {
03017 return owningStatement;
03018 }
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028 protected void setData(ArrayList newData)
03029 {
03030 data = newData;
03031 }
03032
03033
03034
03035
03036
03037
03038
03039 protected void setHasMoreData(boolean hasMore)
03040 {
03041 hasMoreData = hasMore;
03042 }
03043
03044
03045
03046
03047
03048
03049
03050
03051 public java.sql.ResultSetMetaData getMetaData() throws SQLException
03052 {
03053 return new ResultSetMetaData(this);
03054 }
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064 public int findColumn(String columnName) throws SQLException
03065 {
03066 if (columnNameToIndex == null)
03067 buildIndexMapping();
03068
03069 Integer index = (Integer) columnNameToIndex.get(columnName);
03070
03071 if (index == null)
03072 index = (Integer) fullColumnNameToIndex.get(columnName);
03073
03074 if (index != null)
03075 return index.intValue() + 1;
03076 else
03077 {
03078
03079 String columnNameUC = columnName.toUpperCase();
03080 for (int i = 0; i < nbOfColumns; i++)
03081 {
03082 if (fields[i].getFieldName().toUpperCase().equals(columnNameUC))
03083 return i + 1;
03084 else if (fields[i].getFullName().toUpperCase().equals(columnNameUC))
03085 return i + 1;
03086 }
03087 throw new java.sql.SQLException("Column '" + columnName + "' not found.");
03088 }
03089 }
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099
03100
03101
03102
03103
03104 public DriverResultSet(Field[] fields, ArrayList resultData)
03105 {
03106 currentRow = -1;
03107 this.fields = fields;
03108 data = resultData;
03109 if (data == null)
03110 nbOfRows = 0;
03111 else
03112 nbOfRows = data.size();
03113 nbOfColumns = fields.length;
03114 isClosed = false;
03115 }
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128 public DriverResultSet(Field[] fields, ArrayList resultData,
03129 boolean crsHasMoreData, String cursorName)
03130 {
03131 this(fields, resultData);
03132 this.cursorName = cursorName;
03133 hasMoreData = crsHasMoreData;
03134 }
03135
03136
03137
03138
03139
03140
03141
03142 protected void setStatement(Statement stmt) throws SQLException
03143 {
03144 owningStatement = stmt;
03145 fetchSize = stmt.getFetchSize();
03146 resultSetConcurrency = stmt.getResultSetConcurrency();
03147 resultSetType = stmt.getResultSetType();
03148 }
03149
03150
03151
03152
03153 private void buildIndexMapping()
03154 {
03155 int numFields = nbOfColumns;
03156
03157 columnNameToIndex = new Hashtable();
03158 fullColumnNameToIndex = new Hashtable();
03159
03160 for (int i = 0; i < numFields; i++)
03161 {
03162 Integer index = new Integer(i);
03163
03164 String columnName = fields[i].getFieldName();
03165 String fullColumnName = fields[i].getFullName();
03166 if (columnName != null)
03167 {
03168 columnNameToIndex.put(fields[i].getFieldName(), index);
03169 columnNameToIndex.put(fields[i].getFieldName().toUpperCase(), index);
03170 columnNameToIndex.put(fields[i].getFieldName().toLowerCase(), index);
03171 }
03172
03173 if (fullColumnName != null)
03174 {
03175 fullColumnNameToIndex.put(fields[i].getFullName(), index);
03176 fullColumnNameToIndex.put(fields[i].getFullName().toUpperCase(), index);
03177 fullColumnNameToIndex.put(fields[i].getFullName().toLowerCase(), index);
03178 }
03179 }
03180 }
03181
03182
03183
03184
03185
03186
03187 private void buildDeleteStatement() throws SQLException
03188 {
03189
03190 this.checkUpdatability();
03191
03192
03193 StringBuffer sb = new StringBuffer();
03194 sb.append("DELETE FROM ");
03195 sb.append(fields[0].getTableName());
03196 sb.append(" WHERE ");
03197 for (int i = 0; i < primaryKeyColumns.length; ++i)
03198 {
03199 if (i > 0)
03200 sb.append(" AND ");
03201 sb.append(primaryKeyColumns[i]);
03202 sb.append(" = ?");
03203 }
03204
03205
03206 deleteStatement = this.owningStatement.getConnection().prepareStatement(
03207 sb.toString());
03208 }
03209
03210
03211
03212
03213
03214
03215 private void buildInsertStatement() throws SQLException
03216 {
03217
03218 this.checkUpdatability();
03219
03220
03221 StringBuffer sb = new StringBuffer();
03222 sb.append("INSERT INTO ");
03223 sb.append(fields[0].getTableName());
03224 sb.append(" (");
03225 for (int i = 0; i < fields.length; ++i)
03226 {
03227 if (i > 0)
03228 sb.append(", ");
03229 sb.append(fields[i].getFieldName());
03230 }
03231 sb.append(") VALUES (");
03232 for (int i = 0; i < fields.length; ++i)
03233 {
03234 if (i > 0)
03235 sb.append(", ");
03236 sb.append("?");
03237 }
03238 sb.append(")");
03239
03240
03241 insertStatement = this.owningStatement.getConnection().prepareStatement(
03242 sb.toString());
03243 }
03244
03245
03246
03247
03248
03249
03250 private void buildRefreshStatement() throws SQLException
03251 {
03252
03253 this.checkUpdatability();
03254
03255
03256 StringBuffer sb = new StringBuffer();
03257 sb.append("SELECT ");
03258 for (int i = 0; i < fields.length; ++i)
03259 {
03260 if (i > 0)
03261 sb.append(", ");
03262 sb.append(fields[i].getFieldName());
03263 }
03264 sb.append(" FROM ");
03265 sb.append(fields[0].getTableName());
03266 sb.append(" WHERE ");
03267 for (int i = 0; i < primaryKeyColumns.length; ++i)
03268 {
03269 if (i > 0)
03270 sb.append(" AND ");
03271 sb.append(primaryKeyColumns[i]);
03272 sb.append(" = ?");
03273 }
03274
03275
03276 refreshStatement = this.owningStatement.getConnection().prepareStatement(
03277 sb.toString());
03278 }
03279
03280
03281
03282
03283
03284
03285 private void buildUpdateStatement() throws SQLException
03286 {
03287
03288 this.checkUpdatability();
03289
03290
03291 StringBuffer sb = new StringBuffer();
03292 sb.append("UPDATE ");
03293 sb.append(fields[0].getTableName());
03294 sb.append(" SET ");
03295 for (int i = 0; i < fields.length; ++i)
03296 {
03297 if (i > 0)
03298 sb.append(", ");
03299 sb.append(fields[i].getFieldName());
03300 sb.append(" = ?");
03301 }
03302 sb.append(" WHERE ");
03303 for (int i = 0; i < primaryKeyColumns.length; ++i)
03304 {
03305 if (i > 0)
03306 sb.append(" AND ");
03307 sb.append(primaryKeyColumns[i]);
03308 sb.append(" = ?");
03309 }
03310
03311
03312 updateStatement = this.owningStatement.getConnection().prepareStatement(
03313 sb.toString());
03314 }
03315
03316
03317
03318
03319
03320
03321 private void extractPrimaryKey() throws SQLException
03322 {
03323 ResultSet res = ((Connection) this.owningStatement.getConnection())
03324 .getPrimaryKeys(null, null, fields[0].getTableName());
03325
03326 try
03327 {
03328 primaryKeyColumns = new String[((DriverResultSet) res).nbOfRows];
03329 while (res.next())
03330 primaryKeyColumns[res.getRow() - 1] = res.getString(4);
03331 }
03332 finally
03333 {
03334
03335 res.close();
03336 }
03337 }
03338
03339
03340
03341
03342
03343
03344 private void checkUpdatability() throws SQLException
03345 {
03346
03347 switch (resultSetConcurrency)
03348 {
03349 case ResultSet.CONCUR_READ_ONLY :
03350 throw new SQLException("Cannot update ResultSet with "
03351 + "concurrency mode CONCUR_READ_ONLY");
03352 case ResultSet.CONCUR_UPDATABLE :
03353 break;
03354 default :
03355 throw new SQLException("Invalid ResultSet concurrency mode: "
03356 + resultSetConcurrency);
03357 }
03358
03359
03360 String tableName = fields[0].getTableName();
03361 for (int i = 1; i < nbOfColumns; ++i)
03362 if (!tableName.equals(fields[i].getTableName()))
03363 throw new SQLException(UPDATEABLE_MESSAGE);
03364
03365
03366 if (primaryKeyColumns == null)
03367 this.extractPrimaryKey();
03368
03369
03370 for (int i = 0; i < primaryKeyColumns.length; ++i)
03371 try
03372 {
03373 findColumn(primaryKeyColumns[i]);
03374 }
03375 catch (SQLException e)
03376 {
03377 throw new SQLException(UPDATEABLE_MESSAGE);
03378 }
03379 }
03380
03381
03382
03383
03384
03385
03386
03387 private void checkRowAndColPosAndSetNullFlag(int columnIndex)
03388 throws SQLException
03389 {
03390 checkIfClosed();
03391
03392 if (!inserting)
03393 checkRowPos();
03394
03395 if (fields == null)
03396 throw new java.sql.SQLException("Query generated no fields for ResultSet");
03397
03398 if (columnIndex < 1 || columnIndex > nbOfColumns)
03399 throw new java.sql.SQLException("Column Index out of range ( "
03400 + columnIndex + " > " + nbOfColumns + ").");
03401
03402 try
03403 {
03404 Object obj;
03405 if (inserting || updating)
03406 obj = tempRow[columnIndex - 1];
03407 else
03408 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
03409
03410 if (obj == null)
03411 wasNullFlag = true;
03412 else
03413 wasNullFlag = false;
03414 }
03415 catch (NullPointerException e)
03416 {
03417 wasNullFlag = true;
03418 }
03419 }
03420
03421
03422
03423
03424
03425
03426 private void checkRowPos() throws SQLException
03427 {
03428 if (currentRow < 0)
03429 throw new SQLException("Before start of result set");
03430
03431 if (currentRow == nbOfRows)
03432 throw new SQLException("After end of result set");
03433 }
03434
03435
03436
03437
03438
03439
03440
03441 private void checkUpdateFlagAndPrepareUpdateIfNeeded() throws SQLException
03442 {
03443 if (updating)
03444 return;
03445
03446 this.checkRowPos();
03447
03448 if (updateStatement == null)
03449 this.buildUpdateStatement();
03450
03451 tempRow = (Object[]) ((Object[]) data.get(currentRow)).clone();
03452
03453 for (int i = 0; i < nbOfColumns; ++i)
03454 updateStatement.setObject(i + 1, tempRow[i]);
03455
03456 updating = true;
03457 }
03458
03459
03460
03461
03462
03463
03464 private void checkIfClosed() throws SQLException
03465 {
03466 if (isClosed)
03467 throw new SQLException("Trying to access a closed ResultSet");
03468 }
03469
03470
03471
03472
03473
03474
03475
03476
03477
03478
03479
03480
03481
03482
03483
03484
03485
03486
03487 public java.net.URL getURL(int columnIndex) throws SQLException
03488 {
03489 throw new NotImplementedException("getURL");
03490 }
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503
03504
03505 public java.net.URL getURL(String columnName) throws SQLException
03506 {
03507 throw new NotImplementedException("getURL");
03508 }
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522 public void updateRef(int columnIndex, java.sql.Ref x) throws SQLException
03523 {
03524 throw new NotImplementedException("updateRef");
03525 }
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539 public void updateRef(String columnName, java.sql.Ref x) throws SQLException
03540 {
03541 throw new NotImplementedException("updateRef");
03542 }
03543
03544
03545
03546
03547
03548
03549
03550
03551
03552
03553
03554
03555
03556 public void updateBlob(int columnIndex, java.sql.Blob x) throws SQLException
03557 {
03558 throw new NotImplementedException("updateBlob");
03559 }
03560
03561
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571
03572
03573 public void updateBlob(String columnName, java.sql.Blob x)
03574 throws SQLException
03575 {
03576 throw new NotImplementedException("updateBlob");
03577 }
03578
03579
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591 public void updateClob(int columnIndex, java.sql.Clob x) throws SQLException
03592 {
03593 throw new NotImplementedException("updateClob");
03594 }
03595
03596
03597
03598
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608 public void updateClob(String columnName, java.sql.Clob x)
03609 throws SQLException
03610 {
03611 throw new NotImplementedException("updateClob");
03612 }
03613
03614
03615
03616
03617
03618
03619
03620
03621
03622
03623
03624
03625
03626 public void updateArray(int columnIndex, java.sql.Array x)
03627 throws SQLException
03628 {
03629 throw new NotImplementedException("updateArray");
03630 }
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644 public void updateArray(String columnName, java.sql.Array x)
03645 throws SQLException
03646 {
03647 throw new NotImplementedException("updateArray");
03648 }
03649
03650
03651
03652
03653
03654
03655
03656
03657 public byte getByte(int columnIndex) throws SQLException
03658 {
03659 checkRowAndColPosAndSetNullFlag(columnIndex);
03660
03661 if (wasNullFlag)
03662 return 0;
03663
03664 Object obj;
03665 if (inserting || updating)
03666 obj = tempRow[columnIndex - 1];
03667 else
03668 obj = ((Object[]) data.get(currentRow))[columnIndex - 1];
03669
03670 if (obj instanceof Number)
03671 {
03672 return ((Number) obj).byteValue();
03673 }
03674
03675
03676 try
03677 {
03678 String string = obj.toString();
03679 string = string.trim();
03680 return Byte.parseByte(string);
03681 }
03682 catch (NumberFormatException e)
03683 {
03684 throw new SQLException("the value " + obj.toString()
03685 + " is not a valid byte");
03686 }
03687 }
03688
03689
03690
03691
03692 public String toString()
03693 {
03694 return nbOfRows + " rows - " + nbOfColumns + " columns - current row:"
03695 + currentRow + " - hasMoreData:" + hasMoreData + " - isClosed:"
03696 + isClosed;
03697 }
03698 }