📄 vtiresultset.java
字号:
/* Derby - Class org.apache.derby.impl.sql.execute.VTIResultSet Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.sql.execute;import org.apache.derby.iapi.services.loader.ClassFactory;import org.apache.derby.iapi.services.loader.ClassInspector;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.stream.HeaderPrintWriter;import org.apache.derby.iapi.services.stream.InfoStreams;import org.apache.derby.iapi.sql.execute.CursorResultSet;import org.apache.derby.iapi.sql.execute.ExecRow;import org.apache.derby.iapi.sql.execute.NoPutResultSet;import org.apache.derby.iapi.sql.Activation;import org.apache.derby.iapi.sql.ResultDescription;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.loader.GeneratedMethod;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.services.io.FormatableHashtable;import org.apache.derby.vti.DeferModification;import org.apache.derby.vti.IFastPath;import org.apache.derby.vti.VTIEnvironment;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.ResultSetMetaData;/** */public class VTIResultSet extends NoPutResultSetImpl implements CursorResultSet, VTIEnvironment { /* Run time statistics variables */ public int rowsReturned; public String javaClassName; private boolean next; private ClassInspector classInspector; private GeneratedMethod row; private GeneratedMethod constructor; protected GeneratedMethod closeCleanup; private PreparedStatement userPS; private ResultSet userVTI; private ExecRow allocatedRow; private FormatableBitSet referencedColumns; private boolean version2; private boolean reuseablePs; private boolean isTarget; private FormatableHashtable compileTimeConstants; private int ctcNumber; private boolean pushedProjection; private IFastPath fastPath; private Qualifier[][] pushedQualifiers; private boolean[] runtimeNullableColumn; /** Specified isolation level of SELECT (scan). If not set or not application, it will be set to ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL */ private int scanIsolationLevel = ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL; // // class interface // VTIResultSet(Activation activation, GeneratedMethod row, int resultSetNumber, GeneratedMethod constructor, String javaClassName, Qualifier[][] pushedQualifiers, int erdNumber, boolean version2, boolean reuseablePs, int ctcNumber, boolean isTarget, int scanIsolationLevel, double optimizerEstimatedRowCount, double optimizerEstimatedCost, GeneratedMethod closeCleanup) throws StandardException { super(activation, resultSetNumber, optimizerEstimatedRowCount, optimizerEstimatedCost); this.row = row; this.constructor = constructor; this.javaClassName = javaClassName; this.version2 = version2; this.reuseablePs = reuseablePs; this.isTarget = isTarget; this.pushedQualifiers = pushedQualifiers; this.scanIsolationLevel = scanIsolationLevel; if (erdNumber != -1) { this.referencedColumns = (FormatableBitSet)(activation.getPreparedStatement(). getSavedObject(erdNumber)); } this.ctcNumber = ctcNumber; compileTimeConstants = (FormatableHashtable) (activation.getPreparedStatement(). getSavedObject(ctcNumber)); this.closeCleanup = closeCleanup; constructorTime += getElapsedMillis(beginTime); } // // ResultSet interface (leftover from NoPutResultSet) // /** * Sets state to 'open'. * * @exception StandardException thrown if activation closed. */ public void openCore() throws StandardException { beginTime = getCurrentTimeMillis(); if (SanityManager.DEBUG) SanityManager.ASSERT( ! isOpen, "VTIResultSet already open"); isOpen = true; numOpens++; /* We need to Instantiate the user's ResultSet on the each open since * there is no way to close and then reopen a java.sql.ResultSet. * For Version 2 VTIs, we may be able to skip instantiated their * PreparedStatement here. */ try { if (version2) { userPS = (PreparedStatement) constructor.invoke(activation); if (userPS instanceof org.apache.derby.vti.Pushable) { org.apache.derby.vti.Pushable p = (org.apache.derby.vti.Pushable) userPS; if (referencedColumns != null) { pushedProjection = p.pushProjection(this, getProjectedColList()); } } if (userPS instanceof org.apache.derby.vti.IQualifyable) { org.apache.derby.vti.IQualifyable q = (org.apache.derby.vti.IQualifyable) userPS; q.setQualifiers(this, pushedQualifiers); } fastPath = userPS instanceof IFastPath ? (IFastPath) userPS : null; if( isTarget && userPS instanceof DeferModification && activation.getConstantAction() instanceof UpdatableVTIConstantAction) { UpdatableVTIConstantAction constants = (UpdatableVTIConstantAction) activation.getConstantAction(); ((DeferModification) userPS).modificationNotify( constants.statementType, constants.deferred); } if ((fastPath != null) && fastPath.executeAsFastPath()) ; else userVTI = userPS.executeQuery(); /* Save off the target VTI */ if (isTarget) { activation.setTargetVTI(userVTI); } } else { userVTI = (ResultSet) constructor.invoke(activation); } // Set up the nullablity of the runtime columns, may be delayed setNullableColumnList(); } catch (Throwable t) { throw StandardException.unexpectedUserException(t); } openTime += getElapsedMillis(beginTime); } private boolean[] setNullableColumnList() throws SQLException { if (runtimeNullableColumn != null) return runtimeNullableColumn; if (userVTI == null) return null; ResultSetMetaData rsmd = userVTI.getMetaData(); boolean[] nullableColumn = new boolean[rsmd.getColumnCount() + 1]; for (int i = 1; i < nullableColumn.length; i++) { nullableColumn[i] = rsmd.isNullable(i) != ResultSetMetaData.columnNoNulls; } return runtimeNullableColumn = nullableColumn; } /** * If the VTI is a version2 vti that does not * need to be instantiated multiple times then * we simply close the current ResultSet and * create a new one via a call to * PreparedStatement.executeQuery(). * * @see NoPutResultSet#openCore * @exception StandardException thrown if cursor finished. */ public void reopenCore() throws StandardException { if (reuseablePs) { /* close the user ResultSet. */ if (userVTI != null) { try { userVTI.close(); userVTI = userPS.executeQuery(); /* Save off the target VTI */ if (isTarget) { activation.setTargetVTI(userVTI); } } catch (SQLException se) { throw StandardException.unexpectedUserException(se); } } } else { close(); openCore(); } } /** * If open and not returned yet, returns the row * after plugging the parameters into the expressions. * * @exception StandardException thrown on failure. */ public ExecRow getNextRowCore() throws StandardException { ExecRow result = null; beginTime = getCurrentTimeMillis(); if ( isOpen ) { try { if ((userVTI == null) && (fastPath != null)) { result = getAllocatedRow(); int action = fastPath.nextRow(result.getRowArray()); if (action == IFastPath.GOT_ROW) ; else if (action == IFastPath.SCAN_COMPLETED) result = null; else if (action == IFastPath.NEED_RS) { userVTI = userPS.executeQuery(); } } if ((userVTI != null)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -