Skip to content

Commit

Permalink
TEIID-4235 appropriately managing the recursion stack
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 1, 2016
1 parent 6159ec4 commit 8ef2b3f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Expand Up @@ -213,8 +213,17 @@ public void process(ProcedurePlan procEnv) throws BlockedException,
public void process(ProcedurePlan procEnv)
throws BlockedException, TeiidComponentException,
TeiidProcessingException {
super.process(procEnv);
procEnv.getContext().popCall();
boolean done = true;
try {
super.process(procEnv);
} catch (BlockedException e) {
done = false;
throw e;
} finally {
if (done) {
procEnv.getContext().popCall();
}
}
}
};

Expand Down Expand Up @@ -251,6 +260,16 @@ public void process(ProcedurePlan procEnv)
ts.closeSource();
}
}

// do a recursion check
// Add group to recursion stack
if (parentProcCommand.getUpdateType() != Command.TYPE_UNKNOWN) {
procEnv.getContext().pushCall(Command.getCommandToken(parentProcCommand.getUpdateType()) + " " + parentProcCommand.getVirtualGroup()); //$NON-NLS-1$
} else {
if (parentProcCommand.getVirtualGroup() != null) {
procEnv.getContext().pushCall(parentProcCommand.getVirtualGroup().toString());
}
}

procEnv.push(dynamicProgram);
} catch (TeiidProcessingException e) {
Expand Down Expand Up @@ -358,16 +377,6 @@ private void validateDynamicCommand(ProcedurePlan procEnv,
if (procEnv.isValidateAccess() && !context.getDQPWorkContext().isAdmin() && context.getAuthorizationValidator() != null) {
context.getAuthorizationValidator().validate(new String[] {commandString}, command, metadata, context, CommandType.USER);
}

// do a recursion check
// Add group to recursion stack
if (parentProcCommand.getUpdateType() != Command.TYPE_UNKNOWN) {
context.pushCall(Command.getCommandToken(parentProcCommand.getUpdateType()) + " " + parentProcCommand.getVirtualGroup()); //$NON-NLS-1$
} else {
if (parentProcCommand.getVirtualGroup() != null) {
context.pushCall(parentProcCommand.getVirtualGroup().toString());
}
}
}

/**
Expand Down
Expand Up @@ -259,5 +259,24 @@ public class TestProcErrors {

helpTestProcess(plan, new List[] {Arrays.asList(2)}, dataManager, tm);
}

@Test public void testExceptionHandlingDynamicError() throws Exception {
String ddl =
"create virtual procedure vproc (x integer) returns integer as begin " +
"execute immediate 'select x/0';" +
"exception e " +
"execute immediate 'select x' as x integer into #temp; " +
"\"return\" = (select x from #temp);"+
"end;";
TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);

String sql = "call vproc(1)"; //$NON-NLS-1$

ProcessorPlan plan = getProcedurePlan(sql, tm);

HardcodedDataManager dataManager = new HardcodedDataManager(tm);

helpTestProcess(plan, new List[] {Arrays.asList(1)}, dataManager, tm);
}

}

0 comments on commit 8ef2b3f

Please sign in to comment.