private void HookUpNewRealization( StatementAgentInstanceFactoryResult result, StatementContext statementContext) { View dispatchChildView = statementContext.UpdateDispatchView; if (dispatchChildView != null) { result.FinalView.Child = dispatchChildView; } if (statementContext.ContextName == null) { StatementAIFactoryAssignments assignments = new StatementAIFactoryAssignmentsImpl( result.OptionalAggegationService, result.PriorStrategies, result.PreviousGetterStrategies, result.SubselectStrategies, result.TableAccessStrategies, result.RowRecogPreviousStrategy); statementContext.StatementAIFactoryProvider.Assign(assignments); } }
private static EPStatementSPI DeployStatement( bool recovery, StatementLightweight lightweight, EPRuntimeSPI epRuntime) { // statement-create: safe operation for registering things var statementAgentInstanceFactory = lightweight.StatementContext.StatementAIFactoryProvider.Factory; statementAgentInstanceFactory.StatementCreate(lightweight.StatementContext); // add statement var stmt = MakeStatement( lightweight.StatementContext.UpdateDispatchView, lightweight.StatementContext, (StatementResultServiceImpl)lightweight.StatementResultService, epRuntime); // add statement to globals epRuntime.ServicesContext.StatementLifecycleService.AddStatement(stmt); // it is now available for lookup Viewable finalView; StatementDestroyCallback statementDestroyCallback; ICollection <StatementAgentInstancePreload> preloads = null; var contextName = lightweight.StatementInformationals.OptionalContextName; if (contextName == null) { var result = StartStatementNoContext(lightweight, recovery, epRuntime.ServicesContext); finalView = result.FinalView; preloads = result.PreloadList; var createContextStmt = result is StatementAgentInstanceFactoryCreateContextResult; statementDestroyCallback = new ProxyStatementDestroyCallback() { ProcDestroy = ( destroyServices, statementContext) => { // All statements other that create-context: get the agent-instance-context and stop // Create-context statements already got destroyed when the last statement associated to context was removed. if (!createContextStmt) { var holder = statementContext.StatementCPCacheService.MakeOrGetEntryCanNull(-1, statementContext); holder.AgentInstanceStopCallback.Stop(new AgentInstanceStopServices(holder.AgentInstanceContext)); } // Invoke statement-destroy statementAgentInstanceFactory.StatementDestroy(lightweight.StatementContext); }, }; // assign StatementAIFactoryAssignments assignments = new StatementAIFactoryAssignmentsImpl( result.OptionalAggegationService, result.PriorStrategies, result.PreviousGetterStrategies, result.SubselectStrategies, result.TableAccessStrategies, result.RowRecogPreviousStrategy); lightweight.StatementContext.StatementAIFactoryProvider.Assign(assignments); } else { var contextModuleName = lightweight.StatementInformationals.OptionalContextModuleName; var statementAIResourceRegistry = lightweight.StatementContext.StatementAIResourceRegistry; var contextVisibility = lightweight.StatementInformationals.OptionalContextVisibility; var contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId( contextModuleName, contextVisibility, contextName, lightweight.StatementContext.DeploymentId, lightweight.StatementContext.PathContextRegistry); var contextMergeView = lightweight.StatementInformationals.StatementType.IsOnTriggerInfra() ? new ContextMergeViewForwarding(null) : new ContextMergeView(null); finalView = contextMergeView; var statement = new ContextControllerStatementDesc(lightweight, contextMergeView); // assignments before add-statement, since add-statement creates context partitions which may preload lightweight.StatementContext.StatementAIFactoryProvider.Assign(new StatementAIFactoryAssignmentContext(statementAIResourceRegistry)); // add statement epRuntime.ServicesContext.ContextManagementService.AddStatement(contextDeploymentId, contextName, statement, recovery); statementDestroyCallback = new ProxyStatementDestroyCallback() { ProcDestroy = ( destroyServices, statementContext) => { var ctx = statement.Lightweight.StatementContext; epRuntime.ServicesContext.ContextManagementService.StoppedStatement( contextDeploymentId, contextName, ctx.StatementId, ctx.StatementName, ctx.DeploymentId); statementAgentInstanceFactory.StatementDestroy(lightweight.StatementContext); }, }; } // make dispatch view finalView.Child = lightweight.StatementContext.UpdateDispatchView; // assign parent view stmt.StatementContext.DestroyCallback = statementDestroyCallback; stmt.ParentView = finalView; // execute preloads if (preloads != null) { foreach (var preload in preloads) { preload.ExecutePreload(); } } return(stmt); }