📄 compilercontextimpl.java
字号:
/* Derby - Class org.apache.derby.impl.sql.compile.CompilerContextImpl Copyright 1997, 2005 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.sql.compile;import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;import org.apache.derby.iapi.sql.depend.ProviderList;import org.apache.derby.iapi.sql.compile.CompilerContext;import org.apache.derby.iapi.sql.compile.NodeFactory;import org.apache.derby.iapi.sql.compile.Parser;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.sql.compile.TypeCompilerFactory;import org.apache.derby.iapi.sql.depend.Dependent;import org.apache.derby.iapi.sql.depend.Provider;import org.apache.derby.iapi.sql.depend.DependencyManager;import org.apache.derby.iapi.error.ExceptionSeverity;import org.apache.derby.iapi.sql.execute.ExecutionContext;import org.apache.derby.iapi.types.DataTypeDescriptor;import org.apache.derby.iapi.sql.ParameterValueSet;import org.apache.derby.iapi.store.access.StoreCostController;import org.apache.derby.iapi.store.access.SortCostController;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.loader.ClassFactory;import org.apache.derby.iapi.services.compiler.JavaFactory;import org.apache.derby.iapi.services.uuid.UUIDFactory;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.context.ContextImpl;import java.sql.SQLWarning;import java.util.Vector;import java.util.Properties;/* * * CompilerContextImpl * */public class CompilerContextImpl extends ContextImpl implements CompilerContext { // // Context interface // /** @exception StandardException thrown by makeInvalid() call */ public void cleanupOnError(Throwable error) throws StandardException { setInUse(false); resetContext(); if (error instanceof StandardException) { StandardException se = (StandardException) error; // if something went wrong with the compile, // we need to mark the statement invalid. // REVISIT: do we want instead to remove it, // so the cache doesn't get full of garbage input // that won't even parse? if (se.getSeverity() < ExceptionSeverity.SYSTEM_SEVERITY) { if (currentDependent != null) { LanguageConnectionContext lcc; /* Find the LanguageConnectionContext */ lcc = (LanguageConnectionContext) getContextManager().getContext(LanguageConnectionContext.CONTEXT_ID); currentDependent.makeInvalid(DependencyManager.COMPILE_FAILED, lcc); } closeStoreCostControllers(); closeSortCostControllers(); } // anything system or worse, or non-DB errors, // will cause the whole system to shut down. } } /** * Reset compiler context (as for instance, when we recycle a context for * use by another compilation. */ public void resetContext() { nextColumnNumber = 1; nextTableNumber = 0; nextSubqueryNumber = 0; resetNextResultSetNumber(); nextEquivalenceClass = -1; compilationSchema = null; parameterList = null; parameterDescriptors = null; scanIsolationLevel = ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL; warnings = null; savedObjects = null; reliability = CompilerContext.SQL_LEGAL; returnParameterFlag = false; } // // CompilerContext interface // // we might want these to refuse to return // anything if they are in-use -- would require // the interface provide a 'done' call, and // we would mark them in-use whenever a get happened. public Parser getParser() { return parser; } /** * Get the NodeFactory for this context * * @return The NodeFactory for this context. */ public NodeFactory getNodeFactory() { return lcf.getNodeFactory(); } public int getNextColumnNumber() { return nextColumnNumber++; } public int getNextTableNumber() { return nextTableNumber++; } public int getNumTables() { return nextTableNumber; } /** * Get the current next subquery number from this CompilerContext. * * @return int The next subquery number for the current statement. * */ public int getNextSubqueryNumber() { return nextSubqueryNumber++; } /** * Get the number of subquerys in the current statement from this CompilerContext. * * @return int The number of subquerys in the current statement. * */ public int getNumSubquerys() { return nextSubqueryNumber; } public int getNextResultSetNumber() { return nextResultSetNumber++; } public void resetNextResultSetNumber() { nextResultSetNumber = 0; } public int getNumResultSets() { return nextResultSetNumber; } public String getUniqueClassName() { // REMIND: should get a new UUID if we roll over... if (SanityManager.DEBUG) { SanityManager.ASSERT(nextClassName <= Long.MAX_VALUE); } return classPrefix.concat(Long.toHexString(nextClassName++)); } /** * Get the next equivalence class for equijoin clauses. * * @return The next equivalence class for equijoin clauses. */ public int getNextEquivalenceClass() { return ++nextEquivalenceClass; } public ClassFactory getClassFactory() { return lcf.getClassFactory(); } public JavaFactory getJavaFactory() { return lcf.getJavaFactory(); } public Dependent getCurrentDependent() { return currentDependent; } public void setCurrentDependent(Dependent d) { currentDependent = d; } /** * Get the current auxiliary provider list from this CompilerContext. * * @return The current AuxiliaryProviderList. * */ public ProviderList getCurrentAuxiliaryProviderList() { return currentAPL; } /** * Set the current auxiliary provider list for this CompilerContext. * * @param adl The new current AuxiliaryProviderList. * * @return Nothing. */ public void setCurrentAuxiliaryProviderList(ProviderList apl) { currentAPL = apl; } public void createDependency(Provider p) throws StandardException { if (SanityManager.DEBUG) SanityManager.ASSERT(getCurrentDependent() != null, "no current dependent for compilation"); LanguageConnectionContext lcc = (LanguageConnectionContext) getContextManager().getContext(LanguageConnectionContext.CONTEXT_ID); DependencyManager dm = lcc.getDataDictionary().getDependencyManager(); dm.addDependency(getCurrentDependent(), p, getContextManager()); addProviderToAuxiliaryList(p); } /** * Add a dependency between two objects. * * @param d The Dependent object. * @param p The Provider of the dependency. * @exception StandardException thrown on failure. * */ public void createDependency(Dependent d, Provider p) throws StandardException { LanguageConnectionContext lcc = (LanguageConnectionContext) getContextManager().getContext(LanguageConnectionContext.CONTEXT_ID); DependencyManager dm = lcc.getDataDictionary().getDependencyManager(); dm.addDependency(d, p, getContextManager()); addProviderToAuxiliaryList(p); } /** * Add a Provider to the current AuxiliaryProviderList, if one exists. * * @param p The Provider to add. * * @return Nothing. * */ private void addProviderToAuxiliaryList(Provider p) { if (currentAPL != null) { currentAPL.addProvider(p); } } public int addSavedObject(Object obj) { if (savedObjects == null) savedObjects = new Vector(); savedObjects.addElement(obj); return savedObjects.size()-1; } public Object[] getSavedObjects() { if (savedObjects == null) return null; Object[] retVal = new Object[savedObjects.size()]; savedObjects.copyInto(retVal); savedObjects = null; // erase to start over return retVal; } /** @see CompilerContext#setSavedObjects */ public void setSavedObjects(Object[] objs) { if (objs == null) { return; } for (int i = 0; i < objs.length; i++) { addSavedObject(objs[i]); } } /** @see CompilerContext#setParams */ public void setParams(ParameterValueSet params) { this.params = params; } /** @see CompilerContext#getParams */ public ParameterValueSet getParams() { ParameterValueSet tmpParams = this.params; this.params = null; return tmpParams; } /** @see CompilerContext#setCursorInfo */ public void setCursorInfo(Object cursorInfo) { this.cursorInfo = cursorInfo; } /** @see CompilerContext#getCursorInfo */ public Object getCursorInfo() { return cursorInfo; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -