use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.
the class CursorNode method generate.
/**
* Do code generation for this CursorNode
*
* @param acb The ActivationClassBuilder for the class being built
* @param mb The method the generated code is to go into
*
* @exception StandardException Thrown on error
*/
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
if (// if this cursor references session schema tables, do following
indexOfSessionTableNamesInSavedObjects != -1) {
MethodBuilder constructor = acb.getConstructor();
constructor.pushThis();
constructor.push(indexOfSessionTableNamesInSavedObjects);
constructor.putField(org.apache.derby.shared.common.reference.ClassName.BaseActivation, "indexOfSessionTableNamesInSavedObjects", "int");
constructor.endStatement();
}
// generate the parameters
generateParameterValueSet(acb);
// tell the outermost result set that it is the outer
// result set of the statement.
resultSet.markStatementResultSet();
// this will generate an expression that will be a ResultSet
resultSet.generate(acb, mb);
/*
** Generate the position code if this cursor is updatable. This
** involves generating methods to get the cursor result set, and
** the target result set (which is for the base row). Also,
** generate code to store the cursor result set in a generated
** field.
*/
if (needTarget) {
// PUSHCOMPILE - could be put into a single method
acb.rememberCursor(mb);
acb.addCursorPositionCode();
}
}
use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.
the class DMLModStatementNode method generateGenerationClauses.
/**
* Generate the code to evaluate all of the generation clauses. If there
* are generation clauses, this routine builds an Activation method which
* evaluates the generation clauses and fills in the computed columns.
*
* @param rcl describes the row of expressions to be put into the bas table
* @param resultSetNumber index of base table into array of ResultSets
* @param isUpdate true if this is for an UPDATE statement
* @param ecb code generation state variable
* @param mb the method being generated
*
* @exception StandardException Thrown on error
*/
public void generateGenerationClauses(ResultColumnList rcl, int resultSetNumber, boolean isUpdate, ExpressionClassBuilder ecb, MethodBuilder mb) throws StandardException {
boolean hasGenerationClauses = false;
for (ResultColumn rc : rcl) {
//
if (rc.hasGenerationClause()) {
hasGenerationClauses = true;
break;
}
}
// if there are not generation clauses, we just want to pass null.
if (!hasGenerationClauses) {
mb.pushNull(ClassName.GeneratedMethod);
} else {
MethodBuilder userExprFun = generateGenerationClauses(rcl, resultSetNumber, isUpdate, ecb);
// generation clause evaluation is used in the final result set
// as an access of the new static
// field holding a reference to this new method.
ecb.pushMethodReference(mb, userExprFun);
}
}
use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.
the class DMLModStatementNode method generateCodeForTemporaryTable.
/**
* If the DML is on a temporary table, generate the code to mark temporary table as modified in the current UOW.
* At rollback transaction (or savepoint), we will check if the temporary table was modified in that UOW.
* If yes, we will remove all the data from the temporary table
*
* @param acb The ActivationClassBuilder for the class being built
*
* @exception StandardException Thrown on error
*/
protected void generateCodeForTemporaryTable(ActivationClassBuilder acb) throws StandardException {
if (targetTableDescriptor != null && targetTableDescriptor.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE && targetTableDescriptor.isOnRollbackDeleteRows() == true) {
MethodBuilder mb = acb.getExecuteMethod();
mb.pushThis();
mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.Activation, "getLanguageConnectionContext", ClassName.LanguageConnectionContext, 0);
mb.push(targetTableDescriptor.getName());
mb.callMethod(VMOpcode.INVOKEINTERFACE, null, "markTempTableAsModifiedInUnitOfWork", "void", 1);
mb.endStatement();
}
}
use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.
the class CallStatementNode method generate.
/**
* Code generation for CallStatementNode.
* The generated code will contain:
* o A generated void method for the user's method call.
*
* @param acb The ActivationClassBuilder for the class being built
* @param mb The method for the execute() method to be built
*
* @exception StandardException Thrown on error
*/
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
JavaValueNode methodCallBody;
/* generate the parameters */
generateParameterValueSet(acb);
/*
* Skip over the JavaToSQLValueNode and call generate() for the JavaValueNode.
* (This skips over generated code which is unnecessary since we are throwing
* away any return value and which won't work with void methods.)
* generates:
* <methodCall.generate(acb)>;
* and adds it to userExprFun
*/
methodCallBody = methodCall.getJavaValueNode();
/*
** Tell the method call that its return value (if any) will be
** discarded. This is so it doesn't generate the ?: operator
** that would return null if the receiver is null. This is
** important because the ?: operator cannot be made into a statement.
*/
methodCallBody.markReturnValueDiscarded();
// this sets up the method
// generates:
// void userExprFun {
// method_call(<args>);
// }
//
// An expression function is used to avoid reflection.
// Since the arguments to a procedure are simple, this
// will be the only expression function and so it will
// be executed directly as e0.
MethodBuilder userExprFun = acb.newGeneratedFun("void", Modifier.PUBLIC);
userExprFun.addThrownException("java.lang.Exception");
methodCallBody.generate(acb, userExprFun);
userExprFun.endStatement();
userExprFun.methodReturn();
userExprFun.complete();
acb.pushGetResultSetFactoryExpression(mb);
// first arg
acb.pushMethodReference(mb, userExprFun);
// arg 2
acb.pushThisAsActivation(mb);
mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getCallStatementResultSet", ClassName.ResultSet, 2);
}
use of org.apache.derby.iapi.services.compiler.MethodBuilder in project derby by apache.
the class CastNode method genDataValueConversion.
private void genDataValueConversion(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException {
MethodBuilder acbConstructor = acb.getConstructor();
String resultTypeName = getTypeCompiler().interfaceName();
/* field = method call */
/* Allocate an object for re-use to hold the result of the operator */
LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, resultTypeName);
/*
** Store the result of the method call in the field, so we can re-use
** the object.
*/
acb.generateNull(acbConstructor, getTypeCompiler(getTypeId()), getTypeServices().getCollationType());
acbConstructor.setField(field);
if (!sourceCTI.userType() && !getTypeId().userType()) {
// targetDVD reference for the setValue method call
mb.getField(field);
mb.swap();
mb.upCast(ClassName.DataValueDescriptor);
mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.DataValueDescriptor, "setValue", "void", 1);
} else {
/*
** generate: expr.getObject()
*/
mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.DataValueDescriptor, "getObject", "java.lang.Object", 0);
// castExpr
// instance for the setValue/setObjectForCast method call
mb.getField(field);
// push it before the value
mb.swap();
/*
** We are casting a java type, generate:
**
** DataValueDescriptor.setObjectForCast(java.lang.Object castExpr, boolean instanceOfExpr, destinationClassName)
** where instanceOfExpr is "source instanceof destinationClass".
**
*/
String destinationType = getTypeId().getCorrespondingJavaTypeName();
// at this point method instance and cast result are on the stack
// we duplicate the cast value in order to perform the instanceof check
mb.dup();
mb.isInstanceOf(destinationType);
mb.push(destinationType);
mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.DataValueDescriptor, "setObjectForCast", "void", 3);
}
mb.getField(field);
/*
** If we are casting to a variable length datatype, we
** have to make sure we have set it to the correct
** length.
*/
if (getTypeId().variableLength()) {
boolean isNumber = getTypeId().isNumericTypeId();
// to leave the DataValueDescriptor value on the stack, since setWidth is void
mb.dup();
/* setWidth() is on VSDV - upcast since
* decimal implements subinterface
* of VSDV.
*/
mb.push(isNumber ? getTypeServices().getPrecision() : getTypeServices().getMaximumWidth());
mb.push(getTypeServices().getScale());
mb.push(!sourceCTI.variableLength() || isNumber || assignmentSemantics);
mb.callMethod(VMOpcode.INVOKEINTERFACE, ClassName.VariableSizeDataValue, "setWidth", "void", 3);
}
}
Aggregations