KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > DMLVTIResultSet


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.DMLVTIResultSet
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
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.sql.conn.LanguageConnectionContext;
29
30 import org.apache.derby.iapi.sql.execute.ExecRow;
31 import org.apache.derby.iapi.sql.execute.NoPutResultSet;
32
33 import org.apache.derby.iapi.sql.Activation;
34 import org.apache.derby.iapi.sql.ResultDescription;
35
36 import org.apache.derby.iapi.store.access.TransactionController;
37
38 import java.sql.PreparedStatement JavaDoc;
39 import java.sql.ResultSet JavaDoc;
40
41 /**
42  * Base class for Insert, Delete & UpdateVTIResultSet
43  */

44 abstract class DMLVTIResultSet extends DMLWriteResultSet
45 {
46
47     // passed in at construction time
48

49     NoPutResultSet sourceResultSet;
50     NoPutResultSet savedSource;
51     UpdatableVTIConstantAction constants;
52     TransactionController tc;
53
54     ResultDescription resultDescription;
55     private int numOpens;
56     boolean firstExecute;
57
58     /**
59      * Returns the description of the inserted rows.
60      * REVISIT: Do we want this to return NULL instead?
61      */

62     public ResultDescription getResultDescription()
63     {
64         return resultDescription;
65     }
66
67     /**
68      *
69      * @exception StandardException Thrown on error
70      */

71     DMLVTIResultSet(NoPutResultSet source,
72                            Activation activation)
73         throws StandardException
74     {
75         super(activation);
76         sourceResultSet = source;
77         constants = (UpdatableVTIConstantAction) constantAction;
78
79         tc = activation.getTransactionController();
80
81         resultDescription = sourceResultSet.getResultDescription();
82     }
83     
84     /**
85         @exception StandardException Standard Cloudscape error policy
86     */

87     public void open() throws StandardException
88     {
89         // Remember if this is the 1st execution
90
firstExecute = (numOpens == 0);
91
92         rowCount = 0;
93
94         if (numOpens++ == 0)
95         {
96             sourceResultSet.openCore();
97         }
98         else
99         {
100             sourceResultSet.reopenCore();
101         }
102
103         openCore();
104        
105         /* Cache query plan text for source, before it gets blown away */
106         if (lcc.getRunTimeStatisticsMode())
107         {
108             /* savedSource nulled after run time statistics generation */
109             savedSource = sourceResultSet;
110         }
111
112         cleanUp();
113
114         endTime = getCurrentTimeMillis();
115     } // end of open()
116

117     protected abstract void openCore() throws StandardException;
118
119     /**
120      * @see org.apache.derby.iapi.sql.ResultSet#cleanUp
121      *
122      * @exception StandardException Thrown on error
123      */

124     public void cleanUp() throws StandardException
125     {
126         /* Close down the source ResultSet tree */
127         if( null != sourceResultSet)
128             sourceResultSet.close();
129         numOpens = 0;
130         super.close();
131     } // end of cleanUp
132

133     public void finish() throws StandardException
134     {
135
136         sourceResultSet.finish();
137         super.finish();
138     } // end of finish
139
}
140
Popular Tags