Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal override bool FindRowImpl(IDictionary <string, object> rowPattern
                                                     )
        {
            IndexData indexData = _entryCursor.GetIndexData();

            object[] rowValues = indexData.ConstructIndexRow(rowPattern);
            if (rowValues == null)
            {
                // bummer, use the default table scan
                return(base.FindRowImpl(rowPattern));
            }
            // sweet, we can use our index
            if (!FindPotentialRow(rowValues, true))
            {
                // at end of index, no potential matches
                return(false);
            }
            // find actual matching row
            IDictionary <string, object> indexRowPattern = null;

            if (rowPattern.Count == indexData.GetColumns().Count)
            {
                // the rowPattern matches our index columns exactly, so we can
                // streamline our testing below
                indexRowPattern = rowPattern;
            }
            else
            {
                // the rowPattern has more columns than just the index, so we need to
                // do more work when testing below
                indexRowPattern = new LinkedHashMap <string, object>();
                foreach (IndexData.ColumnDescriptor idxCol in indexData.GetColumns())
                {
                    indexRowPattern.Put(idxCol.GetName(), rowValues[idxCol.GetColumnIndex()]);
                }
            }
            do
            {
                // there may be multiple columns which fit the pattern subset used by
                // the index, so we need to keep checking until our index values no
                // longer match
                if (!CurrentRowMatches(indexRowPattern))
                {
                    // there are no more rows which could possibly match
                    break;
                }
                // note, if rowPattern == indexRowPattern, no need to do an extra
                // comparison with the current row
                if ((rowPattern == indexRowPattern) || CurrentRowMatches(rowPattern))
                {
                    // found it!
                    return(true);
                }
            }while (MoveToNextRow());
            // none of the potential rows matched
            return(false);
        }