[Home] DMelt member access. Java source code: org.apache.derby.impl.sql.compile.CompilerContextImpl
/*
Derby - Class org.apache.derby.impl.sql.compile.CompilerContextImpl
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you 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 java.sql.SQLWarning;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.apache.derby.catalog.UUID;
import org.apache.derby.iapi.error.ExceptionSeverity;
import org.apache.derby.iapi.error.StandardException;
import org.apache.derby.iapi.services.compiler.JavaFactory;
import org.apache.derby.iapi.services.context.ContextImpl;
import org.apache.derby.iapi.services.context.ContextManager;
import org.apache.derby.iapi.services.io.FormatableBitSet;
import org.apache.derby.iapi.services.loader.ClassFactory;
import org.apache.derby.shared.common.sanity.SanityManager;
import org.apache.derby.iapi.sql.compile.CompilerContext;
import org.apache.derby.iapi.sql.compile.OptimizerFactory;
import org.apache.derby.iapi.sql.compile.Parser;
import org.apache.derby.iapi.sql.compile.Visitable;
import org.apache.derby.iapi.sql.compile.VisitableFilter;
import org.apache.derby.iapi.sql.compile.TypeCompilerFactory;
import org.apache.derby.iapi.sql.conn.Authorizer;
import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;
import org.apache.derby.iapi.sql.depend.DependencyManager;
import org.apache.derby.iapi.sql.depend.Dependent;
import org.apache.derby.iapi.sql.depend.Provider;
import org.apache.derby.iapi.sql.depend.ProviderList;
import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
import org.apache.derby.iapi.sql.dictionary.PermDescriptor;
import org.apache.derby.iapi.sql.dictionary.PrivilegedSQLObject;
import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
import org.apache.derby.iapi.sql.dictionary.SequenceDescriptor;
import org.apache.derby.iapi.sql.dictionary.StatementColumnPermission;
import org.apache.derby.iapi.sql.dictionary.StatementGenericPermission;
import org.apache.derby.iapi.sql.dictionary.StatementPermission;
import org.apache.derby.iapi.sql.dictionary.StatementRolePermission;
import org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission;
import org.apache.derby.iapi.sql.dictionary.StatementSchemaPermission;
import org.apache.derby.iapi.sql.dictionary.StatementTablePermission;
import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
import org.apache.derby.iapi.store.access.SortCostController;
import org.apache.derby.iapi.store.access.StoreCostController;
import org.apache.derby.iapi.transaction.TransactionControl;
import org.apache.derby.iapi.types.DataTypeDescriptor;
import org.apache.derby.iapi.util.ReuseFactory;
/**
*
* CompilerContextImpl, implementation of CompilerContext.
* CompilerContext and hence CompilerContextImpl objects are private to a LanguageConnectionContext.
*
*/
public class CompilerContextImpl extends ContextImpl
implements CompilerContext {
private static final int SCOPE_CELL = 0;
//
// 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?
int severity = se.getSeverity();
if (severity < ExceptionSeverity.SYSTEM_SEVERITY)
{
if (currentDependent != null)
{
currentDependent.makeInvalid(DependencyManager.COMPILE_FAILED,
lcc);
}
closeStoreCostControllers();
closeSortCostControllers();
}
// anything system or worse, or non-DB errors,
// will cause the whole system to shut down.
if (severity >= ExceptionSeverity.SESSION_SEVERITY)
popMe();
}
}
/**
* 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 = TransactionControl.UNSPECIFIED_ISOLATION_LEVEL;
warnings = null;
savedObjects = null;
reliability = CompilerContext.SQL_LEGAL;
returnParameterFlag = false;
initRequiredPriv();
defaultSchemaStack = null;
referencedSequences = null;
privilegeCheckFilters = null;
namedScopes = null;
skippingTypePrivileges = 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 OptimizerFactory for this context
*
* @return The OptimizerFactory for this context.
*/
public OptimizerFactory getOptimizerFactory()
{ return lcf.getOptimizerFactory(); }
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 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 apl The new current AuxiliaryProviderList.
*/
public void setCurrentAuxiliaryProviderList(ProviderList apl)
{
currentAPL = apl;
}
public void createDependency(Provider p) throws StandardException {
if (SanityManager.DEBUG)
SanityManager.ASSERT(currentDependent != null,
"no current dependent for compilation");
if (dm == null)
dm = lcc.getDataDictionary().getDependencyManager();
dm.addDependency(currentDependent, 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
{
if (dm == null)
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.
*/
private void addProviderToAuxiliaryList(Provider p)
{
if (currentAPL != null)
{
currentAPL.addProvider(p);
}
}
public int addSavedObject(Object obj) {
if (savedObjects == null) {
savedObjects = new ArrayList