001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.DMLVTIResultSet
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.execute;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.error.StandardException;
027:
028: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
029:
030: import org.apache.derby.iapi.sql.execute.ExecRow;
031: import org.apache.derby.iapi.sql.execute.NoPutResultSet;
032:
033: import org.apache.derby.iapi.sql.Activation;
034: import org.apache.derby.iapi.sql.ResultDescription;
035:
036: import org.apache.derby.iapi.store.access.TransactionController;
037:
038: import java.sql.PreparedStatement;
039: import java.sql.ResultSet;
040:
041: /**
042: * Base class for Insert, Delete & UpdateVTIResultSet
043: */
044: abstract class DMLVTIResultSet extends DMLWriteResultSet {
045:
046: // passed in at construction time
047:
048: NoPutResultSet sourceResultSet;
049: NoPutResultSet savedSource;
050: UpdatableVTIConstantAction constants;
051: TransactionController tc;
052:
053: ResultDescription resultDescription;
054: private int numOpens;
055: boolean firstExecute;
056:
057: /**
058: * Returns the description of the inserted rows.
059: * REVISIT: Do we want this to return NULL instead?
060: */
061: public ResultDescription getResultDescription() {
062: return resultDescription;
063: }
064:
065: /**
066: *
067: * @exception StandardException Thrown on error
068: */
069: DMLVTIResultSet(NoPutResultSet source, Activation activation)
070: throws StandardException {
071: super (activation);
072: sourceResultSet = source;
073: constants = (UpdatableVTIConstantAction) constantAction;
074:
075: tc = activation.getTransactionController();
076:
077: resultDescription = sourceResultSet.getResultDescription();
078: }
079:
080: /**
081: @exception StandardException Standard Cloudscape error policy
082: */
083: public void open() throws StandardException {
084: // Remember if this is the 1st execution
085: firstExecute = (numOpens == 0);
086:
087: rowCount = 0;
088:
089: if (numOpens++ == 0) {
090: sourceResultSet.openCore();
091: } else {
092: sourceResultSet.reopenCore();
093: }
094:
095: openCore();
096:
097: /* Cache query plan text for source, before it gets blown away */
098: if (lcc.getRunTimeStatisticsMode()) {
099: /* savedSource nulled after run time statistics generation */
100: savedSource = sourceResultSet;
101: }
102:
103: cleanUp();
104:
105: endTime = getCurrentTimeMillis();
106: } // end of open()
107:
108: protected abstract void openCore() throws StandardException;
109:
110: /**
111: * @see org.apache.derby.iapi.sql.ResultSet#cleanUp
112: *
113: * @exception StandardException Thrown on error
114: */
115: public void cleanUp() throws StandardException {
116: /* Close down the source ResultSet tree */
117: if (null != sourceResultSet)
118: sourceResultSet.close();
119: numOpens = 0;
120: super .close();
121: } // end of cleanUp
122:
123: public void finish() throws StandardException {
124:
125: sourceResultSet.finish();
126: super .finish();
127: } // end of finish
128: }
|