📄 baseactivation.java
字号:
*/ public int getMaxRows() { return maxRows; } public void setTargetVTI(java.sql.ResultSet targetVTI) { this.targetVTI = targetVTI; } public java.sql.ResultSet getTargetVTI() { return targetVTI; } private void shouldWeCheckRowCounts() throws StandardException { /* ** Check the row count only every N executions. OK to check this ** without synchronization, since the value of this number is not ** critical. The value of N is determined by the property ** derby.language.stalePlanCheckInterval. */ int executionCount = getExecutionCount() + 1; /* ** Always check row counts the first time, to establish the ** row counts for each result set. After that, don't check ** if the execution count is below the minimum row count check ** interval. This saves us from checking a database property ** when we don't have to (checking involves querying the store, ** which can be expensive). */ if (executionCount == 1) { checkRowCounts = true; } else if (executionCount < Property.MIN_LANGUAGE_STALE_PLAN_CHECK_INTERVAL) { checkRowCounts = false; } else { int stalePlanCheckInterval = getStalePlanCheckInterval(); /* ** Only query the database property once. We can tell because ** the minimum value of the property is greater than zero. */ if (stalePlanCheckInterval == 0) { TransactionController tc = getTransactionController(); stalePlanCheckInterval = PropertyUtil.getServiceInt( tc, Property.LANGUAGE_STALE_PLAN_CHECK_INTERVAL, Property.MIN_LANGUAGE_STALE_PLAN_CHECK_INTERVAL, Integer.MAX_VALUE, Property.DEFAULT_LANGUAGE_STALE_PLAN_CHECK_INTERVAL ); setStalePlanCheckInterval(stalePlanCheckInterval); } checkRowCounts = (executionCount % stalePlanCheckInterval) == 1; } setExecutionCount(executionCount); } /* ** These accessor methods are provided by the sub-class to help figure ** out whether to check row counts during this execution. */ abstract protected int getExecutionCount(); abstract protected void setExecutionCount(int newValue); /* ** These accessor methods are provided by the sub-class to help figure ** out whether the row count for a particular result set has changed ** enough to force recompilation. */ abstract protected Vector getRowCountCheckVector(); abstract protected void setRowCountCheckVector(Vector newValue); /* ** These accessor methods are provided by the sub-class to remember the ** value of the stale plan check interval property, so that we only ** have to query the database properties once (there is heavyweight ** synchronization around the database properties). */ abstract protected int getStalePlanCheckInterval(); abstract protected void setStalePlanCheckInterval(int newValue); public final boolean getScrollable() { return scrollable; } protected final void setParameterValueSet(int paramCount, boolean hasReturnParam) { pvs = lcc.getLanguageFactory().newParameterValueSet( lcc.getLanguageConnectionFactory().getClassFactory().getClassInspector(), paramCount, hasReturnParam); } /** return the parameters. */ public ParameterValueSet getParameterValueSet() { if (pvs == null) setParameterValueSet(0, false); return pvs; } // how do we do/do we want any sanity checking for // the number of parameters expected? public void setParameters(ParameterValueSet parameterValues, DataTypeDescriptor[] parameterTypes) throws StandardException { if (!isClosed()) { if (this.pvs == null || parameterTypes == null) { pvs = parameterValues; return; } DataTypeDescriptor[] newParamTypes = preStmt.getParameterTypes(); /* ** If there are old parameters but not new ones, ** they aren't compatible. */ boolean match = false; if (newParamTypes != null) { if (newParamTypes.length == parameterTypes.length) { /* Check each parameter */ match = true; for (int i = 0; i < parameterTypes.length; i++) { DataTypeDescriptor oldType = parameterTypes[i]; DataTypeDescriptor newType = newParamTypes[i]; if (!oldType.isExactTypeAndLengthMatch(newType)) { match = false; break; } /* ** We could probably get away without checking nullability, ** since parameters are always nullable. */ if (oldType.isNullable() != newType.isNullable()) { match = false; break; } } } } if (!match) throw StandardException.newException(SQLState.LANG_OBSOLETE_PARAMETERS); parameterValues.transferDataValues(pvs); } else if (SanityManager.DEBUG) { SanityManager.THROWASSERT("isClosed() is expected to return false"); } } /** Throw an exception if any parameters are uninitialized. @return Nothing @exception StandardException Thrown if any parameters are unitialized */ public void throwIfMissingParms() throws StandardException { if (pvs != null && !pvs.allAreSet()) { throw StandardException.newException(SQLState.LANG_MISSING_PARMS); } } /** * Remember the row for the specified ResultSet. */ public void setCurrentRow(ExecRow currentRow, int resultSetNumber) { if (SanityManager.DEBUG) { SanityManager.ASSERT(!isClosed(), "closed"); if (row != null) { if (!(resultSetNumber >=0 && resultSetNumber < row.length)) { SanityManager.THROWASSERT("resultSetNumber = " + resultSetNumber + ", expected to be between 0 and " + row.length); } } } if (row != null) { row[resultSetNumber] = currentRow; } } /** * Clear the current row for the specified ResultSet. */ public void clearCurrentRow(int resultSetNumber) { if (SanityManager.DEBUG) { if (row != null) { if (!(resultSetNumber >=0 && resultSetNumber < row.length)) { SanityManager.THROWASSERT("resultSetNumber = " + resultSetNumber + ", expected to be between 0 and " + row.length); } } } if (row != null) { row[resultSetNumber] = null; } } protected final DataValueDescriptor getColumnFromRow(int rsNumber, int colId) throws StandardException { if( row[rsNumber] == null) { /* This actually happens. NoPutResultSetImpl.clearOrderableCache attempts to prefetch invariant values * into a cache. This fails in some deeply nested joins. See Beetle 4736 and 4880. */ return null; } return row[rsNumber].getColumn(colId); } protected void checkPositionedStatement(String cursorName, String psName) throws StandardException { ExecPreparedStatement ps = getPreparedStatement(); if (ps == null) return; LanguageConnectionContext lcc = getLanguageConnectionContext(); CursorActivation cursorActivation = lcc.lookupCursorActivation(cursorName); if (cursorActivation != null) { // check we are compiled against the correct cursor if (!psName.equals(cursorActivation.getPreparedStatement().getObjectName())) { // our prepared statement is now invalid since there // exists another cursor with the same name but a different // statement. ps.makeInvalid(DependencyManager.CHANGED_CURSOR, lcc); } } } /* This method is used to materialize a resultset if can actually fit in the memory * specified by "maxMemoryPerTable" system property. It converts the result set into * union(union(union...(union(row, row), row), ...row), row). It returns this * in-memory converted resultset, or the original result set if not converted. * See beetle 4373 for details. * * @param rs input result set * @return materialized resultset, or original rs if it can't be materialized */ public NoPutResultSet materializeResultSetIfPossible(NoPutResultSet rs) throws StandardException { rs.openCore(); Vector rowCache = new Vector(); ExecRow aRow; int cacheSize = 0; FormatableBitSet toClone = null; int maxMemoryPerTable = getLanguageConnectionContext().getOptimizerFactory().getMaxMemoryPerTable(); aRow = rs.getNextRowCore(); if (aRow != null) { toClone = new FormatableBitSet(aRow.nColumns() + 1); toClone.set(1); } while (aRow != null) { cacheSize += aRow.getColumn(1).getLength(); if (cacheSize > maxMemoryPerTable) break; rowCache.addElement(aRow.getClone(toClone)); aRow = rs.getNextRowCore(); } rs.close(); if (aRow == null) { int rsNum = rs.resultSetNumber(); int numRows = rowCache.size(); if (numRows == 0) { return new RowResultSet( this, (ExecRow) null, true, rsNum, 0, 0, null); } RowResultSet[] rrs = new RowResultSet[numRows]; UnionResultSet[] urs = new UnionResultSet[numRows - 1]; for (int i = 0; i < numRows; i++) { rrs[i] = new RowResultSet( this, (ExecRow) rowCache.elementAt(i), true, rsNum, 1, 0, null); if (i > 0) { urs[i - 1] = new UnionResultSet ( (i > 1) ? (NoPutResultSet)urs[i - 2] : (NoPutResultSet)rrs[0], rrs[i], this, rsNum, i + 1, 0, null); } } rs.finish(); if (numRows == 1) return rrs[0]; else return urs[urs.length - 1]; } return rs; } //WARNING : this field name is referred in the DeleteNode generate routines. protected CursorResultSet[] raParentResultSets; // maintain hash table of parent result set vector // a table can have more than one parent source. protected Hashtable parentResultSets; public void setParentResultSet(TemporaryRowHolder rs, String resultSetId) { Vector rsVector; if(parentResultSets == null) parentResultSets = new Hashtable(); rsVector = (Vector) parentResultSets.get(resultSetId); if(rsVector == null) { rsVector = new Vector(); rsVector.addElement(rs); }else { rsVector.addElement(rs); } parentResultSets.put(resultSetId , rsVector); } /** * get the reference to parent table ResultSets, that will be needed by the * referential action dependent table scans. */ public Vector getParentResultSet(String resultSetId) { return (Vector) parentResultSets.get(resultSetId); } public Hashtable getParentResultSets() { return parentResultSets; } /** ** prepared statement use the same activation for ** multiple execution. For each excution we create new ** set of temporary resultsets, we should clear this hash table. ** otherwise we will refer to the released resources. */ public void clearParentResultSets() { if(parentResultSets != null) parentResultSets.clear(); } /** * beetle 3865: updateable cursor using index. A way of communication * between cursor activation and update activation. */ public void setForUpdateIndexScan(CursorResultSet forUpdateIndexScan) { this.forUpdateIndexScan = forUpdateIndexScan; } public CursorResultSet getForUpdateIndexScan() { return forUpdateIndexScan; } private java.util.Calendar cal; /** Return a calendar for use by this activation. Calendar objects are not thread safe, the one returned is purely for use by this activation and it is assumed that is it single threded through the single active thread in a connection model. */ protected java.util.Calendar getCalendar() { if (cal == null) cal = new java.util.GregorianCalendar(); return cal; } /* ** Code originally in the parent class BaseExpressionActivation */ /** Get the language connection factory associated with this connection */ public final LanguageConnectionContext getLanguageConnectionContext() { return lcc; } public final TransactionController getTransactionController() { return lcc.getTransactionExecute(); } /** * Get the ExecutionContext. */ ExecutionContext getExecutionContext() { return ec; } /** * Get the Current ContextManager. * * @return Current ContextManager */ public ContextManager getContextManager() { return cm; } /** Used by activations to generate data values. Most DML statements will use this method. Possibly some DDL statements will, as well. */ public DataValueFactory getDataValueFactory() { return dvFactory; } /** * Used to get a proxy for the current connection. * * @exception SQLException Thrown on failure to get connection */ public Connection getCurrentConnection() throws SQLException { ConnectionContext cc = (ConnectionContext) cm.getContext(ConnectionContext.CONTEXT_ID); return cc.getNestedConnection(true); } /** Real implementations of this method are provided by a generated class. */ public java.sql.ResultSet[][] getDynamicResults() { return null; } /** Real implementations of this method are provided by a generated class. */ public int getMaxDynamicResults() { return 0; } /** * Compute the DB2 compatible length of a value. * * @param value * @param constantLength The length, if it is a constant modulo null/not null. -1 if the length is not constant * @param reUse If non-null then re-use this as a container for the length * * @return the DB2 compatible length, set to null if value is null. */ public NumberDataValue getDB2Length( DataValueDescriptor value, int constantLength, NumberDataValue reUse) throws StandardException { if( reUse == null) reUse = getDataValueFactory().getNullInteger( null); if( value.isNull()) reUse.setToNull(); else { if( constantLength >= 0) reUse.setValue( constantLength); else { reUse.setValue(value.getLength()); } } return reUse; } // end of getDB2Length}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -