Source Code Cross Referenced for CompilerContextImpl.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » compile » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.sql.compile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.compile.CompilerContextImpl
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.compile;
023:
024:        import org.apache.derby.catalog.UUID;
025:
026:        import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;
027:
028:        import org.apache.derby.iapi.sql.depend.ProviderList;
029:        import org.apache.derby.iapi.sql.compile.CompilerContext;
030:        import org.apache.derby.iapi.sql.compile.NodeFactory;
031:        import org.apache.derby.iapi.sql.compile.Parser;
032:
033:        import org.apache.derby.iapi.sql.conn.Authorizer;
034:        import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
035:
036:        import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
037:        import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
038:        import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
039:        import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
040:        import org.apache.derby.iapi.sql.dictionary.StatementTablePermission;
041:        import org.apache.derby.iapi.sql.dictionary.StatementSchemaPermission;
042:        import org.apache.derby.iapi.sql.dictionary.StatementColumnPermission;
043:        import org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission;
044:
045:        import org.apache.derby.iapi.types.DataTypeDescriptor;
046:
047:        import org.apache.derby.iapi.sql.compile.TypeCompilerFactory;
048:
049:        import org.apache.derby.iapi.sql.depend.Dependent;
050:        import org.apache.derby.iapi.sql.depend.Provider;
051:        import org.apache.derby.iapi.sql.depend.DependencyManager;
052:        import org.apache.derby.iapi.error.ExceptionSeverity;
053:        import org.apache.derby.iapi.sql.execute.ExecutionContext;
054:
055:        import org.apache.derby.iapi.types.DataTypeDescriptor;
056:        import org.apache.derby.iapi.sql.ParameterValueSet;
057:
058:        import org.apache.derby.iapi.store.access.StoreCostController;
059:        import org.apache.derby.iapi.store.access.SortCostController;
060:
061:        import org.apache.derby.iapi.services.context.ContextManager;
062:        import org.apache.derby.iapi.services.loader.ClassFactory;
063:        import org.apache.derby.iapi.services.compiler.JavaFactory;
064:        import org.apache.derby.iapi.services.uuid.UUIDFactory;
065:        import org.apache.derby.iapi.services.monitor.Monitor;
066:        import org.apache.derby.iapi.services.io.FormatableBitSet;
067:
068:        import org.apache.derby.iapi.error.StandardException;
069:
070:        import org.apache.derby.iapi.reference.SQLState;
071:
072:        import org.apache.derby.iapi.services.sanity.SanityManager;
073:
074:        import org.apache.derby.iapi.services.context.ContextImpl;
075:        import org.apache.derby.iapi.util.ReuseFactory;
076:
077:        import java.sql.SQLWarning;
078:        import java.util.Vector;
079:        import java.util.Properties;
080:        import java.util.HashMap;
081:        import java.util.Iterator;
082:        import java.util.Map.Entry;
083:        import java.util.BitSet;
084:        import java.util.List;
085:        import java.util.Stack;
086:        import java.util.ArrayList;
087:
088:        /**
089:         *
090:         * CompilerContextImpl, implementation of CompilerContext.
091:         * CompilerContext and hence CompilerContextImpl objects are private to a LanguageConnectionContext.
092:         *
093:         */
094:        public class CompilerContextImpl extends ContextImpl implements 
095:                CompilerContext {
096:
097:            //
098:            // Context interface       
099:            //
100:
101:            /**
102:            	@exception StandardException thrown by makeInvalid() call
103:             */
104:            public void cleanupOnError(Throwable error)
105:                    throws StandardException {
106:
107:                setInUse(false);
108:                resetContext();
109:
110:                if (error instanceof  StandardException) {
111:
112:                    StandardException se = (StandardException) error;
113:                    // if something went wrong with the compile,
114:                    // we need to mark the statement invalid.
115:                    // REVISIT: do we want instead to remove it,
116:                    // so the cache doesn't get full of garbage input
117:                    // that won't even parse?
118:
119:                    int severity = se.getSeverity();
120:
121:                    if (severity < ExceptionSeverity.SYSTEM_SEVERITY) {
122:                        if (currentDependent != null) {
123:                            currentDependent.makeInvalid(
124:                                    DependencyManager.COMPILE_FAILED, lcc);
125:                        }
126:                        closeStoreCostControllers();
127:                        closeSortCostControllers();
128:                    }
129:                    // anything system or worse, or non-DB errors,
130:                    // will cause the whole system to shut down.
131:
132:                    if (severity >= ExceptionSeverity.SESSION_SEVERITY)
133:                        popMe();
134:                }
135:
136:            }
137:
138:            /**
139:             *	Reset compiler context (as for instance, when we recycle a context for
140:             *	use by another compilation.
141:             */
142:            public void resetContext() {
143:                nextColumnNumber = 1;
144:                nextTableNumber = 0;
145:                nextSubqueryNumber = 0;
146:                resetNextResultSetNumber();
147:                nextEquivalenceClass = -1;
148:                compilationSchema = null;
149:                parameterList = null;
150:                parameterDescriptors = null;
151:                scanIsolationLevel = ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL;
152:                warnings = null;
153:                savedObjects = null;
154:                reliability = CompilerContext.SQL_LEGAL;
155:                returnParameterFlag = false;
156:                initRequiredPriv();
157:            }
158:
159:            //
160:            // CompilerContext interface
161:            //
162:            // we might want these to refuse to return
163:            // anything if they are in-use -- would require
164:            // the interface provide a 'done' call, and
165:            // we would mark them in-use whenever a get happened.
166:            public Parser getParser() {
167:                return parser;
168:            }
169:
170:            /**
171:             *	Get the NodeFactory for this context
172:             *
173:             *	@return	The NodeFactory for this context.
174:             */
175:            public NodeFactory getNodeFactory() {
176:                return lcf.getNodeFactory();
177:            }
178:
179:            public int getNextColumnNumber() {
180:                return nextColumnNumber++;
181:            }
182:
183:            public int getNextTableNumber() {
184:                return nextTableNumber++;
185:            }
186:
187:            public int getNumTables() {
188:                return nextTableNumber;
189:            }
190:
191:            /**
192:             * Get the current next subquery number from this CompilerContext.
193:             *
194:             * @return int	The next subquery number for the current statement.
195:             *
196:             */
197:
198:            public int getNextSubqueryNumber() {
199:                return nextSubqueryNumber++;
200:            }
201:
202:            /**
203:             * Get the number of subquerys in the current statement from this CompilerContext.
204:             *
205:             * @return int	The number of subquerys in the current statement.
206:             *
207:             */
208:
209:            public int getNumSubquerys() {
210:                return nextSubqueryNumber;
211:            }
212:
213:            public int getNextResultSetNumber() {
214:                return nextResultSetNumber++;
215:            }
216:
217:            public void resetNextResultSetNumber() {
218:                nextResultSetNumber = 0;
219:            }
220:
221:            public int getNumResultSets() {
222:                return nextResultSetNumber;
223:            }
224:
225:            public String getUniqueClassName() {
226:                // REMIND: should get a new UUID if we roll over...
227:                if (SanityManager.DEBUG) {
228:                    SanityManager.ASSERT(nextClassName <= Long.MAX_VALUE);
229:                }
230:                return classPrefix.concat(Long.toHexString(nextClassName++));
231:            }
232:
233:            /**
234:             * Get the next equivalence class for equijoin clauses.
235:             *
236:             * @return The next equivalence class for equijoin clauses.
237:             */
238:            public int getNextEquivalenceClass() {
239:                return ++nextEquivalenceClass;
240:            }
241:
242:            public ClassFactory getClassFactory() {
243:                return lcf.getClassFactory();
244:            }
245:
246:            public JavaFactory getJavaFactory() {
247:                return lcf.getJavaFactory();
248:            }
249:
250:            public void setCurrentDependent(Dependent d) {
251:                currentDependent = d;
252:            }
253:
254:            /**
255:             * Get the current auxiliary provider list from this CompilerContext.
256:             *
257:             * @return	The current AuxiliaryProviderList.
258:             *
259:             */
260:
261:            public ProviderList getCurrentAuxiliaryProviderList() {
262:                return currentAPL;
263:            }
264:
265:            /**
266:             * Set the current auxiliary provider list for this CompilerContext.
267:             *
268:             * @param apl	The new current AuxiliaryProviderList.
269:             */
270:
271:            public void setCurrentAuxiliaryProviderList(ProviderList apl) {
272:                currentAPL = apl;
273:            }
274:
275:            public void createDependency(Provider p) throws StandardException {
276:                if (SanityManager.DEBUG)
277:                    SanityManager.ASSERT(currentDependent != null,
278:                            "no current dependent for compilation");
279:
280:                if (dm == null)
281:                    dm = lcc.getDataDictionary().getDependencyManager();
282:                dm.addDependency(currentDependent, p, getContextManager());
283:                addProviderToAuxiliaryList(p);
284:            }
285:
286:            /**
287:             * Add a dependency between two objects.
288:             *
289:             * @param d	The Dependent object.
290:             * @param p	The Provider of the dependency.
291:             * @exception StandardException thrown on failure.
292:             *
293:             */
294:            public void createDependency(Dependent d, Provider p)
295:                    throws StandardException {
296:                if (dm == null)
297:                    dm = lcc.getDataDictionary().getDependencyManager();
298:
299:                dm.addDependency(d, p, getContextManager());
300:                addProviderToAuxiliaryList(p);
301:            }
302:
303:            /**
304:             * Add a Provider to the current AuxiliaryProviderList, if one exists.
305:             *
306:             * @param p		The Provider to add.
307:             */
308:            private void addProviderToAuxiliaryList(Provider p) {
309:                if (currentAPL != null) {
310:                    currentAPL.addProvider(p);
311:                }
312:            }
313:
314:            public int addSavedObject(Object obj) {
315:                if (savedObjects == null)
316:                    savedObjects = new Vector();
317:
318:                savedObjects.addElement(obj);
319:                return savedObjects.size() - 1;
320:            }
321:
322:            public Object[] getSavedObjects() {
323:                if (savedObjects == null)
324:                    return null;
325:
326:                Object[] retVal = new Object[savedObjects.size()];
327:                savedObjects.copyInto(retVal);
328:                savedObjects = null; // erase to start over
329:                return retVal;
330:            }
331:
332:            /** @see CompilerContext#setSavedObjects */
333:            public void setSavedObjects(Object[] objs) {
334:                if (objs == null) {
335:                    return;
336:                }
337:
338:                for (int i = 0; i < objs.length; i++) {
339:                    addSavedObject(objs[i]);
340:                }
341:            }
342:
343:            /** @see CompilerContext#setCursorInfo */
344:            public void setCursorInfo(Object cursorInfo) {
345:                this .cursorInfo = cursorInfo;
346:            }
347:
348:            /** @see CompilerContext#getCursorInfo */
349:            public Object getCursorInfo() {
350:                return cursorInfo;
351:            }
352:
353:            /** @see CompilerContext#firstOnStack */
354:            public void firstOnStack() {
355:                firstOnStack = true;
356:            }
357:
358:            /** @see CompilerContext#isFirstOnStack */
359:            public boolean isFirstOnStack() {
360:                return firstOnStack;
361:            }
362:
363:            /**
364:             * Set the in use state for the compiler context.
365:             *
366:             * @param inUse	 The new inUse state for the compiler context.
367:             */
368:            public void setInUse(boolean inUse) {
369:                this .inUse = inUse;
370:
371:                /*
372:                 ** Close the StoreCostControllers associated with this CompilerContext
373:                 ** when the context is no longer in use.
374:                 */
375:                if (!inUse) {
376:                    closeStoreCostControllers();
377:                    closeSortCostControllers();
378:                }
379:            }
380:
381:            /**
382:             * Return the in use state for the compiler context.
383:             *
384:             * @return boolean	The in use state for the compiler context.
385:             */
386:            public boolean getInUse() {
387:                return inUse;
388:            }
389:
390:            /**
391:             * Sets which kind of query fragments are NOT allowed. Basically,
392:             * these are fragments which return unstable results. CHECK CONSTRAINTS
393:             * and CREATE PUBLICATION want to forbid certain kinds of fragments.
394:             *
395:             * @param reliability	bitmask of types of query fragments to be forbidden
396:             *						see the reliability bitmasks in CompilerContext.java
397:             *
398:             */
399:            public void setReliability(int reliability) {
400:                this .reliability = reliability;
401:            }
402:
403:            /**
404:             * Return the reliability requirements of this clause. See setReliability()
405:             * for a definition of clause reliability.
406:             *
407:             * @return a bitmask of which types of query fragments are to be forbidden
408:             */
409:            public int getReliability() {
410:                return reliability;
411:            }
412:
413:            /**
414:             * @see CompilerContext#getStoreCostController
415:             *
416:             * @exception StandardException		Thrown on error
417:             */
418:            public StoreCostController getStoreCostController(
419:                    long conglomerateNumber) throws StandardException {
420:                /*
421:                 ** Try to find the given conglomerate number in the array of
422:                 ** conglom ids.
423:                 */
424:                for (int i = 0; i < storeCostConglomIds.size(); i++) {
425:                    Long conglomId = (Long) storeCostConglomIds.elementAt(i);
426:                    if (conglomId.longValue() == conglomerateNumber)
427:                        return (StoreCostController) storeCostControllers
428:                                .elementAt(i);
429:                }
430:
431:                /*
432:                 ** Not found, so get a StoreCostController from the store.
433:                 */
434:                StoreCostController retval = lcc.getTransactionCompile()
435:                        .openStoreCost(conglomerateNumber);
436:
437:                /* Put it in the array */
438:                storeCostControllers.insertElementAt(retval,
439:                        storeCostControllers.size());
440:
441:                /* Put the conglomerate number in its array */
442:                storeCostConglomIds.insertElementAt(
443:                        new Long(conglomerateNumber), storeCostConglomIds
444:                                .size());
445:
446:                return retval;
447:            }
448:
449:            /**
450:             *
451:             */
452:            private void closeStoreCostControllers() {
453:                for (int i = 0; i < storeCostControllers.size(); i++) {
454:                    StoreCostController scc = (StoreCostController) storeCostControllers
455:                            .elementAt(i);
456:                    try {
457:                        scc.close();
458:                    } catch (StandardException se) {
459:                    }
460:                }
461:
462:                storeCostControllers.removeAllElements();
463:                storeCostConglomIds.removeAllElements();
464:            }
465:
466:            /**
467:             * @see CompilerContext#getSortCostController
468:             *
469:             * @exception StandardException		Thrown on error
470:             */
471:            public SortCostController getSortCostController()
472:                    throws StandardException {
473:                /*
474:                 ** Re-use a single SortCostController for each compilation
475:                 */
476:                if (sortCostController == null) {
477:                    /*
478:                     ** Get a StoreCostController from the store.
479:                     */
480:
481:                    sortCostController = lcc.getTransactionCompile()
482:                            .openSortCostController((Properties) null);
483:                }
484:
485:                return sortCostController;
486:            }
487:
488:            /**
489:             *
490:             * @exception StandardException		Thrown on error
491:             */
492:            private void closeSortCostControllers() {
493:                if (sortCostController != null) {
494:                    sortCostController.close();
495:                    sortCostController = null;
496:                }
497:            }
498:
499:            /**
500:             * Get the compilation schema descriptor for this compilation context.
501:               Will be null if no default schema lookups have occured. Ie.
502:               the statement is independent of the current schema.
503:             * 
504:             * @return the compilation schema descirptor
505:             */
506:            public SchemaDescriptor getCompilationSchema() {
507:                return compilationSchema;
508:            }
509:
510:            /**
511:             * Set the compilation schema descriptor for this compilation context.
512:             *
513:             * @param newDefault	the compilation schema
514:             * 
515:             * @return the previous compilation schema descirptor
516:             */
517:            public SchemaDescriptor setCompilationSchema(
518:                    SchemaDescriptor newDefault) {
519:                SchemaDescriptor tmpSchema = compilationSchema;
520:                compilationSchema = newDefault;
521:                return tmpSchema;
522:            }
523:
524:            /**
525:             * @see CompilerContext#setParameterList
526:             */
527:            public void setParameterList(Vector parameterList) {
528:                this .parameterList = parameterList;
529:
530:                /* Don't create param descriptors array if there are no params */
531:                int numberOfParameters = (parameterList == null) ? 0
532:                        : parameterList.size();
533:
534:                if (numberOfParameters > 0) {
535:                    parameterDescriptors = new DataTypeDescriptor[numberOfParameters];
536:                }
537:            }
538:
539:            /**
540:             * @see CompilerContext#getParameterList
541:             */
542:            public Vector getParameterList() {
543:                return parameterList;
544:            }
545:
546:            /**
547:             * @see CompilerContext#setReturnParameterFlag
548:             */
549:            public void setReturnParameterFlag() {
550:                returnParameterFlag = true;
551:            }
552:
553:            /**
554:             * @see CompilerContext#getReturnParameterFlag
555:             */
556:            public boolean getReturnParameterFlag() {
557:                return returnParameterFlag;
558:            }
559:
560:            /**
561:             * @see CompilerContext#getParameterTypes
562:             */
563:            public DataTypeDescriptor[] getParameterTypes() {
564:                return parameterDescriptors;
565:            }
566:
567:            /**
568:             * @see CompilerContext#setScanIsolationLevel
569:             */
570:            public void setScanIsolationLevel(int isolationLevel) {
571:                scanIsolationLevel = isolationLevel;
572:            }
573:
574:            /**
575:             * @see CompilerContext#getScanIsolationLevel
576:             */
577:            public int getScanIsolationLevel() {
578:                return scanIsolationLevel;
579:            }
580:
581:            /**
582:             * @see CompilerContext#setEntryIsolationLevel
583:             */
584:            public void setEntryIsolationLevel(int isolationLevel) {
585:                this .entryIsolationLevel = isolationLevel;
586:            }
587:
588:            /**
589:             * @see CompilerContext#getScanIsolationLevel
590:             */
591:            public int getEntryIsolationLevel() {
592:                return entryIsolationLevel;
593:            }
594:
595:            /**
596:             * @see CompilerContext#getTypeCompilerFactory
597:             */
598:            public TypeCompilerFactory getTypeCompilerFactory() {
599:                return typeCompilerFactory;
600:            }
601:
602:            /**
603:            	Add a compile time warning.
604:             */
605:            public void addWarning(SQLWarning warning) {
606:                if (warnings == null)
607:                    warnings = warning;
608:                else
609:                    warnings.setNextWarning(warning);
610:            }
611:
612:            /**
613:            	Get the chain of compile time warnings.
614:             */
615:            public SQLWarning getWarnings() {
616:                return warnings;
617:            }
618:
619:            /////////////////////////////////////////////////////////////////////////////////////
620:            //
621:            // class interface
622:            //
623:            // this constructor is called with the parser
624:            // to be saved when the context
625:            // is created (when the first statement comes in, likely).
626:            //
627:            /////////////////////////////////////////////////////////////////////////////////////
628:
629:            public CompilerContextImpl(ContextManager cm,
630:                    LanguageConnectionContext lcc,
631:                    TypeCompilerFactory typeCompilerFactory) {
632:                super (cm, CompilerContext.CONTEXT_ID);
633:
634:                this .lcc = lcc;
635:                lcf = lcc.getLanguageConnectionFactory();
636:                this .parser = lcf.newParser(this );
637:                this .typeCompilerFactory = typeCompilerFactory;
638:
639:                // the prefix for classes in this connection
640:                classPrefix = "ac"
641:                        + lcf.getUUIDFactory().createUUID().toString().replace(
642:                                '-', 'x');
643:
644:                initRequiredPriv();
645:            }
646:
647:            private void initRequiredPriv() {
648:                currPrivType = Authorizer.NULL_PRIV;
649:                privTypeStack.clear();
650:                requiredColumnPrivileges = null;
651:                requiredTablePrivileges = null;
652:                requiredSchemaPrivileges = null;
653:                requiredRoutinePrivileges = null;
654:                LanguageConnectionContext lcc = (LanguageConnectionContext) getContextManager()
655:                        .getContext(LanguageConnectionContext.CONTEXT_ID);
656:                if (lcc.usesSqlAuthorization()) {
657:                    requiredColumnPrivileges = new HashMap();
658:                    requiredTablePrivileges = new HashMap();
659:                    requiredSchemaPrivileges = new HashMap();
660:                    requiredRoutinePrivileges = new HashMap();
661:                }
662:            } // end of initRequiredPriv
663:
664:            /**
665:             * Sets the current privilege type context. Column and table nodes do not know
666:             * how they are being used. Higher level nodes in the query tree do not know what
667:             * is being referenced.
668:             * Keeping the context allows the two to come together.
669:             *
670:             * @param privType One of the privilege types in org.apache.derby.iapi.sql.conn.Authorizer.
671:             */
672:            public void pushCurrentPrivType(int privType) {
673:                privTypeStack.push(ReuseFactory.getInteger(currPrivType));
674:                currPrivType = privType;
675:            }
676:
677:            public void popCurrentPrivType() {
678:                currPrivType = ((Integer) privTypeStack.pop()).intValue();
679:            }
680:
681:            /**
682:             * Add a column privilege to the list of used column privileges.
683:             *
684:             * @param column The column whose privileges we're interested in.
685:             */
686:            public void addRequiredColumnPriv(ColumnDescriptor column) {
687:                if (requiredColumnPrivileges == null // Using old style authorization
688:                        || currPrivType == Authorizer.NULL_PRIV
689:                        || currPrivType == Authorizer.DELETE_PRIV // Table privilege only
690:                        || currPrivType == Authorizer.INSERT_PRIV // Table privilege only
691:                        || currPrivType == Authorizer.TRIGGER_PRIV // Table privilege only
692:                        || currPrivType == Authorizer.EXECUTE_PRIV
693:                        || column == null)
694:                    return;
695:                /*
696:                 * Note that to look up the privileges for this column,
697:                 * we need to know what table the column is in. However,
698:                 * not all ColumnDescriptor objects are associated with
699:                 * a table object. Sometimes a ColumnDescriptor
700:                 * describes a column but doesn't specify the table. An
701:                 * example of this occurs in the set-clause of the
702:                 * UPDATE statement in SQL, where we may have a
703:                 * ColumnDescriptor which describes the expression that
704:                 * is being used in the UPDATE statement to provide the
705:                 * new value that will be computed by the UPDATE. In such a
706:                 * case, there is no column privilege to be added, so we
707:                 * just take an early return. DERBY-1583 has more details.
708:                 */
709:                TableDescriptor td = column.getTableDescriptor();
710:                if (td == null)
711:                    return;
712:                UUID tableUUID = td.getUUID();
713:                StatementTablePermission key = new StatementTablePermission(
714:                        tableUUID, currPrivType);
715:                StatementColumnPermission tableColumnPrivileges = (StatementColumnPermission) requiredColumnPrivileges
716:                        .get(key);
717:                if (tableColumnPrivileges == null) {
718:                    tableColumnPrivileges = new StatementColumnPermission(
719:                            tableUUID, currPrivType, new FormatableBitSet(td
720:                                    .getNumberOfColumns()));
721:                    requiredColumnPrivileges.put(key, tableColumnPrivileges);
722:                }
723:                tableColumnPrivileges.getColumns()
724:                        .set(column.getPosition() - 1);
725:            } // end of addRequiredColumnPriv
726:
727:            /**
728:             * Add a table or view privilege to the list of used table privileges.
729:             *
730:             * @see CompilerContext#addRequiredRoutinePriv
731:             */
732:            public void addRequiredTablePriv(TableDescriptor table) {
733:                if (requiredTablePrivileges == null || table == null)
734:                    return;
735:
736:                StatementTablePermission key = new StatementTablePermission(
737:                        table.getUUID(), currPrivType);
738:                requiredTablePrivileges.put(key, key);
739:            }
740:
741:            /**
742:             * Add a routine execute privilege to the list of used routine privileges.
743:             *
744:             * @see CompilerContext#addRequiredRoutinePriv
745:             */
746:            public void addRequiredRoutinePriv(AliasDescriptor routine) {
747:                // routine == null for built in routines
748:                if (requiredRoutinePrivileges == null || routine == null)
749:                    return;
750:
751:                // Ignore SYSFUN routines for permission scheme
752:                if (routine.getSchemaUUID().toString().equals(
753:                        SchemaDescriptor.SYSFUN_SCHEMA_UUID))
754:                    return;
755:
756:                if (requiredRoutinePrivileges.get(routine.getUUID()) == null)
757:                    requiredRoutinePrivileges.put(routine.getUUID(),
758:                            ReuseFactory.getInteger(1));
759:            }
760:
761:            /**
762:             * Add a required schema privilege to the list privileges.
763:             *
764:             * @see CompilerContext#addRequiredSchemaPriv
765:             */
766:            public void addRequiredSchemaPriv(String schemaName, String aid,
767:                    int privType) {
768:                if (requiredSchemaPrivileges == null || schemaName == null)
769:                    return;
770:
771:                StatementSchemaPermission key = new StatementSchemaPermission(
772:                        schemaName, aid, privType);
773:
774:                requiredSchemaPrivileges.put(key, key);
775:            }
776:
777:            /**
778:             * @return The list of required privileges.
779:             */
780:            public List getRequiredPermissionsList() {
781:                int size = 0;
782:                if (requiredRoutinePrivileges != null)
783:                    size += requiredRoutinePrivileges.size();
784:                if (requiredTablePrivileges != null)
785:                    size += requiredTablePrivileges.size();
786:                if (requiredSchemaPrivileges != null)
787:                    size += requiredSchemaPrivileges.size();
788:                if (requiredColumnPrivileges != null)
789:                    size += requiredColumnPrivileges.size();
790:
791:                ArrayList list = new ArrayList(size);
792:                if (requiredRoutinePrivileges != null) {
793:                    for (Iterator itr = requiredRoutinePrivileges.keySet()
794:                            .iterator(); itr.hasNext();) {
795:                        UUID routineUUID = (UUID) itr.next();
796:
797:                        list.add(new StatementRoutinePermission(routineUUID));
798:                    }
799:                }
800:                if (requiredTablePrivileges != null) {
801:                    for (Iterator itr = requiredTablePrivileges.values()
802:                            .iterator(); itr.hasNext();) {
803:                        list.add(itr.next());
804:                    }
805:                }
806:                if (requiredSchemaPrivileges != null) {
807:                    for (Iterator itr = requiredSchemaPrivileges.values()
808:                            .iterator(); itr.hasNext();) {
809:                        list.add(itr.next());
810:                    }
811:                }
812:                if (requiredColumnPrivileges != null) {
813:                    for (Iterator itr = requiredColumnPrivileges.values()
814:                            .iterator(); itr.hasNext();) {
815:                        list.add(itr.next());
816:                    }
817:                }
818:                return list;
819:            } // end of getRequiredPermissionsList
820:
821:            /*
822:             ** Context state must be reset in restContext()
823:             */
824:
825:            private final Parser parser;
826:            private final LanguageConnectionContext lcc;
827:            private final LanguageConnectionFactory lcf;
828:            private TypeCompilerFactory typeCompilerFactory;
829:            private Dependent currentDependent;
830:            private DependencyManager dm;
831:            private boolean firstOnStack;
832:            private boolean inUse;
833:            private int reliability = CompilerContext.SQL_LEGAL;
834:            private int nextColumnNumber = 1;
835:            private int nextTableNumber;
836:            private int nextSubqueryNumber;
837:            private int nextResultSetNumber;
838:            private int entryIsolationLevel;
839:            private int scanIsolationLevel;
840:            private int nextEquivalenceClass = -1;
841:            private long nextClassName;
842:            private Vector savedObjects;
843:            private String classPrefix;
844:            private SchemaDescriptor compilationSchema;
845:            private ProviderList currentAPL;
846:            private boolean returnParameterFlag;
847:
848:            private Vector storeCostControllers = new Vector();
849:            private Vector storeCostConglomIds = new Vector();
850:
851:            private SortCostController sortCostController;
852:
853:            private Vector parameterList;
854:
855:            /* Type descriptors for the ? parameters */
856:            private DataTypeDescriptor[] parameterDescriptors;
857:
858:            private Object cursorInfo;
859:
860:            private SQLWarning warnings;
861:
862:            private Stack privTypeStack = new Stack();
863:            private int currPrivType = Authorizer.NULL_PRIV;
864:            private HashMap requiredColumnPrivileges;
865:            private HashMap requiredTablePrivileges;
866:            private HashMap requiredSchemaPrivileges;
867:            private HashMap requiredRoutinePrivileges;
868:        } // end of class CompilerContextImpl
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.