1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 import org.apache.derby.iapi.services.context.Context; 26 27 28 import org.apache.derby.iapi.jdbc.ConnectionContext; 29 30 import org.apache.derby.iapi.sql.Activation; 31 32 import org.apache.derby.iapi.sql.execute.CursorResultSet; 33 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; 34 import org.apache.derby.iapi.sql.execute.CursorActivation; 35 import org.apache.derby.iapi.sql.ResultSet; 36 import org.apache.derby.iapi.sql.execute.ExecRow; 37 import org.apache.derby.iapi.sql.execute.NoPutResultSet; 38 import org.apache.derby.iapi.sql.ParameterValueSet; 39 import org.apache.derby.iapi.sql.ResultDescription; 40 41 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 42 43 import org.apache.derby.iapi.reference.SQLState; 44 import org.apache.derby.iapi.error.StandardException; 45 46 import org.apache.derby.iapi.sql.execute.ExecutionContext; 47 import org.apache.derby.iapi.sql.execute.ExecutionFactory; 48 import org.apache.derby.iapi.sql.execute.ResultSetFactory; 49 import org.apache.derby.iapi.sql.execute.ConstantAction; 50 51 import org.apache.derby.iapi.types.DataValueFactory; 52 import org.apache.derby.iapi.types.DataValueDescriptor; 53 import org.apache.derby.iapi.types.NumberDataValue; 54 import org.apache.derby.iapi.types.RowLocation; 55 56 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 57 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 58 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 59 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 60 61 import org.apache.derby.iapi.sql.depend.DependencyManager; 62 63 import org.apache.derby.iapi.store.access.Qualifier; 64 import org.apache.derby.iapi.store.access.ConglomerateController; 65 import org.apache.derby.iapi.store.access.ScanController; 66 import org.apache.derby.iapi.store.access.TransactionController; 67 import org.apache.derby.iapi.types.DataTypeDescriptor; 68 69 70 import org.apache.derby.iapi.services.sanity.SanityManager; 71 72 import org.apache.derby.iapi.services.context.ContextService; 73 74 import org.apache.derby.iapi.services.loader.GeneratedClass; 75 import org.apache.derby.iapi.services.loader.GeneratedByteCode; 76 import org.apache.derby.iapi.services.loader.GeneratedMethod; 77 78 import org.apache.derby.iapi.services.loader.ClassFactory; 79 import org.apache.derby.iapi.services.monitor.Monitor; 80 81 import org.apache.derby.iapi.services.property.PropertyUtil; 82 import org.apache.derby.iapi.sql.compile.Optimizer; 83 84 import org.apache.derby.iapi.reference.Property; 85 import org.apache.derby.iapi.services.io.FormatableBitSet; 86 87 import org.apache.derby.iapi.sql.execute.RunTimeStatistics; 88 89 import java.sql.Connection ; 90 import java.sql.SQLException ; 91 import java.sql.SQLWarning ; 92 93 import java.util.ArrayList ; 94 import java.util.Enumeration ; 95 import java.util.Vector ; 96 import java.util.Hashtable ; 97 import java.util.HashSet ; 98 import org.apache.derby.iapi.util.ReuseFactory; 99 import org.apache.derby.iapi.sql.execute.TemporaryRowHolder; 100 101 107 public abstract class BaseActivation implements CursorActivation, GeneratedByteCode 108 109 { 110 111 protected ResultSetFactory rsFactory; 112 protected ExecutionFactory exFactory; 113 protected DataValueFactory dvFactory; 114 protected LanguageConnectionContext lcc; 115 protected ContextManager cm; 116 protected ExecutionContext ec; 117 118 119 protected ExecPreparedStatement preStmt; 120 protected ResultSet resultSet; 121 protected ResultDescription resultDescription; 122 protected boolean closed; 123 private String cursorName; 124 125 protected int numSubqueries; 126 127 private boolean singleExecution; 128 129 private volatile boolean inUse; 132 133 private java.sql.ResultSet targetVTI; 134 private SQLWarning warnings; 135 136 private GeneratedClass gc; 138 private boolean checkRowCounts; 139 private HashSet rowCountsCheckedThisExecution = new HashSet (4, 0.9f); 140 141 private static final long MAX_SQRT = (long) Math.sqrt(Long.MAX_VALUE); 142 143 private static final int TEN_PERCENT_THRESHOLD = 400; 148 149 153 private ConglomerateController updateHeapCC; 154 private ScanController indexSC; 155 private long indexConglomerateNumber = -1; 156 157 private TableDescriptor ddlTableDescriptor; 158 159 private int maxRows = -1; 160 private boolean forCreateTable; 161 162 private boolean scrollable; 163 164 private boolean resultSetHoldability; 165 166 private CursorResultSet forUpdateIndexScan; 169 170 private boolean autoGeneratedKeysResultSetMode; 175 private int[] autoGeneratedKeysColumnIndexes ; 176 private String [] autoGeneratedKeysColumnNames ; 177 178 protected int indexOfSessionTableNamesInSavedObjects = -1; 182 183 protected ExecRow[] row; 187 protected ParameterValueSet pvs; 188 189 193 protected BaseActivation() 194 { 195 super(); 196 } 197 198 public final void initFromContext(Context context) 199 throws StandardException { 200 201 if (SanityManager.DEBUG) 202 { 203 SanityManager.ASSERT(context!=null, "NULL context passed to BaseActivation.initFromContext"); 204 } 205 this.cm = context.getContextManager(); 206 207 lcc = (LanguageConnectionContext) cm.getContext(LanguageConnectionContext.CONTEXT_ID); 208 209 if (SanityManager.DEBUG) { 210 if (lcc == null) 211 SanityManager.THROWASSERT("lcc is null in activation type " + getClass()); 212 } 213 214 dvFactory = lcc.getDataValueFactory(); 215 if (SanityManager.DEBUG) 216 { 217 SanityManager.ASSERT(dvFactory != null, 218 "No data value factory in getDataValueFactory"); 219 } 220 221 ec = lcc.getExecutionContext(); 222 223 rsFactory = ec.getResultSetFactory(); 226 if (SanityManager.DEBUG) 227 { 228 SanityManager.ASSERT(rsFactory!=null, "Unable to find ResultSetFactory"); 229 } 230 231 exFactory = ec.getExecutionFactory(); 232 if (SanityManager.DEBUG) 233 { 234 SanityManager.ASSERT(exFactory!=null, "Unable to find ExecutionFactory"); 235 } 236 237 inUse = true; 239 240 lcc.addActivation(this); 242 } 243 244 245 249 public final ExecPreparedStatement getPreparedStatement() { 250 return preStmt; 251 } 252 253 public ConstantAction getConstantAction() { 254 return preStmt.getConstantAction(); 255 } 256 257 258 public final void checkStatementValidity() throws StandardException { 259 260 if (preStmt == null) 261 return; 262 263 synchronized (preStmt) { 264 265 if ((gc == preStmt.getActivationClass()) && preStmt.upToDate()) 266 return; 267 } 268 269 StandardException se = StandardException.newException(SQLState.LANG_STATEMENT_NEEDS_RECOMPILE); 270 se.setReport(StandardException.REPORT_NEVER); 271 throw se; 272 } 273 274 280 public final void setupActivation(ExecPreparedStatement ps, boolean scrollable) { 281 preStmt = ps; 282 283 if (ps != null) { 284 resultDescription = ps.getResultDescription(); 286 this.scrollable = scrollable; 287 288 if (pvs != null && pvs.getParameterCount() != 0) 291 pvs.initialize(ps.getParameterTypes()); 292 293 } else { 294 resultDescription = null; 295 this.scrollable = false; 296 } 297 } 298 299 public ResultSet getResultSet() { 300 return resultSet; 301 } 302 303 public void clearResultSet() { 304 resultSet = null; 305 } 306 307 314 public RowLocation getRowLocationTemplate(int itemNumber) 315 { 316 if (SanityManager.DEBUG) 317 { 318 SanityManager.ASSERT(itemNumber >= 0, 319 "itemNumber expected to be >= 0"); 320 if (! (getPreparedStatement().getSavedObject(itemNumber) instanceof RowLocation)) 321 { 322 SanityManager.THROWASSERT( 323 "getPreparedStatement().getSavedObject(itemNumber) expected to be " + 324 "instance of RowLocation, not " + 325 getPreparedStatement().getSavedObject(itemNumber).getClass().getName() + 326 ", query is " + getPreparedStatement().getSource()); 327 } 328 RowLocation rl = (RowLocation) getPreparedStatement().getSavedObject(itemNumber); 329 if (! (rl.cloneObject() instanceof RowLocation)) 330 { 331 SanityManager.THROWASSERT( 332 "rl.cloneObject() expected to be " + 333 "instance of RowLocation, not " + 334 rl.getClass().getName() + 335 ", query is " + getPreparedStatement().getSource()); 336 } 337 } 338 341 return (RowLocation) 342 ((RowLocation)(getPreparedStatement().getSavedObject(itemNumber))).cloneObject(); 343 } 344 345 347 public ResultDescription getResultDescription() { 348 if (SanityManager.DEBUG) 349 SanityManager.ASSERT(resultDescription != null, "Must have a result description"); 350 return resultDescription; 351 } 352 353 366 public void reset() throws StandardException 367 { 368 if (resultSet != null) { 370 if (!resultSetHoldability || !resultSet.returnsRows()) { 371 resultSet.close(); 374 resultSet = null; } else if (resultSet.returnsRows()) { 376 resultSet.clearCurrentRow(); 377 } 378 } 379 updateHeapCC = null; 380 382 if (!isSingleExecution()) 383 clearWarnings(); 384 } 385 386 397 public final void close() throws StandardException 398 { 399 if (! closed) { 400 401 403 if (resultSet != null) 406 { 407 resultSet.finish(); 408 resultSet = null; 409 } 410 411 reset(); 418 closed = true; 419 420 LanguageConnectionContext lcc = getLanguageConnectionContext(); 421 422 lcc.removeActivation(this); 423 if (preStmt != null) { 424 preStmt.finish(lcc); 425 preStmt = null; 426 } 427 428 try { 429 closeActivationAction(); 430 } catch (Throwable e) { 431 throw StandardException.plainWrapException(e); 432 } 433 434 } 435 436 } 437 438 442 protected void closeActivationAction() throws Exception { 443 } 446 447 451 public boolean isClosed() { 452 return closed; 453 } 454 455 460 public void setSingleExecution() { 461 singleExecution = true; 462 } 463 464 470 public boolean isSingleExecution() { 471 return singleExecution; 472 } 473 474 478 public int getNumSubqueries() { 479 return numSubqueries; 480 } 481 482 485 public boolean isCursorActivation() 486 { 487 return false; 488 } 489 490 494 public final void setGC(GeneratedClass gc) { 495 this.gc = gc; 496 } 497 498 public final GeneratedClass getGC() { 499 500 if (SanityManager.DEBUG) { 501 if (gc == null) 502 SanityManager.THROWASSERT("move code requiring GC to postConstructor() method!!"); 503 } 504 return gc; 505 } 506 507 public final GeneratedMethod getMethod(String methodName) throws StandardException { 508 509 return getGC().getMethod(methodName); 510 } 511 public Object e0() throws StandardException { return null; } 512 public Object e1() throws StandardException { return null; } 513 public Object e2() throws StandardException { return null; } 514 public Object e3() throws StandardException { return null; } 515 public Object e4() throws StandardException { return null; } 516 public Object e5() throws StandardException { return null; } 517 public Object e6() throws StandardException { return null; } 518 public Object e7() throws StandardException { return null; } 519 public Object e8() throws StandardException { return null; } 520 public Object e9() throws StandardException { return null; } 521 522 526 533 public boolean checkIfThisActivationHasHoldCursor(String tableName) 534 { 535 if (!inUse) 536 return false; 537 538 if (resultSetHoldability == false) return false; 540 541 if (indexOfSessionTableNamesInSavedObjects == -1) return false; 543 544 545 if ((resultSet != null) && !resultSet.isClosed() && resultSet.returnsRows()) 546 { 547 return ((ArrayList )getPreparedStatement().getSavedObject(indexOfSessionTableNamesInSavedObjects)).contains(tableName); 550 } 551 552 return false; 553 } 554 555 558 559 public void setCursorName(String cursorName) 560 { 561 if (isCursorActivation()) 562 this.cursorName = cursorName; 563 } 564 565 566 575 public String getCursorName() { 576 577 return isCursorActivation() ? cursorName : null; 578 } 579 580 public void setResultSetHoldability(boolean resultSetHoldability) 581 { 582 this.resultSetHoldability = resultSetHoldability; 583 } 584 585 public boolean getResultSetHoldability() 586 { 587 return resultSetHoldability; 588 } 589 590 591 public void setAutoGeneratedKeysResultsetInfo(int[] columnIndexes, String [] columnNames) 592 { 593 autoGeneratedKeysResultSetMode = true; 594 autoGeneratedKeysColumnIndexes = columnIndexes; 595 autoGeneratedKeysColumnNames = columnNames; 596 } 597 598 599 public boolean getAutoGeneratedKeysResultsetMode() 600 { 601 return autoGeneratedKeysResultSetMode; 602 } 603 604 605 public int[] getAutoGeneratedKeysColumnIndexes() 606 { 607 return autoGeneratedKeysColumnIndexes; 608 } 609 610 611 public String [] getAutoGeneratedKeysColumnNames() 612 { 613 return autoGeneratedKeysColumnNames; 614 } 615 616 620 621 625 public ResultSetFactory getResultSetFactory() { 626 return rsFactory; 627 } 628 629 632 public ExecutionFactory getExecutionFactory() { 633 return exFactory; 634 } 635 636 637 646 public CursorResultSet getTargetResultSet() { 647 if (SanityManager.DEBUG) 648 SanityManager.THROWASSERT("Must be overridden to be used."); 649 return null; 650 } 651 652 658 protected DataValueDescriptor 659 getSetAutoincrementValue(int columnPosition, long increment) 660 throws StandardException 661 { 662 DataValueDescriptor l = 663 ((InsertResultSet)resultSet).getSetAutoincrementValue(columnPosition, increment); 664 return l; 665 666 } 667 668 677 public CursorResultSet getCursorResultSet() { 678 if (SanityManager.DEBUG) 679 SanityManager.THROWASSERT("Must be overridden to be used."); 680 return null; 681 } 682 683 712 public void throwIfClosed(String op) throws StandardException { 713 if (closed) 714 throw StandardException.newException(SQLState.LANG_ACTIVATION_CLOSED, op); 715 } 716 717 724 public static void setColumnPosition( 725 int[] columnPositions, 726 int positionToSet, 727 int column) 728 { 729 columnPositions[positionToSet] = column; 730 } 731 732 739 public static void allocateQualArray( 740 Qualifier[][] qualifiers, 741 int position, 742 int length) 743 { 744 qualifiers[position] = new Qualifier[length]; 745 } 746 747 748 760 public static void setQualifier( 761 Qualifier[][] qualifiers, 762 Qualifier qualifier, 763 int position_1, 764 int position_2) 765 { 766 qualifiers[position_1][position_2] = qualifier; 767 } 768 769 774 public static void reinitializeQualifiers(Qualifier[][] qualifiers) 775 { 776 if (qualifiers != null) 777 { 778 for (int term = 0; term < qualifiers.length; term++) 779 { 780 for (int i = 0; i < qualifiers[term].length; i++) 781 { 782 qualifiers[term][i].reinitialize(); 783 } 784 } 785 } 786 } 787 788 791 public final void markUnused() 792 { 793 if(isInUse()) { 794 inUse = false; 795 lcc.notifyUnusedActivation(); 796 } 797 } 798 799 804 public final boolean isInUse() 805 { 806 return inUse; 807 } 808 809 812 public void addWarning(SQLWarning w) 813 { 814 if (warnings == null) 815 warnings = w; 816 else 817 warnings.setNextWarning(w); 818 } 819 820 823 public SQLWarning getWarnings() 824 { 825 return warnings; 826 } 827 828 831 public void clearWarnings() 832 { 833 warnings = null; 834 } 835 836 839 protected static void nullToPrimitiveTest(DataValueDescriptor dvd, String primitiveType) 840 throws StandardException 841 { 842 if (dvd.isNull()) 843 { 844 throw StandardException.newException(SQLState.LANG_NULL_TO_PRIMITIVE_PARAMETER, primitiveType); 845 } 846 } 847 848 852 public void informOfRowCount(NoPutResultSet resultSet, long currentRowCount) 853 throws StandardException 854 { 855 856 857 if (checkRowCounts) 858 { 859 boolean significantChange = false; 860 861 int resultSetNumber = resultSet.resultSetNumber(); 862 Integer rsn = ReuseFactory.getInteger(resultSetNumber); 863 864 865 if (rowCountsCheckedThisExecution.add(rsn)) 866 { 867 synchronized (getPreparedStatement()) 868 { 869 Vector rowCountCheckVector = getRowCountCheckVector(); 870 871 if (rowCountCheckVector == null) { 872 rowCountCheckVector = new Vector (); 873 setRowCountCheckVector(rowCountCheckVector); 874 } 875 876 Long firstRowCount = null; 877 878 881 if (resultSetNumber < rowCountCheckVector.size()) 882 { 883 firstRowCount = 884 (Long ) rowCountCheckVector.elementAt(resultSetNumber); 885 } 886 else 887 { 888 rowCountCheckVector.setSize(resultSetNumber + 1); 889 } 890 891 if (firstRowCount != null) 892 { 893 897 long n1 = firstRowCount.longValue(); 898 899 if (currentRowCount != n1) 900 { 901 if (n1 >= TEN_PERCENT_THRESHOLD) 902 { 903 908 long changeFactor = n1 / (currentRowCount - n1); 909 if (Math.abs(changeFactor) <= 10) 910 significantChange = true; 911 } 912 else 913 { 914 953 long changediff = currentRowCount - n1; 954 955 966 if (Math.abs(changediff) <= MAX_SQRT) 967 { 968 if ((changediff * changediff) > 969 Math.abs(4 * n1)) 970 { 971 significantChange = true; 972 } 973 } 974 } 975 } 976 } 977 else 978 { 979 firstRowCount = new Long (currentRowCount); 980 rowCountCheckVector.setElementAt( 981 firstRowCount, 982 resultSetNumber 983 ); 984 985 } 986 } 987 } 988 989 990 if (significantChange) 991 { 992 preStmt.makeInvalid(DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc); 993 } 994 } 995 996 } 997 998 1003 public void startExecution() throws StandardException 1004 { 1005 shouldWeCheckRowCounts(); 1007 1008 if (checkRowCounts) 1011 rowCountsCheckedThisExecution.clear(); 1012 } 1013 1014 1017 public ConglomerateController getHeapConglomerateController() 1018 { 1019 return updateHeapCC; 1020 } 1021 1022 1023 1026 public void setHeapConglomerateController(ConglomerateController updateHeapCC) 1027 { 1028 this.updateHeapCC = updateHeapCC; 1029 } 1030 1031 1034 public void clearHeapConglomerateController() 1035 { 1036 updateHeapCC = null; 1037 } 1038 1039 1042 public ScanController getIndexScanController() 1043 { 1044 return indexSC; 1045 } 1046 1047 1050 public void setIndexScanController(ScanController indexSC) 1051 { 1052 this.indexSC = indexSC; 1053 } 1054 1055 1058 public long getIndexConglomerateNumber() 1059 { 1060 return indexConglomerateNumber; 1061 } 1062 1063 1066 public void setIndexConglomerateNumber(long indexConglomerateNumber) 1067 { 1068 this.indexConglomerateNumber = indexConglomerateNumber; 1069 } 1070 1071 1074 public void clearIndexScanInfo() 1075 { 1076 indexSC = null; 1077 indexConglomerateNumber = -1; 1078 } 1079 1080 1083 public void setForCreateTable() 1084 { 1085 forCreateTable = true; 1086 } 1087 1088 1091 public boolean getForCreateTable() 1092 { 1093 return forCreateTable; 1094 } 1095 1096 1099 public void setDDLTableDescriptor(TableDescriptor td) 1100 { 1101 ddlTableDescriptor = td; 1102 } 1103 1104 1107 public TableDescriptor getDDLTableDescriptor() 1108 { 1109 return ddlTableDescriptor; 1110 } 1111 1112 1115 public void setMaxRows(int maxRows) 1116 { 1117 this.maxRows = maxRows; 1118 } 1119 1120 1123 public int getMaxRows() 1124 { 1125 return maxRows; 1126 } 1127 1128 public void setTargetVTI(java.sql.ResultSet targetVTI) 1129 { 1130 this.targetVTI = targetVTI; 1131 } 1132 1133 public java.sql.ResultSet getTargetVTI() 1134 { 1135 return targetVTI; 1136 } 1137 1138 private void shouldWeCheckRowCounts() throws StandardException 1139 { 1140 1146 int executionCount = getExecutionCount() + 1; 1147 1148 1156 1157 if (executionCount == 1) 1158 { 1159 checkRowCounts = true; 1160 } 1161 else if (executionCount < 1162 Property.MIN_LANGUAGE_STALE_PLAN_CHECK_INTERVAL) 1163 { 1164 checkRowCounts = false; 1165 } 1166 else 1167 { 1168 int stalePlanCheckInterval = getStalePlanCheckInterval(); 1169 1170 1174 if (stalePlanCheckInterval == 0) 1175 { 1176 TransactionController tc = getTransactionController(); 1177 1178 stalePlanCheckInterval = 1179 PropertyUtil.getServiceInt( 1180 tc, 1181 Property.LANGUAGE_STALE_PLAN_CHECK_INTERVAL, 1182 Property.MIN_LANGUAGE_STALE_PLAN_CHECK_INTERVAL, 1183 Integer.MAX_VALUE, 1184 Property.DEFAULT_LANGUAGE_STALE_PLAN_CHECK_INTERVAL 1185 ); 1186 setStalePlanCheckInterval(stalePlanCheckInterval); 1187 } 1188 1189 checkRowCounts = (executionCount % stalePlanCheckInterval) == 1; 1190 1191 1192 } 1193 1194 setExecutionCount(executionCount); 1195 } 1196 1197 1201 abstract protected int getExecutionCount(); 1202 1203 abstract protected void setExecutionCount(int newValue); 1204 1205 1210 abstract protected Vector getRowCountCheckVector(); 1211 1212 abstract protected void setRowCountCheckVector(Vector newValue); 1213 1214 1220 abstract protected int getStalePlanCheckInterval(); 1221 1222 abstract protected void setStalePlanCheckInterval(int newValue); 1223 1224 public final boolean getScrollable() { 1225 return scrollable; 1226 } 1227 1228 protected final void setParameterValueSet(int paramCount, boolean hasReturnParam) { 1229 1230 pvs = lcc.getLanguageFactory().newParameterValueSet( 1231 lcc.getLanguageConnectionFactory().getClassFactory().getClassInspector(), 1232 paramCount, hasReturnParam); 1233 } 1234 1235 1241 protected final DataValueDescriptor getParameter(int position) throws StandardException { 1242 return pvs.getParameter(position); 1243 } 1244 1245 1248 public ParameterValueSet getParameterValueSet() 1249 { 1250 if (pvs == null) 1251 setParameterValueSet(0, false); 1252 return pvs; 1253 } 1254 1255 public void setParameters(ParameterValueSet parameterValues, DataTypeDescriptor[] parameterTypes) throws StandardException 1258 { 1259 if (!isClosed()) 1260 { 1261 1262 if (this.pvs == null || parameterTypes == null) { 1263 pvs = parameterValues; 1264 return; 1265 1266 } 1267 1268 DataTypeDescriptor[] newParamTypes = preStmt.getParameterTypes(); 1269 1270 1274 boolean match = false; 1275 if (newParamTypes != null) { 1276 1277 if (newParamTypes.length == parameterTypes.length) { 1278 1279 1280 match = true; 1281 for (int i = 0; i < parameterTypes.length; i++) 1282 { 1283 DataTypeDescriptor oldType = parameterTypes[i]; 1284 DataTypeDescriptor newType = newParamTypes[i]; 1285 1286 if (!oldType.isExactTypeAndLengthMatch(newType)) { 1287 match = false; 1288 break; 1289 } 1290 1294 if (oldType.isNullable() != newType.isNullable()) { 1295 match = false; 1296 break; 1297 } 1298 } 1299 } 1300 1301 } 1302 1303 if (!match) 1304 throw StandardException.newException(SQLState.LANG_OBSOLETE_PARAMETERS); 1305 1306 1307 parameterValues.transferDataValues(pvs); 1308 1309 } 1310 else if (SanityManager.DEBUG) 1311 { 1312 SanityManager.THROWASSERT("isClosed() is expected to return false"); 1313 } 1314 } 1315 1316 1322 1323 public void throwIfMissingParms() throws StandardException 1324 { 1325 if (pvs != null && !pvs.allAreSet()) 1326 { 1327 throw StandardException.newException(SQLState.LANG_MISSING_PARMS); 1328 } 1329 } 1330 1331 1334 public void setCurrentRow(ExecRow currentRow, int resultSetNumber) 1335 { 1336 if (SanityManager.DEBUG) 1337 { 1338 SanityManager.ASSERT(!isClosed(), "closed"); 1339 if (row != null) 1340 { 1341 if (!(resultSetNumber >=0 && resultSetNumber < row.length)) 1342 { 1343 SanityManager.THROWASSERT("resultSetNumber = " + resultSetNumber + 1344 ", expected to be between 0 and " + row.length); 1345 } 1346 } 1347 } 1348 if (row != null) 1349 { 1350 row[resultSetNumber] = currentRow; 1351 } 1352 } 1353 1354 1357 public void clearCurrentRow(int resultSetNumber) 1358 { 1359 if (SanityManager.DEBUG) 1360 { 1361 if (row != null) 1362 { 1363 if (!(resultSetNumber >=0 && resultSetNumber < row.length)) 1364 { 1365 SanityManager.THROWASSERT("resultSetNumber = " + resultSetNumber + 1366 ", expected to be between 0 and " + row.length); 1367 } 1368 } 1369 } 1370 if (row != null) 1371 { 1372 row[resultSetNumber] = null; 1373 } 1374 } 1375 1376 protected final DataValueDescriptor getColumnFromRow(int rsNumber, int colId) 1377 throws StandardException { 1378 1379 if( row[rsNumber] == null) 1380 { 1381 1384 return null; 1385 } 1386 return row[rsNumber].getColumn(colId); 1387 } 1388 1389 protected void checkPositionedStatement(String cursorName, String psName) 1390 throws StandardException { 1391 1392 ExecPreparedStatement ps = getPreparedStatement(); 1393 if (ps == null) 1394 return; 1395 1396 LanguageConnectionContext lcc = getLanguageConnectionContext(); 1397 1398 CursorActivation cursorActivation = lcc.lookupCursorActivation(cursorName); 1399 1400 if (cursorActivation != null) 1401 { 1402 if (!psName.equals(cursorActivation.getPreparedStatement().getObjectName())) { 1404 1405 ps.makeInvalid(DependencyManager.CHANGED_CURSOR, lcc); 1409 } 1410 } 1411 } 1412 1413 1435 public NoPutResultSet materializeResultSetIfPossible(NoPutResultSet rs) 1436 throws StandardException 1437 { 1438 rs.openCore(); 1439 Vector rowCache = new Vector (); 1440 ExecRow aRow; 1441 int cacheSize = 0; 1442 FormatableBitSet toClone = null; 1443 1444 int maxMemoryPerTable = getLanguageConnectionContext().getOptimizerFactory().getMaxMemoryPerTable(); 1445 1446 aRow = rs.getNextRowCore(); 1447 if (aRow != null) 1448 { 1449 toClone = new FormatableBitSet(aRow.nColumns() + 1); 1450 toClone.set(1); 1451 } 1452 while (aRow != null) 1453 { 1454 cacheSize += aRow.getColumn(1).getLength(); 1455 if (cacheSize > maxMemoryPerTable || 1456 rowCache.size() > Optimizer.MAX_DYNAMIC_MATERIALIZED_ROWS) 1457 break; 1458 rowCache.addElement(aRow.getClone(toClone)); 1459 aRow = rs.getNextRowCore(); 1460 } 1461 rs.close(); 1462 1463 if (aRow == null) 1464 { 1465 int rsNum = rs.resultSetNumber(); 1466 1467 int numRows = rowCache.size(); 1468 if (numRows == 0) 1469 { 1470 return new RowResultSet( 1471 this, 1472 (ExecRow) null, 1473 true, 1474 rsNum, 1475 0, 1476 0); 1477 } 1478 RowResultSet[] rrs = new RowResultSet[numRows]; 1479 UnionResultSet[] urs = new UnionResultSet[numRows - 1]; 1480 1481 for (int i = 0; i < numRows; i++) 1482 { 1483 rrs[i] = new RowResultSet( 1484 this, 1485 (ExecRow) rowCache.elementAt(i), 1486 true, 1487 rsNum, 1488 1, 1489 0); 1490 if (i > 0) 1491 { 1492 urs[i - 1] = new UnionResultSet ( 1493 (i > 1) ? (NoPutResultSet)urs[i - 2] : (NoPutResultSet)rrs[0], 1494 rrs[i], 1495 this, 1496 rsNum, 1497 i + 1, 1498 0); 1499 } 1500 } 1501 1502 rs.finish(); 1503 1504 if (numRows == 1) 1505 return rrs[0]; 1506 else 1507 return urs[urs.length - 1]; 1508 } 1509 return rs; 1510 } 1511 1512 1513 1514 protected CursorResultSet[] raParentResultSets; 1516 1517 1518 protected Hashtable parentResultSets; 1521 public void setParentResultSet(TemporaryRowHolder rs, String resultSetId) 1522 { 1523 Vector rsVector; 1524 if(parentResultSets == null) 1525 parentResultSets = new Hashtable (); 1526 rsVector = (Vector ) parentResultSets.get(resultSetId); 1527 if(rsVector == null) 1528 { 1529 rsVector = new Vector (); 1530 rsVector.addElement(rs); 1531 }else 1532 { 1533 rsVector.addElement(rs); 1534 } 1535 parentResultSets.put(resultSetId , rsVector); 1536 } 1537 1538 1542 public Vector getParentResultSet(String resultSetId) 1543 { 1544 return (Vector ) parentResultSets.get(resultSetId); 1545 } 1546 1547 public Hashtable getParentResultSets() 1548 { 1549 return parentResultSets; 1550 } 1551 1552 1558 public void clearParentResultSets() 1559 { 1560 if(parentResultSets != null) 1561 parentResultSets.clear(); 1562 } 1563 1564 1568 public void setForUpdateIndexScan(CursorResultSet forUpdateIndexScan) 1569 { 1570 this.forUpdateIndexScan = forUpdateIndexScan; 1571 } 1572 1573 public CursorResultSet getForUpdateIndexScan() 1574 { 1575 return forUpdateIndexScan; 1576 } 1577 1578 private java.util.Calendar cal; 1579 1586 protected java.util.Calendar getCalendar() { 1587 if (cal == null) 1588 cal = new java.util.GregorianCalendar (); 1589 return cal; 1590 1591 } 1592 1593 1594 1597 1600 public final LanguageConnectionContext getLanguageConnectionContext() 1601 { 1602 return lcc; 1603 } 1604 1605 public final TransactionController getTransactionController() 1606 { 1607 return lcc.getTransactionExecute(); 1608 } 1609 1610 1613 ExecutionContext getExecutionContext() 1614 { 1615 return ec; 1616 } 1617 1618 1623 public ContextManager getContextManager() 1624 { 1625 return cm; 1626 } 1627 1628 1632 public DataValueFactory getDataValueFactory() 1633 { 1634 return dvFactory; 1635 } 1636 1637 1642 public Connection getCurrentConnection() throws SQLException { 1643 1644 ConnectionContext cc = 1645 (ConnectionContext) cm.getContext(ConnectionContext.CONTEXT_ID); 1646 1647 return cc.getNestedConnection(true); 1648 } 1649 1650 1653 public java.sql.ResultSet [][] getDynamicResults() { 1654 return null; 1655 } 1656 1659 public int getMaxDynamicResults() { 1660 return 0; 1661 } 1662 1663 1672 public NumberDataValue getDB2Length( DataValueDescriptor value, 1673 int constantLength, 1674 NumberDataValue reUse) 1675 throws StandardException 1676 { 1677 if( reUse == null) 1678 reUse = getDataValueFactory().getNullInteger( null); 1679 if( value.isNull()) 1680 reUse.setToNull(); 1681 else 1682 { 1683 if( constantLength >= 0) 1684 reUse.setValue( constantLength); 1685 else 1686 { 1687 reUse.setValue(value.getLength()); 1688 } 1689 } 1690 return reUse; 1691 } } 1693 | Popular Tags |