1 21 22 package org.apache.derby.impl.jdbc; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.jdbc.EngineResultSet; 29 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 30 import org.apache.derby.iapi.sql.conn.StatementContext; 31 32 import org.apache.derby.iapi.sql.ResultSet; 33 import org.apache.derby.iapi.sql.ParameterValueSet; 34 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 35 import org.apache.derby.iapi.sql.execute.ExecCursorTableReference; 36 import org.apache.derby.iapi.sql.execute.ExecRow; 37 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 38 import org.apache.derby.impl.sql.execute.ScrollInsensitiveResultSet; 39 40 import org.apache.derby.iapi.sql.Activation; 41 import org.apache.derby.iapi.sql.execute.CursorActivation; 42 43 import org.apache.derby.iapi.types.DataTypeDescriptor; 44 import org.apache.derby.iapi.types.DataValueDescriptor; 45 import org.apache.derby.iapi.types.RawToBinaryFormatStream; 46 import org.apache.derby.iapi.types.ReaderToUTF8Stream; 47 import org.apache.derby.iapi.types.UserDataValue; 48 import org.apache.derby.iapi.types.VariableSizeDataValue; 49 import org.apache.derby.iapi.sql.ResultDescription; 50 import org.apache.derby.iapi.services.io.StreamStorable; 51 52 import org.apache.derby.iapi.services.io.LimitInputStream; 53 import org.apache.derby.iapi.services.io.NewByteArrayInputStream; 54 import org.apache.derby.iapi.services.io.LimitReader; 55 import org.apache.derby.iapi.error.ExceptionSeverity; 56 import org.apache.derby.iapi.reference.JDBC20Translation; 57 import org.apache.derby.iapi.reference.JDBC30Translation; 58 import org.apache.derby.iapi.reference.SQLState; 59 import org.apache.derby.iapi.util.StringUtil; 60 import org.apache.derby.iapi.util.ReuseFactory; 61 62 65 import java.sql.Blob ; 66 import java.sql.Clob ; 67 import java.sql.Statement ; 68 import java.sql.SQLException ; 69 import java.sql.SQLWarning ; 70 import java.sql.ResultSetMetaData ; 71 import java.sql.Date ; 72 import java.sql.Time ; 73 import java.sql.Timestamp ; 74 import java.sql.Types ; 75 76 import java.io.Reader ; 77 import java.io.InputStream ; 78 import java.io.IOException ; 79 import java.net.URL ; 80 81 import java.util.Map ; 82 import java.util.HashMap ; 83 import java.util.Arrays ; 84 import java.util.Calendar ; 85 86 94 95 public abstract class EmbedResultSet extends ConnectionChild 96 implements EngineResultSet, Comparable { 97 98 protected static final int FIRST = 1; 100 protected static final int NEXT = 2; 101 protected static final int LAST = 3; 102 protected static final int PREVIOUS = 4; 103 protected static final int BEFOREFIRST = 5; 104 protected static final int AFTERLAST = 6; 105 protected static final int ABSOLUTE = 7; 106 protected static final int RELATIVE = 8; 107 108 113 private final ExecRow currentRow; 114 protected boolean wasNull; 115 116 124 boolean isClosed; 125 126 private boolean isOnInsertRow; 127 private Object currentStream; 128 129 private ResultSet theResults; 131 private boolean forMetaData; 132 private ResultSetMetaData rMetaData; 133 private SQLWarning topWarning; 134 135 144 Activation singleUseActivation; 145 146 final int order; 148 149 150 private final ResultDescription resultDescription; 151 152 156 private Map columnNameMap; 157 158 private int maxRows; 160 private final int maxFieldSize; 162 163 168 private int NumberofFetchedRows; 169 170 171 176 private final EmbedStatement stmt; 177 178 186 private EmbedStatement owningStmt; 187 188 192 private Statement applicationStmt; 193 194 private long timeoutMillis; 195 196 private final boolean isAtomic; 197 198 private final int concurrencyOfThisResultSet; 199 200 204 private final ExecRow updateRow; 205 206 208 private boolean[] columnGotUpdated; 209 private boolean currentRowHasBeenUpdated; 211 private int fetchDirection; 212 private int fetchSize; 213 214 218 private boolean[] streamUsedFlags; 219 220 224 public EmbedResultSet(EmbedConnection conn, ResultSet resultsToWrap, 225 boolean forMetaData, EmbedStatement stmt, boolean isAtomic) 226 throws SQLException { 227 228 super(conn); 229 230 if (SanityManager.DEBUG) 231 SanityManager.ASSERT(resultsToWrap!=null); 232 theResults = resultsToWrap; 233 234 if (this.forMetaData = forMetaData) 238 singleUseActivation = resultsToWrap.getActivation(); 239 this.applicationStmt = this.stmt = owningStmt = stmt; 240 241 this.timeoutMillis = stmt == null 242 ? 0L 243 : (long)stmt.getQueryTimeout() * 1000L; 244 245 this.isAtomic = isAtomic; 246 247 248 if (stmt == null) 254 concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY; 255 else if (stmt.getResultSetConcurrency() == JDBC20Translation.CONCUR_READ_ONLY) 256 concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY; 257 else { 258 if (!isForUpdate()) { concurrencyOfThisResultSet = JDBC20Translation.CONCUR_READ_ONLY; 260 SQLWarning w = StandardException.newWarning(SQLState.QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET); 261 addWarning(w); 262 } else 263 concurrencyOfThisResultSet = JDBC20Translation.CONCUR_UPDATABLE; 264 } 265 266 resultDescription = theResults.getResultDescription(); 268 final ExecutionFactory factory = conn.getLanguageConnection(). 269 getLanguageConnectionFactory().getExecutionFactory(); 270 final int columnCount = getMetaData().getColumnCount(); 271 this.currentRow = factory.getValueRow(columnCount); 272 this.columnNameMap = null; 273 currentRow.setRowArray(null); 274 275 if (concurrencyOfThisResultSet == JDBC20Translation.CONCUR_UPDATABLE) 278 { 279 columnGotUpdated = new boolean[columnCount]; 281 updateRow = factory.getValueRow(columnCount); 282 for (int i = 1; i <= columnCount; i++) { 283 updateRow.setColumn(i, resultDescription.getColumnDescriptor(i). 284 getType().getNull()); 285 } 286 initializeUpdateRowModifiers(); 287 } else { 288 updateRow = null; 289 } 290 291 if (stmt != null) 293 { 294 if (stmt.resultSetType == JDBC20Translation.TYPE_FORWARD_ONLY) 296 maxRows = stmt.maxRows; 297 298 maxFieldSize = stmt.MaxFieldSize; 299 } 300 else 301 maxFieldSize = 0; 302 303 order = conn.getResultSetOrderId(); 304 } 305 306 313 protected void finalize() throws Throwable { 314 super.finalize(); 315 316 if (singleUseActivation != null) { 317 singleUseActivation.markUnused(); 318 } 319 } 320 321 private void checkNotOnInsertRow() throws SQLException { 322 if (isOnInsertRow) { 323 throw newSQLException(SQLState.NO_CURRENT_ROW); 324 } 325 } 326 327 protected final void checkOnRow() throws SQLException 331 { 332 if (currentRow.getRowArray() == null) { 333 throw newSQLException(SQLState.NO_CURRENT_ROW); 334 } 335 } 336 337 340 private void initializeUpdateRowModifiers() { 341 currentRowHasBeenUpdated = false; 342 Arrays.fill(columnGotUpdated, false); 343 } 344 345 350 final int getColumnType(int columnIndex) throws SQLException { 351 if (!isOnInsertRow) checkOnRow(); 353 if (columnIndex < 1 || 354 columnIndex > resultDescription.getColumnCount()) 355 throw newSQLException(SQLState.COLUMN_NOT_FOUND, 356 new Integer (columnIndex)); 357 358 return resultDescription.getColumnDescriptor(columnIndex).getType().getJDBCTypeId(); 359 } 360 361 364 377 public boolean next() throws SQLException 378 { 379 if (maxRows !=0 ) 382 { 383 NumberofFetchedRows++; 384 if (NumberofFetchedRows > maxRows) 386 { 387 closeCurrentStream(); 389 return false; 390 } 391 } 392 return movePosition(NEXT, 0, "next"); 393 } 394 395 protected boolean movePosition(int position, String positionText) 396 throws SQLException 397 { 398 return movePosition(position, 0, positionText); 399 } 400 401 protected boolean movePosition(int position, int row, String positionText) 402 throws SQLException 403 { 404 closeCurrentStream(); 408 checkExecIfClosed(positionText); 412 if (isOnInsertRow) { 413 moveToCurrentRow(); 414 } 415 416 417 synchronized (getConnectionSynchronization()) { 418 419 setupContextStack(); 420 try { 421 LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection(); 422 final ExecRow newRow; 423 try { 424 425 430 StatementContext statementContext = 431 lcc.pushStatementContext(isAtomic, 432 concurrencyOfThisResultSet==JDBC20Translation.CONCUR_READ_ONLY, 433 getSQLText(), 434 getParameterValueSet(), 435 false, timeoutMillis); 436 437 switch (position) 438 { 439 case BEFOREFIRST: 440 newRow = theResults.setBeforeFirstRow(); 441 break; 442 443 case FIRST: 444 newRow = theResults.getFirstRow(); 445 break; 446 447 case NEXT: 448 newRow = theResults.getNextRow(); 449 break; 450 451 case LAST: 452 newRow = theResults.getLastRow(); 453 break; 454 455 case AFTERLAST: 456 newRow = theResults.setAfterLastRow(); 457 break; 458 459 case PREVIOUS: 460 newRow = theResults.getPreviousRow(); 461 break; 462 463 case ABSOLUTE: 464 newRow = theResults.getAbsoluteRow(row); 465 break; 466 467 case RELATIVE: 468 newRow = theResults.getRelativeRow(row); 469 break; 470 471 default: 472 newRow = null; 473 if (SanityManager.DEBUG) 474 { 475 SanityManager.THROWASSERT( 476 "Unexpected value for position - " + position); 477 } 478 } 479 480 lcc.popStatementContext(statementContext, null); 481 482 } catch (Throwable t) { 483 488 throw closeOnTransactionError(t); 489 } 490 491 SQLWarning w = theResults.getWarnings(); 492 if (w != null) { 493 if (topWarning == null) 494 topWarning = w; 495 else 496 topWarning.setNextWarning(w); 497 } 498 499 boolean onRow = (newRow!=null); 500 if (onRow) { 501 currentRow.setRowArray(newRow.getRowArray()); 502 } else { 503 currentRow.setRowArray(null); 504 } 505 506 507 510 if (!onRow && (position == NEXT)) { 514 515 if (forMetaData && (lcc.getActivationCount() > 1)) { 528 } else if (owningStmt != null && 531 owningStmt.getResultSetType() == TYPE_FORWARD_ONLY) { 532 owningStmt.resultSetClosing(this); 534 } 535 } 536 537 if (streamUsedFlags != null) 539 Arrays.fill(streamUsedFlags, false); 540 if (columnGotUpdated != null && currentRowHasBeenUpdated) { 541 initializeUpdateRowModifiers(); 542 } 543 544 return onRow; 545 } finally { 546 restoreContextStack(); 547 } 548 } 549 550 } 551 552 553 554 555 568 public void close() throws SQLException { 569 570 575 if (isClosed) 576 return; 577 578 closeCurrentStream(); 585 synchronized (getConnectionSynchronization()) { 588 589 try { 590 setupContextStack(); } catch (SQLException se) { 592 return; 596 } 597 598 try { 599 try { 600 theResults.finish(); 602 if (this.singleUseActivation != null) 603 { 604 this.singleUseActivation.close(); 605 this.singleUseActivation = null; 606 } 607 608 } catch (Throwable t) { 609 throw handleException(t); 610 } 611 612 if (forMetaData) { 624 625 LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection(); 626 if (lcc.getActivationCount() > 1) { 627 } else if (owningStmt != null) 630 owningStmt.resultSetClosing(this); 632 633 } else if (owningStmt != null) { 634 owningStmt.resultSetClosing(this); 636 } 637 638 } finally { 639 isClosed = true; 640 restoreContextStack(); 641 } 642 643 currentRow.setRowArray(null); 645 rMetaData = null; 647 } 650 651 } 652 653 667 public final boolean wasNull() throws SQLException { 668 checkIfClosed("wasNull"); 669 return wasNull; 670 } 671 672 676 683 public final String getString(int columnIndex) throws SQLException { 684 checkIfClosed("getString"); 685 686 try { 687 688 DataValueDescriptor dvd = getColumn(columnIndex); 689 690 if (wasNull = dvd.isNull()) 691 return null; 692 693 String value = dvd.getString(); 694 695 if (maxFieldSize > 0 && isMaxFieldSizeType(getColumnType(columnIndex))) 697 { 698 if (value.length() > maxFieldSize ) 699 { 700 value = value.substring(0, maxFieldSize); 701 } 702 } 703 704 return value; 705 706 } catch (Throwable t) { 707 throw noStateChangeException(t); 708 } 709 } 710 711 718 public final boolean getBoolean(int columnIndex) throws SQLException { 719 checkIfClosed("getBoolean"); 720 721 try { 722 723 DataValueDescriptor dvd = getColumn(columnIndex); 724 725 if (wasNull = dvd.isNull()) 726 return false; 727 728 return dvd.getBoolean(); 729 730 } catch (StandardException t) { 731 throw noStateChangeException(t); 732 } 733 } 734 735 742 public final byte getByte(int columnIndex) throws SQLException { 743 checkIfClosed("getByte"); 744 try { 745 746 DataValueDescriptor dvd = getColumn(columnIndex); 747 748 if (wasNull = dvd.isNull()) 749 return 0; 750 751 return dvd.getByte(); 752 753 } catch (StandardException t) { 754 throw noStateChangeException(t); 755 } 756 } 757 758 765 public final short getShort(int columnIndex) throws SQLException { 766 checkIfClosed("getShort"); 767 768 try { 769 770 DataValueDescriptor dvd = getColumn(columnIndex); 771 772 if (wasNull = dvd.isNull()) 773 return 0; 774 775 return dvd.getShort(); 776 777 } catch (StandardException t) { 778 throw noStateChangeException(t); 779 } 780 } 781 782 789 public final int getInt(int columnIndex) throws SQLException { 790 checkIfClosed("getInt"); 791 try { 792 793 DataValueDescriptor dvd = getColumn(columnIndex); 794 795 if (wasNull = dvd.isNull()) 796 return 0; 797 798 return dvd.getInt(); 799 800 } catch (StandardException t) { 801 throw noStateChangeException(t); 802 } 803 } 804 805 812 public final long getLong(int columnIndex) throws SQLException { 813 checkIfClosed("getLong"); 814 try { 815 816 DataValueDescriptor dvd = getColumn(columnIndex); 817 818 if (wasNull = dvd.isNull()) 819 return 0; 820 821 return dvd.getLong(); 822 823 } catch (StandardException t) { 824 throw noStateChangeException(t); 825 } 826 } 827 828 835 public final float getFloat(int columnIndex) throws SQLException { 836 checkIfClosed("getFloat"); 837 try { 838 839 DataValueDescriptor dvd = getColumn(columnIndex); 840 841 if (wasNull = dvd.isNull()) 842 return 0.0F; 843 844 return dvd.getFloat(); 845 846 } catch (StandardException t) { 847 throw noStateChangeException(t); 848 } 849 } 850 851 858 public final double getDouble(int columnIndex) throws SQLException { 859 checkIfClosed("getDouble"); 860 try { 861 862 DataValueDescriptor dvd = getColumn(columnIndex); 863 864 if (wasNull = dvd.isNull()) 865 return 0.0; 866 867 return dvd.getDouble(); 868 869 } catch (StandardException t) { 870 throw noStateChangeException(t); 871 } 872 } 873 874 882 public final byte[] getBytes(int columnIndex) throws SQLException { 883 checkIfClosed("getBytes"); 884 try { 885 886 DataValueDescriptor dvd = getColumn(columnIndex); 887 888 if (wasNull = dvd.isNull()) 889 return null; 890 891 byte[] value = dvd.getBytes(); 892 893 if (maxFieldSize > 0 && isMaxFieldSizeType(getColumnType(columnIndex))) 895 { 896 if (value.length > maxFieldSize) 897 { 898 byte [] limited_value = new byte[maxFieldSize]; 899 System.arraycopy(value, 0, limited_value, 900 0 , maxFieldSize); 901 value = limited_value; 902 } 903 } 904 905 return value; 906 907 } catch (StandardException t) { 908 throw noStateChangeException(t); 909 } 910 } 911 912 919 public final Date getDate(int columnIndex) throws SQLException { 920 return getDate( columnIndex, (Calendar ) null); 921 } 922 923 930 public final Time getTime(int columnIndex) throws SQLException { 931 return getTime( columnIndex, (Calendar ) null); 932 } 933 934 941 public final Timestamp getTimestamp(int columnIndex) throws SQLException { 942 return getTimestamp( columnIndex, (Calendar ) null); 943 } 944 945 958 public java.sql.Date getDate(int columnIndex, Calendar cal) 959 throws SQLException 960 { 961 checkIfClosed("getDate"); 962 try { 963 964 DataValueDescriptor dvd = getColumn(columnIndex); 965 966 if (wasNull = dvd.isNull()) 967 return null; 968 969 if( cal == null) 970 cal = getCal(); 971 972 return dvd.getDate( cal); 973 974 } catch (StandardException t) { 975 throw noStateChangeException(t); 976 } 977 } 978 979 992 public java.sql.Date getDate(String columnName, Calendar cal) 993 throws SQLException 994 { 995 checkIfClosed("getDate"); 996 return getDate( findColumnName(columnName), cal); 997 } 998 999 1012 public java.sql.Time getTime(int columnIndex, Calendar cal) 1013 throws SQLException 1014 { 1015 checkIfClosed("getTime"); 1016 try { 1017 1018 DataValueDescriptor dvd = getColumn(columnIndex); 1019 1020 if (wasNull = dvd.isNull()) 1021 return null; 1022 1023 if( cal == null) 1024 cal = getCal(); 1025 return dvd.getTime( cal); 1026 1027 } catch (StandardException t) { 1028 throw noStateChangeException(t); 1029 } 1030 } 1031 1032 1045 public java.sql.Time getTime(String columnName, Calendar cal) 1046 throws SQLException 1047 { 1048 checkIfClosed("getTime"); 1049 return getTime( findColumnName( columnName), cal); 1050 } 1051 1052 1065 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) 1066 throws SQLException 1067 { 1068 checkIfClosed("getTimestamp"); 1069 return getTimestamp(findColumnName(columnName), cal); 1070 } 1071 1072 1085 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) 1086 throws SQLException 1087 { 1088 checkIfClosed("getTimestamp"); 1089 try { 1090 1091 DataValueDescriptor dvd = getColumn(columnIndex); 1092 1093 if (wasNull = dvd.isNull()) 1094 return null; 1095 1096 if( cal == null) 1097 cal = getCal(); 1098 return dvd.getTimestamp( cal); 1099 1100 } catch (StandardException t) { 1101 throw noStateChangeException(t); 1102 } 1103 } 1104 1105 1112 public final java.io.Reader getCharacterStream(int columnIndex) 1113 throws SQLException 1114 { 1115 checkIfClosed("getCharacterStream"); 1116 int lmfs; 1117 int colType = getColumnType(columnIndex); 1118 switch (colType) { 1119 case Types.CHAR: 1120 case Types.VARCHAR: 1121 case Types.LONGVARCHAR: 1122 lmfs = maxFieldSize; 1123 break; 1124 case Types.CLOB: lmfs = 0; 1126 break; 1127 1128 case Types.BINARY: 1131 case Types.VARBINARY: 1132 case Types.LONGVARBINARY: 1133 case Types.BLOB: 1134 try { 1135 java.io.InputStream is = getBinaryStream(columnIndex); 1136 if (is == null) 1137 return null; 1138 java.io.Reader r = new java.io.InputStreamReader (is, "UTF-16BE"); 1139 currentStream = r; 1140 return r; 1141 } catch (java.io.UnsupportedEncodingException uee) { 1142 throw new SQLException (uee.getMessage()); 1143 } 1144 default: 1145 throw dataTypeConversion("java.io.Reader", columnIndex); 1146 } 1147 1148 Object syncLock = getConnectionSynchronization(); 1149 1150 synchronized (syncLock) { 1151 1152 boolean pushStack = false; 1153 try { 1154 1155 useStream(columnIndex); 1156 1157 DataValueDescriptor dvd = getColumn(columnIndex); 1158 1159 if (wasNull = dvd.isNull()) { return null; } 1160 1161 pushStack = true; 1162 setupContextStack(); 1163 1164 StreamStorable ss = (StreamStorable) dvd; 1165 1166 InputStream stream = ss.returnStream(); 1167 1168 if (stream == null) { 1169 1170 String val = dvd.getString(); 1171 if (lmfs > 0) { 1172 if (val.length() > lmfs) 1173 val = val.substring(0, lmfs); 1174 } 1175 java.io.Reader ret = new java.io.StringReader (val); 1176 currentStream = ret; 1177 return ret; 1178 } 1179 1180 java.io.Reader ret = new UTF8Reader(stream, lmfs, this, syncLock); 1181 currentStream = ret; 1182 return ret; 1183 1184 } catch (Throwable t) { 1185 throw noStateChangeException(t); 1186 } finally { 1187 if (pushStack) { restoreContextStack(); } 1188 } 1189 } 1190 } 1191 1192 1201 public final InputStream getAsciiStream(int columnIndex) throws SQLException { 1202 checkIfClosed("getAsciiStream"); 1203 int colType = getColumnType(columnIndex); 1204 switch (colType) { 1205 case Types.CHAR: 1206 case Types.VARCHAR: 1207 case Types.LONGVARCHAR: 1208 case Types.CLOB: break; 1210 1211 case Types.BINARY: 1213 case Types.VARBINARY: 1214 case Types.LONGVARBINARY: 1215 case Types.BLOB: 1216 return getBinaryStream(columnIndex); 1217 1218 default: 1219 throw dataTypeConversion("java.io.InputStream(ASCII)", columnIndex); 1220 } 1221 1222 java.io.Reader reader = getCharacterStream(columnIndex); 1223 if (reader == null) 1224 return null; 1225 1226 return new ReaderToAscii(reader); 1227 } 1228 1229 1240 public final InputStream getBinaryStream(int columnIndex) throws SQLException { 1241 checkIfClosed("getBinaryStream"); 1242 int lmfs; 1243 int colType = getColumnType(columnIndex); 1244 switch (colType) { 1245 case Types.BINARY: 1246 case Types.VARBINARY: 1247 case Types.LONGVARBINARY: 1248 lmfs = maxFieldSize; 1249 break; 1250 case Types.BLOB: 1251 lmfs = 0; 1252 break; 1253 1254 default: 1255 throw dataTypeConversion("java.io.InputStream", columnIndex); 1256 } 1257 1258 Object syncLock = getConnectionSynchronization(); 1259 1260 synchronized (syncLock) { 1261 1262 boolean pushStack = false; 1263 try { 1264 1265 useStream(columnIndex); 1266 1267 DataValueDescriptor dvd = getColumn(columnIndex); 1268 1269 if (wasNull = dvd.isNull()) { return null; } 1270 1271 pushStack = true; 1272 setupContextStack(); 1273 1274 StreamStorable ss = (StreamStorable) dvd; 1275 1276 InputStream stream = ss.returnStream(); 1277 1278 if (stream == null) 1279 { 1280 stream = new NewByteArrayInputStream(dvd.getBytes()); 1281 } else 1282 { 1283 stream = new BinaryToRawStream(stream, dvd); 1284 } 1285 1286 if (lmfs > 0) 1287 { 1288 LimitInputStream limitResultIn = new LimitInputStream(stream); 1290 limitResultIn.setLimit(lmfs); 1291 stream = limitResultIn; 1292 } 1293 currentStream = stream; 1294 return stream; 1295 1296 } catch (Throwable t) { 1297 throw noStateChangeException(t); 1298 } finally { 1299 if (pushStack) { restoreContextStack(); } 1300 } 1301 } 1302 } 1303 1304 1308 1309 1316 public final String getString(String columnName) throws SQLException { 1317 checkIfClosed("getString"); 1318 return (getString(findColumnName(columnName))); 1319 } 1320 1321 1328 public final boolean getBoolean(String columnName) throws SQLException { 1329 checkIfClosed("getBoolean"); 1330 return (getBoolean(findColumnName(columnName))); 1331 } 1332 1333 1340 public final byte getByte(String columnName) throws SQLException { 1341 checkIfClosed("getByte"); 1342 return (getByte(findColumnName(columnName))); 1343 } 1344 1345 1352 public final short getShort(String columnName) throws SQLException { 1353 checkIfClosed("getShort"); 1354 return (getShort(findColumnName(columnName))); 1355 } 1356 1357 1364 public final int getInt(String columnName) throws SQLException { 1365 checkIfClosed("getInt"); 1366 return (getInt(findColumnName(columnName))); 1367 } 1368 1369 1376 public final long getLong(String columnName) throws SQLException { 1377 checkIfClosed("getLong"); 1378 return (getLong(findColumnName(columnName))); 1379 } 1380 1381 1388 public final float getFloat(String columnName) throws SQLException { 1389 checkIfClosed("getFloat"); 1390 return (getFloat(findColumnName(columnName))); 1391 } 1392 1393 1400 public final double getDouble(String columnName) throws SQLException { 1401 checkIfClosed("getDouble"); 1402 return (getDouble(findColumnName(columnName))); 1403 } 1404 1405 1413 public final byte[] getBytes(String columnName) throws SQLException { 1414 checkIfClosed("getBytes"); 1415 return (getBytes(findColumnName(columnName))); 1416 } 1417 1418 1425 public final Date getDate(String columnName) throws SQLException { 1426 checkIfClosed("getDate"); 1427 return (getDate(findColumnName(columnName))); 1428 } 1429 1430 1437 public final Time getTime(String columnName) throws SQLException { 1438 checkIfClosed("getTime"); 1439 return (getTime(findColumnName(columnName))); 1440 } 1441 1442 1449 public final Timestamp getTimestamp(String columnName) throws SQLException { 1450 checkIfClosed("getTimestamp"); 1451 return (getTimestamp(findColumnName(columnName))); 1452 } 1453 1454 1461 public final java.io.Reader getCharacterStream(String columnName) 1462 throws SQLException { 1463 checkIfClosed("getCharacterStream"); 1464 return (getCharacterStream(findColumnName(columnName))); 1465 } 1466 1467 1483 public final InputStream getAsciiStream(String columnName) throws SQLException { 1484 checkIfClosed("getAsciiStream"); 1485 return (getAsciiStream(findColumnName(columnName))); 1486 } 1487 1488 1503 public final InputStream getBinaryStream(String columnName) throws SQLException { 1504 checkIfClosed("getBinaryStream"); 1505 return (getBinaryStream(findColumnName(columnName))); 1506 } 1507 1508 1522 public URL getURL(int columnIndex) throws SQLException { 1523 throw Util.notImplemented(); 1524 } 1525 1526 1540 public URL getURL(String columnName) throws SQLException { 1541 throw Util.notImplemented(); 1542 } 1543 1544 1548 1565 public final SQLWarning getWarnings() throws SQLException { 1566 checkIfClosed("getWarnings"); 1567 return topWarning; 1568 } 1569 1570 1576 public final void clearWarnings() throws SQLException { 1577 checkIfClosed("clearWarnings"); 1578 topWarning = null; 1579 } 1580 1581 1599 public final String getCursorName() throws SQLException { 1600 1601 checkIfClosed("getCursorName"); 1605 return theResults.getCursorName(); 1606 } 1607 1608 1615 public ResultSetMetaData getMetaData() throws SQLException { 1616 1617 checkIfClosed("getMetaData"); 1621 synchronized (getConnectionSynchronization()) { 1622 1623 1624 if (rMetaData == null) { 1625 rMetaData = newEmbedResultSetMetaData(resultDescription); 1627 } 1628 return rMetaData; 1629 } 1630 } 1631 1632 1644 public final int getHoldability() throws SQLException { 1645 checkIfClosed("getHoldability"); 1646 if (theResults.getActivation().getResultSetHoldability()) { 1647 return JDBC30Translation.HOLD_CURSORS_OVER_COMMIT; 1648 } 1649 return JDBC30Translation.CLOSE_CURSORS_AT_COMMIT; 1650 } 1651 1652 1676 public final Object getObject(int columnIndex) throws SQLException { 1677 checkIfClosed("getObject"); 1678 1679 int colType = getColumnType(columnIndex); 1681 switch (colType) { 1682 case Types.CHAR: 1683 case Types.VARCHAR: 1684 case Types.LONGVARCHAR: 1685 return getString(columnIndex); 1687 1688 case Types.CLOB: 1689 return getClob(columnIndex); 1690 1691 case Types.BINARY: 1692 case Types.VARBINARY: 1693 case Types.LONGVARBINARY: 1694 return getBytes(columnIndex); 1696 1697 case Types.BLOB: 1698 return getBlob(columnIndex); 1699 1700 default: 1701 break; 1702 } 1703 1704 try { 1705 1706 DataValueDescriptor dvd = getColumn(columnIndex); 1707 if (wasNull = dvd.isNull()) 1708 return null; 1709 1710 return dvd.getObject(); 1711 1712 } catch (StandardException t) { 1713 throw noStateChangeException(t); 1714 } 1715 } 1716 1717 1741 public final Object getObject(String columnName) throws SQLException { 1742 checkIfClosed("getObject"); 1743 return (getObject(findColumnName(columnName))); 1744 } 1745 1746 1747 1749 1756 public final int findColumn(String columnName) throws SQLException { 1757 checkIfClosed("findColumn"); 1758 return findColumnName(columnName); 1759 } 1760 1761 1767 1768 1772 1782 public final Statement getStatement() throws SQLException 1783 { 1784 checkIfClosed("getStatement"); 1785 return applicationStmt; 1786 } 1787 1788 1793 public final void setApplicationStatement(Statement applicationStmt) 1794 { 1795 this.applicationStmt = applicationStmt; 1796 } 1797 1798 1802 1813 public boolean isBeforeFirst() throws SQLException { 1814 return checkRowPosition(ResultSet.ISBEFOREFIRST, "isBeforeFirst"); 1815 } 1816 1817 1828 public boolean isAfterLast() throws SQLException { 1829 return checkRowPosition(ResultSet.ISAFTERLAST, "isAfterLast"); 1830 } 1831 1832 1842 public boolean isFirst() throws SQLException { 1843 return checkRowPosition(ResultSet.ISFIRST, "isFirst"); 1844 } 1845 1846 1859 public boolean isLast() throws SQLException { 1860 return checkRowPosition(ResultSet.ISLAST, "isLast"); 1861 } 1862 1863 1874 public void beforeFirst() throws SQLException { 1875 checkScrollCursor("beforeFirst()"); 1877 movePosition(BEFOREFIRST, "beforeFirst"); 1878 } 1879 1880 1891 public void afterLast() throws SQLException { 1892 checkScrollCursor("afterLast()"); 1894 movePosition(AFTERLAST, "afterLast"); 1895 } 1896 1897 1908 public boolean first() throws SQLException { 1909 checkScrollCursor("first()"); 1911 return movePosition(FIRST, "first"); 1912 } 1913 1914 1925 public boolean last() throws SQLException { 1926 checkScrollCursor("last()"); 1928 return movePosition(LAST, "last"); 1929 } 1930 1931 1942 public int getRow() throws SQLException { 1943 checkScrollCursor("getRow()"); 1945 1946 1951 return theResults.getRowNumber(); 1952 } 1953 1954 1983 public boolean absolute(int row) throws SQLException { 1984 checkScrollCursor("absolute()"); 1986 return movePosition(ABSOLUTE, row, "absolute"); 1987 } 1988 1989 2009 public boolean relative(int row) throws SQLException { 2010 checkScrollCursor("relative()"); 2012 return movePosition(RELATIVE, row, "relative"); 2013 } 2014 2015 2030 public boolean previous() throws SQLException { 2031 checkScrollCursor("previous()"); 2033 return movePosition(PREVIOUS, "previous"); 2034 } 2035 2036 2040 2051 public void setFetchDirection(int direction) throws SQLException { 2052 checkScrollCursor("setFetchDirection()"); 2053 2057 fetchDirection = direction; 2058 } 2059 2060 2068 public int getFetchDirection() throws SQLException { 2069 checkIfClosed("getFetchDirection"); 2070 if (fetchDirection == 0) { 2071 return stmt.getFetchDirection(); 2074 } else 2075 return fetchDirection; 2076 } 2077 2078 2094 public void setFetchSize(int rows) throws SQLException { 2095 checkIfClosed("setFetchSize"); 2096 if (rows < 0 || (stmt.getMaxRows() != 0 && rows > stmt.getMaxRows())) { 2097 throw Util.generateCsSQLException(SQLState.INVALID_FETCH_SIZE, 2098 new Integer (rows)); 2099 } else if (rows > 0) { 2101 fetchSize = rows; 2102 } 2103 } 2104 2105 2113 public int getFetchSize() throws SQLException { 2114 checkIfClosed("getFetchSize"); 2115 if (fetchSize == 0) { 2116 return stmt.getFetchSize(); 2119 } else 2120 return fetchSize; 2121 } 2122 2123 2134 public int getType() throws SQLException { 2135 checkIfClosed("getType"); 2136 return stmt.getResultSetType(); 2137 } 2138 2139 2156 public int getConcurrency() throws SQLException { 2157 checkIfClosed("getConcurrency"); 2158 return concurrencyOfThisResultSet; 2159 } 2160 2161 2165 2178 public boolean rowUpdated() throws SQLException { 2179 checkIfClosed("rowUpdated"); 2180 checkNotOnInsertRow(); 2181 checkOnRow(); 2182 2183 boolean rvalue = false; 2184 2185 try { 2186 if (isForUpdate() && 2187 getType() == java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE) { 2188 rvalue = ((ScrollInsensitiveResultSet)theResults).isUpdated(); 2189 } 2190 } catch (Throwable t) { 2191 handleException(t); 2192 } 2193 return rvalue; 2194 } 2195 2196 2208 public boolean rowInserted() throws SQLException { 2209 checkIfClosed("rowInserted"); 2210 checkNotOnInsertRow(); 2211 checkOnRow(); 2212 2213 return false; 2214 } 2215 2216 2230 public boolean rowDeleted() throws SQLException { 2231 checkIfClosed("rowUpdated"); 2232 checkNotOnInsertRow(); 2233 checkOnRow(); 2234 2235 boolean rvalue = false; 2236 2237 try { 2238 if (isForUpdate() && 2239 getType() == java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE) { 2240 rvalue = ((ScrollInsensitiveResultSet)theResults).isDeleted(); 2241 } 2242 } catch (Throwable t) { 2243 handleException(t); 2244 } 2245 return rvalue; 2246 } 2247 2248 protected void checksBeforeUpdateXXX(String methodName, int columnIndex) throws SQLException { 2250 checksBeforeUpdateOrDelete(methodName, columnIndex); 2251 2252 ResultDescription rd = theResults.getResultDescription(); 2254 if (columnIndex < 1 || columnIndex > rd.getColumnCount()) 2255 throw Util.generateCsSQLException(SQLState.LANG_INVALID_COLUMN_POSITION, 2256 new Integer (columnIndex), String.valueOf(rd.getColumnCount())); 2257 2258 if (rd.getColumnDescriptor(columnIndex).getSourceTableName() == null) 2260 throw Util.generateCsSQLException(SQLState.COLUMN_NOT_FROM_BASE_TABLE, 2261 methodName); 2262 2263 if (!getMetaData().isWritable(columnIndex)) 2265 throw Util.generateCsSQLException(SQLState.LANG_COLUMN_NOT_UPDATABLE_IN_CURSOR, 2266 theResults.getResultDescription().getColumnDescriptor(columnIndex).getName(), 2267 getCursorName()); 2268 } 2269 2270 protected void checksBeforeUpdateOrDelete(String methodName, int columnIndex) throws SQLException { 2276 2277 checkIfClosed(methodName); 2279 2280 checkUpdatableCursor(methodName); 2282 2283 if (!isOnInsertRow) checkOnRow(); 2289 if (theResults.isClosed()) 2291 throw Util.generateCsSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, methodName); 2292 } 2293 2294 protected DataValueDescriptor getDVDforColumnToBeUpdated(int columnIndex, String updateMethodName) throws StandardException, SQLException { 2296 checksBeforeUpdateXXX(updateMethodName, columnIndex); 2297 columnGotUpdated[columnIndex-1] = true; 2298 currentRowHasBeenUpdated = true; 2299 2300 return updateRow.getColumn(columnIndex); 2301 } 2302 2303 2309 protected void checksBeforeInsert() throws SQLException { 2310 checkIfClosed("insertRow"); 2312 2313 checkUpdatableCursor("insertRow"); 2316 2317 if (!isOnInsertRow) { 2319 throw newSQLException(SQLState.CURSOR_NOT_POSITIONED_ON_INSERT_ROW); 2320 } 2321 2322 if (theResults.isClosed()) { 2324 throw Util.generateCsSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, "insertRow"); 2325 } 2326 } 2327 2328 2336 private void checksBeforeUpdateAsciiStream(int columnIndex) 2337 throws SQLException 2338 { 2339 checksBeforeUpdateXXX("updateAsciiStream", columnIndex); 2340 int colType = getColumnType(columnIndex); 2341 if (!DataTypeDescriptor.isAsciiStreamAssignable(colType)) { 2342 throw dataTypeConversion(columnIndex, "java.io.InputStream"); 2343 } 2344 } 2345 2346 2354 private void checksBeforeUpdateBinaryStream(int columnIndex) 2355 throws SQLException 2356 { 2357 checksBeforeUpdateXXX("updateBinaryStream", columnIndex); 2358 int colType = getColumnType(columnIndex); 2359 if (!DataTypeDescriptor.isBinaryStreamAssignable(colType)) { 2360 throw dataTypeConversion(columnIndex, "java.io.InputStream"); 2361 } 2362 } 2363 2364 2372 private void checksBeforeUpdateCharacterStream(int columnIndex) 2373 throws SQLException 2374 { 2375 checksBeforeUpdateXXX("updateCharacterStream", columnIndex); 2376 int colType = getColumnType(columnIndex); 2377 if (!DataTypeDescriptor.isCharacterStreamAssignable(colType)) { 2378 throw dataTypeConversion(columnIndex, "java.io.Reader"); 2379 } 2380 } 2381 2382 2397 public void updateNull(int columnIndex) throws SQLException { 2398 try { 2399 getDVDforColumnToBeUpdated(columnIndex, "updateNull").setToNull(); 2400 } catch (StandardException t) { 2401 throw noStateChangeException(t); 2402 } 2403 } 2404 2405 2422 public void updateBoolean(int columnIndex, boolean x) throws SQLException { 2423 try { 2424 getDVDforColumnToBeUpdated(columnIndex, "updateBoolean").setValue(x); 2425 } catch (StandardException t) { 2426 throw noStateChangeException(t); 2427 } 2428 } 2429 2430 2447 public void updateByte(int columnIndex, byte x) throws SQLException { 2448 try { 2449 getDVDforColumnToBeUpdated(columnIndex, "updateByte").setValue(x); 2450 } catch (StandardException t) { 2451 throw noStateChangeException(t); 2452 } 2453 } 2454 2455 2472 public void updateShort(int columnIndex, short x) throws SQLException { 2473 try { 2474 getDVDforColumnToBeUpdated(columnIndex, "updateShort").setValue(x); 2475 } catch (StandardException t) { 2476 throw noStateChangeException(t); 2477 } 2478 } 2479 2480 2497 public void updateInt(int columnIndex, int x) throws SQLException { 2498 try { 2499 getDVDforColumnToBeUpdated(columnIndex, "updateInt").setValue(x); 2500 } catch (StandardException t) { 2501 throw noStateChangeException(t); 2502 } 2503 } 2504 2505 2522 public void updateLong(int columnIndex, long x) throws SQLException { 2523 try { 2524 getDVDforColumnToBeUpdated(columnIndex, "updateLong").setValue(x); 2525 } catch (StandardException t) { 2526 throw noStateChangeException(t); 2527 } 2528 } 2529 2530 2547 public void updateFloat(int columnIndex, float x) throws SQLException { 2548 try { 2549 getDVDforColumnToBeUpdated(columnIndex, "updateFloat").setValue(x); 2550 } catch (StandardException t) { 2551 throw noStateChangeException(t); 2552 } 2553 } 2554 2555 2572 public void updateDouble(int columnIndex, double x) throws SQLException { 2573 try { 2574 getDVDforColumnToBeUpdated(columnIndex, "updateDouble").setValue(x); 2575 } catch (StandardException t) { 2576 throw noStateChangeException(t); 2577 } 2578 } 2579 2580 2597 public void updateString(int columnIndex, String x) throws SQLException { 2598 try { 2599 getDVDforColumnToBeUpdated(columnIndex, "updateString").setValue(x); 2600 } catch (StandardException t) { 2601 throw noStateChangeException(t); 2602 } 2603 } 2604 2605 2622 public void updateBytes(int columnIndex, byte x[]) throws SQLException { 2623 try { 2624 getDVDforColumnToBeUpdated(columnIndex, "updateBytes").setValue(x); 2625 } catch (StandardException t) { 2626 throw noStateChangeException(t); 2627 } 2628 } 2629 2630 2647 public void updateDate(int columnIndex, java.sql.Date x) 2648 throws SQLException { 2649 try { 2650 getDVDforColumnToBeUpdated(columnIndex, "updateDate").setValue(x); 2651 } catch (StandardException t) { 2652 throw noStateChangeException(t); 2653 } 2654 } 2655 2656 2673 public void updateTime(int columnIndex, java.sql.Time x) 2674 throws SQLException { 2675 try { 2676 getDVDforColumnToBeUpdated(columnIndex, "updateTime").setValue(x); 2677 } catch (StandardException t) { 2678 throw noStateChangeException(t); 2679 } 2680 } 2681 2682 2699 public void updateTimestamp(int columnIndex, java.sql.Timestamp x) 2700 throws SQLException { 2701 try { 2702 getDVDforColumnToBeUpdated(columnIndex, "updateTimestamp").setValue(x); 2703 } catch (StandardException t) { 2704 throw noStateChangeException(t); 2705 } 2706 } 2707 2708 2726 public void updateAsciiStream(int columnIndex, java.io.InputStream x, 2727 long length) throws SQLException { 2728 checksBeforeUpdateAsciiStream(columnIndex); 2729 2730 java.io.Reader r = null; 2731 if (x != null) 2732 { 2733 try { 2734 r = new java.io.InputStreamReader (x, "ISO-8859-1"); 2735 } catch (java.io.UnsupportedEncodingException uee) { 2736 throw new SQLException (uee.getMessage()); 2737 } 2738 } 2739 updateCharacterStreamInternal(columnIndex, r, false, length, 2740 "updateAsciiStream"); 2741 } 2742 2743 2760 public void updateAsciiStream(int columnIndex, InputStream x) 2761 throws SQLException { 2762 checksBeforeUpdateAsciiStream(columnIndex); 2763 2764 java.io.Reader r = null; 2765 if (x != null) { 2766 try { 2767 r = new java.io.InputStreamReader (x, "ISO-8859-1"); 2768 } catch (java.io.UnsupportedEncodingException uee) { 2769 throw new SQLException (uee.getMessage()); 2770 } 2771 } 2772 updateCharacterStreamInternal(columnIndex, r, true, -1, 2773 "updateAsciiStream"); 2774 } 2775 2776 2794 public void updateBinaryStream(int columnIndex, java.io.InputStream x, 2795 long length) throws SQLException { 2796 checksBeforeUpdateBinaryStream(columnIndex); 2797 2798 if (x == null) 2799 { 2800 updateNull(columnIndex); 2801 return; 2802 } 2803 2804 updateBinaryStreamInternal(columnIndex, x, false, length, 2805 "updateBinaryStream"); 2806 } 2807 2808 2825 public void updateBinaryStream(int columnIndex, InputStream x) 2826 throws SQLException { 2827 checksBeforeUpdateBinaryStream(columnIndex); 2828 updateBinaryStreamInternal(columnIndex, x, true, -1, 2829 "updateBinaryStream"); 2830 } 2831 2832 2853 private void updateBinaryStreamInternal(int columnIndex, InputStream x, 2854 final boolean lengthLess, long length, String updateMethodName) 2855 throws SQLException { 2856 RawToBinaryFormatStream rawStream; 2857 if (!lengthLess) { 2858 if (length < 0) 2859 throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH); 2860 2861 if (length > Integer.MAX_VALUE ) { 2865 throw newSQLException(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE, 2866 getColumnSQLType(columnIndex)); 2867 } 2868 rawStream = new RawToBinaryFormatStream(x, (int)length); 2869 } else { 2870 length = -1; 2872 rawStream = new RawToBinaryFormatStream(x, 2873 getMaxColumnWidth(columnIndex), 2874 getColumnSQLType(columnIndex)); 2875 } 2876 2877 try { 2878 getDVDforColumnToBeUpdated(columnIndex, updateMethodName).setValue( 2879 rawStream, (int) length); 2880 } catch (StandardException t) { 2881 throw noStateChangeException(t); 2882 } 2883 } 2884 2885 2904 public void updateCharacterStream(int columnIndex, java.io.Reader x, 2905 long length) throws SQLException { 2906 checksBeforeUpdateCharacterStream(columnIndex); 2907 updateCharacterStreamInternal(columnIndex, x, false, length, 2908 "updateCharacterStream"); 2909 } 2910 2911 2928 public void updateCharacterStream(int columnIndex, Reader x) 2929 throws SQLException { 2930 checksBeforeUpdateCharacterStream(columnIndex); 2931 updateCharacterStreamInternal(columnIndex, x, true, -1, 2932 "updateCharacterStream"); 2933 } 2934 2935 2954 private void updateCharacterStreamInternal(int columnIndex, Reader reader, 2955 final boolean lengthLess, 2956 long length, 2957 String updateMethodName) 2958 throws SQLException 2959 { 2960 try { 2961 2962 if (reader == null) 2963 { 2964 updateNull(columnIndex); 2965 return; 2966 } 2967 2968 ReaderToUTF8Stream utfIn; 2969 int usableLength = -1; 2970 if (!lengthLess) { 2971 if (length < 0) 2973 throw newSQLException(SQLState.NEGATIVE_STREAM_LENGTH); 2974 2975 if (length > Integer.MAX_VALUE ) { 2979 throw newSQLException( 2980 SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE, 2981 getColumnSQLType(columnIndex)); 2982 } 2983 2984 usableLength = (int) length; 2987 int truncationLength = 0; 2988 2989 if (getColumnType(columnIndex) == Types.CLOB) { 3000 int colWidth = getMaxColumnWidth(columnIndex); 3003 3004 if (usableLength > colWidth) { 3011 truncationLength = usableLength - colWidth; 3012 usableLength = colWidth; 3013 } 3014 } 3015 3016 utfIn = new ReaderToUTF8Stream(reader, usableLength, 3017 truncationLength, getColumnSQLType(columnIndex)); 3018 } else { 3019 int colWidth = getMaxColumnWidth(columnIndex); 3020 utfIn = new ReaderToUTF8Stream( 3021 reader, colWidth, getColumnSQLType(columnIndex)); 3022 } 3023 3024 getDVDforColumnToBeUpdated(columnIndex, updateMethodName).setValue( 3027 utfIn, (int) usableLength); 3028 } catch (StandardException t) { 3029 throw noStateChangeException(t); 3030 } 3031 } 3032 3033 3054 public void updateObject(int columnIndex, Object x, int scale) 3055 throws SQLException { 3056 updateObject(columnIndex, x); 3057 3061 int colType = getColumnType(columnIndex); 3062 if ((colType == Types.DECIMAL) || (colType == Types.NUMERIC)) { 3063 if (scale < 0) 3064 throw newSQLException(SQLState.BAD_SCALE_VALUE, new Integer (scale)); 3065 3066 try { 3067 DataValueDescriptor value = updateRow.getColumn(columnIndex); 3068 3069 int origvaluelen = value.getLength(); 3070 ((VariableSizeDataValue) 3071 value).setWidth(VariableSizeDataValue.IGNORE_PRECISION, 3072 scale, 3073 false); 3074 3075 } catch (StandardException t) { 3076 throw EmbedResultSet.noStateChangeException(t); 3077 } 3078 } 3079 } 3080 3081 3098 public void updateObject(int columnIndex, Object x) throws SQLException { 3099 checksBeforeUpdateXXX("updateObject", columnIndex); 3100 int colType = getColumnType(columnIndex); 3101 if (colType == org.apache.derby.iapi.reference.JDBC20Translation.SQL_TYPES_JAVA_OBJECT) { 3102 try { 3103 ((UserDataValue) getDVDforColumnToBeUpdated(columnIndex, "updateObject")).setValue(x); 3104 return; 3105 } catch (StandardException t) { 3106 throw noStateChangeException(t); 3107 } 3108 } 3109 3110 if (x == null) { 3111 updateNull(columnIndex); 3112 return; 3113 } 3114 3115 if (x instanceof String ) { 3116 updateString(columnIndex, (String ) x); 3117 return; 3118 } 3119 3120 if (x instanceof Boolean ) { 3121 updateBoolean(columnIndex, ((Boolean ) x).booleanValue()); 3122 return; 3123 } 3124 3125 if (x instanceof Short ) { 3126 updateShort(columnIndex, ((Short ) x).shortValue()); 3127 return; 3128 } 3129 3130 if (x instanceof Integer ) { 3131 updateInt(columnIndex, ((Integer ) x).intValue()); 3132 return; 3133 } 3134 3135 if (x instanceof Long ) { 3136 updateLong(columnIndex, ((Long ) x).longValue()); 3137 return; 3138 } 3139 3140 if (x instanceof Float ) { 3141 updateFloat(columnIndex, ((Float ) x).floatValue()); 3142 return; 3143 } 3144 3145 if (x instanceof Double ) { 3146 updateDouble(columnIndex, ((Double ) x).doubleValue()); 3147 return; 3148 } 3149 3150 if (x instanceof byte[]) { 3151 updateBytes(columnIndex, (byte[]) x); 3152 return; 3153 } 3154 3155 if (x instanceof Date ) { 3156 updateDate(columnIndex, (Date ) x); 3157 return; 3158 } 3159 3160 if (x instanceof Time ) { 3161 updateTime(columnIndex, (Time ) x); 3162 return; 3163 } 3164 3165 if (x instanceof Timestamp ) { 3166 updateTimestamp(columnIndex, (Timestamp ) x); 3167 return; 3168 } 3169 3170 if (x instanceof Blob ) { 3171 updateBlob(columnIndex, (Blob ) x); 3172 return; 3173 } 3174 3175 if (x instanceof Clob ) { 3176 updateClob(columnIndex, (Clob ) x); 3177 return; 3178 } 3179 3180 throw dataTypeConversion(columnIndex, x.getClass().getName()); 3181 } 3182 3183 3198 public void updateNull(String columnName) throws SQLException { 3199 checkIfClosed("updateNull"); 3200 updateNull(findColumnName(columnName)); 3201 } 3202 3203 3220 public void updateBoolean(String columnName, boolean x) throws SQLException { 3221 checkIfClosed("updateBoolean"); 3222 updateBoolean(findColumnName(columnName), x); 3223 } 3224 3225 3242 public void updateByte(String columnName, byte x) throws SQLException { 3243 checkIfClosed("updateByte"); 3244 updateByte(findColumnName(columnName), x); 3245 } 3246 3247 3264 public void updateShort(String columnName, short x) throws SQLException { 3265 checkIfClosed("updateShort"); 3266 updateShort(findColumnName(columnName), x); 3267 } 3268 3269 3286 public void updateInt(String columnName, int x) throws SQLException { 3287 checkIfClosed("updateInt"); 3288 updateInt(findColumnName(columnName), x); 3289 } 3290 3291 3308 public void updateLong(String columnName, long x) throws SQLException { 3309 checkIfClosed("updateLong"); 3310 updateLong(findColumnName(columnName), x); 3311 } 3312 3313 3330 public void updateFloat(String columnName, float x) throws SQLException { 3331 checkIfClosed("updateFloat"); 3332 updateFloat(findColumnName(columnName), x); 3333 } 3334 3335 3352 public void updateDouble(String columnName, double x) throws SQLException { 3353 checkIfClosed("updateDouble"); 3354 updateDouble(findColumnName(columnName), x); 3355 } 3356 3357 3374 public void updateString(String columnName, String x) throws SQLException { 3375 checkIfClosed("updateString"); 3376 updateString(findColumnName(columnName), x); 3377 } 3378 3379 3396 public void updateBytes(String columnName, byte x[]) throws SQLException { 3397 checkIfClosed("updateBytes"); 3398 updateBytes(findColumnName(columnName), x); 3399 } 3400 3401 3418 public void updateDate(String columnName, java.sql.Date x) 3419 throws SQLException { 3420 checkIfClosed("updateDate"); 3421 updateDate(findColumnName(columnName), x); 3422 } 3423 3424 3441 public void updateTime(String columnName, java.sql.Time x) 3442 throws SQLException { 3443 checkIfClosed("updateTime"); 3444 updateTime(findColumnName(columnName), x); 3445 } 3446 3447 3464 public void updateTimestamp(String columnName, java.sql.Timestamp x) 3465 throws SQLException { 3466 checkIfClosed("updateTimestamp"); 3467 updateTimestamp(findColumnName(columnName), x); 3468 } 3469 3470 3489 public void updateAsciiStream(String columnName, java.io.InputStream x, 3490 int length) throws SQLException { 3491 checkIfClosed("updateAsciiStream"); 3492 updateAsciiStream(findColumnName(columnName), x, length); 3493 } 3494 3495 3514 public void updateBinaryStream(String columnName, java.io.InputStream x, 3515 int length) throws SQLException { 3516 checkIfClosed("updateBinaryStream"); 3517 updateBinaryStream(findColumnName(columnName), x, length); 3518 } 3519 3520 3539 public void updateCharacterStream(String columnName, java.io.Reader reader, 3540 int length) throws SQLException { 3541 checkIfClosed("updateCharacterStream"); 3542 updateCharacterStream(findColumnName(columnName), reader, length); 3543 } 3544 3545 3562 public void updateObject(String columnName, Object x, int scale) 3563 throws SQLException { 3564 checkIfClosed("updateObject"); 3565 updateObject(findColumnName(columnName), x, scale); 3566 } 3567 3568 3585 public void updateObject(String columnName, Object x) throws SQLException { 3586 checkIfClosed("updateObject"); 3587 updateObject(findColumnName(columnName), x); 3588 } 3589 3590 3601 public void insertRow() throws SQLException { 3602 synchronized (getConnectionSynchronization()) { 3603 checksBeforeInsert(); 3604 setupContextStack(); 3605 LanguageConnectionContext lcc = null; 3606 StatementContext statementContext = null; 3607 try { 3608 3616 3617 boolean foundOneColumnAlready = false; 3618 StringBuffer insertSQL = new StringBuffer ("INSERT INTO "); 3619 StringBuffer valuesSQL = new StringBuffer ("VALUES ("); 3620 CursorActivation activation = getEmbedConnection(). 3621 getLanguageConnection().lookupCursorActivation(getCursorName()); 3622 3623 ExecCursorTableReference targetTable = 3624 activation.getPreparedStatement().getTargetTable(); 3625 insertSQL.append(getFullBaseTableName(targetTable)); 3627 ResultDescription rd = theResults.getResultDescription(); 3628 3629 insertSQL.append(" ("); 3630 for (int i=1; i<=rd.getColumnCount(); i++) { 3633 if (foundOneColumnAlready) { 3634 insertSQL.append(","); 3635 valuesSQL.append(","); 3636 } 3637 insertSQL.append(quoteSqlIdentifier( 3640 rd.getColumnDescriptor(i).getName())); 3641 if (columnGotUpdated[i-1]) { 3642 valuesSQL.append("?"); 3643 } else { 3644 valuesSQL.append("DEFAULT"); 3645 } 3646 foundOneColumnAlready = true; 3647 } 3648 insertSQL.append(") "); 3649 valuesSQL.append(") "); 3650 insertSQL.append(valuesSQL); 3651 3652 lcc = getEmbedConnection().getLanguageConnection(); 3653 3654 statementContext = lcc.pushStatementContext( 3656 isAtomic, 3657 false, 3658 insertSQL.toString(), 3659 null, 3660 false, 3661 0L); 3662 org.apache.derby.iapi.sql.PreparedStatement ps = 3663 lcc.prepareInternalStatement(insertSQL.toString()); 3664 Activation act = ps.getActivation(lcc, false); 3665 3666 for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) { 3669 if (columnGotUpdated[i-1]) { 3671 act.getParameterValueSet(). 3672 getParameterForSet(paramPosition++). 3673 setValue(updateRow.getColumn(i)); 3674 } 3675 } 3676 org.apache.derby.iapi.sql.ResultSet rs = 3679 ps.execute(act, true, 0L); 3680 rs.close(); 3681 rs.finish(); 3682 3683 lcc.popStatementContext(statementContext, null); 3684 } catch (StandardException t) { 3685 throw closeOnTransactionError(t); 3686 } finally { 3687 if (statementContext != null) 3688 lcc.popStatementContext(statementContext, null); 3689 restoreContextStack(); 3690 } 3691 } 3692 } 3693 3694 3703 public void updateRow() throws SQLException { 3704 synchronized (getConnectionSynchronization()) { 3705 checksBeforeUpdateOrDelete("updateRow", -1); 3706 3707 checkNotOnInsertRow(); 3709 3710 setupContextStack(); 3711 LanguageConnectionContext lcc = null; 3712 StatementContext statementContext = null; 3713 try { 3714 if (currentRowHasBeenUpdated == false) return; 3717 boolean foundOneColumnAlready = false; 3719 StringBuffer updateWhereCurrentOfSQL = new StringBuffer ("UPDATE "); 3720 CursorActivation activation = getEmbedConnection().getLanguageConnection().lookupCursorActivation(getCursorName()); 3721 3722 3723 ExecCursorTableReference targetTable = activation.getPreparedStatement().getTargetTable(); 3724 updateWhereCurrentOfSQL.append(getFullBaseTableName(targetTable)); updateWhereCurrentOfSQL.append(" SET "); 3726 ResultDescription rd = theResults.getResultDescription(); 3727 3728 for (int i=1; i<=rd.getColumnCount(); i++) { if (columnGotUpdated[i-1]) { if (foundOneColumnAlready) 3731 updateWhereCurrentOfSQL.append(","); 3732 updateWhereCurrentOfSQL.append(quoteSqlIdentifier( 3734 rd.getColumnDescriptor(i).getName()) + "=?"); 3735 foundOneColumnAlready = true; 3736 } 3737 } 3738 updateWhereCurrentOfSQL.append(" WHERE CURRENT OF " + 3740 quoteSqlIdentifier(getCursorName())); 3741 lcc = getEmbedConnection().getLanguageConnection(); 3742 3743 statementContext = lcc.pushStatementContext(isAtomic, false, updateWhereCurrentOfSQL.toString(), null, false, 0L); 3745 org.apache.derby.iapi.sql.PreparedStatement ps = lcc.prepareInternalStatement(updateWhereCurrentOfSQL.toString()); 3746 Activation act = ps.getActivation(lcc, false); 3747 3748 for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) { 3750 if (columnGotUpdated[i-1]) act.getParameterValueSet().getParameterForSet(paramPosition++).setValue(updateRow.getColumn(i)); 3752 } 3753 org.apache.derby.iapi.sql.ResultSet rs = ps.execute(act, true, 0L); 3756 SQLWarning w = act.getWarnings(); 3757 if (w != null) { 3758 addWarning(w); 3759 } 3760 rs.close(); 3761 rs.finish(); 3762 if (getType() == TYPE_FORWARD_ONLY) { 3764 currentRow.setRowArray(null); 3765 } else { 3766 movePosition(RELATIVE, 0, "relative"); 3767 } 3768 lcc.popStatementContext(statementContext, null); 3769 } catch (StandardException t) { 3770 throw closeOnTransactionError(t); 3771 } finally { 3772 if (statementContext != null) 3773 lcc.popStatementContext(statementContext, null); 3774 restoreContextStack(); 3775 initializeUpdateRowModifiers(); 3776 } 3777 } 3778 } 3779 3780 3789 public void deleteRow() throws SQLException { 3790 synchronized (getConnectionSynchronization()) { 3791 checksBeforeUpdateOrDelete("deleteRow", -1); 3792 3793 checkNotOnInsertRow(); 3795 3796 setupContextStack(); 3797 3798 LanguageConnectionContext lcc = null; 3799 StatementContext statementContext = null; 3800 3801 try { 3803 StringBuffer deleteWhereCurrentOfSQL = new StringBuffer ("DELETE FROM "); 3804 CursorActivation activation = getEmbedConnection().getLanguageConnection().lookupCursorActivation(getCursorName()); 3805 deleteWhereCurrentOfSQL.append(getFullBaseTableName(activation.getPreparedStatement().getTargetTable())); deleteWhereCurrentOfSQL.append(" WHERE CURRENT OF " + 3808 quoteSqlIdentifier(getCursorName())); 3809 3810 lcc = getEmbedConnection().getLanguageConnection(); 3811 3812 statementContext = lcc.pushStatementContext(isAtomic, false, deleteWhereCurrentOfSQL.toString(), null, false, 0L); 3814 org.apache.derby.iapi.sql.PreparedStatement ps = lcc.prepareInternalStatement(deleteWhereCurrentOfSQL.toString()); 3815 Activation act = ps.getActivation(lcc, false); 3817 org.apache.derby.iapi.sql.ResultSet rs = 3820 ps.execute(act, true, 0L); 3821 SQLWarning w = act.getWarnings(); 3822 if (w != null) { 3823 addWarning(w); 3824 } 3825 rs.close(); 3826 rs.finish(); 3827 currentRow.setRowArray(null); 3830 lcc.popStatementContext(statementContext, null); 3831 } catch (StandardException t) { 3832 throw closeOnTransactionError(t); 3833 } finally { 3834 if (statementContext != null) 3835 lcc.popStatementContext(statementContext, null); 3836 restoreContextStack(); 3837 initializeUpdateRowModifiers(); 3838 } 3839 } 3840 } 3841 3842 private String getFullBaseTableName(ExecCursorTableReference targetTable) { 3843 if (targetTable.getSchemaName() != null) 3845 return quoteSqlIdentifier(targetTable.getSchemaName()) + "." + 3846 quoteSqlIdentifier(targetTable.getBaseName()); 3847 else 3848 return quoteSqlIdentifier(targetTable.getBaseName()); 3849 } 3850 3851 private String quoteSqlIdentifier(String orgValue) { 3852 int i = 0, start = 0; 3853 String retValue = ""; 3854 while ((i = orgValue.indexOf("\"", start) + 1) > 0) { 3855 retValue += orgValue.substring(start, i) + "\""; 3856 start = i; 3857 } 3858 retValue += orgValue.substring(start, orgValue.length()); 3859 return "\"" + retValue + "\""; 3860 } 3861 3862 3884 public void refreshRow() throws SQLException { 3885 throw Util.notImplemented(); 3886 } 3887 3888 3901 public void cancelRowUpdates () throws SQLException { 3902 checksBeforeUpdateOrDelete("cancelRowUpdates", -1); 3903 3904 checkNotOnInsertRow(); 3905 3906 initializeUpdateRowModifiers(); 3907 } 3908 3909 3928 public void moveToInsertRow() throws SQLException { 3929 checkExecIfClosed("moveToInsertRow"); 3930 3931 checkUpdatableCursor("moveToInsertRow"); 3933 3934 synchronized (getConnectionSynchronization()) { 3935 try { 3936 initializeUpdateRowModifiers(); 3938 isOnInsertRow = true; 3939 3940 for (int i=1; i <= columnGotUpdated.length; i++) { 3941 updateRow.setColumn(i, 3942 resultDescription.getColumnDescriptor(i).getType().getNull()); 3943 } 3944 } catch (Throwable ex) { 3945 handleException(ex); 3946 } 3947 } 3948 } 3949 3950 3960 public void moveToCurrentRow() throws SQLException { 3961 checkExecIfClosed("moveToCurrentRow"); 3962 3963 checkUpdatableCursor("moveToCurrentRow"); 3965 3966 synchronized (getConnectionSynchronization()) { 3967 try { 3968 3969 if (isOnInsertRow) { 3970 initializeUpdateRowModifiers(); 3972 3973 isOnInsertRow = false; 3974 } 3975 } catch (Throwable ex) { 3976 handleException(ex); 3977 } 3978 } 3979 } 3980 3981 3989 public Blob getBlob(int columnIndex) throws SQLException { 3990 3991 closeCurrentStream(); 3995 checkIfClosed("getBlob"); 3999 synchronized (getConnectionSynchronization()) { 4000 int colType = getColumnType(columnIndex); 4001 4002 if (colType != Types.BLOB) 4004 throw dataTypeConversion("java.sql.Blob", columnIndex); 4005 4006 boolean pushStack = false; 4007 try { 4008 DataValueDescriptor dvd = getColumn(columnIndex); 4009 4010 if (wasNull = dvd.isNull()) 4011 return null; 4012 4013 if (dvd.getStream() != null) 4017 pushStack = true; 4018 4019 if (pushStack) 4020 setupContextStack(); 4021 4022 return new EmbedBlob(dvd, getEmbedConnection()); 4023 } catch (Throwable t) { 4024 throw handleException(t); 4025 } finally { 4026 if (pushStack) 4027 restoreContextStack(); 4028 } 4029 } 4030 } 4031 4032 4040 public final Clob getClob(int columnIndex) throws SQLException { 4041 4042 closeCurrentStream(); 4046 checkIfClosed("getClob"); 4050 synchronized (getConnectionSynchronization()) { 4051 int colType = getColumnType(columnIndex); 4052 4053 if (colType != Types.CLOB) 4055 throw dataTypeConversion("java.sql.Clob", columnIndex); 4056 4057 boolean pushStack = false; 4058 try { 4059 4060 DataValueDescriptor dvd = getColumn(columnIndex); 4061 4062 if (wasNull = dvd.isNull()) 4063 return null; 4064 4065 if (dvd.getStream() != null) 4069 pushStack = true; 4070 4071 if (pushStack) 4072 setupContextStack(); 4073 4074 return new EmbedClob(dvd, getEmbedConnection()); 4075 } catch (Throwable t) { 4076 throw handleException(t); 4077 } finally { 4078 if (pushStack) 4079 restoreContextStack(); 4080 } 4081 } 4082 } 4083 4084 4092 public final Blob getBlob(String columnName) throws SQLException { 4093 checkIfClosed("getBlob"); 4094 return (getBlob(findColumnName(columnName))); 4095 } 4096 4097 4107 public final Clob getClob(String columnName) throws SQLException { 4108 checkIfClosed("getClob"); 4109 return (getClob(findColumnName(columnName))); 4110 } 4111 4112 4113 4128 public void updateBlob(int columnIndex, Blob x) throws SQLException { 4129 checksBeforeUpdateXXX("updateBlob", columnIndex); 4130 int colType = getColumnType(columnIndex); 4131 if (colType != Types.BLOB) 4132 throw dataTypeConversion(columnIndex, "java.sql.Blob"); 4133 4134 if (x == null) 4135 updateNull(columnIndex); 4136 else { 4137 long length = x.length(); 4138 updateBinaryStreamInternal(columnIndex, x.getBinaryStream(), false, 4139 length, "updateBlob"); 4140 } 4141 } 4142 4143 4158 public void updateBlob(String columnName, Blob x) throws SQLException { 4159 checkIfClosed("updateBlob"); 4160 updateBlob(findColumnName(columnName), x); 4161 } 4162 4163 4178 public void updateClob(int columnIndex, Clob x) throws SQLException { 4179 checksBeforeUpdateXXX("updateClob", columnIndex); 4180 int colType = getColumnType(columnIndex); 4181 if (colType != Types.CLOB) 4182 throw dataTypeConversion(columnIndex, "java.sql.Clob"); 4183 4184 if (x == null) 4185 { 4186 updateNull(columnIndex); 4187 } 4188 else 4189 { 4190 4191 long length = x.length(); 4192 4193 updateCharacterStreamInternal( 4194 columnIndex, x.getCharacterStream(), false, length, 4195 "updateClob"); 4196 } 4197 } 4198 4199 4214 public void updateClob(String columnName, Clob x) throws SQLException { 4215 checkIfClosed("updateClob"); 4216 updateClob(findColumnName(columnName), x); 4217 } 4218 4219 4220 4223 4224 4233 protected int findColumnName(String columnName) 4234 throws SQLException { 4235 4239 if (columnName == null) 4240 throw newSQLException(SQLState.NULL_COLUMN_NAME); 4241 4242 final Map workMap; 4243 4244 synchronized (this) { 4245 if (columnNameMap==null) { 4246 columnNameMap = new HashMap (); 4250 for (int i = resultDescription.getColumnCount(); i>=1; i--) { 4251 4252 final String key = StringUtil. 4253 SQLToUpperCase(resultDescription. 4254 getColumnDescriptor(i).getName()); 4255 4256 final Integer value = ReuseFactory.getInteger(i); 4257 4258 columnNameMap.put(key, value); 4259 } 4260 } 4261 workMap = columnNameMap; 4262 } 4263 4264 Integer val = (Integer ) workMap.get(columnName); 4265 if (val==null) { 4266 val = (Integer ) workMap.get(StringUtil.SQLToUpperCase(columnName)); 4267 } 4268 if (val==null) { 4269 throw newSQLException(SQLState.COLUMN_NOT_FOUND, columnName); 4270 } else { 4271 return val.intValue(); 4272 } 4273 } 4274 4275 4276 4277 protected EmbedResultSetMetaData newEmbedResultSetMetaData(ResultDescription resultDesc) { 4282 return factory.newEmbedResultSetMetaData(resultDesc.getColumnInfo()); 4283 } 4284 4285 4289 private final void closeCurrentStream() { 4290 4291 if (currentStream != null) { 4292 try { 4293 synchronized(this) 4295 { 4296 if (currentStream != null) { 4297 if (currentStream instanceof java.io.Reader ) 4298 ((java.io.Reader ) currentStream).close(); 4299 else 4300 ((java.io.InputStream ) currentStream).close(); 4301 } 4302 } 4303 } catch (IOException ioe) { 4304 } finally { 4306 currentStream = null; 4307 } 4308 } 4309 } 4310 4311 4318 final void checkIfClosed(String operation) throws SQLException { 4319 if (isClosed) { 4320 throw newSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, operation); 4321 } 4322 } 4323 4324 4330 final void checkExecIfClosed(String operation) throws SQLException { 4331 4332 checkIfClosed(operation); 4333 4334 java.sql.Connection appConn = getEmbedConnection().getApplicationConnection(); 4335 4336 if (appConn == null) 4338 throw Util.noCurrentConnection(); 4339 4340 if (appConn.isClosed()) { 4341 closeCurrentStream(); 4342 isClosed = true; 4343 throw Util.noCurrentConnection(); 4344 } 4345 } 4346 4347 4352 protected String getSQLText() 4353 { 4354 if (stmt == null) 4355 return null; 4356 4357 return stmt.getSQLText(); 4358 } 4359 4360 4365 protected ParameterValueSet getParameterValueSet() 4366 { 4367 if (stmt == null) 4368 return null; 4369 4370 return stmt.getParameterValueSet(); 4371 } 4372 4373 private static boolean isMaxFieldSizeType(int colType){ 4374 return (colType == Types.BINARY || colType == Types.VARBINARY || 4375 colType == Types.LONGVARBINARY || colType == Types.CHAR || 4376 colType == Types.VARCHAR || colType == Types.LONGVARCHAR); 4377 } 4378 4381 final SQLException closeOnTransactionError(Throwable thrownException) throws SQLException 4382 { 4383 SQLException sqle = handleException(thrownException); 4384 if (thrownException instanceof StandardException) 4385 { 4386 StandardException se = (StandardException) thrownException; 4387 int severity = se.getSeverity(); 4388 if (severity == ExceptionSeverity.TRANSACTION_SEVERITY) 4389 { 4390 try { 4391 close(); 4392 } catch (Throwable t) { 4393 SQLException top = handleException(t); 4394 top.setNextException(sqle); 4395 sqle = top; 4396 } 4397 } 4398 } 4399 4400 return sqle; 4401 } 4402 4403 4404 4415 protected final DataValueDescriptor getColumn(int columnIndex) 4416 throws SQLException , StandardException { 4417 4418 closeCurrentStream(); 4419 4420 if (columnIndex < 1 || columnIndex > currentRow.nColumns()) { 4421 throw newSQLException(SQLState.COLUMN_NOT_FOUND, 4422 new Integer (columnIndex)); 4423 } 4424 if (isOnInsertRow || currentRowHasBeenUpdated && columnGotUpdated[columnIndex -1]) { 4425 return updateRow.getColumn(columnIndex); 4426 } else { 4427 checkOnRow(); return currentRow.getColumn(columnIndex); 4429 } 4430 } 4431 4432 4433 4445 static final SQLException noStateChangeException(Throwable thrownException) { 4446 4447 4451 return TransactionResourceImpl.wrapInSQLException((SQLException ) null, thrownException); 4452 4453 } 4454 4455 4461 void setDynamicResultSet(EmbedStatement owningStmt) { 4462 4463 this.owningStmt = owningStmt; 4464 this.localConn = owningStmt.getEmbedConnection(); 4465 } 4466 4467 4470 4471 public final int compareTo(Object other) { 4472 4473 EmbedResultSet olrs = (EmbedResultSet) other; 4474 4475 return order - olrs.order; 4476 4477 } 4478 4479 4486 private void checkScrollCursor(String methodName) throws SQLException { 4487 checkIfClosed(methodName); 4488 if (stmt.getResultSetType() == JDBC20Translation.TYPE_FORWARD_ONLY) 4489 throw Util 4490 .newEmbedSQLException( 4491 SQLState.NOT_ON_FORWARD_ONLY_CURSOR, 4492 new Object [] { methodName }, 4493 StandardException 4494 .getSeverityFromIdentifier(SQLState.NOT_ON_FORWARD_ONLY_CURSOR)); 4495 } 4496 4497 private void checkUpdatableCursor(String operation) throws SQLException { 4498 if (getConcurrency() != JDBC20Translation.CONCUR_UPDATABLE) { 4499 throw Util.generateCsSQLException( 4500 SQLState.UPDATABLE_RESULTSET_API_DISALLOWED, 4501 operation); 4502 } 4503 } 4504 4505 4506 private boolean checkRowPosition(int position, String positionText) 4507 throws SQLException { 4508 checkScrollCursor(positionText); 4510 4511 synchronized (getConnectionSynchronization()) { 4512 setupContextStack(); 4513 try { 4514 try { 4515 4516 4521 LanguageConnectionContext lcc = getEmbedConnection() 4522 .getLanguageConnection(); 4523 StatementContext statementContext = 4525 lcc.pushStatementContext(isAtomic, 4526 concurrencyOfThisResultSet==JDBC20Translation.CONCUR_READ_ONLY, 4527 getSQLText(), 4528 getParameterValueSet(), 4529 false, 0L); 4530 4531 boolean result = theResults.checkRowPosition(position); 4532 4533 lcc.popStatementContext(statementContext, null); 4534 4535 return result; 4536 4537 } catch (Throwable t) { 4538 4543 throw closeOnTransactionError(t); 4544 } 4545 4546 } finally { 4547 restoreContextStack(); 4548 } 4549 } 4550 } 4551 4554 public final boolean isForUpdate() 4555 { 4556 if (theResults instanceof NoPutResultSet) 4557 return ((NoPutResultSet) theResults).isForUpdate(); 4558 return false; 4559 } 4560 4561 final String getColumnSQLType(int column) 4562 { 4563 return resultDescription.getColumnDescriptor(column) 4564 .getType().getTypeId().getSQLTypeName(); 4565 } 4566 4567 4576 private final int getMaxColumnWidth(int columnIndex) { 4577 return resultDescription.getColumnDescriptor(columnIndex). 4578 getType().getMaximumWidth(); 4579 } 4580 4581 private final SQLException dataTypeConversion(String targetType, int column) { 4582 return newSQLException(SQLState.LANG_DATA_TYPE_GET_MISMATCH, targetType, 4583 getColumnSQLType(column)); 4584 } 4585 4586 private final SQLException dataTypeConversion(int column, String targetType) { 4587 return newSQLException(SQLState.LANG_DATA_TYPE_GET_MISMATCH, 4588 getColumnSQLType(column), targetType); 4589 } 4590 4591 4597 final void useStream(int columnIndex) throws SQLException { 4598 4599 if (streamUsedFlags == null) 4600 streamUsedFlags = new boolean[getMetaData().getColumnCount()]; 4601 4602 else if (streamUsedFlags[columnIndex - 1]) 4603 throw newSQLException(SQLState.LANG_STREAM_RETRIEVED_ALREADY); 4604 4605 streamUsedFlags[columnIndex - 1] = true; 4606 } 4607 4608 4620 public final boolean isClosed() throws SQLException { 4621 if (isClosed) return true; 4622 try { 4623 checkExecIfClosed(""); 4627 return false; 4628 } catch (SQLException sqle) { 4629 return isClosed; 4630 } 4631 } 4632 4633 4638 private void addWarning(SQLWarning w) { 4639 if (topWarning == null) { 4640 topWarning = w; 4641 } else { 4642 topWarning.setNextWarning(w); 4643 } 4644 } 4645 4646 4666 public void updateAsciiStream(int columnIndex, java.io.InputStream x, 4667 int length) throws SQLException { 4668 checkIfClosed("updateAsciiStream"); 4669 updateAsciiStream(columnIndex,x,(long)length); 4670 } 4671 4672 4692 public void updateBinaryStream(int columnIndex, java.io.InputStream x, 4693 int length) throws SQLException { 4694 checkIfClosed("updateBinaryStream"); 4695 updateBinaryStream(columnIndex,x,(long)length); 4696 } 4697 4698 4718 public void updateCharacterStream(int columnIndex, java.io.Reader x, 4719 int length) throws SQLException { 4720 checkIfClosed("updateCharacterStream"); 4721 updateCharacterStream(columnIndex,x,(long)length); 4722 } 4723 4724 4744 public void updateAsciiStream(String columnName, java.io.InputStream x, 4745 long length) throws SQLException { 4746 checkIfClosed("updateAsciiStream"); 4747 updateAsciiStream(findColumnName(columnName),x,length); 4748 } 4749 4750 4769 public void updateAsciiStream(String columnName, InputStream x) 4770 throws SQLException { 4771 checkIfClosed("updateAsciiStream"); 4772 updateAsciiStream(findColumnName(columnName), x); 4773 } 4774 4775 4795 4796 public void updateBinaryStream(String columnName, java.io.InputStream x, 4797 long length) throws SQLException { 4798 checkIfClosed("updateBinaryStream"); 4799 updateBinaryStream(findColumnName(columnName),x,length); 4800 } 4801 4802 4821 public void updateBinaryStream(String columnName, InputStream x) 4822 throws SQLException { 4823 checkIfClosed("updateBinaryStream"); 4824 updateBinaryStream(findColumnName(columnName), x); 4825 } 4826 4827 4846 public void updateCharacterStream(String columnName, java.io.Reader reader, 4847 long length) throws SQLException { 4848 checkIfClosed("updateCharacterStream"); 4849 updateCharacterStream(findColumnName(columnName),reader,length); 4850 } 4851 4852 4871 public void updateCharacterStream(String columnName, Reader reader) 4872 throws SQLException { 4873 checkIfClosed("updateCharacterStream"); 4874 updateCharacterStream(findColumnName(columnName), reader); 4875 } 4876 4877 4895 public void updateBlob(int columnIndex, InputStream x, long length) 4896 throws SQLException { 4897 checksBeforeUpdateXXX("updateBlob", columnIndex); 4898 int colType = getColumnType(columnIndex); 4899 if (colType != Types.BLOB) 4900 throw dataTypeConversion(columnIndex, "java.sql.Blob"); 4901 4902 if (x == null) 4903 updateNull(columnIndex); 4904 else { 4905 updateBinaryStreamInternal(columnIndex, x, false, length, 4906 "updateBlob"); 4907 } 4908 } 4909 4910 4927 public void updateBlob(int columnIndex, InputStream x) 4928 throws SQLException { 4929 checksBeforeUpdateXXX("updateBlob", columnIndex); 4930 int colType = getColumnType(columnIndex); 4931 if (colType != Types.BLOB) { 4932 throw dataTypeConversion(columnIndex, "java.sql.Blob"); 4933 } 4934 updateBinaryStreamInternal(columnIndex, x, true, -1, "updateBlob"); 4935 } 4936 4937 4955 4956 public void updateBlob(String columnName, InputStream x, long length) 4957 throws SQLException { 4958 checkIfClosed("updateBlob"); 4959 updateBlob(findColumnName(columnName),x,length); 4960 } 4961 4962 4981 public void updateBlob(String columnName, InputStream x) 4982 throws SQLException { 4983 checkIfClosed("updateBlob"); 4984 updateBlob(findColumnName(columnName), x); 4985 } 4986 4987 5003 public void updateClob(int columnIndex, Reader x, long length) 5004 throws SQLException { 5005 checksBeforeUpdateXXX("updateClob", columnIndex); 5006 int colType = getColumnType(columnIndex); 5007 if (colType != Types.CLOB) 5008 throw dataTypeConversion(columnIndex, "java.sql.Clob"); 5009 5010 if (x == null) { 5011 updateNull(columnIndex); 5012 } else { 5013 updateCharacterStreamInternal( 5014 columnIndex, x, false, length, "updateClob"); 5015 } 5016 } 5017 5018 5039 public void updateClob(int columnIndex, Reader x) 5040 throws SQLException { 5041 checksBeforeUpdateXXX("updateClob", columnIndex); 5042 int colType = getColumnType(columnIndex); 5043 if (colType != Types.CLOB) { 5044 throw dataTypeConversion(columnIndex, "java.sql.Clob"); 5045 } 5046 updateCharacterStreamInternal(columnIndex, x, true, -1, "updateClob"); 5047 } 5048 5049 5065 5066 public void updateClob(String columnName, Reader x, long length) 5067 throws SQLException { 5068 checkIfClosed("updateClob"); 5069 updateClob(findColumnName(columnName),x,length); 5070 } 5071 5072 5095 public void updateClob(String columnName, Reader x) 5096 throws SQLException { 5097 checkIfClosed("updateClob"); 5098 updateClob(findColumnName(columnName), x); 5099 } 5100} 5101 | Popular Tags |