KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.GenericExecutionFactory
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.Activation;
25
26 import org.apache.derby.impl.sql.GenericColumnDescriptor;
27 import org.apache.derby.impl.sql.GenericResultDescription;
28 import org.apache.derby.iapi.services.monitor.ModuleControl;
29 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
30 import org.apache.derby.iapi.services.monitor.Monitor;
31 import org.apache.derby.iapi.services.io.FormatIdUtil;
32 import org.apache.derby.iapi.error.StandardException;
33 import org.apache.derby.iapi.types.DataValueFactory;
34
35 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
36 import org.apache.derby.iapi.sql.execute.ExecRow;
37 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
38 import org.apache.derby.iapi.sql.execute.ExecutionContext;
39 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
40 import org.apache.derby.iapi.sql.execute.ResultSetFactory;
41 import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory;
42 import org.apache.derby.iapi.sql.execute.ScanQualifier;
43 import org.apache.derby.iapi.sql.Activation;
44 import org.apache.derby.iapi.sql.ResultColumnDescriptor;
45 import org.apache.derby.iapi.sql.ResultDescription;
46
47 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
48 import org.apache.derby.iapi.store.access.Qualifier;
49 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
50 import org.apache.derby.iapi.store.access.TransactionController;
51 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator;
52 import org.apache.derby.iapi.sql.execute.RowChanger;
53 import org.apache.derby.iapi.jdbc.ConnectionContext;
54
55 import org.apache.derby.iapi.services.loader.GeneratedMethod;
56
57 import org.apache.derby.iapi.services.context.ContextManager;
58 import org.apache.derby.catalog.UUID;
59 import org.apache.derby.iapi.services.io.FormatableBitSet;
60 import org.apache.derby.iapi.services.io.FormatableArrayHolder;
61 import org.apache.derby.iapi.services.io.FormatableHashtable;
62 import org.apache.derby.iapi.services.io.FormatableIntHolder;
63 import org.apache.derby.iapi.services.io.FormatableProperties;
64 import org.apache.derby.catalog.TypeDescriptor;
65 import java.util.Properties JavaDoc;
66 import java.util.Vector JavaDoc;
67
68 /**
69     This Factory is for creating the execution items needed
70     by a connection for a given database. Once created for
71     the connection, they should be pushed onto the execution context
72     so that they can be found again by subsequent actions during the session.
73
74     @author ames
75  */

76 public class GenericExecutionFactory
77     implements ModuleControl, ModuleSupportable, ExecutionFactory {
78
79     //
80
// ModuleControl interface
81
//
82
public boolean canSupport(Properties startParams)
83     {
84         return Monitor.isDesiredType( startParams, org.apache.derby.iapi.reference.EngineType.NONE);
85     }
86
87     /**
88         This Factory is expected to be booted relative to a
89         LanguageConnectionFactory.
90
91         @see org.apache.derby.iapi.sql.conn.LanguageConnectionFactory
92      * @exception StandardException Thrown on error
93      */

94     public void boot(boolean create, Properties startParams)
95         throws StandardException
96     {
97         // do we need to/ is there some way to check that
98
// we are configured per database?
99

100         /* Creation of the connection execution factories
101          * for this database deferred until needed to reduce
102          * boot time.
103          */

104
105         // REMIND: removed boot of LanguageFactory because
106
// that is done in BasicDatabase.
107
}
108
109     public void stop() {
110     }
111
112     //
113
// ExecutionFactory interface
114
//
115
/**
116      * Factories are generic and can be used by all connections.
117      * We defer instantiation until needed to reduce boot time.
118      * We may instantiate too many instances in rare multi-user
119      * situation, but consistency will be maintained and at some
120      * point, usually always, we will have 1 and only 1 instance
121      * of each factory because assignment is atomic.
122      */

123     public ResultSetFactory getResultSetFactory()
124     {
125         if (rsFactory == null)
126         {
127             rsFactory = new GenericResultSetFactory();
128         }
129         return rsFactory;
130     }
131
132     /**
133       * Get the factory for constant actions.
134       *
135       * @return the factory for constant actions.
136       */

137     public GenericConstantActionFactory getConstantActionFactory()
138     {
139         if (genericConstantActionFactory == null)
140         {
141             genericConstantActionFactory = new GenericConstantActionFactory();
142         }
143         return genericConstantActionFactory;
144     }
145
146     /**
147         We want a dependency context so that we can push it onto
148         the stack. We could instead require the implementation
149         push it onto the stack for us, but this way we know
150         which context object exactly was pushed onto the stack.
151      */

152     public ExecutionContext newExecutionContext(ContextManager cm)
153     {
154         /* Pass in nulls for execution factories. GEC
155          * will call back to get factories when needed.
156          * This allows us to reduce boot time class loading.
157          * (Replication currently instantiates factories
158          * at boot time.)
159          */

160         return new GenericExecutionContext(
161                             (ResultSetFactory) null,
162                             cm, this);
163     }
164
165     /*
166      * @see ExecutionFactory#getScanQualifier
167      */

168     public ScanQualifier[][] getScanQualifier(int numQualifiers)
169     {
170         ScanQualifier[] sqArray = new GenericScanQualifier[numQualifiers];
171
172         for (int ictr = 0; ictr < numQualifiers; ictr++)
173         {
174             sqArray[ictr] = new GenericScanQualifier();
175         }
176
177         ScanQualifier[][] ret_sqArray = { sqArray };
178
179         return(ret_sqArray);
180     }
181
182     /**
183         Make a result description
184      */

185     public ResultDescription getResultDescription(
186         ResultColumnDescriptor[] columns, String JavaDoc statementType) {
187         return new GenericResultDescription(columns, statementType);
188     }
189
190     /**
191      * Create an execution time ResultColumnDescriptor from a
192      * compile time RCD.
193      *
194      * @param compileRCD The compile time RCD.
195      *
196      * @return The execution time ResultColumnDescriptor
197      */

198     public ResultColumnDescriptor getResultColumnDescriptor(ResultColumnDescriptor compileRCD)
199     {
200         return new GenericColumnDescriptor(compileRCD);
201     }
202
203     /**
204      * @see ExecutionFactory#releaseScanQualifier
205      */

206     public void releaseScanQualifier(ScanQualifier[][] qualifiers)
207     {
208     }
209
210     /**
211      * @see ExecutionFactory#getQualifier
212      */

213     public Qualifier getQualifier(
214                             int columnId,
215                             int operator,
216                             GeneratedMethod orderableGetter,
217                             Activation activation,
218                             boolean orderedNulls,
219                             boolean unknownRV,
220                             boolean negateCompareResult,
221                             int variantType)
222     {
223         return new GenericQualifier(columnId, operator, orderableGetter,
224                                     activation, orderedNulls, unknownRV,
225                                     negateCompareResult, variantType);
226     }
227
228     /**
229       @exception StandardException Thrown on error
230       @see ExecutionFactory#getRowChanger
231       */

232     public RowChanger
233     getRowChanger(long heapConglom,
234                   StaticCompiledOpenConglomInfo heapSCOCI,
235                   DynamicCompiledOpenConglomInfo heapDCOCI,
236                   IndexRowGenerator[] irgs,
237                   long[] indexCIDS,
238                   StaticCompiledOpenConglomInfo[] indexSCOCIs,
239                   DynamicCompiledOpenConglomInfo[] indexDCOCIs,
240                   int numberOfColumns,
241                   TransactionController tc,
242                   int[] changedColumnIds,
243                   int[] streamStorableHeapColIds,
244                   Activation activation) throws StandardException
245     {
246         return new RowChangerImpl( heapConglom,
247                                    heapSCOCI, heapDCOCI,
248                                    irgs, indexCIDS, indexSCOCIs, indexDCOCIs,
249                                    numberOfColumns,
250                                    changedColumnIds, tc, null,
251                                    streamStorableHeapColIds, activation );
252     }
253
254     /**
255       @exception StandardException Thrown on error
256       @see ExecutionFactory#getRowChanger
257       */

258     public RowChanger getRowChanger(
259                long heapConglom,
260                StaticCompiledOpenConglomInfo heapSCOCI,
261                DynamicCompiledOpenConglomInfo heapDCOCI,
262                IndexRowGenerator[] irgs,
263                long[] indexCIDS,
264                StaticCompiledOpenConglomInfo[] indexSCOCIs,
265                DynamicCompiledOpenConglomInfo[] indexDCOCIs,
266                int numberOfColumns,
267                TransactionController tc,
268                int[] changedColumnIds,
269                FormatableBitSet baseRowReadList,
270                int[] baseRowReadMap,
271                int[] streamStorableColIds,
272                Activation activation
273                )
274          throws StandardException
275     {
276         return new RowChangerImpl( heapConglom,
277                                    heapSCOCI, heapDCOCI,
278                                    irgs, indexCIDS, indexSCOCIs, indexDCOCIs,
279                                    numberOfColumns,
280                                    changedColumnIds, tc, baseRowReadList,
281                                    baseRowReadMap, activation );
282     }
283
284
285     /**
286      * Get a trigger execution context
287      *
288      * @exception StandardException Thrown on error
289      */

290     public InternalTriggerExecutionContext getTriggerExecutionContext
291     (
292         LanguageConnectionContext lcc,
293         ConnectionContext cc,
294         String JavaDoc statementText,
295         int dmlType,
296         int[] changedColIds,
297         String JavaDoc[] changedColNames,
298         UUID targetTableId,
299         String JavaDoc targetTableName,
300         Vector JavaDoc aiCounters
301     ) throws StandardException
302     {
303         return new InternalTriggerExecutionContext(lcc, cc,
304                                                    statementText, dmlType,
305                                                    changedColIds,
306                                                    changedColNames,
307                                                    targetTableId,
308                                                    targetTableName,
309                                                    aiCounters);
310     }
311
312     /*
313         Old RowFactory interface
314      */

315
316     public ExecRow getValueRow(int numColumns) {
317         return new ValueRow(numColumns);
318     }
319
320     public ExecIndexRow getIndexableRow(int numColumns) {
321         return new IndexRow(numColumns);
322     }
323
324     public ExecIndexRow getIndexableRow(ExecRow valueRow) {
325         if (valueRow instanceof ExecIndexRow)
326             return (ExecIndexRow)valueRow;
327         return new IndexValueRow(valueRow);
328     }
329
330    /**
331      Packages up a clump of constants which the Plugin uses at execute()
332      time for COPY PUBLICATION.
333     */

334     public Object JavaDoc getJdbcCopyConstants
335     (
336         int[][] paramReferences,
337         TypeDescriptor[][] columnTypes,
338         int[][] publishedTableSchemaCounts
339     )
340     { return null; }
341
342    /**
343      Packages up a clump of constants which the Plugin uses at execute()
344      time for CREATE PUBLICATION.
345     */

346     public Object JavaDoc getJdbcCreateConstants
347     (
348         UUID[] publishedJarFileIDs,
349         Object JavaDoc publishedItems,
350         int[][] tableSchemaCounts
351     )
352     { return null; }
353
354     //
355
// class interface
356
//
357
public GenericExecutionFactory() {
358     }
359
360     //
361
// fields
362
//
363
public ResultSetFactory rsFactory;
364     protected GenericConstantActionFactory genericConstantActionFactory;
365 }
366
Popular Tags