Esempio n. 1
0
 public virtual void Start()
 {
     if (inMemory)
     {
         if (query != null && query.HasOrderBy())
         {
             result = new InMemoryBTreeCollection <T>((int)nbObjects, query.GetOrderByType());
         }
         else
         {
             result = new SimpleList <T>((int)nbObjects);
         }
     }
     else
     {
         // result = new InMemoryBTreeCollection((int) nbObjects);
         if (query != null && query.HasOrderBy())
         {
             result = new LazyBTreeCollection <T>((int)nbObjects, storageEngine, returnObjects);
         }
         else
         {
             result = new LazySimpleListFromOid <T>((int)nbObjects, storageEngine, returnObjects);
         }
     }
 }
Esempio n. 2
0
 public CollectionQueryResultAction(NeoDatis.Odb.Core.Query.IQuery query, bool inMemory
                                    , NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine storageEngine, bool returnObjects
                                    , NeoDatis.Odb.Core.Layers.Layer2.Instance.IInstanceBuilder instanceBuilder) : base
         ()
 {
     // TODO check if Object is ok here
     this.query           = query;
     this.inMemory        = inMemory;
     this.storageEngine   = storageEngine;
     this.returnObjects   = returnObjects;
     this.queryHasOrderBy = query.HasOrderBy();
     this.instanceBuilder = instanceBuilder;
 }
Esempio n. 3
0
        /// <summary>
        /// Query execution full scan
        /// <pre>
        /// startIndex &amp; endIndex
        /// A B C D E F G H I J K L
        /// [1,3] : nb &gt;=1 &amp;&amp; nb&lt;3
        /// 1)
        /// analyze A
        /// nb = 0
        /// nb E [1,3] ? no
        /// r=[]
        /// 2)
        /// analyze B
        /// nb = 1
        /// nb E [1,3] ? yes
        /// r=[B]
        /// 3) analyze C
        /// nb = 2
        /// nb E [1,3] ? yes
        /// r=[B,C]
        /// 4) analyze C
        /// nb = 3
        /// nb E [1,3] ? no and 3&gt; upperBound([1,3]) =&gt; exit
        /// </pre>
        /// </summary>
        /// <param name="inMemory"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <param name="returnObjects"></param>
        /// <returns></returns>
        /// <exception cref="System.Exception">System.Exception</exception>
        private NeoDatis.Odb.Objects <T> ExecuteFullScan <T>(bool inMemory, int startIndex,
                                                             int endIndex, bool returnObjects, NeoDatis.Odb.Core.Query.Execution.IMatchingObjectAction
                                                             queryResultAction)
        {
            bool objectInRange = false;
            bool objectMatches = false;

            if (storageEngine.IsClosed())
            {
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.OdbIsClosed
                                                           .AddParameter(storageEngine.GetBaseIdentification().GetIdentification()));
            }
            long nbObjects = classInfo.GetNumberOfObjects();

            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("loading " + nbObjects + " instance(s) of " + classInfo
                                            .GetFullClassName());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.Start();
            }
            NeoDatis.Odb.OID currentOID = null;
            NeoDatis.Odb.OID prevOID    = null;
            // TODO check if all instances are in the cache! and then load from the
            // cache
            nextOID = classInfo.GetCommitedZoneInfo().first;
            if (nbObjects > 0 && nextOID == null)
            {
                // This means that some changes have not been commited!
                // Take next position from uncommited zone
                nextOID = classInfo.GetUncommittedZoneInfo().first;
            }
            PrepareQuery();
            if (query != null)
            {
                queryHasOrderBy = query.HasOrderBy();
            }
            bool monitorMemory = NeoDatis.Odb.OdbConfiguration.IsMonitoringMemory();
            // used when startIndex and endIndex are not negative
            int nbObjectsInResult = 0;

            for (int i = 0; i < nbObjects; i++)
            {
                //Console.WriteLine(i);
                if (monitorMemory && i % 10000 == 0)
                {
                    NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory(string.Empty + (i + 1),
                                                                              true);
                }
                // Reset the order by key
                orderByKey    = null;
                objectMatches = false;
                prevOID       = currentOID;
                currentOID    = nextOID;
                // This is an error
                if (currentOID == null)
                {
                    if (NeoDatis.Odb.OdbConfiguration.ThrowExceptionWhenInconsistencyFound())
                    {
                        throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.NullNextObjectOid
                                                                   .AddParameter(classInfo.GetFullClassName()).AddParameter(i).AddParameter(nbObjects
                                                                                                                                            ).AddParameter(prevOID));
                    }
                    break;
                }
                // If there is an endIndex condition
                if (endIndex != -1 && nbObjectsInResult >= endIndex)
                {
                    break;
                }
                // If there is a startIndex condition
                if (startIndex != -1 && nbObjectsInResult < startIndex)
                {
                    objectInRange = false;
                }
                else
                {
                    objectInRange = true;
                }
                // There is no query
                if (!inMemory && query == null)
                {
                    nbObjectsInResult++;
                    // keep object position if we must
                    if (objectInRange)
                    {
                        orderByKey = BuildOrderByKey(currentNnoi);
                        // TODO Where is the key for order by
                        queryResultAction.ObjectMatch(nextOID, orderByKey);
                    }
                    nextOID = objectReader.GetNextObjectOID(currentOID);
                }
                else
                {
                    objectMatches = MatchObjectWithOid(currentOID, returnObjects, inMemory);
                    if (objectMatches)
                    {
                        nbObjectsInResult++;
                        if (objectInRange)
                        {
                            if (queryHasOrderBy)
                            {
                                orderByKey = BuildOrderByKey(GetCurrentObjectMetaRepresentation());
                            }
                            queryResultAction.ObjectMatch(currentOID, GetCurrentObjectMetaRepresentation(), orderByKey
                                                          );
                            if (callback != null)
                            {
                                callback.ReadingObject(i, -1);
                            }
                        }
                    }
                }
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.End();
            }
            return(queryResultAction.GetObjects <T>());
        }