Example #1
0
 public long GetObjectPositionWithOid(OID oid, bool useCache)
 {
     return(_objectReader.GetObjectPositionFromItsOid(oid, useCache, true));
 }
        /// <summary>
        ///   Execute query using index
        /// </summary>
        /// <param name="index"> </param>
        /// <param name="inMemory"> </param>
        /// <param name="returnObjects"> </param>
        /// <param name="queryResultAction"> </param>
        private IInternalObjectSet <T> ExecuteUsingIndex <T>(ClassInfoIndex index, bool inMemory,
                                                             bool returnObjects, IMatchingObjectAction queryResultAction)
        {
            // Index that have not been used yet do not have persister!
            if (index.BTree.GetPersister() == null)
            {
                index.BTree.SetPersister(new LazyOdbBtreePersister(StorageEngine));
            }

            var nbObjects = ClassInfo.NumberOfObjects;
            var btreeSize = index.BTree.GetSize();

            // the two values should be equal
            if (nbObjects != btreeSize)
            {
                var classInfo = StorageEngine.GetSession().GetMetaModel().GetClassInfoFromId(index.ClassInfoId);

                throw new OdbRuntimeException(
                          NDatabaseError.IndexIsCorrupted.AddParameter(index.Name).AddParameter(classInfo.FullClassName).
                          AddParameter(nbObjects).AddParameter(btreeSize));
            }

            if (OdbConfiguration.IsLoggingEnabled())
            {
                DLogger.Debug(string.Format("GenericQueryExecutor: loading {0} instance(s) of {1}", nbObjects, ClassInfo.FullClassName));
            }

            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.Start();
            }

            PrepareQuery();
            if (Query != null)
            {
                _queryHasOrderBy = Query.HasOrderBy();
            }

            var tree     = index.BTree;
            var isUnique = index.IsUnique;

            // Iterator iterator = new BTreeIterator(tree,
            // OrderByConstants.ORDER_BY_ASC);
            var   key  = ComputeIndexKey(index);
            IList list = null;

            // If index is unique, get the object
            if (isUnique)
            {
                var treeSingle = (IBTreeSingleValuePerKey)tree;
                var value      = treeSingle.Search(key);
                if (value != null)
                {
                    list = new List <object> {
                        value
                    }
                }
                ;
            }
            else
            {
                var treeMultiple = (IBTreeMultipleValuesPerKey)tree;
                list = treeMultiple.Search(key);
            }

            if (list != null)
            {
                foreach (OID oid in list)
                {
                    // FIXME Why calling this method
                    ObjectReader.GetObjectPositionFromItsOid(oid, true, true);
                    _orderByKey = null;

                    var objectMatches = MatchObjectWithOid(oid, returnObjects, inMemory);
                    if (objectMatches)
                    {
                        queryResultAction.ObjectMatch(oid, GetCurrentObjectMetaRepresentation(), _orderByKey);
                    }
                }

                queryResultAction.End();
                return(queryResultAction.GetObjects <T>());
            }

            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.End();
            }

            return(queryResultAction.GetObjects <T>());
        }