public StatementAgentInstanceFactoryOnTriggerResult newContext(final AgentInstanceContext agentInstanceContext, boolean isRecoveringResilient)
{
final List<StopCallback> stopCallbacks = new ArrayList<StopCallback>();
View onExprView;
Map<ExprSubselectNode, SubSelectStrategyHolder> subselectStrategies;
AggregationService aggregationService = null;
EvalRootState optPatternRoot;
try {
if (services.getSchedulableAgentInstanceDirectory() != null) {
services.getSchedulableAgentInstanceDirectory().add(agentInstanceContext.getEpStatementAgentInstanceHandle());
}
OnTriggerDesc onTriggerDesc = statementSpec.getOnTriggerDesc();
// Start: for on-delete and on-select and on-update triggers
if (onTriggerDesc instanceof OnTriggerWindowDesc)
{
OnTriggerWindowDesc onTriggerWindowDesc = (OnTriggerWindowDesc) onTriggerDesc;
// get result set processor and aggregation services
Pair<ResultSetProcessor, AggregationService> pair = EPStatementStartMethodHelperUtil.startResultSetAndAggregation(resultSetProcessorPrototype, agentInstanceContext);
aggregationService = pair.getSecond();
// get named window processor instance
NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(onTriggerWindowDesc.getWindowName());
NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceContext);
// obtain on-expr view
NamedWindowOnExprBaseView onExprBaseView = processorInstance.getRootViewInstance().addOnExpr(onExprFactory, agentInstanceContext, validatedJoin, activatorResultEventType, pair.getFirst(), onTriggerWindowDesc.getOptionalAsName(), excludePlanHint, indexHint);
onExprView = onExprBaseView;
stopCallbacks.add(onExprBaseView);
}
// variable assignments
else if (statementSpec.getOnTriggerDesc() instanceof OnTriggerSetDesc)
{
onExprView = onSetVariableViewFactory.instantiate(agentInstanceContext);
}
// split-stream use case
else
{
ResultSetProcessor[] processors = new ResultSetProcessor[splitDesc.getProcessorFactories().length];
for (int i = 0; i < processors.length; i++) {
ResultSetProcessorFactoryDesc factory = splitDesc.getProcessorFactories()[i];
ResultSetProcessor processor = factory.getResultSetProcessorFactory().instantiate(null, null, agentInstanceContext);
processors[i] = processor;
}
OnTriggerSplitStreamDesc desc = (OnTriggerSplitStreamDesc) statementSpec.getOnTriggerDesc();
onExprView = new RouteResultView(desc.isFirst(), activatorResultEventType, statementContext.getEpStatementHandle(), services.getInternalEventRouter(), splitDesc.getNamedWindowInsert(), processors, splitDesc.getWhereClauses(), agentInstanceContext);
}
// attach stream to view
final ViewableActivationResult activationResult = activator.activate(agentInstanceContext, false, isRecoveringResilient);
activationResult.getViewable().addView(onExprView);
stopCallbacks.add(activationResult.getStopCallback());
optPatternRoot = activationResult.getOptionalPatternRoot();
// start subselects
subselectStrategies = EPStatementStartMethodHelperSubselect.startSubselects(services, subSelectStrategyCollection, agentInstanceContext, stopCallbacks);
// attach view to output: for on-delete, create an output processor that passes on as a wildcard the underlying event
if ((statementSpec.getOnTriggerDesc().getOnTriggerType() == OnTriggerType.ON_DELETE) ||
(statementSpec.getOnTriggerDesc().getOnTriggerType() == OnTriggerType.ON_SET) ||
(statementSpec.getOnTriggerDesc().getOnTriggerType() == OnTriggerType.ON_UPDATE) ||
(statementSpec.getOnTriggerDesc().getOnTriggerType() == OnTriggerType.ON_MERGE))
{
ResultSetProcessor outputResultSetProcessor = outputResultSetProcessorPrototype.getResultSetProcessorFactory().instantiate(null, null, agentInstanceContext);
// Attach output view
View outputView = outputProcessViewFactory.makeView(outputResultSetProcessor, agentInstanceContext);
onExprView.addView(outputView);
onExprView = outputView;
}
}
catch (RuntimeException ex) {