001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.GenericExecutionFactory
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.Activation;
025:
026: import org.apache.derby.impl.sql.GenericColumnDescriptor;
027: import org.apache.derby.impl.sql.GenericResultDescription;
028: import org.apache.derby.iapi.services.monitor.ModuleControl;
029: import org.apache.derby.iapi.services.monitor.ModuleSupportable;
030: import org.apache.derby.iapi.services.monitor.Monitor;
031: import org.apache.derby.iapi.services.io.FormatIdUtil;
032: import org.apache.derby.iapi.error.StandardException;
033: import org.apache.derby.iapi.types.DataValueFactory;
034:
035: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
036: import org.apache.derby.iapi.sql.execute.ExecRow;
037: import org.apache.derby.iapi.sql.execute.ExecIndexRow;
038: import org.apache.derby.iapi.sql.execute.ExecutionContext;
039: import org.apache.derby.iapi.sql.execute.ExecutionFactory;
040: import org.apache.derby.iapi.sql.execute.ResultSetFactory;
041: import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory;
042: import org.apache.derby.iapi.sql.execute.ScanQualifier;
043: import org.apache.derby.iapi.sql.Activation;
044: import org.apache.derby.iapi.sql.ResultColumnDescriptor;
045: import org.apache.derby.iapi.sql.ResultDescription;
046:
047: import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
048: import org.apache.derby.iapi.store.access.Qualifier;
049: import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
050: import org.apache.derby.iapi.store.access.TransactionController;
051: import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;
052: import org.apache.derby.iapi.sql.execute.RowChanger;
053: import org.apache.derby.iapi.jdbc.ConnectionContext;
054:
055: import org.apache.derby.iapi.services.loader.GeneratedMethod;
056:
057: import org.apache.derby.iapi.services.context.ContextManager;
058: import org.apache.derby.catalog.UUID;
059: import org.apache.derby.iapi.services.io.FormatableBitSet;
060: import org.apache.derby.iapi.services.io.FormatableArrayHolder;
061: import org.apache.derby.iapi.services.io.FormatableHashtable;
062: import org.apache.derby.iapi.services.io.FormatableIntHolder;
063: import org.apache.derby.iapi.services.io.FormatableProperties;
064: import org.apache.derby.catalog.TypeDescriptor;
065: import java.util.Properties;
066: import java.util.Vector;
067:
068: /**
069: This Factory is for creating the execution items needed
070: by a connection for a given database. Once created for
071: the connection, they should be pushed onto the execution context
072: so that they can be found again by subsequent actions during the session.
073:
074: @author ames
075: */
076: public class GenericExecutionFactory implements ModuleControl,
077: ModuleSupportable, ExecutionFactory {
078:
079: //
080: // ModuleControl interface
081: //
082: public boolean canSupport(Properties startParams) {
083: return Monitor.isDesiredType(startParams,
084: org.apache.derby.iapi.reference.EngineType.NONE);
085: }
086:
087: /**
088: This Factory is expected to be booted relative to a
089: LanguageConnectionFactory.
090:
091: @see org.apache.derby.iapi.sql.conn.LanguageConnectionFactory
092: * @exception StandardException Thrown on error
093: */
094: public void boot(boolean create, Properties startParams)
095: throws StandardException {
096: // do we need to/ is there some way to check that
097: // we are configured per database?
098:
099: /* Creation of the connection execution factories
100: * for this database deferred until needed to reduce
101: * boot time.
102: */
103:
104: // REMIND: removed boot of LanguageFactory because
105: // that is done in BasicDatabase.
106: }
107:
108: public void stop() {
109: }
110:
111: //
112: // ExecutionFactory interface
113: //
114: /**
115: * Factories are generic and can be used by all connections.
116: * We defer instantiation until needed to reduce boot time.
117: * We may instantiate too many instances in rare multi-user
118: * situation, but consistency will be maintained and at some
119: * point, usually always, we will have 1 and only 1 instance
120: * of each factory because assignment is atomic.
121: */
122: public ResultSetFactory getResultSetFactory() {
123: if (rsFactory == null) {
124: rsFactory = new GenericResultSetFactory();
125: }
126: return rsFactory;
127: }
128:
129: /**
130: * Get the factory for constant actions.
131: *
132: * @return the factory for constant actions.
133: */
134: public GenericConstantActionFactory getConstantActionFactory() {
135: if (genericConstantActionFactory == null) {
136: genericConstantActionFactory = new GenericConstantActionFactory();
137: }
138: return genericConstantActionFactory;
139: }
140:
141: /**
142: We want a dependency context so that we can push it onto
143: the stack. We could instead require the implementation
144: push it onto the stack for us, but this way we know
145: which context object exactly was pushed onto the stack.
146: */
147: public ExecutionContext newExecutionContext(ContextManager cm) {
148: /* Pass in nulls for execution factories. GEC
149: * will call back to get factories when needed.
150: * This allows us to reduce boot time class loading.
151: * (Replication currently instantiates factories
152: * at boot time.)
153: */
154: return new GenericExecutionContext((ResultSetFactory) null, cm,
155: this );
156: }
157:
158: /*
159: * @see ExecutionFactory#getScanQualifier
160: */
161: public ScanQualifier[][] getScanQualifier(int numQualifiers) {
162: ScanQualifier[] sqArray = new GenericScanQualifier[numQualifiers];
163:
164: for (int ictr = 0; ictr < numQualifiers; ictr++) {
165: sqArray[ictr] = new GenericScanQualifier();
166: }
167:
168: ScanQualifier[][] ret_sqArray = { sqArray };
169:
170: return (ret_sqArray);
171: }
172:
173: /**
174: Make a result description
175: */
176: public ResultDescription getResultDescription(
177: ResultColumnDescriptor[] columns, String statementType) {
178: return new GenericResultDescription(columns, statementType);
179: }
180:
181: /**
182: * Create an execution time ResultColumnDescriptor from a
183: * compile time RCD.
184: *
185: * @param compileRCD The compile time RCD.
186: *
187: * @return The execution time ResultColumnDescriptor
188: */
189: public ResultColumnDescriptor getResultColumnDescriptor(
190: ResultColumnDescriptor compileRCD) {
191: return new GenericColumnDescriptor(compileRCD);
192: }
193:
194: /**
195: * @see ExecutionFactory#releaseScanQualifier
196: */
197: public void releaseScanQualifier(ScanQualifier[][] qualifiers) {
198: }
199:
200: /**
201: * @see ExecutionFactory#getQualifier
202: */
203: public Qualifier getQualifier(int columnId, int operator,
204: GeneratedMethod orderableGetter, Activation activation,
205: boolean orderedNulls, boolean unknownRV,
206: boolean negateCompareResult, int variantType) {
207: return new GenericQualifier(columnId, operator,
208: orderableGetter, activation, orderedNulls, unknownRV,
209: negateCompareResult, variantType);
210: }
211:
212: /**
213: @exception StandardException Thrown on error
214: @see ExecutionFactory#getRowChanger
215: */
216: public RowChanger getRowChanger(long heapConglom,
217: StaticCompiledOpenConglomInfo heapSCOCI,
218: DynamicCompiledOpenConglomInfo heapDCOCI,
219: IndexRowGenerator[] irgs, long[] indexCIDS,
220: StaticCompiledOpenConglomInfo[] indexSCOCIs,
221: DynamicCompiledOpenConglomInfo[] indexDCOCIs,
222: int numberOfColumns, TransactionController tc,
223: int[] changedColumnIds, int[] streamStorableHeapColIds,
224: Activation activation) throws StandardException {
225: return new RowChangerImpl(heapConglom, heapSCOCI, heapDCOCI,
226: irgs, indexCIDS, indexSCOCIs, indexDCOCIs,
227: numberOfColumns, changedColumnIds, tc, null,
228: streamStorableHeapColIds, activation);
229: }
230:
231: /**
232: @exception StandardException Thrown on error
233: @see ExecutionFactory#getRowChanger
234: */
235: public RowChanger getRowChanger(long heapConglom,
236: StaticCompiledOpenConglomInfo heapSCOCI,
237: DynamicCompiledOpenConglomInfo heapDCOCI,
238: IndexRowGenerator[] irgs, long[] indexCIDS,
239: StaticCompiledOpenConglomInfo[] indexSCOCIs,
240: DynamicCompiledOpenConglomInfo[] indexDCOCIs,
241: int numberOfColumns, TransactionController tc,
242: int[] changedColumnIds, FormatableBitSet baseRowReadList,
243: int[] baseRowReadMap, int[] streamStorableColIds,
244: Activation activation) throws StandardException {
245: return new RowChangerImpl(heapConglom, heapSCOCI, heapDCOCI,
246: irgs, indexCIDS, indexSCOCIs, indexDCOCIs,
247: numberOfColumns, changedColumnIds, tc, baseRowReadList,
248: baseRowReadMap, activation);
249: }
250:
251: /**
252: * Get a trigger execution context
253: *
254: * @exception StandardException Thrown on error
255: */
256: public InternalTriggerExecutionContext getTriggerExecutionContext(
257: LanguageConnectionContext lcc, ConnectionContext cc,
258: String statementText, int dmlType, int[] changedColIds,
259: String[] changedColNames, UUID targetTableId,
260: String targetTableName, Vector aiCounters)
261: throws StandardException {
262: return new InternalTriggerExecutionContext(lcc, cc,
263: statementText, dmlType, changedColIds, changedColNames,
264: targetTableId, targetTableName, aiCounters);
265: }
266:
267: /*
268: Old RowFactory interface
269: */
270:
271: public ExecRow getValueRow(int numColumns) {
272: return new ValueRow(numColumns);
273: }
274:
275: public ExecIndexRow getIndexableRow(int numColumns) {
276: return new IndexRow(numColumns);
277: }
278:
279: public ExecIndexRow getIndexableRow(ExecRow valueRow) {
280: if (valueRow instanceof ExecIndexRow)
281: return (ExecIndexRow) valueRow;
282: return new IndexValueRow(valueRow);
283: }
284:
285: /**
286: Packages up a clump of constants which the Plugin uses at execute()
287: time for COPY PUBLICATION.
288: */
289: public Object getJdbcCopyConstants(int[][] paramReferences,
290: TypeDescriptor[][] columnTypes,
291: int[][] publishedTableSchemaCounts) {
292: return null;
293: }
294:
295: /**
296: Packages up a clump of constants which the Plugin uses at execute()
297: time for CREATE PUBLICATION.
298: */
299: public Object getJdbcCreateConstants(UUID[] publishedJarFileIDs,
300: Object publishedItems, int[][] tableSchemaCounts) {
301: return null;
302: }
303:
304: //
305: // class interface
306: //
307: public GenericExecutionFactory() {
308: }
309:
310: //
311: // fields
312: //
313: public ResultSetFactory rsFactory;
314: protected GenericConstantActionFactory genericConstantActionFactory;
315: }
|