org.apache.derby.impl.sql.compile
Class CompilerContextImpl

java.lang.Object
  extended byorg.apache.derby.iapi.services.context.ContextImpl
      extended byorg.apache.derby.impl.sql.compile.CompilerContextImpl
All Implemented Interfaces:
CompilerContext, Context

public class CompilerContextImpl
extends ContextImpl
implements CompilerContext


Field Summary
private  java.lang.String classPrefix
           
private  SchemaDescriptor compilationSchema
           
private  ProviderList currentAPL
           
private  Dependent currentDependent
           
private  java.lang.Object cursorInfo
           
private  DependencyManager dmgr
           
private  int entryIsolationLevel
           
private  boolean firstOnStack
           
private  boolean inUse
           
private  LanguageConnectionFactory lcf
           
private  long nextClassName
           
private  int nextColumnNumber
           
private  int nextEquivalenceClass
           
private  int nextResultSetNumber
           
private  int nextSubqueryNumber
           
private  int nextTableNumber
           
private  DataTypeDescriptor[] parameterDescriptors
           
private  java.util.Vector parameterList
           
private  ParameterValueSet params
           
private  Parser parser
           
private  int reliability
           
private  boolean returnParameterFlag
           
private  java.util.Vector savedObjects
           
private  int scanIsolationLevel
           
private  SortCostController sortCostController
           
private  java.util.Vector storeCostConglomIds
           
private  java.util.Vector storeCostControllers
           
private  TypeCompilerFactory typeCompilerFactory
           
private  java.sql.SQLWarning warnings
           
 
Fields inherited from class org.apache.derby.iapi.services.context.ContextImpl
 
Fields inherited from interface org.apache.derby.iapi.sql.compile.CompilerContext
CHECK_CONSTRAINT, COLUMN_REFERENCE_ILLEGAL, CONTEXT_ID, CURRENT_CONNECTION_ILLEGAL, DATETIME_ILLEGAL, DEFAULT_RESTRICTION, DIAGNOSTICS_ILLEGAL, FUNCTION_CALL_ILLEGAL, IGNORE_MISSING_CLASSES, INTERNAL_SQL_ILLEGAL, INTERNAL_SQL_LEGAL, SCHEMA_ILLEGAL, SQL_LEGAL, SUBQUERY_ILLEGAL, UNNAMED_PARAMETER_ILLEGAL, USER_ILLEGAL
 
Constructor Summary
CompilerContextImpl(ContextManager cm, LanguageConnectionFactory lcf, TypeCompilerFactory typeCompilerFactory)
           
 
Method Summary
private  void addProviderToAuxiliaryList(Provider p)
          Add a Provider to the current AuxiliaryProviderList, if one exists.
 int addSavedObject(java.lang.Object obj)
          Add an object to the pool that is created at compile time and used at execution time.
 void addWarning(java.sql.SQLWarning warning)
          Add a compile time warning.
 void cleanupOnError(java.lang.Throwable error)
          Contexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action.
private  void closeSortCostControllers()
           
private  void closeStoreCostControllers()
           
 void createDependency(Dependent d, Provider p)
          Add a dependency between two objects.
 void createDependency(Provider p)
          Add a dependency for the current dependent.
 void firstOnStack()
          Mark this CompilerContext as the first on the stack, so we can avoid continually popping and pushing a CompilerContext.
 ClassFactory getClassFactory()
          Return the class factory to use in this compilation.
 SchemaDescriptor getCompilationSchema()
          Get the compilation schema descriptor for this compilation context.
 ProviderList getCurrentAuxiliaryProviderList()
          Get the current auxiliary provider list from this CompilerContext.
 Dependent getCurrentDependent()
          Get the current dependent from this CompilerContext.
 java.lang.Object getCursorInfo()
          Get the cursor info stored in the context.
 int getEntryIsolationLevel()
          Get the entry isolation level from this CC.
 boolean getInUse()
          Return the in use state for the compiler context.
 JavaFactory getJavaFactory()
          Get the JavaFactory from this CompilerContext.
 int getNextColumnNumber()
          Get the current next column number (for generated column names) from this CompilerContext.
 int getNextEquivalenceClass()
          Get the next equivalence class for equijoin clauses.
 int getNextParameterNumber()
          Get the next parameter number.
 int getNextResultSetNumber()
          Get the current next ResultSet number from this CompilerContext.
 int getNextSubqueryNumber()
          Get the current next subquery number from this CompilerContext.
 int getNextTableNumber()
          Get the current next table number from this CompilerContext.
 NodeFactory getNodeFactory()
          Get the NodeFactory for this context
 int getNumResultSets()
          Get the number of Results in the current statement from this CompilerContext.
 int getNumSubquerys()
          Get the number of subquerys in the current statement from this CompilerContext.
 int getNumTables()
          Get the number of tables in the current statement from this CompilerContext.
 java.util.Vector getParameterList()
          Get the parameter list.
 DataTypeDescriptor[] getParameterTypes()
          Get the array of DataTypeDescriptor representing the types of the ?
 ParameterValueSet getParams()
          Get the params stored vai setParams.
 Parser getParser()
          Get the Parser from this CompilerContext
 int getReliability()
          Return the reliability requirements of this clause.
 boolean getReturnParameterFlag()
          Is the callable statement uses ?
 java.lang.Object[] getSavedObjects()
          Get the saved object pool (for putting into the prepared statement).
 int getScanIsolationLevel()
          Get the isolation level for the scans in this query.
 SortCostController getSortCostController()
          Get a SortCostController.
 StoreCostController getStoreCostController(long conglomerateNumber, LanguageConnectionContext lcc)
          Get a StoreCostController for the given conglomerate.
 TypeCompilerFactory getTypeCompilerFactory()
          Get the TypeCompilerFactory from this CompilerContext.
 java.lang.String getUniqueClassName()
          Get a unique Class name from this CompilerContext.
 java.sql.SQLWarning getWarnings()
          Get the chain of compile time warnings.
 boolean isFirstOnStack()
          Is this the first CompilerContext on the stack?
 void resetContext()
          Reset compiler context (as for instance, when we recycle a context for use by another compilation.
 void resetNextResultSetNumber()
          Reset the next ResultSet number from this CompilerContext.
 SchemaDescriptor setCompilationSchema(SchemaDescriptor newDefault)
          Set the compilation schema descriptor for this compilation context.
 void setCurrentAuxiliaryProviderList(ProviderList apl)
          Set the current auxiliary provider list for this CompilerContext.
 void setCurrentDependent(Dependent d)
          Set the current dependent from this CompilerContext.
 void setCursorInfo(java.lang.Object cursorInfo)
          Set params
 void setEntryIsolationLevel(int isolationLevel)
          Set the isolation level on entry to this CC so that it can be restored on exit.
 void setInUse(boolean inUse)
          Set the in use state for the compiler context.
 void setParameterList(java.util.Vector parameterList)
          Set the parameter list.
 void setParams(ParameterValueSet params)
          Set params
 void setReliability(int reliability)
          Sets which kind of query fragments are NOT allowed.
 void setReturnParameterFlag()
          If callable statement uses ?
 void setSavedObjects(java.lang.Object[] objs)
          Set the saved object pool (for putting into the prepared statement).
 void setScanIsolationLevel(int isolationLevel)
          Set the isolation level for the scans in this query.
 
Methods inherited from class org.apache.derby.iapi.services.context.ContextImpl
appendErrorInfo, getContextManager, getIdName, isLastHandler, popMe, pushMe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.services.context.Context
getContextManager, getIdName, isLastHandler, popMe, pushMe
 

Field Detail

parser

private final Parser parser

lcf

private LanguageConnectionFactory lcf

typeCompilerFactory

private TypeCompilerFactory typeCompilerFactory

currentDependent

private Dependent currentDependent

dmgr

private DependencyManager dmgr

firstOnStack

private boolean firstOnStack

inUse

private boolean inUse

reliability

private int reliability

nextColumnNumber

private int nextColumnNumber

nextTableNumber

private int nextTableNumber

nextSubqueryNumber

private int nextSubqueryNumber

nextResultSetNumber

private int nextResultSetNumber

entryIsolationLevel

private int entryIsolationLevel

scanIsolationLevel

private int scanIsolationLevel

nextEquivalenceClass

private int nextEquivalenceClass

nextClassName

private long nextClassName

savedObjects

private java.util.Vector savedObjects

classPrefix

private java.lang.String classPrefix

params

private ParameterValueSet params

compilationSchema

private SchemaDescriptor compilationSchema

currentAPL

private ProviderList currentAPL

returnParameterFlag

private boolean returnParameterFlag

storeCostControllers

private java.util.Vector storeCostControllers

storeCostConglomIds

private java.util.Vector storeCostConglomIds

sortCostController

private SortCostController sortCostController

parameterList

private java.util.Vector parameterList

parameterDescriptors

private DataTypeDescriptor[] parameterDescriptors

cursorInfo

private java.lang.Object cursorInfo

warnings

private java.sql.SQLWarning warnings
Constructor Detail

CompilerContextImpl

public CompilerContextImpl(ContextManager cm,
                           LanguageConnectionFactory lcf,
                           TypeCompilerFactory typeCompilerFactory)
Method Detail

cleanupOnError

public void cleanupOnError(java.lang.Throwable error)
                    throws StandardException
Description copied from interface: Context
Contexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action. They will be told what the error is, so that they can react appropriately. Most of the time, the contexts will react by either doing nothing or by removing themselves from the context manager. If there are no other references to the context, removing itself from the manager equates to freeing it.

Contexts must release all their resources before removing themselves from their context manager.

The context manager will "unwind" the contexts during cleanup in the reverse order they were placed on its global stack.

If error is an instance of StandardException then an implementation of this method may throw a new exception if and only if the new exception is an instance of StandardException that is more severe than the original error or the new exception is a not an instance of StandardException (e.g java.lang.NullPointerException).

Specified by:
cleanupOnError in interface Context
Throws:
StandardException - thrown by makeInvalid() call

resetContext

public void resetContext()
Reset compiler context (as for instance, when we recycle a context for use by another compilation.

Specified by:
resetContext in interface CompilerContext

getParser

public Parser getParser()
Description copied from interface: CompilerContext
Get the Parser from this CompilerContext. *

Specified by:
getParser in interface CompilerContext
Returns:
The parser associated with this CompilerContext

getNodeFactory

public NodeFactory getNodeFactory()
Get the NodeFactory for this context

Specified by:
getNodeFactory in interface CompilerContext
Returns:
The NodeFactory for this context.

getNextColumnNumber

public int getNextColumnNumber()
Description copied from interface: CompilerContext
Get the current next column number (for generated column names) from this CompilerContext.

Specified by:
getNextColumnNumber in interface CompilerContext
Returns:
int The next column number for the current statement.

getNextTableNumber

public int getNextTableNumber()
Description copied from interface: CompilerContext
Get the current next table number from this CompilerContext.

Specified by:
getNextTableNumber in interface CompilerContext
Returns:
int The next table number for the current statement.

getNumTables

public int getNumTables()
Description copied from interface: CompilerContext
Get the number of tables in the current statement from this CompilerContext.

Specified by:
getNumTables in interface CompilerContext
Returns:
int The number of tables in the current statement.

getNextSubqueryNumber

public int getNextSubqueryNumber()
Get the current next subquery number from this CompilerContext.

Specified by:
getNextSubqueryNumber in interface CompilerContext
Returns:
int The next subquery number for the current statement.

getNumSubquerys

public int getNumSubquerys()
Get the number of subquerys in the current statement from this CompilerContext.

Specified by:
getNumSubquerys in interface CompilerContext
Returns:
int The number of subquerys in the current statement.

getNextResultSetNumber

public int getNextResultSetNumber()
Description copied from interface: CompilerContext
Get the current next ResultSet number from this CompilerContext.

Specified by:
getNextResultSetNumber in interface CompilerContext
Returns:
int The next ResultSet number for the current statement.

resetNextResultSetNumber

public void resetNextResultSetNumber()
Description copied from interface: CompilerContext
Reset the next ResultSet number from this CompilerContext.

Specified by:
resetNextResultSetNumber in interface CompilerContext
Returns:
None.

getNumResultSets

public int getNumResultSets()
Description copied from interface: CompilerContext
Get the number of Results in the current statement from this CompilerContext.

Specified by:
getNumResultSets in interface CompilerContext
Returns:
int The number of ResultSets in the current statement.

getUniqueClassName

public java.lang.String getUniqueClassName()
Description copied from interface: CompilerContext
Get a unique Class name from this CompilerContext. Ensures it is globally unique for this JVM.

Specified by:
getUniqueClassName in interface CompilerContext
Returns:
String A unique-enough class name.

getNextEquivalenceClass

public int getNextEquivalenceClass()
Get the next equivalence class for equijoin clauses.

Specified by:
getNextEquivalenceClass in interface CompilerContext
Returns:
The next equivalence class for equijoin clauses.

getClassFactory

public ClassFactory getClassFactory()
Description copied from interface: CompilerContext
Return the class factory to use in this compilation.

Specified by:
getClassFactory in interface CompilerContext

getJavaFactory

public JavaFactory getJavaFactory()
Description copied from interface: CompilerContext
Get the JavaFactory from this CompilerContext.

Specified by:
getJavaFactory in interface CompilerContext
Returns:
The JavaFactory associated with this CompilerContext

getCurrentDependent

public Dependent getCurrentDependent()
Description copied from interface: CompilerContext
Get the current dependent from this CompilerContext.

Specified by:
getCurrentDependent in interface CompilerContext
Returns:
The Dependent currently being compiled.

setCurrentDependent

public void setCurrentDependent(Dependent d)
Description copied from interface: CompilerContext
Set the current dependent from this CompilerContext. This should be called at the start of a compile to register who has the dependencies needed for the compilation.

Specified by:
setCurrentDependent in interface CompilerContext
Parameters:
d - The Dependent currently being compiled.

getCurrentAuxiliaryProviderList

public ProviderList getCurrentAuxiliaryProviderList()
Get the current auxiliary provider list from this CompilerContext.

Specified by:
getCurrentAuxiliaryProviderList in interface CompilerContext
Returns:
The current AuxiliaryProviderList.

setCurrentAuxiliaryProviderList

public void setCurrentAuxiliaryProviderList(ProviderList apl)
Set the current auxiliary provider list for this CompilerContext.

Specified by:
setCurrentAuxiliaryProviderList in interface CompilerContext
Parameters:
apl - The new current AuxiliaryProviderList.
Returns:
Nothing.

createDependency

public void createDependency(Provider p)
                      throws StandardException
Description copied from interface: CompilerContext
Add a dependency for the current dependent.

Specified by:
createDependency in interface CompilerContext
Parameters:
p - The Provider of the dependency.
Throws:
StandardException - thrown on failure.

createDependency

public void createDependency(Dependent d,
                             Provider p)
                      throws StandardException
Add a dependency between two objects.

Specified by:
createDependency in interface CompilerContext
Parameters:
d - The Dependent object.
p - The Provider of the dependency.
Throws:
StandardException - thrown on failure.

addProviderToAuxiliaryList

private void addProviderToAuxiliaryList(Provider p)
                                 throws StandardException
Add a Provider to the current AuxiliaryProviderList, if one exists.

Parameters:
p - The Provider to add.
Returns:
Nothing.
Throws:
StandardException - thrown on failure.

addSavedObject

public int addSavedObject(java.lang.Object obj)
Description copied from interface: CompilerContext
Add an object to the pool that is created at compile time and used at execution time. Use the integer to reference it in execution constructs. Execution code will have to generate:
	(#objectType) (this.getPreparedStatement().getSavedObject(#int))
  <\pre>

Specified by:
addSavedObject in interface CompilerContext
Returns:
the entry # for the object

getSavedObjects

public java.lang.Object[] getSavedObjects()
Description copied from interface: CompilerContext
Get the saved object pool (for putting into the prepared statement). This turns it into its storable form, an array of objects.

Specified by:
getSavedObjects in interface CompilerContext
Returns:
the saved object pool.

setSavedObjects

public void setSavedObjects(java.lang.Object[] objs)
Description copied from interface: CompilerContext
Set the saved object pool (for putting into the prepared statement).

Specified by:
setSavedObjects in interface CompilerContext
Parameters:
objs - The new saved objects
See Also:
CompilerContext.setSavedObjects(java.lang.Object[])

setParams

public void setParams(ParameterValueSet params)
Description copied from interface: CompilerContext
Set params

Specified by:
setParams in interface CompilerContext
Parameters:
params - the params
See Also:
CompilerContext.setParams(org.apache.derby.iapi.sql.ParameterValueSet)

getParams

public ParameterValueSet getParams()
Description copied from interface: CompilerContext
Get the params stored vai setParams. WARNING: nulls out the params value before returning it, so a subsequent get will get a null.

Specified by:
getParams in interface CompilerContext
Returns:
the parameters
See Also:
CompilerContext.getParams()

setCursorInfo

public void setCursorInfo(java.lang.Object cursorInfo)
Description copied from interface: CompilerContext
Set params

Specified by:
setCursorInfo in interface CompilerContext
Parameters:
cursorInfo - the cursor info
See Also:
CompilerContext.setCursorInfo(java.lang.Object)

getCursorInfo

public java.lang.Object getCursorInfo()
Description copied from interface: CompilerContext
Get the cursor info stored in the context.

Specified by:
getCursorInfo in interface CompilerContext
Returns:
the cursor info
See Also:
CompilerContext.getCursorInfo()

firstOnStack

public void firstOnStack()
Description copied from interface: CompilerContext
Mark this CompilerContext as the first on the stack, so we can avoid continually popping and pushing a CompilerContext.

Specified by:
firstOnStack in interface CompilerContext
See Also:
CompilerContext.firstOnStack()

isFirstOnStack

public boolean isFirstOnStack()
Description copied from interface: CompilerContext
Is this the first CompilerContext on the stack?

Specified by:
isFirstOnStack in interface CompilerContext
See Also:
CompilerContext.isFirstOnStack()

setInUse

public void setInUse(boolean inUse)
Set the in use state for the compiler context.

Specified by:
setInUse in interface CompilerContext
Parameters:
inUse - The new inUse state for the compiler context.
Returns:
Nothing.

getInUse

public boolean getInUse()
Return the in use state for the compiler context.

Specified by:
getInUse in interface CompilerContext
Returns:
boolean The in use state for the compiler context.

setReliability

public void setReliability(int reliability)
Sets which kind of query fragments are NOT allowed. Basically, these are fragments which return unstable results. CHECK CONSTRAINTS and CREATE PUBLICATION want to forbid certain kinds of fragments.

Specified by:
setReliability in interface CompilerContext
Parameters:
reliability - bitmask of types of query fragments to be forbidden see the reliability bitmasks in CompilerContext.java

getReliability

public int getReliability()
Return the reliability requirements of this clause. See setReliability() for a definition of clause reliability.

Specified by:
getReliability in interface CompilerContext
Returns:
a bitmask of which types of query fragments are to be forbidden

getStoreCostController

public StoreCostController getStoreCostController(long conglomerateNumber,
                                                  LanguageConnectionContext lcc)
                                           throws StandardException
Description copied from interface: CompilerContext
Get a StoreCostController for the given conglomerate.

Specified by:
getStoreCostController in interface CompilerContext
Parameters:
conglomerateNumber - The conglomerate for which to get a StoreCostController.
lcc - Current LanguageConnectionContext.
Returns:
The appropriate StoreCostController.
Throws:
StandardException - Thrown on error
See Also:
CompilerContext.getStoreCostController(long, org.apache.derby.iapi.sql.conn.LanguageConnectionContext)

closeStoreCostControllers

private void closeStoreCostControllers()

getSortCostController

public SortCostController getSortCostController()
                                         throws StandardException
Description copied from interface: CompilerContext
Get a SortCostController.

Specified by:
getSortCostController in interface CompilerContext
Throws:
StandardException - Thrown on error
See Also:
CompilerContext.getSortCostController()

closeSortCostControllers

private void closeSortCostControllers()
Throws:
StandardException - Thrown on error

getCompilationSchema

public SchemaDescriptor getCompilationSchema()
Get the compilation schema descriptor for this compilation context. Will be null if no default schema lookups have occured. Ie. the statement is independent of the current schema.

Specified by:
getCompilationSchema in interface CompilerContext
Returns:
the compilation schema descirptor

setCompilationSchema

public SchemaDescriptor setCompilationSchema(SchemaDescriptor newDefault)
Set the compilation schema descriptor for this compilation context.

Specified by:
setCompilationSchema in interface CompilerContext
Returns:
the previous compilation schema descirptor

setParameterList

public void setParameterList(java.util.Vector parameterList)
Description copied from interface: CompilerContext
Set the parameter list.

Specified by:
setParameterList in interface CompilerContext
Parameters:
parameterList - The parameter list.
Returns:
Nothing.
See Also:
CompilerContext.setParameterList(java.util.Vector)

getParameterList

public java.util.Vector getParameterList()
Description copied from interface: CompilerContext
Get the parameter list.

Specified by:
getParameterList in interface CompilerContext
Returns:
The parameter list.
See Also:
CompilerContext.getParameterList()

setReturnParameterFlag

public void setReturnParameterFlag()
Description copied from interface: CompilerContext
If callable statement uses ? = form

Specified by:
setReturnParameterFlag in interface CompilerContext
Returns:
Nothing.
See Also:
CompilerContext.setReturnParameterFlag()

getReturnParameterFlag

public boolean getReturnParameterFlag()
Description copied from interface: CompilerContext
Is the callable statement uses ? for return parameter.

Specified by:
getReturnParameterFlag in interface CompilerContext
Returns:
true if ? = call else false
See Also:
CompilerContext.getReturnParameterFlag()

getParameterTypes

public DataTypeDescriptor[] getParameterTypes()
Description copied from interface: CompilerContext
Get the array of DataTypeDescriptor representing the types of the ? parameters.

Specified by:
getParameterTypes in interface CompilerContext
Returns:
The parameter descriptors
See Also:
CompilerContext.getParameterTypes()

getNextParameterNumber

public int getNextParameterNumber()
Description copied from interface: CompilerContext
Get the next parameter number. Useful when generating "associated" parameters.

Specified by:
getNextParameterNumber in interface CompilerContext
Returns:
The next parameter number for the statement.
See Also:
CompilerContext.getNextParameterNumber()

setScanIsolationLevel

public void setScanIsolationLevel(int isolationLevel)
Description copied from interface: CompilerContext
Set the isolation level for the scans in this query.

Specified by:
setScanIsolationLevel in interface CompilerContext
Parameters:
isolationLevel - The isolation level to use.
Returns:
Nothing.
See Also:
CompilerContext.setScanIsolationLevel(int)

getScanIsolationLevel

public int getScanIsolationLevel()
Description copied from interface: CompilerContext
Get the isolation level for the scans in this query.

Specified by:
getScanIsolationLevel in interface CompilerContext
Returns:
The isolation level for the scans in this query.
See Also:
CompilerContext.getScanIsolationLevel()

setEntryIsolationLevel

public void setEntryIsolationLevel(int isolationLevel)
Description copied from interface: CompilerContext
Set the isolation level on entry to this CC so that it can be restored on exit.

Specified by:
setEntryIsolationLevel in interface CompilerContext
Parameters:
isolationLevel - The isolation level on entry.
Returns:
Nothing.
See Also:
CompilerContext.setEntryIsolationLevel(int)

getEntryIsolationLevel

public int getEntryIsolationLevel()
Description copied from interface: CompilerContext
Get the entry isolation level from this CC.

Specified by:
getEntryIsolationLevel in interface CompilerContext
Returns:
The entry isolation level.
See Also:
CompilerContext.getScanIsolationLevel()

getTypeCompilerFactory

public TypeCompilerFactory getTypeCompilerFactory()
Description copied from interface: CompilerContext
Get the TypeCompilerFactory from this CompilerContext.

Specified by:
getTypeCompilerFactory in interface CompilerContext
Returns:
The TypeCompilerFactory associated with this CompilerContext
See Also:
CompilerContext.getTypeCompilerFactory()

addWarning

public void addWarning(java.sql.SQLWarning warning)
Add a compile time warning.

Specified by:
addWarning in interface CompilerContext

getWarnings

public java.sql.SQLWarning getWarnings()
Get the chain of compile time warnings.

Specified by:
getWarnings in interface CompilerContext


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.