Class ExpressionClassBuilder
- All Implemented Interfaces:
ExpressionClassBuilderInterface
- Direct Known Subclasses:
ActivationClassBuilder
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ClassBuilder
protected LocalField
protected MethodBuilder
protected static final String
private String
(package private) MethodBuilder
protected GeneratedClass
private Object
Get/reuse the Expression for getting the DataValueFactoryprivate Object
This is a utility method to get a common expression -- "BaseActivation.getExecutionFactory()".private Object
This is a utility method to get a common expression -- "BaseActivation.getResultSetFactory()".(package private) CompilerContext
protected int
protected int
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionExpressionClassBuilder
(String superClass, String className, CompilerContext cc) By the time this is done, it has constructed the following class: -
Method Summary
Modifier and TypeMethodDescription(package private) FormatableArrayHolder
addColumnToOrdering
(FormatableArrayHolder orderingHolder, int columnNum) Add a column to the existing Ordering list.(package private) int
private void
addNewArrayOfRows
(int numResultSets) Generate the assignment for row = new ExecRow[numResultSets]private void
(package private) void
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 String
Return the base class of the activation's hierarchy (the subclass of Object).(package private) ClassBuilder
(package private) FormatableArrayHolder
getColumnOrdering
(OrderedColumnList<?> oclist) (package private) FormatableArrayHolder
getColumnOrdering
(ResultColumnList rclist) These utility methods buffers compilation from the IndexColumnOrder class.(package private) MethodBuilder
(package private) void
This utility method returns an expression for CURRENT_DATE.protected LocalField
(package private) void
This utility method returns an expression for CURRENT_TIME.(package private) void
This utility method generates an expression for CURRENT_TIMESTAMP.(package private) MethodBuilder
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 String
Get the name of the package that the generated class will live in.(package private) abstract int
Get the number of ExecRows that must be allocated(package private) String
protected TypeCompiler
getTypeCompiler
(TypeId typeId) Get the TypeCompiler associated with the given TypeId(package private) MethodBuilder
"ExprFun"s are the "expression functions" that are specific to a given JSQL statement.(package private) LocalField
newFieldDeclaration
(int modifiers, String type) Add an arbitrarily named field to the generated class.(package private) LocalField
newFieldDeclaration
(int modifiers, String type, String name) Add a field declaration to the generated classprivate String
generated the next field name available.(package private) 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.(package private) MethodBuilder
newGeneratedFun
(String returnType, int modifiers, String[] params) private MethodBuilder
newGeneratedFun
(String exprName, String returnType, int modifiers, String[] params) (package private) String
generates a variable name for the rowscanresultset.(package private) MethodBuilder
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
(package private) void
(package private) void
(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
Generate a reference to the parameter value set that all activations use.(package private) void
Get a "this" expression declared as an Activation.(package private) abstract void
Sets the number of subqueries under this expression
-
Field Details
-
currentDatetimeFieldName
- See Also:
-
cb
-
gc
-
nextExprNum
protected int nextExprNum -
nextNonFastExpr
protected int nextNonFastExpr -
nextFieldNum
protected int nextFieldNum -
constructor
-
myCompCtx
CompilerContext myCompCtx -
executeMethod
MethodBuilder executeMethod -
cdtField
-
currentRowScanResultSetName
-
getDVF
Get/reuse the Expression for getting the DataValueFactory -
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
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 Details
-
ExpressionClassBuilder
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(); } }
- Throws:
StandardException
- thrown on failure
-
-
Method Details
-
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
Get the number of ExecRows that must be allocated- Returns:
- number of ExecRows that must be allocated
- Throws:
StandardException
- thrown on failure
-
setNumSubqueries
Sets the number of subqueries under this expression- Throws:
StandardException
- thrown on failure
-
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
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
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
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
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:
-
newGeneratedFun
-
newGeneratedFun
private MethodBuilder newGeneratedFun(String exprName, String returnType, int modifiers, 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
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
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
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
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
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
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
-
addItem
-
pushDataValueFactory
-
pushGetResultSetFactoryExpression
-
pushGetExecutionFactoryExpression
-
pushColumnReference
Generate a reference to a colunm in a result set.- Parameters:
rsNumber
- the result set numbercolId
- the column number
-
pushPVSReference
Generate a reference to the parameter value set that all activations use. -
getCurrentSetup
-
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
Get the TypeCompiler associated with the given TypeId- Parameters:
typeId
- The TypeId to get a TypeCompiler for- Returns:
- The corresponding TypeCompiler
-
getGeneratedClass
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
Get a "this" expression declared as an Activation. This is the commonly used type of the this expression. -
generateNull
Generate a Null data value. Nothing is required on the stack, a SQL null data value is pushed. -
generateNullWithExpress
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
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
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
String getRowLocationScanResultSetName()
-