Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv abstract Class ExpressionClassBuilder

extends Object
implements ExpressionClassBuilderInterface
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.compile.ExpressionClassBuilderInterface
Known Direct Subclasses
org.apache.derby.impl.sql.compile.ActivationClassBuilder
Imports
java.io.Serializable, java.lang.reflect.Modifier, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.ClassBuilder, .JavaFactory, .LocalField, .MethodBuilder, org.apache.derby.iapi.services.io.FormatableArrayHolder, org.apache.derby.iapi.services.loader.GeneratedClass, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.CompilerContext, .ExpressionClassBuilderInterface, .TypeCompiler, org.apache.derby.iapi.store.access.ColumnOrdering, org.apache.derby.iapi.types.TypeId, org.apache.derby.iapi.util.ByteArray, org.apache.derby.impl.sql.execute.IndexColumnOrder

ExpressionClassBuilder provides an interface to satisfy generation's common tasks in building classes that involve expressions. This is the common superclass of ActivationClassBuilder and FilterClassBuilder. See the documentation on ActivationClassBuilder.

Field Summary

Modifier and TypeField and Description
protected ClassBuilder
protected LocalField
protected MethodBuilder
protected static final String
private String
pack-priv MethodBuilder
protected GeneratedClass
private Object
getDVF

Get/reuse the Expression for getting the DataValueFactory

private Object
getEF

This is a utility method to get a common expression -- "BaseActivation.getExecutionFactory()".

private Object
getRSF

This is a utility method to get a common expression -- "BaseActivation.getResultSetFactory()".

pack-priv CompilerContext
protected int
protected int
protected int

Constructor Summary

AccessConstructor and Description
pack-priv
ExpressionClassBuilder(String superClass, String className, CompilerContext cc)

By the time this is done, it has constructed the following class:

   final public class #className extends #superClass {
     public #className() { super(); }
   }

Method Summary

Modifier and TypeMethod and Description
pack-priv FormatableArrayHolder

Returns:

the ColumnOrdering array
addColumnToOrdering
(FormatableArrayHolder orderingHolder, int columnNum)

Add a column to the existing Ordering list.

pack-priv int
private void
addNewArrayOfRows(int
The size of the array.
numResultSets
)

Generate the assignment for row = new ExecRow[numResultSets]

private void
pack-priv void
finishConstructor()

Finish the constructor by newing the array of Rows and putting a return at the end of it.

pack-priv void
generateDataValue(MethodBuilder mb, TypeCompiler tc, int collationType, LocalField field)

Generate a data value.

pack-priv void
generateNull(MethodBuilder mb, TypeCompiler tc, int collationType)

Generate a Null data value.

pack-priv void
generateNullWithExpress(MethodBuilder mb, TypeCompiler tc, int collationType)

Generate a Null data value.

pack-priv abstract String
getBaseClassName()

Return the base class of the activation's hierarchy (the subclass of Object).

pack-priv ClassBuilder
pack-priv FormatableArrayHolder
getColumnOrdering(ResultColumnList rclist)

These utility methods buffers compilation from the IndexColumnOrder class.

pack-priv FormatableArrayHolder
pack-priv MethodBuilder
pack-priv void
getCurrentDateExpression(MethodBuilder mb)

This utility method returns an expression for CURRENT_DATE.

protected LocalField
pack-priv void
getCurrentTimeExpression(MethodBuilder mb)

This utility method returns an expression for CURRENT_TIME.

pack-priv void
getCurrentTimestampExpression(MethodBuilder mb)

This utility method generates an expression for CURRENT_TIMESTAMP.

pack-priv MethodBuilder
getExecuteMethod()

Get a method builder for adding code to the execute() method.

pack-priv GeneratedClass
getGeneratedClass(ByteArray
place to save generated bytes. if null, it is ignored
savedBytes
)

Take the generated class, and turn it into an actual class.

pack-priv abstract String

Returns:

name of package that the generated class will live in.
getPackageName
()

Get the name of the package that the generated class will live in.

pack-priv abstract int

Returns:

number of ExecRows that must be allocated
getRowCount
()

Get the number of ExecRows that must be allocated

pack-priv String
protected TypeCompiler

Returns:

The corresponding TypeCompiler
getTypeCompiler
(TypeId
The TypeId to get a TypeCompiler for
typeId
)

Get the TypeCompiler associated with the given TypeId

pack-priv MethodBuilder
newExprFun()

"ExprFun"s are the "expression functions" that are specific to a given JSQL statement.

pack-priv LocalField

Returns:

None.
newFieldDeclaration
(int
The | of the modifier values such as public, static, etc.
modifiers
,
String
The type of the field in java language.
type
,
String
The name of the field.
name
)

Add a field declaration to the generated class

pack-priv LocalField

Returns:

The name of the new field
newFieldDeclaration
(int
The | of the modifier values such as public, static, etc.
modifiers
,
String
The type of the field in java language.
type
)

Add an arbitrarily named field to the generated class.

private String
newFieldName()

generated the next field name available.

pack-priv MethodBuilder
newGeneratedFun(String
the return type of the function
returnType
,
int
the modifiers on the function
modifiers
)

Activations might have need of internal functions that are not used by the result sets, but by other activation functions.

pack-priv MethodBuilder
newGeneratedFun(String returnType, int modifiers, String[] params)

private MethodBuilder
newGeneratedFun(String exprName, String returnType, int modifiers, String[] params)

pack-priv String
newRowLocationScanResultSetName()

generates a variable name for the rowscanresultset.

pack-priv MethodBuilder

Returns:

A new MethodBuilder
newUserExprFun
()

Start a user expression.

pack-priv void
pushColumnReference(MethodBuilder mb, int
the result set number
rsNumber
,
int
the column number
colId
)

Generate a reference to a colunm in a result set.

pack-priv void
pack-priv void
pack-priv void
pack-priv void
pushMethodReference(MethodBuilder mb, MethodBuilder exprMethod)

Push an expression that is a GeneratedMethod reference to the passed in method.

pack-priv void
pushPVSReference(MethodBuilder mb)

Generate a reference to the parameter value set that all activations use.

pack-priv void
pushThisAsActivation(MethodBuilder mb)

Get a "this" expression declared as an Activation.

pack-priv abstract void
setNumSubqueries()

Sets the number of subqueries under this expression

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cbback to summary
protected ClassBuilder cb
cdtFieldback to summary
protected LocalField cdtField
constructorback to summary
protected MethodBuilder constructor
currentDatetimeFieldNameback to summary
protected static final String currentDatetimeFieldName
currentRowScanResultSetNameback to summary
private String currentRowScanResultSetName
executeMethodback to summary
pack-priv MethodBuilder executeMethod
gcback to summary
protected GeneratedClass gc
getDVFback to summary
private Object getDVF

Get/reuse the Expression for getting the DataValueFactory

getEFback to summary
private Object getEF

This is a utility method to get a common expression -- "BaseActivation.getExecutionFactory()".

Revisit

could the same expression objects be reused within the tree and have the correct java generated each time?

BaseActivation gets the factory from the context and caches it for faster retrieval.

getRSFback to summary
private Object getRSF

This is a utility method to get a common expression -- "BaseActivation.getResultSetFactory()".

BaseActivation gets the factory from the context and caches it for faster retrieval.

myCompCtxback to summary
pack-priv CompilerContext myCompCtx
nextExprNumback to summary
protected int nextExprNum
nextFieldNumback to summary
protected int nextFieldNum
nextNonFastExprback to summary
protected int nextNonFastExpr

Constructor Detail

ExpressionClassBuilderback to summary
pack-priv ExpressionClassBuilder(String superClass, String className, CompilerContext cc) throws StandardException

By the time this is done, it has constructed the following class:

   final public class #className extends #superClass {
     public #className() { super(); }
   }
Exceptions
StandardException:
thrown on failure

Method Detail

addColumnToOrderingback to summary
pack-priv FormatableArrayHolder addColumnToOrdering(FormatableArrayHolder orderingHolder, int columnNum)

Add a column to the existing Ordering list. Takes a column id and only adds it if it isn't in the list.

Returns:FormatableArrayHolder

the ColumnOrdering array

addItemback to summary
pack-priv int addItem(Object o)
addNewArrayOfRowsback to summary
private void addNewArrayOfRows(int numResultSets)

Generate the assignment for row = new ExecRow[numResultSets]

Parameters
numResultSets:int

The size of the array.

beginConstructorback to summary
private void beginConstructor()
finishConstructorback to summary
pack-priv void finishConstructor() throws StandardException

Finish the constructor by newing the array of Rows and putting a return at the end of it.

Exceptions
StandardException:
thrown on failure
generateDataValueback to summary
pack-priv void generateDataValue(MethodBuilder mb, TypeCompiler tc, int collationType, LocalField field)

Generate a data value. The value is to be set in the SQL data value is required on the stack and will be popped, a SQL data value is pushed.

generateNullback to summary
pack-priv void generateNull(MethodBuilder mb, TypeCompiler tc, int collationType)

Generate a Null data value. Nothing is required on the stack, a SQL null data value is pushed.

generateNullWithExpressback to summary
pack-priv void generateNullWithExpress(MethodBuilder mb, TypeCompiler tc, int collationType)

Generate a Null data value. The express value is required on the stack and will be popped, a SQL null data value is pushed.

getBaseClassNameback to summary
pack-priv abstract String getBaseClassName()

Return the base class of the activation's hierarchy (the subclass of Object). This class is expected to hold methods used by all compilation code, such as datatype compilation code, e.g. getDataValueFactory.

getClassBuilderback to summary
pack-priv ClassBuilder getClassBuilder()
getColumnOrderingback to summary
pack-priv FormatableArrayHolder getColumnOrdering(ResultColumnList rclist)

These utility methods buffers compilation from the IndexColumnOrder class. They create an ordering based on their parameter, stuff that into the prepared statement, and then return the entry # for use in the generated code. We could write another utility method to generate code to turn an entry # back into an object, but so far no-one needs it.

Warning

this is a crafty method that ASSUMES that you want every column in the list ordered, and that every column in the list is the entire actual result colunm. It is only useful for DISTINCT in select.

getColumnOrderingback to summary
pack-priv FormatableArrayHolder getColumnOrdering(OrderedColumnList<?> oclist)
getConstructorback to summary
pack-priv MethodBuilder getConstructor()
getCurrentDateExpressionback to summary
pack-priv void getCurrentDateExpression(MethodBuilder mb)

This utility method returns an expression for CURRENT_DATE. Get the expression this way, because the activation needs to generate support information for CURRENT_DATE, that would otherwise be painful to create manually.

getCurrentSetupback to summary
protected LocalField getCurrentSetup()
getCurrentTimeExpressionback to summary
pack-priv void getCurrentTimeExpression(MethodBuilder mb)

This utility method returns an expression for CURRENT_TIME. Get the expression this way, because the activation needs to generate support information for CURRENT_TIME, that would otherwise be painful to create manually.

getCurrentTimestampExpressionback to summary
pack-priv void getCurrentTimestampExpression(MethodBuilder mb)

This utility method generates an expression for CURRENT_TIMESTAMP. Get the expression this way, because the activation needs to generate support information for CURRENT_TIMESTAMP, that would otherwise be painful to create manually.

getExecuteMethodback to summary
pack-priv MethodBuilder getExecuteMethod()

Get a method builder for adding code to the execute() method. The method builder does not actually build a method called execute. Instead, it creates a method that overrides the reinit() method, which is called from execute() on every execution in order to reinitialize the data structures.

getGeneratedClassback to summary
pack-priv GeneratedClass getGeneratedClass(ByteArray savedBytes) throws StandardException

Take the generated class, and turn it into an actual class.

This method assumes, does not check, that the class and its parts are all complete.

Parameters
savedBytes:ByteArray

place to save generated bytes. if null, it is ignored

Exceptions
StandardException:
thrown when exception occurs
getPackageNameback to summary
pack-priv abstract String getPackageName()

Get the name of the package that the generated class will live in.

Returns:String

name of package that the generated class will live in.

getRowCountback to summary
pack-priv abstract int getRowCount() throws StandardException

Get the number of ExecRows that must be allocated

Returns:int

number of ExecRows that must be allocated

Exceptions
StandardException:
thrown on failure
getRowLocationScanResultSetNameback to summary
pack-priv String getRowLocationScanResultSetName()
getTypeCompilerback to summary
protected TypeCompiler getTypeCompiler(TypeId typeId)

Get the TypeCompiler associated with the given TypeId

Parameters
typeId:TypeId

The TypeId to get a TypeCompiler for

Returns:TypeCompiler

The corresponding TypeCompiler

newExprFunback to summary
pack-priv MethodBuilder newExprFun()

"ExprFun"s are the "expression functions" that are specific to a given JSQL statement. For example, an ExprFun is generated to evaluate the where clause of a select statement and return a boolean result.

All methods return by this are expected to be called via the GeneratedMethod interface. Thus the methods are public and return java.lang.Object.

Once the exprfun has been created, the caller will need to add statements to it, minimally a return statement.

ExprFuns return Object types, since they are invoked through reflection and thus their return type would get wrapped in an object anyway. For example: return java.lang.Boolean, not boolean.

newFieldDeclarationback to summary
pack-priv LocalField newFieldDeclaration(int modifiers, String type, String name)

Add a field declaration to the generated class

Parameters
modifiers:int

The | of the modifier values such as public, static, etc.

type:String

The type of the field in java language.

name:String

The name of the field.

Returns:LocalField

None.

newFieldDeclarationback to summary
pack-priv LocalField newFieldDeclaration(int modifiers, String type)

Add an arbitrarily named field to the generated class. This is used to generate fields where the caller doesn't care what the field is named. It is especially useful for generating arbitrary numbers of fields, where the caller doesn't know in advance how many fields will be used. For example, it is used for generating fields to hold intermediate values from expressions.

Parameters
modifiers:int

The | of the modifier values such as public, static, etc.

type:String

The type of the field in java language.

Returns:LocalField

The name of the new field

newFieldNameback to summary
private String newFieldName()

generated the next field name available. these are of the form 'e#', where # is incremented each time. This shares the name space with the expression methods as Java allows names and fields to have the same name. This reduces the number of constant pool entries created for a generated class file.

newGeneratedFunback to summary
pack-priv MethodBuilder newGeneratedFun(String returnType, int modifiers)

Activations might have need of internal functions that are not used by the result sets, but by other activation functions. Thus, we make it possible for functions to be generated directly as well as through the newExprFun interface. newExprFun should be used when a static field pointing to the expression function is needed.

The generated function will generally have a generated name that can be viewed through the MethodBuilder interface. This name is generated to ensure uniqueness from other function names in the activation class. If you pass in a function name, think carefully about whether it will collide with other names.

Parameters
returnType:String

the return type of the function

modifiers:int

the modifiers on the function

See Also
newExprFun
newGeneratedFunback to summary
pack-priv MethodBuilder newGeneratedFun(String returnType, int modifiers, String[] params)
newGeneratedFunback to summary
private MethodBuilder newGeneratedFun(String exprName, String returnType, int modifiers, String[] params)
newRowLocationScanResultSetNameback to summary
pack-priv String newRowLocationScanResultSetName()

generates a variable name for the rowscanresultset. This can not be a fixed name because in cases like cascade delete same activation class will be dealing more than one RowScanResultSets for dependent tables.

newUserExprFunback to summary
pack-priv MethodBuilder newUserExprFun()

Start a user expression. The difference between a normal expression (returned by newExprFun) and a user expression is that a user expression catches all exceptions (because we don't want random exceptions thrown from user methods to propagate to the rest of the system.

Returns:MethodBuilder

A new MethodBuilder

pushColumnReferenceback to summary
pack-priv void pushColumnReference(MethodBuilder mb, int rsNumber, int colId)

Generate a reference to a colunm in a result set.

Parameters
rsNumber:int

the result set number

colId:int

the column number

pushDataValueFactoryback to summary
pack-priv void pushDataValueFactory(MethodBuilder mb)
pushGetExecutionFactoryExpressionback to summary
pack-priv void pushGetExecutionFactoryExpression(MethodBuilder mb)
pushGetResultSetFactoryExpressionback to summary
pack-priv void pushGetResultSetFactoryExpression(MethodBuilder mb)
pushMethodReferenceback to summary
pack-priv void pushMethodReference(MethodBuilder mb, MethodBuilder exprMethod)

Push an expression that is a GeneratedMethod reference to the passed in method. aka. a "function pointer".

pushPVSReferenceback to summary
pack-priv void pushPVSReference(MethodBuilder mb)

Generate a reference to the parameter value set that all activations use.

pushThisAsActivationback to summary
pack-priv void pushThisAsActivation(MethodBuilder mb)

Get a "this" expression declared as an Activation. This is the commonly used type of the this expression.

setNumSubqueriesback to summary
pack-priv abstract void setNumSubqueries() throws StandardException

Sets the number of subqueries under this expression

Exceptions
StandardException:
thrown on failure