001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.GenericExecutionContext
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.sql.execute.ExecutionContext;
025: import org.apache.derby.iapi.sql.execute.ExecutionFactory;
026: import org.apache.derby.iapi.sql.execute.ResultSetFactory;
027: import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory;
028:
029: import org.apache.derby.iapi.sql.ResultSet;
030:
031: import org.apache.derby.iapi.services.sanity.SanityManager;
032:
033: import org.apache.derby.iapi.services.context.ContextImpl;
034: import org.apache.derby.iapi.services.context.ContextManager;
035:
036: import org.apache.derby.iapi.services.monitor.Monitor;
037:
038: import org.apache.derby.iapi.error.StandardException;
039:
040: import java.util.Properties;
041: import org.apache.derby.iapi.error.ExceptionSeverity;
042:
043: /**
044: * ExecutionContext stores the result set factory to be used by
045: * the current connection, and manages execution-level connection
046: * activities.
047: * <p>
048: * An execution context is expected to be on the stack for the
049: * duration of the connection.
050: *
051: * @author ames
052: */
053: class GenericExecutionContext extends ContextImpl implements
054: ExecutionContext {
055:
056: private ResultSet sourceRS;
057:
058: //
059: // class implementation
060: //
061: private ResultSetFactory rsFactory;
062: private ResultSetStatisticsFactory rssFactory;
063: private ExecutionFactory execFactory;
064:
065: //
066: // ExecutionContext interface
067: //
068: /**
069: * Get the ResultSetFactory from this ExecutionContext.
070: *
071: * @return The result set factory associated with this
072: * ExecutionContext
073: */
074: public ResultSetFactory getResultSetFactory() {
075: /* null rsFactory may have been passed to
076: * constructor in order to speed up boot time.
077: */
078: if (rsFactory == null) {
079: rsFactory = execFactory.getResultSetFactory();
080: }
081: return rsFactory;
082: }
083:
084: /**
085: * Get the ResultSetStatisticsFactory from this ExecutionContext.
086: *
087: * @return The result set statistics factory associated with this
088: * ExecutionContext
089: *
090: * @exception StandardException Thrown on error
091: */
092: public ResultSetStatisticsFactory getResultSetStatisticsFactory()
093: throws StandardException {
094: if (rssFactory == null) {
095: rssFactory = (ResultSetStatisticsFactory) Monitor
096: .bootServiceModule(false, execFactory,
097: ResultSetStatisticsFactory.MODULE,
098: (Properties) null);
099: }
100:
101: return rssFactory;
102: }
103:
104: public ExecutionFactory getExecutionFactory() {
105: return execFactory;
106: }
107:
108: /**
109: * @see ExecutionContext#beginStatement
110: * @exception StandardException Thrown on error
111: */
112: public void beginStatement(ResultSet sourceRS)
113: throws StandardException {
114: this .sourceRS = sourceRS;
115: }
116:
117: /**
118: * @see ExecutionContext#endStatement
119: * @exception StandardException Thrown on error
120: */
121: public void endStatement() throws StandardException {
122: sourceRS = null;
123: }
124:
125: /**
126: * @see ExecutionContext#siftForeignKeys
127: * @exception StandardException Thrown on error
128: */
129: public Object[] siftForeignKeys(Object[] fullList)
130: throws StandardException {
131: // for the Core Language, this routine is a NOP. The interesting
132: // cases occur during REFRESH and the initial boot of a Target
133: // database. See RepExecutionContext for the interesting cases.
134:
135: return fullList;
136: }
137:
138: /**
139: * @see ExecutionContext#siftTriggers
140: * @exception StandardException Thrown on error
141: */
142: public Object siftTriggers(Object triggerInfo)
143: throws StandardException {
144: // for the Core Language, this routine is a NOP. The interesting
145: // cases occur during REFRESH and the initial boot of a Target
146: // database. See RepExecutionContext for the interesting cases.
147: return triggerInfo;
148: }
149:
150: //
151: // Context interface
152: //
153:
154: /**
155: * @exception StandardException Thrown on error
156: */
157: public void cleanupOnError(Throwable error)
158: throws StandardException {
159: if (error instanceof StandardException) {
160:
161: StandardException se = (StandardException) error;
162: int severity = se.getSeverity();
163: if (severity >= ExceptionSeverity.SESSION_SEVERITY) {
164: popMe();
165: return;
166: }
167: if (severity > ExceptionSeverity.STATEMENT_SEVERITY) {
168: return;
169: }
170:
171: if (sourceRS != null) {
172: sourceRS.close();
173: sourceRS = null;
174: }
175:
176: endStatement();
177: return;
178: }
179: }
180:
181: //
182: // class interface
183: //
184: GenericExecutionContext(ResultSetFactory rsf, ContextManager cm,
185: ExecutionFactory ef) {
186:
187: super(cm, ExecutionContext.CONTEXT_ID);
188: rsFactory = rsf;
189: execFactory = ef;
190: }
191:
192: }
|