Class ExpressionClassBuilder
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.ExpressionClassBuilder
-
- All Implemented Interfaces:
ExpressionClassBuilderInterface
- Direct Known Subclasses:
ActivationClassBuilder
abstract class ExpressionClassBuilder extends java.lang.Object implements ExpressionClassBuilderInterface
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
Fields Modifier and Type Field Description protected ClassBuilder
cb
protected LocalField
cdtField
protected MethodBuilder
constructor
protected static java.lang.String
currentDatetimeFieldName
private java.lang.String
currentRowScanResultSetName
(package private) MethodBuilder
executeMethod
protected GeneratedClass
gc
private java.lang.Object
getDVF
Get/reuse the Expression for getting the DataValueFactoryprivate java.lang.Object
getEF
This is a utility method to get a common expression -- "BaseActivation.getExecutionFactory()".private java.lang.Object
getRSF
This is a utility method to get a common expression -- "BaseActivation.getResultSetFactory()".(package private) CompilerContext
myCompCtx
protected int
nextExprNum
protected int
nextFieldNum
protected int
nextNonFastExpr
-
Constructor Summary
Constructors Constructor Description ExpressionClassBuilder(java.lang.String superClass, java.lang.String className, CompilerContext cc)
By the time this is done, it has constructed the following class:
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) FormatableArrayHolder
addColumnToOrdering(FormatableArrayHolder orderingHolder, int columnNum)
Add a column to the existing Ordering list.(package private) int
addItem(java.lang.Object o)
private void
addNewArrayOfRows(int numResultSets)
Generate the assignment for row = new ExecRow[numResultSets]private void
beginConstructor()
(package private) void
finishConstructor()
Finish the constructor by newing the array of Rows and putting a return at the end of it.(package private) void
generateDataValue(MethodBuilder mb, TypeCompiler tc, int collationType, LocalField field)
Generate a data value.(package private) void
generateNull(MethodBuilder mb, TypeCompiler tc, int collationType)
Generate a Null data value.(package private) void
generateNullWithExpress(MethodBuilder mb, TypeCompiler tc, int collationType)
Generate a Null data value.(package private) abstract java.lang.String
getBaseClassName()
Return the base class of the activation's hierarchy (the subclass of Object).(package private) ClassBuilder
getClassBuilder()
(package private) FormatableArrayHolder
getColumnOrdering(OrderedColumnList<?> oclist)
(package private) FormatableArrayHolder
getColumnOrdering(ResultColumnList rclist)
These utility methods buffers compilation from the IndexColumnOrder class.(package private) MethodBuilder
getConstructor()
(package private) void
getCurrentDateExpression(MethodBuilder mb)
This utility method returns an expression for CURRENT_DATE.protected LocalField
getCurrentSetup()
(package private) void
getCurrentTimeExpression(MethodBuilder mb)
This utility method returns an expression for CURRENT_TIME.(package private) void
getCurrentTimestampExpression(MethodBuilder mb)
This utility method generates an expression for CURRENT_TIMESTAMP.(package private) MethodBuilder
getExecuteMethod()
Get a method builder for adding code to the execute() method.(package private) GeneratedClass
getGeneratedClass(ByteArray savedBytes)
Take the generated class, and turn it into an actual class.(package private) abstract java.lang.String
getPackageName()
Get the name of the package that the generated class will live in.(package private) abstract int
getRowCount()
Get the number of ExecRows that must be allocated(package private) java.lang.String
getRowLocationScanResultSetName()
protected TypeCompiler
getTypeCompiler(TypeId typeId)
Get the TypeCompiler associated with the given TypeId(package private) MethodBuilder
newExprFun()
"ExprFun"s are the "expression functions" that are specific to a given JSQL statement.(package private) LocalField
newFieldDeclaration(int modifiers, java.lang.String type)
Add an arbitrarily named field to the generated class.(package private) LocalField
newFieldDeclaration(int modifiers, java.lang.String type, java.lang.String name)
Add a field declaration to the generated classprivate java.lang.String
newFieldName()
generated the next field name available.(package private) MethodBuilder
newGeneratedFun(java.lang.String returnType, int modifiers)
Activations might have need of internal functions that are not used by the result sets, but by other activation functions.(package private) MethodBuilder
newGeneratedFun(java.lang.String returnType, int modifiers, java.lang.String[] params)
private MethodBuilder
newGeneratedFun(java.lang.String exprName, java.lang.String returnType, int modifiers, java.lang.String[] params)
(package private) java.lang.String
newRowLocationScanResultSetName()
generates a variable name for the rowscanresultset.(package private) MethodBuilder
newUserExprFun()
Start a user expression.(package private) void
pushColumnReference(MethodBuilder mb, int rsNumber, int colId)
Generate a reference to a colunm in a result set.(package private) void
pushDataValueFactory(MethodBuilder mb)
(package private) void
pushGetExecutionFactoryExpression(MethodBuilder mb)
(package private) void
pushGetResultSetFactoryExpression(MethodBuilder mb)
(package private) void
pushMethodReference(MethodBuilder mb, MethodBuilder exprMethod)
Push an expression that is a GeneratedMethod reference to the passed in method. aka. a "function pointer".(package private) void
pushPVSReference(MethodBuilder mb)
Generate a reference to the parameter value set that all activations use.(package private) void
pushThisAsActivation(MethodBuilder mb)
Get a "this" expression declared as an Activation.(package private) abstract void
setNumSubqueries()
Sets the number of subqueries under this expression
-
-
-
Field Detail
-
currentDatetimeFieldName
protected static final java.lang.String currentDatetimeFieldName
- See Also:
- Constant Field Values
-
cb
protected ClassBuilder cb
-
gc
protected GeneratedClass gc
-
nextExprNum
protected int nextExprNum
-
nextNonFastExpr
protected int nextNonFastExpr
-
nextFieldNum
protected int nextFieldNum
-
constructor
protected MethodBuilder constructor
-
myCompCtx
CompilerContext myCompCtx
-
executeMethod
MethodBuilder executeMethod
-
cdtField
protected LocalField cdtField
-
currentRowScanResultSetName
private java.lang.String currentRowScanResultSetName
-
getDVF
private java.lang.Object getDVF
Get/reuse the Expression for getting the DataValueFactory
-
getRSF
private java.lang.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.
-
getEF
private java.lang.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.
-
-
Constructor Detail
-
ExpressionClassBuilder
ExpressionClassBuilder(java.lang.String superClass, java.lang.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(); } }
- Throws:
StandardException
- thrown on failure
-
-
Method Detail
-
getPackageName
abstract java.lang.String getPackageName()
Get the name of the package that the generated class will live in.- Returns:
- name of package that the generated class will live in.
-
getRowCount
abstract int getRowCount() throws StandardException
Get the number of ExecRows that must be allocated- Returns:
- number of ExecRows that must be allocated
- Throws:
StandardException
- thrown on failure
-
setNumSubqueries
abstract void setNumSubqueries() throws StandardException
Sets the number of subqueries under this expression- Throws:
StandardException
- thrown on failure
-
getBaseClassName
abstract java.lang.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.
-
getConstructor
MethodBuilder getConstructor()
-
getClassBuilder
ClassBuilder getClassBuilder()
-
getExecuteMethod
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.
-
beginConstructor
private void beginConstructor()
-
finishConstructor
void finishConstructor() throws StandardException
Finish the constructor by newing the array of Rows and putting a return at the end of it.- Throws:
StandardException
- thrown on failure
-
addNewArrayOfRows
private void addNewArrayOfRows(int numResultSets)
Generate the assignment for row = new ExecRow[numResultSets]- Parameters:
numResultSets
- The size of the array.
-
newFieldDeclaration
LocalField newFieldDeclaration(int modifiers, java.lang.String type, java.lang.String name)
Add a field declaration to the generated class- Parameters:
modifiers
- The | of the modifier values such as public, static, etc.type
- The type of the field in java language.name
- The name of the field.- Returns:
- None.
-
newFieldDeclaration
LocalField newFieldDeclaration(int modifiers, java.lang.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
- The | of the modifier values such as public, static, etc.type
- The type of the field in java language.- Returns:
- The name of the new field
-
newGeneratedFun
MethodBuilder newGeneratedFun(java.lang.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
- the return type of the functionmodifiers
- the modifiers on the function- See Also:
newExprFun()
-
newGeneratedFun
MethodBuilder newGeneratedFun(java.lang.String returnType, int modifiers, java.lang.String[] params)
-
newGeneratedFun
private MethodBuilder newGeneratedFun(java.lang.String exprName, java.lang.String returnType, int modifiers, java.lang.String[] params)
-
newExprFun
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.
-
pushMethodReference
void pushMethodReference(MethodBuilder mb, MethodBuilder exprMethod)
Push an expression that is a GeneratedMethod reference to the passed in method. aka. a "function pointer".
-
newUserExprFun
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:
- A new MethodBuilder
-
getCurrentDateExpression
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.
-
getCurrentTimeExpression
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.
-
getCurrentTimestampExpression
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.
-
getColumnOrdering
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.
-
addColumnToOrdering
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:
- the ColumnOrdering array
-
getColumnOrdering
FormatableArrayHolder getColumnOrdering(OrderedColumnList<?> oclist)
-
addItem
int addItem(java.lang.Object o)
-
pushDataValueFactory
void pushDataValueFactory(MethodBuilder mb)
-
pushGetResultSetFactoryExpression
void pushGetResultSetFactoryExpression(MethodBuilder mb)
-
pushGetExecutionFactoryExpression
void pushGetExecutionFactoryExpression(MethodBuilder mb)
-
pushColumnReference
void pushColumnReference(MethodBuilder mb, int rsNumber, int colId)
Generate a reference to a colunm in a result set.- Parameters:
rsNumber
- the result set numbercolId
- the column number
-
pushPVSReference
void pushPVSReference(MethodBuilder mb)
Generate a reference to the parameter value set that all activations use.
-
getCurrentSetup
protected LocalField getCurrentSetup()
-
newFieldName
private java.lang.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.
-
getTypeCompiler
protected TypeCompiler getTypeCompiler(TypeId typeId)
Get the TypeCompiler associated with the given TypeId- Parameters:
typeId
- The TypeId to get a TypeCompiler for- Returns:
- The corresponding TypeCompiler
-
getGeneratedClass
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
- place to save generated bytes. if null, it is ignored- Throws:
StandardException
- thrown when exception occurs
-
pushThisAsActivation
void pushThisAsActivation(MethodBuilder mb)
Get a "this" expression declared as an Activation. This is the commonly used type of the this expression.
-
generateNull
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.
-
generateNullWithExpress
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.
-
generateDataValue
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.
-
newRowLocationScanResultSetName
java.lang.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.
-
getRowLocationScanResultSetName
java.lang.String getRowLocationScanResultSetName()
-
-