KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.GenericExecutionContext
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.sql.execute.ExecutionContext;
25 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
26 import org.apache.derby.iapi.sql.execute.ResultSetFactory;
27 import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory;
28
29 import org.apache.derby.iapi.sql.ResultSet;
30
31 import org.apache.derby.iapi.services.sanity.SanityManager;
32
33 import org.apache.derby.iapi.services.context.ContextImpl;
34 import org.apache.derby.iapi.services.context.ContextManager;
35
36 import org.apache.derby.iapi.services.monitor.Monitor;
37
38 import org.apache.derby.iapi.error.StandardException;
39
40 import java.util.Properties JavaDoc;
41 import org.apache.derby.iapi.error.ExceptionSeverity;
42 /**
43  * ExecutionContext stores the result set factory to be used by
44  * the current connection, and manages execution-level connection
45  * activities.
46  * <p>
47  * An execution context is expected to be on the stack for the
48  * duration of the connection.
49  *
50  * @author ames
51  */

52 class GenericExecutionContext
53     extends ContextImpl
54     implements ExecutionContext {
55
56     private ResultSet sourceRS;
57
58     //
59
// class implementation
60
//
61
private ResultSetFactory rsFactory;
62     private ResultSetStatisticsFactory rssFactory;
63     private ExecutionFactory execFactory;
64
65     //
66
// ExecutionContext interface
67
//
68
/**
69      * Get the ResultSetFactory from this ExecutionContext.
70      *
71      * @return The result set factory associated with this
72      * ExecutionContext
73      */

74     public ResultSetFactory getResultSetFactory()
75     {
76         /* null rsFactory may have been passed to
77          * constructor in order to speed up boot time.
78          */

79         if (rsFactory == null)
80         {
81             rsFactory = execFactory.getResultSetFactory();
82         }
83         return rsFactory;
84     }
85
86     /**
87      * Get the ResultSetStatisticsFactory from this ExecutionContext.
88      *
89      * @return The result set statistics factory associated with this
90      * ExecutionContext
91      *
92      * @exception StandardException Thrown on error
93      */

94     public ResultSetStatisticsFactory getResultSetStatisticsFactory()
95                     throws StandardException {
96         if (rssFactory == null) {
97             rssFactory = (ResultSetStatisticsFactory)
98                 Monitor.bootServiceModule(
99                                     false,
100                                     execFactory,
101                                     ResultSetStatisticsFactory.MODULE,
102                                     (Properties JavaDoc) null);
103         }
104
105         return rssFactory;
106     }
107
108     public ExecutionFactory getExecutionFactory() {
109         return execFactory;
110     }
111
112     /**
113      * @see ExecutionContext#beginStatement
114      * @exception StandardException Thrown on error
115      */

116     public void beginStatement(ResultSet sourceRS) throws StandardException {
117         this.sourceRS = sourceRS;
118     }
119
120     /**
121      * @see ExecutionContext#endStatement
122      * @exception StandardException Thrown on error
123      */

124     public void endStatement() throws StandardException {
125         sourceRS = null;
126     }
127
128     /**
129      * @see ExecutionContext#siftForeignKeys
130      * @exception StandardException Thrown on error
131      */

132     public Object JavaDoc[] siftForeignKeys( Object JavaDoc[] fullList ) throws StandardException
133     {
134         // for the Core Language, this routine is a NOP. The interesting
135
// cases occur during REFRESH and the initial boot of a Target
136
// database. See RepExecutionContext for the interesting cases.
137

138         return fullList;
139     }
140
141     /**
142      * @see ExecutionContext#siftTriggers
143      * @exception StandardException Thrown on error
144      */

145     public Object JavaDoc siftTriggers(Object JavaDoc triggerInfo) throws StandardException
146     {
147         // for the Core Language, this routine is a NOP. The interesting
148
// cases occur during REFRESH and the initial boot of a Target
149
// database. See RepExecutionContext for the interesting cases.
150
return triggerInfo;
151     }
152
153     //
154
// Context interface
155
//
156

157     /**
158      * @exception StandardException Thrown on error
159      */

160     public void cleanupOnError(Throwable JavaDoc error) throws StandardException {
161         if (error instanceof StandardException) {
162
163             StandardException se = (StandardException) error;
164             int severity = se.getSeverity();
165             if (severity >= ExceptionSeverity.SESSION_SEVERITY)
166             {
167                popMe();
168                return;
169             }
170             if (severity > ExceptionSeverity.STATEMENT_SEVERITY)
171             {
172                 return;
173             }
174
175
176             if (sourceRS != null)
177             {
178                 sourceRS.close();
179                 sourceRS = null;
180             }
181
182             endStatement();
183             return;
184         }
185     }
186
187     //
188
// class interface
189
//
190
GenericExecutionContext(
191             ResultSetFactory rsf,
192             ContextManager cm,
193             ExecutionFactory ef)
194     {
195
196         super(cm, ExecutionContext.CONTEXT_ID);
197         rsFactory = rsf;
198         execFactory = ef;
199     }
200
201 }
202
Popular Tags