src/org/objectweb/cjdbc/driver/DriverResultSet.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.driver; 00026 00027 import java.io.ByteArrayInputStream; 00028 import java.io.InputStream; 00029 import java.math.BigDecimal; 00030 import java.math.BigInteger; 00031 import java.sql.SQLException; 00032 import java.sql.SQLWarning; 00033 import java.sql.Time; 00034 import java.sql.Timestamp; 00035 import java.util.ArrayList; 00036 import java.util.Calendar; 00037 import java.util.Hashtable; 00038 00039 import org.objectweb.cjdbc.common.sql.NotImplementedException; 00040 00091 public class DriverResultSet 00092 implements 00093 java.sql.ResultSet, 00094 java.io.Serializable, 00095 java.lang.Cloneable 00096 { 00098 protected int currentRow = -1; 00100 protected int nbOfRows = -1; 00102 protected int nbOfColumns = -1; 00104 protected ArrayList data; 00106 private boolean hasMoreData; 00108 protected int fetchDirection = FETCH_FORWARD; 00110 protected int fetchSize = 0; 00112 private String cursorName; 00113 00115 protected Field[] fields; 00117 protected boolean wasNullFlag = false; 00119 protected transient Hashtable columnNameToIndex = null; 00121 protected transient Hashtable fullColumnNameToIndex = null; 00122 00124 protected int resultSetType = 0; 00126 protected int resultSetConcurrency = 0; 00128 protected SQLWarning warnings = null; 00130 protected transient Statement owningStatement; 00131 00132 private boolean isClosed = true; 00133 00134 private static final String UPDATEABLE_MESSAGE = "ResultSet not updateable. The " 00135 + "query that generated this result set must select only one table, and must " 00136 + "select all primary keys from that table. See the JDBC 2.1 API Specification, " 00137 + "section 5.6 for more details."; 00138 00139 //--------------------------------------------------------------------- 00140 // Traversal/Positioning 00141 //--------------------------------------------------------------------- 00142 00155 public boolean next() throws java.sql.SQLException 00156 { 00157 checkIfClosed(); 00158 00159 if (nbOfRows == 0) 00160 return false; 00161 else 00162 { 00163 if (currentRow + 1 >= nbOfRows) 00164 { 00165 if (hasMoreData) 00166 { 00167 owningStatement.connection.fetchNextData(cursorName, fetchSize, this); 00168 currentRow = 0; 00169 if (data == null) 00170 { 00171 nbOfRows = 0; 00172 return false; 00173 } 00174 else 00175 { 00176 nbOfRows = data.size(); 00177 return true; 00178 } 00179 } 00180 // force scroll past end 00181 currentRow = nbOfRows; 00182 return false; 00183 } 00184 else 00185 { 00186 clearWarnings(); 00187 currentRow++; 00188 return true; 00189 } 00190 } 00191 } 00192 00205 public boolean prev() throws SQLException 00206 { 00207 checkIfClosed(); 00208 if (currentRow - 1 >= 0) 00209 { 00210 currentRow--; 00211 return true; 00212 } 00213 else 00214 return false; 00215 } 00216 00227 public boolean isBeforeFirst() throws SQLException 00228 { 00229 checkIfClosed(); 00230 if (nbOfRows == 0) 00231 return false; 00232 else 00233 return (currentRow == -1); 00234 } 00235 00246 public boolean isAfterLast() throws SQLException 00247 { 00248 checkIfClosed(); 00249 if (nbOfRows == 0) 00250 return false; 00251 else 00252 return (currentRow >= nbOfRows); 00253 } 00254 00264 public boolean isFirst() throws SQLException 00265 { 00266 checkIfClosed(); 00267 if (nbOfRows == 0) 00268 return false; 00269 else 00270 return (currentRow == 0); 00271 } 00272 00285 public boolean isLast() throws SQLException 00286 { 00287 checkIfClosed(); 00288 if (nbOfRows == 0) 00289 return false; 00290 else 00291 return (currentRow == nbOfRows - 1); 00292 } 00293 00303 public void beforeFirst() throws SQLException 00304 { 00305 checkIfClosed(); 00306 currentRow = -1; 00307 } 00308 00318 public void afterLast() throws SQLException 00319 { 00320 checkIfClosed(); 00321 if (nbOfRows != 0) 00322 currentRow = nbOfRows; 00323 } 00324 00335 public boolean first() throws SQLException 00336 { 00337 checkIfClosed(); 00338 if (nbOfRows == 0) 00339 return false; 00340 00341 currentRow = 0; 00342 return true; 00343 } 00344 00355 public boolean last() throws SQLException 00356 { 00357 checkIfClosed(); 00358 if (nbOfRows == 0) 00359 return false; 00360 00361 currentRow = nbOfRows - 1; 00362 return true; 00363 } 00364 00374 public int getRow() throws SQLException 00375 { 00376 checkIfClosed(); 00377 if (currentRow < 0 || currentRow >= nbOfRows || nbOfRows == 0) 00378 return 0; 00379 else 00380 return currentRow + 1; 00381 } 00382 00406 public boolean absolute(int row) throws SQLException 00407 { 00408 checkIfClosed(); 00409 if (nbOfRows == 0) 00410 return false; 00411 else 00412 { 00413 if (row == 0) 00414 throw new SQLException("Cannot absolute position to row 0"); 00415 00416 if (row == 1) 00417 return first(); 00418 else if (row == -1) 00419 return last(); 00420 else if (row > nbOfRows) 00421 { 00422 afterLast(); 00423 return false; 00424 } 00425 else 00426 { 00427 if (row < 0) 00428 { // adjust to reflect after end of result set 00429 int newRowPosition = nbOfRows + row + 1; 00430 00431 if (newRowPosition <= 0) 00432 { 00433 beforeFirst(); 00434 return false; 00435 } 00436 else 00437 return absolute(newRowPosition); 00438 } 00439 else 00440 { 00441 row--; // adjust for index difference 00442 currentRow = row; 00443 return true; 00444 } 00445 } 00446 } 00447 } 00448 00467 public boolean relative(int rows) throws SQLException 00468 { 00469 checkIfClosed(); 00470 if (nbOfRows == 0) 00471 return false; 00472 00473 return absolute(currentRow + rows + 1); 00474 } 00475 00488 public boolean previous() throws SQLException 00489 { 00490 return prev(); 00491 } 00492 00505 public void setFetchDirection(int direction) throws SQLException 00506 { 00507 if (direction != FETCH_FORWARD && direction != FETCH_REVERSE) 00508 throw new SQLException("Illegal value for fetch direction"); 00509 else 00510 fetchDirection = direction; 00511 } 00512 00519 public int getFetchDirection() throws SQLException 00520 { 00521 return fetchDirection; 00522 } 00523 00537 public void setFetchSize(int rows) throws SQLException 00538 { 00539 if (rows < 0 || rows > nbOfRows) 00540 throw new SQLException("Value must be between 0 and getMaxRows()"); 00541 fetchSize = rows; 00542 } 00543 00550 public int getFetchSize() throws SQLException 00551 { 00552 return fetchSize; 00553 } 00554 00555 // 00556 //--------------------------------------------------------------------- 00557 // Getter's and Setter's 00558 //--------------------------------------------------------------------- 00559 // 00560 00568 public String getString(int columnIndex) throws SQLException 00569 { 00570 checkRowAndColPosAndSetNullFlag(columnIndex); 00571 00572 if (wasNullFlag) 00573 return null; 00574 00575 return (((Object[]) data.get(currentRow))[columnIndex - 1]).toString(); 00576 } 00577 00585 public boolean getBoolean(int columnIndex) throws SQLException 00586 { 00587 checkRowAndColPosAndSetNullFlag(columnIndex); 00588 00589 if (wasNullFlag) 00590 return false; 00591 else 00592 { 00593 Object object = (((Object[]) data.get(currentRow))[columnIndex - 1]); 00594 String stringVal = object.toString(); 00595 00596 if ((stringVal != null) && (stringVal.length() > 0)) 00597 { 00598 stringVal = stringVal.toLowerCase(); 00599 00600 // first we check the connection values to be consistent 00601 if (owningStatement.connection.getPreparedStatementBooleanTrue() 00602 .equals(stringVal)) 00603 { 00604 return true; 00605 } 00606 else if (owningStatement.connection.getPreparedStatementBooleanFalse() 00607 .equals(stringVal)) 00608 { 00609 return false; 00610 } 00611 00612 // now we check some other possible string representations of boolean 00613 else if ("t".equals(stringVal)) 00614 { 00615 return true; 00616 } 00617 else if ("f".equals(stringVal)) 00618 { 00619 return false; 00620 } 00621 else if ("true".equals(stringVal)) 00622 { 00623 return true; 00624 } 00625 else if ("false".equals(stringVal)) 00626 { 00627 return false; 00628 } 00629 else if ("1".equals(stringVal)) 00630 { 00631 return true; 00632 } 00633 else if ("0".equals(stringVal)) 00634 { 00635 return false; 00636 } 00637 00638 else if ("y".equals(stringVal)) 00639 { 00640 return true; 00641 } 00642 else if ("n".equals(stringVal)) 00643 { 00644 return false; 00645 } 00646 else if ("yes".equals(stringVal)) 00647 { 00648 return true; 00649 } 00650 else if ("no".equals(stringVal)) 00651 { 00652 return false; 00653 } 00654 00655 // we didn't find anything reasonable and throw an exception 00656 throw new SQLException("column value " + stringVal 00657 + " could not be converted to boolean"); 00658 } 00659 else 00660 { 00661 return false; 00662 } 00663 } 00664 } 00665 00673 public short getShort(int columnIndex) throws SQLException 00674 { 00675 checkRowAndColPosAndSetNullFlag(columnIndex); 00676 00677 if (wasNullFlag) 00678 return 0; 00679 else 00680 { 00681 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00682 if (obj instanceof Number) 00683 { 00684 return ((Number) obj).shortValue(); 00685 } 00686 00687 // the object is not of type number we parse the string representation 00688 try 00689 { 00690 String string = obj.toString(); 00691 string = string.trim(); 00692 return Short.parseShort(string); 00693 } 00694 catch (NumberFormatException e) 00695 { 00696 throw new SQLException("the value " + obj.toString() 00697 + " is not a valid short number"); 00698 } 00699 } 00700 } 00701 00709 public int getInt(int columnIndex) throws SQLException 00710 { 00711 checkRowAndColPosAndSetNullFlag(columnIndex); 00712 00713 if (wasNullFlag) 00714 return 0; 00715 else 00716 { 00717 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00718 if (obj instanceof Number) 00719 { 00720 return ((Number) obj).intValue(); 00721 } 00722 00723 // the object is not of type number we parse the string representation 00724 try 00725 { 00726 String string = obj.toString(); 00727 string = string.trim(); 00728 return Integer.parseInt(string); 00729 } 00730 catch (NumberFormatException e) 00731 { 00732 throw new SQLException("the value " + obj.toString() 00733 + " is not a valid int number"); 00734 } 00735 } 00736 } 00737 00745 public long getLong(int columnIndex) throws SQLException 00746 { 00747 checkRowAndColPosAndSetNullFlag(columnIndex); 00748 00749 if (wasNullFlag) 00750 return 0; 00751 else 00752 { 00753 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00754 if (obj instanceof Number) 00755 { 00756 return ((Number) obj).longValue(); 00757 } 00758 00759 // the object is not of type number we parse the string representation 00760 try 00761 { 00762 String string = obj.toString(); 00763 string = string.trim(); 00764 return Long.parseLong(string); 00765 } 00766 catch (NumberFormatException e) 00767 { 00768 throw new SQLException("the value " + obj.toString() 00769 + " is not a valid long number"); 00770 } 00771 } 00772 } 00773 00781 public float getFloat(int columnIndex) throws SQLException 00782 { 00783 checkRowAndColPosAndSetNullFlag(columnIndex); 00784 00785 if (wasNullFlag) 00786 return 0; 00787 else 00788 { 00789 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00790 if (obj instanceof Number) 00791 { 00792 return ((Number) obj).floatValue(); 00793 } 00794 00795 // the object is not of type number we parse the string representation 00796 try 00797 { 00798 String string = obj.toString(); 00799 string = string.trim(); 00800 return Float.parseFloat(string); 00801 } 00802 catch (NumberFormatException e) 00803 { 00804 throw new SQLException("the value " + obj.toString() 00805 + " is not a valid float number"); 00806 } 00807 } 00808 } 00809 00817 public double getDouble(int columnIndex) throws SQLException 00818 { 00819 checkRowAndColPosAndSetNullFlag(columnIndex); 00820 00821 if (wasNullFlag) 00822 return 0; 00823 else 00824 { 00825 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00826 if (obj instanceof Number) 00827 { 00828 return ((Number) obj).doubleValue(); 00829 } 00830 00831 // the object is not of type number we parse the string representation 00832 try 00833 { 00834 String string = obj.toString(); 00835 string = string.trim(); 00836 return Double.parseDouble(string); 00837 } 00838 catch (NumberFormatException e) 00839 { 00840 throw new SQLException("the value " + obj.toString() 00841 + " is not a valid double number"); 00842 } 00843 } 00844 } 00845 00856 public BigDecimal getBigDecimal(int columnIndex, int scale) 00857 throws SQLException 00858 { 00859 BigDecimal bigDecimal = getBigDecimal(columnIndex); 00860 if (bigDecimal == null) 00861 return null; 00862 else 00863 return bigDecimal.setScale(scale); 00864 } 00865 00875 public byte[] getBytes(int columnIndex) throws SQLException 00876 { 00877 checkRowAndColPosAndSetNullFlag(columnIndex); 00878 00879 if (wasNullFlag) 00880 return null; 00881 00882 Object o = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00883 byte[] tmp; 00884 if (o instanceof java.lang.String) 00885 { 00886 tmp = ((String) o).getBytes(); 00887 } 00888 else 00889 { 00890 tmp = (byte[]) o; 00891 } 00892 //return Blob.rescapeblock(tmp); 00893 return owningStatement.connection.getBlobFilter().decode(tmp); 00894 } 00895 00903 public java.sql.Date getDate(int columnIndex) throws SQLException 00904 { 00905 checkRowAndColPosAndSetNullFlag(columnIndex); 00906 00907 if (wasNullFlag) 00908 { 00909 return null; 00910 } 00911 else 00912 { 00913 // we may be reading a timestamp column and have to convert it to date 00914 // the client is asking for the date field only, we have to make sure 00915 // hour,minutes,... are cleared 00916 String dateString = ((Object[]) data.get(currentRow))[columnIndex - 1] 00917 .toString(); 00918 if (dateString.length() == 10) 00919 return java.sql.Date.valueOf(dateString); 00920 else 00921 { 00922 return java.sql.Date.valueOf(dateString.substring(0, 10)); 00923 } 00924 } 00925 } 00926 00934 public Time getTime(int columnIndex) throws SQLException 00935 { 00936 checkRowAndColPosAndSetNullFlag(columnIndex); 00937 00938 if (wasNullFlag) 00939 return null; 00940 else 00941 { 00942 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00943 if (obj instanceof java.util.Date) 00944 { 00945 java.util.Date time = (java.util.Date) obj; 00946 // the driver returns the format of the column, but we are asking for 00947 // the 00948 // time values only. 00949 String timeString = time.toString(); 00950 if (timeString.length() == 8) 00951 { 00952 // ok we have got a timefield of the format HH:mm:ss, exactly the way 00953 // we 00954 // need it, no further processing is required 00955 return new Time(time.getTime()); 00956 } 00957 00958 // we have got the date fields too and have to clear the year, month and 00959 // date field 00960 Calendar cal = Calendar.getInstance(); 00961 cal.setTime(time); 00962 cal.clear(Calendar.YEAR); 00963 cal.clear(Calendar.MONTH); 00964 cal.clear(Calendar.DATE); 00965 cal.clear(Calendar.MILLISECOND); 00966 return new Time(cal.getTimeInMillis()); 00967 } 00968 // the object is not of type date we parse the string representation 00969 try 00970 { 00971 String string = obj.toString(); 00972 string = string.trim(); 00973 return Time.valueOf(string); 00974 } 00975 catch (IllegalArgumentException e) 00976 { 00977 throw new SQLException("the value " + obj.toString() 00978 + " is not a valid time"); 00979 } 00980 } 00981 } 00982 00990 public Timestamp getTimestamp(int columnIndex) throws SQLException 00991 { 00992 checkRowAndColPosAndSetNullFlag(columnIndex); 00993 00994 if (wasNullFlag) 00995 return null; 00996 else 00997 { 00998 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 00999 if (obj instanceof java.util.Date) 01000 { 01001 return new Timestamp(((java.util.Date) obj).getTime()); 01002 } 01003 01004 // the object is not of type timestamp we parse the string representation 01005 try 01006 { 01007 String string = obj.toString(); 01008 string = string.trim(); 01009 return Timestamp.valueOf(string); 01010 } 01011 catch (IllegalArgumentException e) 01012 { 01013 throw new SQLException("the value " + obj.toString() 01014 + " is not a valid timestamp"); 01015 } 01016 } 01017 } 01018 01037 public InputStream getAsciiStream(int columnIndex) throws SQLException 01038 { 01039 checkRowAndColPosAndSetNullFlag(columnIndex); 01040 01041 return getBinaryStream(columnIndex); 01042 } 01043 01057 public InputStream getUnicodeStream(int columnIndex) throws SQLException 01058 { 01059 checkRowAndColPosAndSetNullFlag(columnIndex); 01060 01061 return getBinaryStream(columnIndex); 01062 } 01063 01076 public InputStream getBinaryStream(int columnIndex) throws SQLException 01077 { 01078 checkRowAndColPosAndSetNullFlag(columnIndex); 01079 01080 byte b[] = getBytes(columnIndex); 01081 if (b != null) 01082 return new ByteArrayInputStream(b); 01083 else 01084 return null; // SQL NULL 01085 } 01086 01095 public String getString(String columnName) throws SQLException 01096 { 01097 return this.getString(findColumn(columnName)); 01098 } 01099 01103 public boolean getBoolean(String columnName) throws SQLException 01104 { 01105 return getBoolean(findColumn(columnName)); 01106 } 01107 01111 public byte getByte(String columnName) throws SQLException 01112 { 01113 return getByte(findColumn(columnName)); 01114 } 01115 01119 public short getShort(String columnName) throws SQLException 01120 { 01121 return getShort(findColumn(columnName)); 01122 } 01123 01127 public int getInt(String columnName) throws SQLException 01128 { 01129 return getInt(findColumn(columnName)); 01130 } 01131 01135 public long getLong(String columnName) throws SQLException 01136 { 01137 return getLong(findColumn(columnName)); 01138 } 01139 01143 public float getFloat(String columnName) throws SQLException 01144 { 01145 return getFloat(findColumn(columnName)); 01146 } 01147 01151 public double getDouble(String columnName) throws SQLException 01152 { 01153 return getDouble(findColumn(columnName)); 01154 } 01155 01160 public BigDecimal getBigDecimal(String columnName, int scale) 01161 throws SQLException 01162 { 01163 return getBigDecimal(findColumn(columnName), scale); 01164 } 01165 01169 public byte[] getBytes(String columnName) throws SQLException 01170 { 01171 return getBytes(findColumn(columnName)); 01172 } 01173 01177 public java.sql.Date getDate(String columnName) throws SQLException 01178 { 01179 return getDate(findColumn(columnName)); 01180 } 01181 01185 public Time getTime(String columnName) throws SQLException 01186 { 01187 return getTime(findColumn(columnName)); 01188 } 01189 01193 public Timestamp getTimestamp(String columnName) throws SQLException 01194 { 01195 return getTimestamp(findColumn(columnName)); 01196 } 01197 01201 public InputStream getAsciiStream(String columnName) throws SQLException 01202 { 01203 return getAsciiStream(findColumn(columnName)); 01204 } 01205 01210 public InputStream getUnicodeStream(String columnName) throws SQLException 01211 { 01212 return getUnicodeStream(findColumn(columnName)); 01213 } 01214 01218 public InputStream getBinaryStream(String columnName) throws SQLException 01219 { 01220 return getBinaryStream(findColumn(columnName)); 01221 } 01222 01236 public java.sql.SQLWarning getWarnings() throws SQLException 01237 { 01238 return warnings; 01239 } 01240 01248 public void clearWarnings() throws SQLException 01249 { 01250 warnings = null; 01251 } 01252 01270 public String getCursorName() throws SQLException 01271 { 01272 throw new NotImplementedException("getCursorName()"); 01273 } 01274 01289 public Object getObject(int columnIndex) throws SQLException 01290 { 01291 checkRowAndColPosAndSetNullFlag(columnIndex); 01292 01293 if (wasNullFlag) 01294 return null; 01295 else 01296 { 01297 Object o = ((Object[]) data.get(currentRow))[columnIndex - 1]; 01298 01299 if (o instanceof byte[]) 01300 return owningStatement.connection.getBlobFilter().decode((byte[]) o); 01301 else 01302 return o; 01303 } 01304 } 01305 01320 public Object getObject(String columnName) throws SQLException 01321 { 01322 return getObject(findColumn(columnName)); 01323 } 01324 01325 //--------------------------JDBC 2.0----------------------------------- 01326 01330 public java.io.Reader getCharacterStream(int columnIndex) throws SQLException 01331 { 01332 char[] data = getString(columnIndex).toCharArray(); 01333 return new java.io.CharArrayReader(data); 01334 } 01335 01339 public java.io.Reader getCharacterStream(String columnName) 01340 throws SQLException 01341 { 01342 return getCharacterStream(findColumn(columnName)); 01343 } 01344 01354 public BigDecimal getBigDecimal(int columnIndex) throws SQLException 01355 { 01356 checkRowAndColPosAndSetNullFlag(columnIndex); 01357 01358 if (wasNullFlag) 01359 return null; 01360 else 01361 { 01362 Object obj = ((Object[]) data.get(currentRow))[columnIndex - 1]; 01363 if (obj instanceof BigDecimal) 01364 return (BigDecimal) obj; 01365 else if (obj instanceof Long) 01366 { 01367 return new BigDecimal(((Long) obj).longValue()); 01368 } 01369 else if (obj instanceof BigInteger) 01370 { 01371 return new BigDecimal(((BigInteger) obj)); 01372 } 01373 else if (obj instanceof Short) 01374 { 01375 return new BigDecimal(((Short) obj).shortValue()); 01376 } 01377 else if (obj instanceof Integer) 01378 { 01379 return new BigDecimal(((Integer) obj).intValue()); 01380 } 01381 else if (obj instanceof String) 01382 { 01383 return new BigDecimal((String) obj); 01384 } 01385 else if (obj instanceof Number) 01386 { 01387 // float and double have to be converted via string 01388 // othwerwise we produce errors 01389 // javadoc for BigDecimal : 01390 // Note: the results of this constructor can be somewhat unpredictable. 01391 // One might assume that new BigDecimal(.1) is exactly equal to .1, but 01392 // it is actually equal to 01393 // .1000000000000000055511151231257827021181583404541015625. This is so 01394 // because .1 cannot be represented exactly as a double (or, for that 01395 // matter, as a binary fraction of any finite length). Thus, the long 01396 // value that is being passed in to the constructor is not exactly equal 01397 // to .1, appearances nonwithstanding. 01398 01399 // The (String) constructor, on the other hand, is perfectly 01400 // predictable: new BigDecimal(".1") is exactly equal to .1, as one 01401 // would expect. Therefore, it is generally recommended that the 01402 // (String) constructor be used in preference to this one. 01403 return new BigDecimal(obj.toString()); 01404 } 01405 else 01406 { 01407 throw new SQLException("Type " + obj.getClass().getName() 01408 + " is not compatible with BigDecimal"); 01409 } 01410 } 01411 } 01412 01416 public BigDecimal getBigDecimal(String columnName) throws SQLException 01417 { 01418 return getBigDecimal(findColumn(columnName)); 01419 } 01420 01431 public Object getObject(int i, java.util.Map map) throws SQLException 01432 { 01433 throw new NotImplementedException("getObject(int, java.util.Map)"); 01434 } 01435 01443 public java.sql.Ref getRef(int i) throws SQLException 01444 { 01445 throw new NotImplementedException("getRef"); 01446 } 01447 01455 public java.sql.Blob getBlob(int columnIndex) throws SQLException 01456 { 01457 checkRowAndColPosAndSetNullFlag(columnIndex); 01458 01459 if (wasNullFlag) 01460 return null; 01461 01462 Object o = (((Object[]) data.get(currentRow))[columnIndex - 1]); 01463 // Test if the type of the Blob is indeed a Blob else we assume these are 01464 // just bytes. 01465 if (o instanceof Blob) 01466 return (java.sql.Blob) o; 01467 else 01468 return new Blob(getBytes(columnIndex)); 01469 } 01470 01478 public java.sql.Clob getClob(int columnIndex) throws SQLException 01479 { 01480 checkRowAndColPosAndSetNullFlag(columnIndex); 01481 01482 if (wasNullFlag) 01483 return null; 01484 Object o = (((Object[]) data.get(currentRow))[columnIndex - 1]); 01485 // Test if the type of the Clob is indeed a Clob or just a String 01486 //throw new SQLException("Class:"+o.getClass()); 01487 if (o instanceof String) 01488 return new Clob((String) o); 01489 else if (o instanceof Clob) 01490 return (java.sql.Clob) o; 01491 else 01492 return new Clob(new String(o.toString())); 01493 } 01494 01502 public java.sql.Array getArray(int columnIndex) throws SQLException 01503 { 01504 checkRowAndColPosAndSetNullFlag(columnIndex); 01505 01506 if (wasNullFlag) 01507 return null; 01508 01509 return (java.sql.Array) (((Object[]) data.get(currentRow))[columnIndex - 1]); 01510 } 01511 01522 public Object getObject(String colName, java.util.Map map) 01523 throws SQLException 01524 { 01525 throw new NotImplementedException("getObject(String, java.util.Map)"); 01526 } 01527 01535 public java.sql.Ref getRef(String colName) throws SQLException 01536 { 01537 throw new NotImplementedException("getRef(String)"); 01538 } 01539 01547 public java.sql.Blob getBlob(String colName) throws SQLException 01548 { 01549 return getBlob(findColumn(colName)); 01550 } 01551 01559 public java.sql.Clob getClob(String colName) throws SQLException 01560 { 01561 return getClob(findColumn(colName)); 01562 } 01563 01571 public java.sql.Array getArray(String colName) throws SQLException 01572 { 01573 return getArray(findColumn(colName)); 01574 } 01575 01586 public java.sql.Date getDate(int columnIndex, Calendar cal) 01587 throws SQLException 01588 { 01589 throw new NotImplementedException("getDate(int, Calendar)"); 01590 } 01591 01602 public java.sql.Date getDate(String columnName, Calendar cal) 01603 throws SQLException 01604 { 01605 throw new NotImplementedException("getDate(String, Calendar)"); 01606 } 01607 01618 public java.sql.Time getTime(int columnIndex, Calendar cal) 01619 throws SQLException 01620 { 01621 throw new NotImplementedException("getTime(int, Calendar)"); 01622 } 01623 01634 public java.sql.Time getTime(String columnName, Calendar cal) 01635 throws SQLException 01636 { 01637 throw new NotImplementedException("getTime(String, Calendar)"); 01638 } 01639 01651 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) 01652 throws SQLException 01653 { 01654 throw new NotImplementedException("getTimestamp(int, Calendar)"); 01655 } 01656 01668 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) 01669 throws SQLException 01670 { 01671 throw new NotImplementedException("getTimestamp(String, Calendar)"); 01672 } 01673 01674 //--------------------------------------------------------------------- 01675 // Updates 01676 //--------------------------------------------------------------------- 01677 01687 public boolean rowUpdated() throws SQLException 01688 { 01689 throw new NotImplementedException("rowUpdated"); 01690 } 01691 01700 public boolean rowInserted() throws SQLException 01701 { 01702 throw new NotImplementedException("rowInserted"); 01703 } 01704 01715 public boolean rowDeleted() throws SQLException 01716 { 01717 throw new NotImplementedException("rowDeleted"); 01718 } 01719 01729 public void updateNull(int columnIndex) throws SQLException 01730 { 01731 throw new NotImplementedException("updateNull"); 01732 } 01733 01745 public void updateBoolean(int columnIndex, boolean x) throws SQLException 01746 { 01747 throw new NotImplementedException("updateBoolean"); 01748 } 01749 01760 public void updateByte(int columnIndex, byte x) throws SQLException 01761 { 01762 throw new NotImplementedException("updateByte"); 01763 } 01764 01775 public void updateShort(int columnIndex, short x) throws SQLException 01776 { 01777 throw new NotImplementedException("updateShort"); 01778 } 01779 01790 public void updateInt(int columnIndex, int x) throws SQLException 01791 { 01792 throw new NotImplementedException("updateInt"); 01793 } 01794 01805 public void updateLong(int columnIndex, long x) throws SQLException 01806 { 01807 throw new NotImplementedException("updateLong"); 01808 } 01809 01820 public void updateFloat(int columnIndex, float x) throws SQLException 01821 { 01822 throw new NotImplementedException("updateFloat"); 01823 } 01824 01835 public void updateDouble(int columnIndex, double x) throws SQLException 01836 { 01837 throw new NotImplementedException("updateDouble"); 01838 } 01839 01850 public void updateBigDecimal(int columnIndex, BigDecimal x) 01851 throws SQLException 01852 { 01853 throw new NotImplementedException("updateBigDecimal"); 01854 } 01855 01866 public void updateString(int columnIndex, String x) throws SQLException 01867 { 01868 throw new NotImplementedException("updateString"); 01869 } 01870 01881 public void updateBytes(int columnIndex, byte x[]) throws SQLException 01882 { 01883 throw new NotImplementedException("updateBytes"); 01884 } 01885 01896 public void updateDate(int columnIndex, java.sql.Date x) throws SQLException 01897 { 01898 throw new NotImplementedException("updateDate"); 01899 } 01900 01911 public void updateTime(int columnIndex, java.sql.Time x) throws SQLException 01912 { 01913 throw new NotImplementedException("updateTime"); 01914 } 01915 01926 public void updateTimestamp(int columnIndex, java.sql.Timestamp x) 01927 throws SQLException 01928 { 01929 throw new NotImplementedException("updateTimestamp"); 01930 } 01931 01943 public void updateAsciiStream(int columnIndex, java.io.InputStream x, 01944 int length) throws SQLException 01945 { 01946 throw new NotImplementedException("updateAsciiStream"); 01947 } 01948 01960 public void updateBinaryStream(int columnIndex, java.io.InputStream x, 01961 int length) throws SQLException 01962 { 01963 throw new NotImplementedException("updateBinaryStream"); 01964 } 01965 01977 public void updateCharacterStream(int columnIndex, java.io.Reader x, 01978 int length) throws SQLException 01979 { 01980 throw new NotImplementedException("updateCharacterStream"); 01981 } 01982 01996 public void updateObject(int columnIndex, Object x, int scale) 01997 throws SQLException 01998 { 01999 throw new NotImplementedException("updateObject"); 02000 } 02001 02012 public void updateObject(int columnIndex, Object x) throws SQLException 02013 { 02014 throw new NotImplementedException("updateObject"); 02015 } 02016 02027 public void updateNull(String columnName) throws SQLException 02028 { 02029 throw new NotImplementedException("updateNull"); 02030 } 02031 02042 public void updateBoolean(String columnName, boolean x) throws SQLException 02043 { 02044 throw new NotImplementedException("updateBoolean"); 02045 } 02046 02057 public void updateByte(String columnName, byte x) throws SQLException 02058 { 02059 throw new NotImplementedException("updateByte"); 02060 } 02061 02072 public void updateShort(String columnName, short x) throws SQLException 02073 { 02074 throw new NotImplementedException("updateShort"); 02075 } 02076 02087 public void updateInt(String columnName, int x) throws SQLException 02088 { 02089 throw new NotImplementedException("updateInt"); 02090 } 02091 02102 public void updateLong(String columnName, long x) throws SQLException 02103 { 02104 throw new NotImplementedException("updateLong"); 02105 } 02106 02117 public void updateFloat(String columnName, float x) throws SQLException 02118 { 02119 throw new NotImplementedException("updateFloat"); 02120 } 02121 02132 public void updateDouble(String columnName, double x) throws SQLException 02133 { 02134 throw new NotImplementedException("updateDouble"); 02135 } 02136 02147 public void updateBigDecimal(String columnName, BigDecimal x) 02148 throws SQLException 02149 { 02150 throw new NotImplementedException("updateBigDecimal"); 02151 } 02152 02163 public void updateString(String columnName, String x) throws SQLException 02164 { 02165 throw new NotImplementedException("updateString"); 02166 } 02167 02178 public void updateBytes(String columnName, byte x[]) throws SQLException 02179 { 02180 throw new NotImplementedException("updateBytes"); 02181 } 02182 02193 public void updateDate(String columnName, java.sql.Date x) 02194 throws SQLException 02195 { 02196 throw new NotImplementedException("updateDate"); 02197 } 02198 02209 public void updateTime(String columnName, java.sql.Time x) 02210 throws SQLException 02211 { 02212 throw new NotImplementedException("updateTime"); 02213 } 02214 02225 public void updateTimestamp(String columnName, java.sql.Timestamp x) 02226 throws SQLException 02227 { 02228 throw new NotImplementedException("updateTimestamp"); 02229 } 02230 02242 public void updateAsciiStream(String columnName, java.io.InputStream x, 02243 int length) throws SQLException 02244 { 02245 throw new NotImplementedException("updateAsciiStream"); 02246 } 02247 02259 public void updateBinaryStream(String columnName, java.io.InputStream x, 02260 int length) throws SQLException 02261 { 02262 throw new NotImplementedException("updateBinaryStream"); 02263 } 02264 02276 public void updateCharacterStream(String columnName, java.io.Reader reader, 02277 int length) throws SQLException 02278 { 02279 throw new NotImplementedException("updateCharacterStream"); 02280 } 02281 02295 public void updateObject(String columnName, Object x, int scale) 02296 throws SQLException 02297 { 02298 throw new NotImplementedException("updateObject"); 02299 } 02300 02311 public void updateObject(String columnName, Object x) throws SQLException 02312 { 02313 throw new NotImplementedException("updateObject"); 02314 } 02315 02324 public void insertRow() throws SQLException 02325 { 02326 throw new NotImplementedException("insertRow"); 02327 } 02328 02336 public void updateRow() throws SQLException 02337 { 02338 throw new NotImplementedException("updateRow"); 02339 } 02340 02348 public void deleteRow() throws SQLException 02349 { 02350 throw new NotImplementedException("deleteRow"); 02351 } 02352 02369 public void refreshRow() throws SQLException 02370 { 02371 throw new NotImplementedException("refreshRow"); 02372 } 02373 02383 public void cancelRowUpdates() throws SQLException 02384 { 02385 throw new NotImplementedException("cancelRowUpdates"); 02386 } 02387 02402 public void moveToInsertRow() throws SQLException 02403 { 02404 throw new NotImplementedException("moveToInsertRow"); 02405 } 02406 02414 public void moveToCurrentRow() throws SQLException 02415 { 02416 throw new NotImplementedException("moveToCurrentRow"); 02417 } 02418 02419 // 02420 // ------------------------------------------ 02421 // ResultSet meta-data related functions 02422 // ------------------------------------------ 02423 // 02424 02433 public int getType() throws SQLException 02434 { 02435 return resultSetType; 02436 } 02437 02446 public int getConcurrency() throws SQLException 02447 { 02448 return CONCUR_READ_ONLY; 02449 } 02450 02457 public void close() throws SQLException 02458 { 02459 if (hasMoreData) 02460 owningStatement.connection.closeRemoteResultSet(cursorName); 02461 isClosed = true; 02462 } 02463 02474 public boolean wasNull() throws SQLException 02475 { 02476 return wasNullFlag; 02477 } 02478 02488 public java.sql.Statement getStatement() throws SQLException 02489 { 02490 return owningStatement; 02491 } 02492 02498 protected void setResultSetType(int typeFlag) 02499 { 02500 resultSetType = typeFlag; 02501 } 02502 02508 protected void setResultSetConcurrency(int concurrencyFlag) 02509 { 02510 resultSetConcurrency = concurrencyFlag; 02511 // Issue warning is asked for updateable result set, but result set is not 02512 // updatable 02513 if (concurrencyFlag == CONCUR_UPDATABLE) 02514 warnings = new java.sql.SQLWarning(UPDATEABLE_MESSAGE); 02515 } 02516 02525 protected void setData(ArrayList newData) 02526 { 02527 data = newData; 02528 } 02529 02536 protected void setHasMoreData(boolean hasMore) 02537 { 02538 hasMoreData = hasMore; 02539 } 02540 02548 public java.sql.ResultSetMetaData getMetaData() throws SQLException 02549 { 02550 return new ResultSetMetaData(this); 02551 } 02552 02561 public int findColumn(String columnName) throws SQLException 02562 { 02563 if (columnNameToIndex == null) 02564 buildIndexMapping(); 02565 02566 Integer index = (Integer) columnNameToIndex.get(columnName); 02567 02568 if (index == null) 02569 index = (Integer) fullColumnNameToIndex.get(columnName); 02570 02571 if (index != null) 02572 return index.intValue() + 1; 02573 else 02574 { 02575 // Try this inefficient way, now 02576 String columnNameUC = columnName.toUpperCase(); 02577 for (int i = 0; i < nbOfColumns; i++) 02578 { 02579 if (fields[i].getFieldName().toUpperCase().equals(columnNameUC)) 02580 return i + 1; 02581 else if (fields[i].getFullName().toUpperCase().equals(columnNameUC)) 02582 return i + 1; 02583 } 02584 throw new java.sql.SQLException("Column '" + columnName + "' not found."); 02585 } 02586 } 02587 02588 // **************************************************************** 02589 // 02590 // END OF PUBLIC INTERFACE 02591 // 02592 // **************************************************************** 02593 02601 public DriverResultSet(Field[] fields, ArrayList resultData) 02602 { 02603 currentRow = -1; 02604 this.fields = fields; 02605 data = resultData; 02606 if (data == null) 02607 nbOfRows = 0; 02608 else 02609 nbOfRows = data.size(); 02610 nbOfColumns = fields.length; 02611 isClosed = false; 02612 } 02613 02625 public DriverResultSet(Field[] fields, ArrayList resultData, 02626 boolean crsHasMoreData, String cursorName) 02627 { 02628 this(fields, resultData); 02629 this.cursorName = cursorName; 02630 hasMoreData = crsHasMoreData; 02631 } 02632 02639 protected void setStatement(Statement stmt) throws SQLException 02640 { 02641 owningStatement = stmt; 02642 fetchSize = stmt.getFetchSize(); 02643 } 02644 02648 private void buildIndexMapping() 02649 { 02650 int numFields = nbOfColumns; 02651 02652 columnNameToIndex = new Hashtable(); 02653 fullColumnNameToIndex = new Hashtable(); 02654 02655 for (int i = 0; i < numFields; i++) 02656 { 02657 Integer index = new Integer(i); 02658 02659 String columnName = fields[i].getFieldName(); 02660 String fullColumnName = fields[i].getFullName(); 02661 if (columnName != null) 02662 { 02663 columnNameToIndex.put(fields[i].getFieldName(), index); 02664 columnNameToIndex.put(fields[i].getFieldName().toUpperCase(), index); 02665 columnNameToIndex.put(fields[i].getFieldName().toLowerCase(), index); 02666 } 02667 02668 if (fullColumnName != null) 02669 { 02670 fullColumnNameToIndex.put(fields[i].getFullName(), index); 02671 fullColumnNameToIndex.put(fields[i].getFullName().toUpperCase(), index); 02672 fullColumnNameToIndex.put(fields[i].getFullName().toLowerCase(), index); 02673 } 02674 } 02675 } 02676 02683 private void checkRowAndColPosAndSetNullFlag(int columnIndex) 02684 throws SQLException 02685 { 02686 checkIfClosed(); 02687 02688 if (currentRow < 0) 02689 throw new SQLException("Before start of result set"); 02690 02691 if (currentRow == nbOfRows) 02692 throw new SQLException("After end of result set"); 02693 02694 if (fields == null) 02695 throw new java.sql.SQLException("Query generated no fields for ResultSet"); 02696 02697 if (columnIndex < 1 || columnIndex > nbOfColumns) 02698 throw new java.sql.SQLException("Column Index out of range ( " 02699 + columnIndex + " > " + nbOfColumns + ")."); 02700 02701 try 02702 { 02703 if (((Object[]) data.get(currentRow))[columnIndex - 1] == null) 02704 wasNullFlag = true; 02705 else 02706 wasNullFlag = false; 02707 } 02708 catch (NullPointerException e) 02709 { 02710 wasNullFlag = true; 02711 } 02712 } 02713 02719 private void checkIfClosed() throws SQLException 02720 { 02721 if (isClosed) 02722 throw new SQLException("Trying to access a closed ResultSet"); 02723 } 02724 02725 //-------------------------- JDBC 3.0 02726 // ---------------------------------------- 02727 02742 public java.net.URL getURL(int columnIndex) throws SQLException 02743 { 02744 throw new NotImplementedException("getURL"); 02745 } 02746 02760 public java.net.URL getURL(String columnName) throws SQLException 02761 { 02762 throw new NotImplementedException("getURL"); 02763 } 02764 02777 public void updateRef(int columnIndex, java.sql.Ref x) throws SQLException 02778 { 02779 throw new NotImplementedException("updateRef"); 02780 } 02781 02794 public void updateRef(String columnName, java.sql.Ref x) throws SQLException 02795 { 02796 throw new NotImplementedException("updateRef"); 02797 } 02798 02811 public void updateBlob(int columnIndex, java.sql.Blob x) throws SQLException 02812 { 02813 throw new NotImplementedException("updateBlob"); 02814 } 02815 02828 public void updateBlob(String columnName, java.sql.Blob x) 02829 throws SQLException 02830 { 02831 throw new NotImplementedException("updateBlob"); 02832 } 02833 02846 public void updateClob(int columnIndex, java.sql.Clob x) throws SQLException 02847 { 02848 throw new NotImplementedException("updateClob"); 02849 } 02850 02863 public void updateClob(String columnName, java.sql.Clob x) 02864 throws SQLException 02865 { 02866 throw new NotImplementedException("updateClob"); 02867 } 02868 02881 public void updateArray(int columnIndex, java.sql.Array x) 02882 throws SQLException 02883 { 02884 throw new NotImplementedException("updateArray"); 02885 } 02886 02899 public void updateArray(String columnName, java.sql.Array x) 02900 throws SQLException 02901 { 02902 throw new NotImplementedException("updateArray"); 02903 } 02904 02912 public byte getByte(int columnIndex) throws SQLException 02913 { 02914 checkRowAndColPosAndSetNullFlag(columnIndex); 02915 02916 if (wasNullFlag) 02917 return 0; 02918 else 02919 return ((Byte) (((Object[]) data.get(currentRow))[columnIndex - 1])) 02920 .byteValue(); 02921 } 02922 02926 public String toString() 02927 { 02928 return nbOfRows + " rows - " + nbOfColumns + " columns - current row:" 02929 + currentRow + " - hasMoreData:" + hasMoreData + " - isClosed:" 02930 + isClosed; 02931 } 02932 }

CJDBCversion1.0.4に対してTue Oct 12 15:16:05 2004に生成されました。 doxygen 1.3.8