public override EventBean[] ProcessInsert(EPPreparedExecuteIUDSingleStreamExecInsert insert)
        {
            EPPreparedExecuteTableHelper.AssignTableAccessStrategies(insert.Services, insert.OptionalTableNodes, _processorInstance.TailViewInstance.AgentInstanceContext);
            try {
                var @event   = insert.InsertHelper.Process(new EventBean[0], true, true, insert.ExprEvaluatorContext);
                var inserted = new EventBean[] { @event };

                var ctx    = _processorInstance.TailViewInstance.AgentInstanceContext;
                var ailock = ctx.AgentInstanceLock;
                using (ailock.AcquireWriteLock())
                {
                    try
                    {
                        _processorInstance.RootViewInstance.Update(inserted, null);
                    }
                    catch (EPException)
                    {
                        _processorInstance.RootViewInstance.Update(null, inserted);
                    }
                }

                return(inserted);
            }
            finally {
                insert.Services.TableService.TableExprEvaluatorContext.ReleaseAcquiredLocks();
            }
        }
        private ICollection <EventBean> GetStreamFilterSnapshot(int streamNum, ContextPartitionSelector contextPartitionSelector)
        {
            var streamSpec = _statementSpec.StreamSpecs[streamNum];
            IList <ExprNode> filterExpressions = Collections.GetEmptyList <ExprNode>();

            if (streamSpec is NamedWindowConsumerStreamSpec)
            {
                var namedSpec = (NamedWindowConsumerStreamSpec)streamSpec;
                filterExpressions = namedSpec.FilterExpressions;
            }
            else
            {
                var tableSpec = (TableQueryStreamSpec)streamSpec;
                filterExpressions = tableSpec.FilterExpressions;
            }

            var fireAndForgetProcessor = _processors[streamNum];

            // handle the case of a single or matching agent instance
            var processorInstance = fireAndForgetProcessor.GetProcessorInstance(_agentInstanceContext);

            if (processorInstance != null)
            {
                EPPreparedExecuteTableHelper.AssignTableAccessStrategies(_services, _statementSpec.TableNodes, _agentInstanceContext);
                return(GetStreamSnapshotInstance(streamNum, filterExpressions, processorInstance));
            }

            // context partition runtime query
            var contextPartitions = EPPreparedExecuteMethodHelper.GetAgentInstanceIds(fireAndForgetProcessor, contextPartitionSelector, _services.ContextManagementService, fireAndForgetProcessor.ContextName);

            // collect events
            var events = new ArrayDeque <EventBean>();

            foreach (int agentInstanceId in contextPartitions)
            {
                processorInstance = fireAndForgetProcessor.GetProcessorInstanceContextById(agentInstanceId);
                if (processorInstance != null)
                {
                    var coll = processorInstance.SnapshotBestEffort(this, _filters[streamNum], _statementSpec.Annotations);
                    events.AddAll(coll);
                }
            }
            return(events);
        }
        /// <summary>
        /// Executes the prepared query.
        /// </summary>
        /// <returns>query results</returns>
        public EPPreparedQueryResult Execute(ContextPartitionSelector[] contextPartitionSelectors)
        {
            try {
                var numStreams = _processors.Length;

                if (contextPartitionSelectors != null && contextPartitionSelectors.Length != numStreams)
                {
                    throw new ArgumentException("Number of context partition selectors does not match the number of named windows in the from-clause");
                }

                // handle non-context case
                if (_statementSpec.OptionalContextName == null)
                {
                    ICollection <EventBean>[] snapshots = new ICollection <EventBean> [numStreams];
                    for (var i = 0; i < numStreams; i++)
                    {
                        var selector = contextPartitionSelectors == null ? null : contextPartitionSelectors[i];
                        snapshots[i] = GetStreamFilterSnapshot(i, selector);
                    }

                    _resultSetProcessor.Clear();
                    return(Process(snapshots));
                }

                IList <ContextPartitionResult> contextPartitionResults = new List <ContextPartitionResult>();
                var singleSelector = contextPartitionSelectors != null && contextPartitionSelectors.Length > 0 ? contextPartitionSelectors[0] : null;

                // context partition runtime query
                ICollection <int> agentInstanceIds = EPPreparedExecuteMethodHelper.GetAgentInstanceIds(_processors[0], singleSelector, _services.ContextManagementService, _statementSpec.OptionalContextName);

                // collect events and agent instances
                foreach (int agentInstanceId in agentInstanceIds)
                {
                    var processorInstance = _processors[0].GetProcessorInstanceContextById(agentInstanceId);
                    if (processorInstance != null)
                    {
                        EPPreparedExecuteTableHelper.AssignTableAccessStrategies(_services, _statementSpec.TableNodes, processorInstance.AgentInstanceContext);
                        var coll = processorInstance.SnapshotBestEffort(this, _filters[0], _statementSpec.Annotations);
                        contextPartitionResults.Add(new ContextPartitionResult(coll, processorInstance.AgentInstanceContext));
                    }
                }

                // process context partitions
                var events = new ArrayDeque <EventBean[]>();
                foreach (var contextPartitionResult in contextPartitionResults)
                {
                    var snapshot = contextPartitionResult.Events;
                    if (_statementSpec.FilterRootNode != null)
                    {
                        snapshot = GetFiltered(snapshot, Collections.SingletonList(_statementSpec.FilterRootNode));
                    }
                    EventBean[] rows = snapshot.ToArray();
                    _resultSetProcessor.AgentInstanceContext = contextPartitionResult.Context;
                    var results = _resultSetProcessor.ProcessViewResult(rows, null, true);
                    if (results != null && results.First != null && results.First.Length > 0)
                    {
                        events.Add(results.First);
                    }
                }
                return(new EPPreparedQueryResult(_resultSetProcessor.ResultEventType, EventBeanUtility.Flatten(events)));
            }
            finally {
                if (_hasTableAccess)
                {
                    _services.TableService.TableExprEvaluatorContext.ReleaseAcquiredLocks();
                }
            }
        }
 public override ICollection <EventBean> SnapshotBestEffort(EPPreparedExecuteMethodQuery query, FilterSpecCompiled filter, Attribute[] annotations)
 {
     EPPreparedExecuteTableHelper.AssignTableAccessStrategies(query.Services, query.TableNodes, _processorInstance.TailViewInstance.AgentInstanceContext);
     return(_processorInstance.TailViewInstance.Snapshot(filter, annotations));
 }
 public override EventBean[] ProcessUpdate(EPPreparedExecuteIUDSingleStreamExecUpdate update)
 {
     EPPreparedExecuteTableHelper.AssignTableAccessStrategies(update.Services, update.OptionalTableNodes, _processorInstance.TailViewInstance.AgentInstanceContext);
     return(_processorInstance.TailViewInstance.SnapshotUpdate(update.Filter, update.OptionalWhereClause, update.UpdateHelper, update.Annotations));
 }
Beispiel #6
0
 public override EventBean[] ProcessDelete(EPPreparedExecuteIUDSingleStreamExecDelete delete)
 {
     EPPreparedExecuteTableHelper.AssignTableAccessStrategies(delete.Services, delete.OptionalTableNodes, _processorInstance.TailViewInstance.AgentInstanceContext);
     return(_processorInstance.TailViewInstance.SnapshotDelete(delete.QueryGraph, delete.OptionalWhereClause, delete.Annotations));
 }