예제 #1
0
        internal Type[] KeyPropTypes; // { get; private set; }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            HistoricalStreamIndexDesc that = (HistoricalStreamIndexDesc)obj;

            if (!Collections.AreEqual(IndexPropTypes, that.IndexPropTypes))
            {
                return(false);
            }
            if (!Collections.AreEqual(IndexProperties, that.IndexProperties))
            {
                return(false);
            }
            if (!Collections.AreEqual(KeyPropTypes, that.KeyPropTypes))
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>Get the strategies to use for polling from a given stream. </summary>
        /// <param name="streamViewStreamNum">the stream providing the polling events</param>
        /// <returns>looking and indexing strategy</returns>
        public Pair <HistoricalIndexLookupStrategy, PollResultIndexingStrategy> GetStrategy(int streamViewStreamNum)
        {
            // If there is only a single polling stream, then build a single index
            if (_pollingStreams.Count == 1)
            {
                return(JoinSetComposerPrototypeFactory.DetermineIndexing(_queryGraph, _typesPerStream[_historicalStreamNum], _typesPerStream[streamViewStreamNum], _historicalStreamNum, streamViewStreamNum));
            }

            // If there are multiple polling streams, determine if a single index is appropriate.
            // An index can be reused if:
            //  (a) indexed property names are the same
            //  (b) indexed property types are the same
            //  (c) key property types are the same (because of coercion)
            // A index lookup strategy is always specific to the providing stream.
            if (_indexesUsedByStreams == null)
            {
                _indexesUsedByStreams = new LinkedHashMap <HistoricalStreamIndexDesc, IList <int> >();
                foreach (var pollingStream in _pollingStreams)
                {
                    var queryGraphValue = _queryGraph.GetGraphValue(pollingStream, _historicalStreamNum);
                    var hashKeyProps    = queryGraphValue.HashKeyProps;
                    var indexProperties = hashKeyProps.Indexed;

                    var keyTypes   = GetPropertyTypes(hashKeyProps.Keys);
                    var indexTypes = GetPropertyTypes(_typesPerStream[_historicalStreamNum], indexProperties);

                    var desc          = new HistoricalStreamIndexDesc(indexProperties, indexTypes, keyTypes);
                    var usedByStreams = _indexesUsedByStreams.Get(desc);
                    if (usedByStreams == null)
                    {
                        usedByStreams = new List <int>();
                        _indexesUsedByStreams.Put(desc, usedByStreams);
                    }
                    usedByStreams.Add(pollingStream);
                }

                // There are multiple indexes required:
                // Build a master indexing strategy that forms multiple indexes and numbers each.
                if (_indexesUsedByStreams.Count > 1)
                {
                    var numIndexes         = _indexesUsedByStreams.Count;
                    var indexingStrategies = new PollResultIndexingStrategy[numIndexes];

                    // create an indexing strategy for each index
                    var count = 0;
                    foreach (var desc in _indexesUsedByStreams)
                    {
                        var sampleStreamViewStreamNum = desc.Value[0];
                        indexingStrategies[count] = JoinSetComposerPrototypeFactory.DetermineIndexing(_queryGraph, _typesPerStream[_historicalStreamNum], _typesPerStream[sampleStreamViewStreamNum], _historicalStreamNum, sampleStreamViewStreamNum).Second;
                        count++;
                    }

                    // create a master indexing strategy that utilizes each indexing strategy to create a set of indexes
                    var streamNum = streamViewStreamNum;
                    _masterIndexingStrategy = new ProxyPollResultIndexingStrategy
                    {
                        ProcIndex = (pollResult, isActiveCache, statementContext) =>
                        {
                            var tables = new EventTable[numIndexes];
                            for (var i = 0; i < numIndexes; i++)
                            {
                                tables[i] = indexingStrategies[i].Index(pollResult, isActiveCache, statementContext)[0];
                            }

                            var organization = new EventTableOrganization(null, false, false, streamNum, null, EventTableOrganizationType.MULTIINDEX);
                            return(new EventTable[]
                            {
                                new MultiIndexEventTable(tables, organization)
                            });
                        },
                        ProcToQueryPlan = () =>
                        {
                            var writer    = new StringWriter();
                            var delimiter = "";
                            foreach (var strategy in indexingStrategies)
                            {
                                writer.Write(delimiter);
                                writer.Write(strategy.ToQueryPlan());
                                delimiter = ", ";
                            }
                            return(GetType().FullName + " " + writer);
                        }
                    };
                }
            }

            // there is one type of index
            if (_indexesUsedByStreams.Count == 1)
            {
                return(JoinSetComposerPrototypeFactory.DetermineIndexing(
                           _queryGraph, _typesPerStream[_historicalStreamNum], _typesPerStream[streamViewStreamNum], _historicalStreamNum, streamViewStreamNum));
            }

            // determine which index number the polling stream must use
            var indexUsed = 0;
            var found     = false;

            foreach (var desc in _indexesUsedByStreams.Values)
            {
                if (desc.Contains(streamViewStreamNum))
                {
                    found = true;
                    break;
                }
                indexUsed++;
            }
            if (!found)
            {
                throw new IllegalStateException("MapIndex not found for use by stream " + streamViewStreamNum);
            }

            // Use one of the indexes built by the master index and a lookup strategy
            var indexNumber = indexUsed;
            HistoricalIndexLookupStrategy innerLookupStrategy = JoinSetComposerPrototypeFactory.DetermineIndexing(_queryGraph, _typesPerStream[_historicalStreamNum], _typesPerStream[streamViewStreamNum], _historicalStreamNum, streamViewStreamNum).First;

            var lookupStrategy = new ProxyHistoricalIndexLookupStrategy
            {
                ProcLookup = (lookupEvent, index, context) =>
                {
                    var multiIndex = (MultiIndexEventTable)index[0];
                    var indexToUse = multiIndex.Tables[indexNumber];
                    return(innerLookupStrategy.Lookup(lookupEvent, new EventTable[] { indexToUse }, context));
                },
                ProcToQueryPlan = () => GetType().FullName + " inner: " + innerLookupStrategy.ToQueryPlan()
            };

            return(new Pair <HistoricalIndexLookupStrategy, PollResultIndexingStrategy> (lookupStrategy, _masterIndexingStrategy));
        }