KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > compile > CompilerContext


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.compile.CompilerContext
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.iapi.sql.compile;
23
24 import org.apache.derby.iapi.services.context.Context;
25 import org.apache.derby.iapi.services.compiler.JavaFactory;
26 import org.apache.derby.iapi.services.loader.ClassFactory;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
31
32 import org.apache.derby.iapi.sql.ParameterValueSet;
33
34 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
35 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
36 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
37 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
38
39 import org.apache.derby.iapi.sql.depend.Dependent;
40 import org.apache.derby.iapi.sql.depend.Provider;
41 import org.apache.derby.iapi.sql.depend.ProviderList;
42
43 import org.apache.derby.iapi.sql.compile.TypeCompilerFactory;
44
45 import org.apache.derby.iapi.types.DataTypeDescriptor;
46
47 import org.apache.derby.iapi.store.access.StoreCostController;
48 import org.apache.derby.iapi.store.access.SortCostController;
49
50 import java.util.List JavaDoc;
51 import java.util.Vector JavaDoc;
52 import java.sql.SQLWarning JavaDoc;
53
54 /**
55  * CompilerContext stores the parser and type id factory to be used by
56  * the compiler. Stack compiler contexts when a new, local parser is needed
57  * (if calling the compiler recursively from within the compiler,
58  * for example).
59  * CompilerContext objects are private to a LanguageConnectionContext.
60  *
61  * @author ames
62  *
63  * History:
64  * 5/22/97 Moved getExternalInterfaceFactory() to LanguageConnectionContext
65  * because it had to be used at execution. - Jeff
66  */

67 public interface CompilerContext extends Context
68 {
69     /////////////////////////////////////////////////////////////////////////////////////
70
//
71
// CONSTANTS
72
//
73
/////////////////////////////////////////////////////////////////////////////////////
74

75     /**
76      * this is the ID we expect compiler contexts
77      * to be stored into a context manager under.
78      */

79     String JavaDoc CONTEXT_ID = "CompilerContext";
80
81     // bit masks for query fragments which are potentially unreliable. these are used
82
// by setReliability() and checkReliability().
83

84     public static final int DATETIME_ILLEGAL = 0x00000001;
85     // NOTE: getCurrentConnection() is currently legal everywhere
86
public static final int CURRENT_CONNECTION_ILLEGAL = 0x00000002;
87     public static final int FUNCTION_CALL_ILLEGAL = 0x00000004;
88     public static final int UNNAMED_PARAMETER_ILLEGAL = 0x00000008;
89     public static final int DIAGNOSTICS_ILLEGAL = 0x00000010;
90     public static final int SUBQUERY_ILLEGAL = 0x00000020;
91     public static final int USER_ILLEGAL = 0x00000040;
92     public static final int COLUMN_REFERENCE_ILLEGAL = 0x00000080;
93     public static final int IGNORE_MISSING_CLASSES = 0x00000100;
94     public static final int SCHEMA_ILLEGAL = 0x00000200;
95     public static final int INTERNAL_SQL_ILLEGAL = 0x00000400;
96     
97     /**
98      * Calling procedures that modify sql data from before triggers is illegal.
99      *
100      */

101     public static final int MODIFIES_SQL_DATA_PROCEDURE_ILLEGAL = 0x00000800;
102
103     /** Standard SQL is legal */
104     public static final int SQL_LEGAL = (INTERNAL_SQL_ILLEGAL);
105
106     /** Any SQL we support is legal */
107     public static final int INTERNAL_SQL_LEGAL = 0;
108
109     public static final int CHECK_CONSTRAINT = (
110                                                                             DATETIME_ILLEGAL |
111                                                                             UNNAMED_PARAMETER_ILLEGAL |
112                                                                             DIAGNOSTICS_ILLEGAL |
113                                                                             SUBQUERY_ILLEGAL |
114                                                                             USER_ILLEGAL |
115                                                                             SCHEMA_ILLEGAL |
116                                                                             INTERNAL_SQL_ILLEGAL
117                                                                           );
118
119     public static final int DEFAULT_RESTRICTION = (
120                                                                             SUBQUERY_ILLEGAL |
121                                                                             UNNAMED_PARAMETER_ILLEGAL |
122                                                                             COLUMN_REFERENCE_ILLEGAL |
123                                                                             INTERNAL_SQL_ILLEGAL
124                                                                             );
125
126
127     /////////////////////////////////////////////////////////////////////////////////////
128
//
129
// BEHAVIOR
130
//
131
/////////////////////////////////////////////////////////////////////////////////////
132

133     /**
134      * Get the Parser from this CompilerContext.
135      * *
136      * @return The parser associated with this CompilerContext
137      *
138      */

139
140     Parser getParser();
141
142     /**
143      * Get the NodeFactory from this CompilerContext.
144      *
145      * @return The NodeFactory associated with this CompilerContext
146      *
147      */

148
149     NodeFactory getNodeFactory();
150
151     /**
152      * Get the TypeCompilerFactory from this CompilerContext.
153      *
154      * @return The TypeCompilerFactory associated with this CompilerContext
155      *
156      */

157     TypeCompilerFactory getTypeCompilerFactory();
158
159     /**
160         Return the class factory to use in this compilation.
161     */

162     ClassFactory getClassFactory();
163
164     /**
165      * Get the JavaFactory from this CompilerContext.
166      *
167      * @return The JavaFactory associated with this CompilerContext
168      *
169      */

170
171     JavaFactory getJavaFactory();
172
173     /**
174      * Get the current next column number (for generated column names)
175      * from this CompilerContext.
176      *
177      * @return int The next column number for the current statement.
178      *
179      */

180
181     int getNextColumnNumber();
182
183     /**
184       * Reset compiler context (as for instance, when we recycle a context for
185       * use by another compilation.
186       */

187     void resetContext();
188
189     /**
190      * Get the current next table number from this CompilerContext.
191      *
192      * @return int The next table number for the current statement.
193      *
194      */

195
196     int getNextTableNumber();
197
198     /**
199      * Get the number of tables in the current statement from this CompilerContext.
200      *
201      * @return int The number of tables in the current statement.
202      *
203      */

204
205     int getNumTables();
206
207     /**
208      * Get the current next subquery number from this CompilerContext.
209      *
210      * @return int The next subquery number for the current statement.
211      *
212      */

213
214     int getNextSubqueryNumber();
215
216     /**
217      * Get the number of subquerys in the current statement from this CompilerContext.
218      *
219      * @return int The number of subquerys in the current statement.
220      *
221      */

222
223     int getNumSubquerys();
224
225     /**
226      * Get the current next ResultSet number from this CompilerContext.
227      *
228      * @return int The next ResultSet number for the current statement.
229      *
230      */

231
232     int getNextResultSetNumber();
233
234     /**
235      * Reset the next ResultSet number from this CompilerContext.
236      */

237
238     void resetNextResultSetNumber();
239
240     /**
241      * Get the number of Results in the current statement from this CompilerContext.
242      *
243      * @return The number of ResultSets in the current statement.
244      *
245      */

246
247     int getNumResultSets();
248
249     /**
250      * Get a unique Class name from this CompilerContext.
251      * Ensures it is globally unique for this JVM.
252      *
253      * @return String A unique-enough class name.
254      *
255      */

256
257     String JavaDoc getUniqueClassName();
258
259     /**
260      * Set the current dependent from this CompilerContext.
261      * This should be called at the start of a compile to
262      * register who has the dependencies needed for the compilation.
263      *
264      * @param d The Dependent currently being compiled.
265      *
266      */

267
268     void setCurrentDependent(Dependent d);
269
270     /**
271      * Get the current auxiliary provider list from this CompilerContext.
272      *
273      * @return The current AuxiliaryProviderList.
274      *
275      */

276
277     ProviderList getCurrentAuxiliaryProviderList();
278
279     /**
280      * Set the current auxiliary provider list for this CompilerContext.
281      *
282      * @param apl The new current AuxiliaryProviderList.
283      *
284      */

285
286     void setCurrentAuxiliaryProviderList(ProviderList apl);
287
288     /**
289      * Add a dependency for the current dependent.
290      *
291      * @param p The Provider of the dependency.
292      * @exception StandardException thrown on failure.
293      *
294      */

295     void createDependency(Provider p) throws StandardException;
296
297     /**
298      * Add a dependency between two objects.
299      *
300      * @param d The Dependent object.
301      * @param p The Provider of the dependency.
302      * @exception StandardException thrown on failure.
303      *
304      */

305     public void createDependency(Dependent d, Provider p) throws StandardException;
306
307     /**
308      * Add an object to the pool that is created at compile time
309      * and used at execution time. Use the integer to reference it
310      * in execution constructs. Execution code will have to generate:
311      * <pre>
312      * (#objectType) (this.getPreparedStatement().getSavedObject(#int))
313      * <\pre>
314      *
315      * @param o object to add to the pool of saved objects
316      * @return the entry # for the object
317      */

318     int addSavedObject(Object JavaDoc o);
319
320     /**
321      * Get the saved object pool (for putting into the prepared statement).
322      * This turns it into its storable form, an array of objects.
323      *
324      * @return the saved object pool.
325      */

326     Object JavaDoc[] getSavedObjects();
327
328     /**
329      * Set the saved object pool (for putting into the prepared statement).
330      *
331      * @param objs The new saved objects
332      */

333     public void setSavedObjects(Object JavaDoc[] objs);
334
335     /**
336      * Set the in use state for the compiler context.
337      *
338      * @param inUse The new inUse state for the compiler context.
339      */

340     public void setInUse(boolean inUse);
341
342     /**
343      * Return the in use state for the compiler context.
344      *
345      * @return boolean The in use state for the compiler context.
346      */

347     public boolean getInUse();
348
349     /**
350      * Mark this CompilerContext as the first on the stack, so we can avoid
351      * continually popping and pushing a CompilerContext.
352      */

353     public void firstOnStack();
354
355     /**
356      * Is this the first CompilerContext on the stack?
357      */

358     public boolean isFirstOnStack();
359
360     /**
361      * Sets which kind of query fragments are NOT allowed. Basically,
362      * these are fragments which return unstable results. CHECK CONSTRAINTS
363      * and CREATE PUBLICATION want to forbid certain kinds of fragments.
364      *
365      * @param reliability bitmask of types of query fragments to be forbidden
366      * see the reliability bitmasks above
367      *
368      */

369     public void setReliability(int reliability);
370
371     /**
372      * Return the reliability requirements of this clause. See setReliability()
373      * for a definition of clause reliability.
374      *
375      * @return a bitmask of which types of query fragments are to be forbidden
376      */

377     public int getReliability();
378
379     /**
380      * Get the compilation schema descriptor for this compilation context.
381        Will be null if no default schema lookups have occured. Ie.
382        the statement is independent of the current schema.
383      *
384      * @return the compilation schema descirptor
385      */

386     public SchemaDescriptor getCompilationSchema();
387
388     /**
389      * Set the compilation schema descriptor for this compilation context.
390      *
391      * @param newDefault compilation schema
392      *
393      * @return the previous compilation schema descirptor
394      */

395     public SchemaDescriptor setCompilationSchema(SchemaDescriptor newDefault);
396
397     /**
398      * Get a StoreCostController for the given conglomerate.
399      *
400      * @param conglomerateNumber The conglomerate for which to get a
401      * StoreCostController.
402      *
403      * @return The appropriate StoreCostController.
404      *
405      * @exception StandardException Thrown on error
406      */

407     public StoreCostController getStoreCostController(long conglomerateNumber)
408             throws StandardException;
409
410     /**
411      * Get a SortCostController.
412      *
413      * @exception StandardException Thrown on error
414      */

415     public SortCostController getSortCostController() throws StandardException;
416
417     /**
418      * Set the parameter list.
419      *
420      * @param parameterList The parameter list.
421      */

422     public void setParameterList(Vector JavaDoc parameterList);
423
424     /**
425      * Get the parameter list.
426      *
427      * @return The parameter list.
428      */

429     public Vector JavaDoc getParameterList();
430
431     /**
432      * If callable statement uses ? = form
433      */

434     public void setReturnParameterFlag();
435
436     /**
437      * Is the callable statement uses ? for return parameter.
438      *
439      * @return true if ? = call else false
440      */

441     public boolean getReturnParameterFlag();
442
443     /**
444      * Get the array of DataTypeDescriptor representing the types of
445      * the ? parameters.
446      *
447      * @return The parameter descriptors
448      */

449
450     public DataTypeDescriptor[] getParameterTypes();
451
452     /**
453      * Get the cursor info stored in the context.
454      *
455      * @return the cursor info
456      */

457     public Object JavaDoc getCursorInfo();
458     
459     /**
460      * Set params
461      *
462      * @param cursorInfo the cursor info
463      */

464     public void setCursorInfo(Object JavaDoc cursorInfo);
465
466     /**
467      * Set the isolation level for the scans in this query.
468      *
469      * @param isolationLevel The isolation level to use.
470      */

471     public void setScanIsolationLevel(int isolationLevel);
472
473     /**
474      * Get the isolation level for the scans in this query.
475      *
476      * @return The isolation level for the scans in this query.
477      */

478     public int getScanIsolationLevel();
479
480     /**
481      * Set the isolation level on entry to this CC so that it can be restored on exit.
482      *
483      * @param isolationLevel The isolation level on entry.
484      */

485     public void setEntryIsolationLevel(int isolationLevel);
486
487     /**
488      * Get the entry isolation level from this CC.
489      *
490      * @return The entry isolation level.
491      */

492     public int getEntryIsolationLevel();
493
494     /**
495      * Get the next equivalence class for equijoin clauses.
496      *
497      * @return The next equivalence class for equijoin clauses.
498      */

499     public int getNextEquivalenceClass();
500
501     /**
502         Add a compile time warning.
503     */

504     public void addWarning(SQLWarning JavaDoc warning);
505
506     /**
507         Get the chain of compile time warnings.
508     */

509     public SQLWarning JavaDoc getWarnings();
510
511     /**
512      * Sets the current privilege type context and pushes the previous on onto a stack.
513      * Column and table nodes do not know how they are
514      * being used. Higher level nodes in the query tree do not know what is being
515      * referenced. Keeping the context allows the two to come together.
516      *
517      * @param privType One of the privilege types in
518      * org.apache.derby.iapi.sql.conn.Authorizer.
519      */

520     public void pushCurrentPrivType( int privType);
521     
522     public void popCurrentPrivType();
523     
524     /**
525      * Add a column privilege to the list of used column privileges.
526      *
527      * @param column
528      */

529     public void addRequiredColumnPriv( ColumnDescriptor column);
530
531     /**
532      * Add a table or view privilege to the list of used table privileges.
533      *
534      * @param table
535      */

536     public void addRequiredTablePriv( TableDescriptor table);
537
538     /**
539      * Add a schema privilege to the list of used privileges.
540      *
541      * @param schema Schema name of the object that is being accessed
542      * @param aid Requested authorizationId for new schema
543      * @param privType CREATE_SCHEMA_PRIV, MODIFY_SCHEMA_PRIV or DROP_SCHEMA_PRIV
544      */

545     public void addRequiredSchemaPriv(String JavaDoc schema, String JavaDoc aid, int privType);
546
547     /**
548      * Add a routine execute privilege to the list of used routine privileges.
549      *
550      * @param routine
551      */

552     public void addRequiredRoutinePriv( AliasDescriptor routine);
553
554     /**
555      * @return The list of required privileges.
556      */

557     public List getRequiredPermissionsList();
558 }
559
Popular Tags