예제 #1
0
 public virtual void AddClass(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo
                              )
 {
     if (classInfo.IsSystemClass())
     {
         rapidAccessForSystemClassesByName.Add(classInfo.GetFullClassName(), classInfo);
     }
     else
     {
         rapidAccessForUserClassesByName.Add(classInfo.GetFullClassName(), classInfo);
     }
     rapidAccessForClassesByOid.Add(classInfo.GetId(), classInfo);
     allClassInfos.Add(classInfo);
 }
예제 #2
0
        /// <summary>It is overiden to manage triggers</summary>
        public override void DeleteObjectWithOid(NeoDatis.Odb.OID oid)
        {
            // Check if oih is in the cache
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = GetSession(true).GetCache
                                                                            ().GetObjectInfoHeaderFromOid(oid, false);
            if (oih == null)
            {
                oih = GetObjectReader().ReadObjectInfoHeaderFromOid(oid, true);
            }
            // Only necessary to check if there is some trigger
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = GetMetaModel().GetClassInfoFromId
                                                                    (oih.GetClassInfoId());
            string className   = ci.GetFullClassName();
            bool   hasTriggers = triggerManager.HasDeleteTriggersFor(className);

            NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = null;
            if (hasTriggers)
            {
                nnoi = GetObjectReader().ReadNonNativeObjectInfoFromOid(ci, oid, true, false);
                triggerManager.ManageInsertTriggerBefore(className, nnoi);
            }
            base.DeleteObjectWithOid(oid);
            if (hasTriggers)
            {
                triggerManager.ManageInsertTriggerAfter(className, nnoi, oid);
            }
        }
예제 #3
0
 public ClassInfoList(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo mainClassInfo
                      )
 {
     this.classInfos = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <string, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                                  >();
     this.classInfos[mainClassInfo.GetFullClassName()] = mainClassInfo;
     this.mainClassInfo = mainClassInfo;
 }
예제 #4
0
 /// <exception cref="System.IO.IOException"></exception>
 public virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo AddClass(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                                        newClassInfo, bool addDependentClasses)
 {
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = GetObjectWriter().AddClass(newClassInfo
                                                                                    , addDependentClasses);
     NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession lsession = (NeoDatis.Odb.Impl.Core.Server.Transaction.ServerSession
                                                                         )GetSession(true);
     lsession.SetClassInfoId(newClassInfo.GetFullClassName(), ci.GetId());
     return(ci);
 }
예제 #5
0
 public override string ToString()
 {
     System.Text.StringBuilder buffer = new System.Text.StringBuilder();
     if (message != null)
     {
         buffer.Append(message).Append(" | ");
     }
     if (oldCi.GetId() != newCi.GetId())
     {
         buffer.Append("old class=").Append(oldCi.GetFullClassName()).Append(" | new class="
                                                                             ).Append(newCi.GetFullClassName());
     }
     else
     {
         buffer.Append("class=").Append(oldCi.GetFullClassName());
     }
     buffer.Append(" | field=").Append(oldCi.GetAttributeInfo(fieldIndex).GetName());
     buffer.Append(" | old=").Append(oldValue.ToString()).Append(" | new=").Append(newValue
                                                                                   .ToString());
     buffer.Append(" | obj. hier. level=").Append(objectRecursionLevel);
     return(buffer.ToString());
 }
예제 #6
0
 public virtual System.Collections.Generic.IDictionary <string, object> GetHistory(
     )
 {
     System.Collections.Generic.IDictionary <string, object> map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
                                                                   <string, object>();
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
     System.Collections.Generic.IEnumerator <NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                             > iterator = allClassInfos.GetEnumerator();
     while (iterator.MoveNext())
     {
         ci = iterator.Current;
         map.Add(ci.GetFullClassName(), ci.GetHistory());
     }
     return(map);
 }
예제 #7
0
        /// <summary>This method is only used by the odb explorer.</summary>
        /// <remarks>
        /// This method is only used by the odb explorer. So there is no too much
        /// problem with performance issue.
        /// </remarks>
        /// <param name="ci"></param>
        /// <returns>The index of the class info</returns>
        public virtual int SlowGetUserClassInfoIndex(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                     ci)
        {
            System.Collections.IEnumerator iterator = rapidAccessForUserClassesByName.Values.
                                                      GetEnumerator();
            int i = 0;

            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci2 = null;
            while (iterator.MoveNext())
            {
                ci2 = (NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator.Current;
                if (ci2.GetId() == ci.GetId())
                {
                    return(i);
                }
                i++;
            }
            throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.ClassInfoDoesNotExistInMetaModel
                                                       .AddParameter(ci.GetFullClassName()));
        }
예제 #8
0
 /// <summary>
 /// Used to commit meta model : classes This is useful when running in client
 /// server mode TODO Check this
 /// </summary>
 protected virtual void CommitMetaModel()
 {
     NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel sessionMetaModel = session.GetMetaModel
                                                                           ();
     // If meta model has not been modified, there is nothing to do
     if (!sessionMetaModel.HasChanged())
     {
         return;
     }
     if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
     {
         NeoDatis.Tool.DLogger.Debug("Start commitMetaModel");
     }
     NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel lastCommitedMetaModel = new NeoDatis.Odb.Core.Layers.Layer2.Meta.SessionMetaModel
                                                                                ();
     if (isLocal)
     {
         // In local mode, we must not reload the meta model as there is no
         // concurrent access
         lastCommitedMetaModel = sessionMetaModel;
     }
     else
     {
         // In ClientServer mode, re-read the meta-model from the database
         // base to get last update.
         lastCommitedMetaModel = session.GetStorageEngine().GetObjectReader().ReadMetaModel
                                     (lastCommitedMetaModel, false);
     }
     // Gets the classes that have changed (that have modified ,deleted or
     // inserted objects)
     System.Collections.Generic.IEnumerator <NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                             >      cis             = sessionMetaModel.GetChangedClassInfo().GetEnumerator();
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo newCi           = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo lastCommittedCI = null;
     NeoDatis.Odb.Core.Layers.Layer3.IObjectWriter  writer          = session.GetStorageEngine()
                                                                      .GetObjectWriter();
     NeoDatis.Odb.OID lastCommittedObjectOIDOfThisTransaction = null;
     NeoDatis.Odb.OID lastCommittedObjectOIDOfPrevTransaction = null;
     // for all changes between old and new meta model
     while (cis.MoveNext())
     {
         newCi = cis.Current;
         if (lastCommitedMetaModel.ExistClass(newCi.GetFullClassName()))
         {
             // The last CI represents the last committed meta model of the
             // database
             lastCommittedCI = lastCommitedMetaModel.GetClassInfoFromId(newCi.GetId());
             // Just be careful to keep track of current CI committed zone
             // deleted objects
             lastCommittedCI.GetCommitedZoneInfo().SetNbDeletedObjects(newCi.GetCommitedZoneInfo
                                                                           ().GetNbDeletedObjects());
         }
         else
         {
             lastCommittedCI = newCi;
         }
         lastCommittedObjectOIDOfThisTransaction = newCi.GetCommitedZoneInfo().last;
         lastCommittedObjectOIDOfPrevTransaction = lastCommittedCI.GetCommitedZoneInfo().last;
         NeoDatis.Odb.OID lastCommittedObjectOID = lastCommittedObjectOIDOfPrevTransaction;
         // If some object have been created then
         if (lastCommittedObjectOIDOfPrevTransaction != null)
         {
             // Checks if last object of committed meta model has not been
             // deleted
             if (session.GetCache().IsDeleted(lastCommittedObjectOIDOfPrevTransaction))
             {
                 // TODO This is wrong: if a committed transaction deleted a
                 // committed object and creates x new
                 // objects, then all these new objects will be lost:
                 // if it has been deleted then use the last object of the
                 // session class info
                 lastCommittedObjectOID = lastCommittedObjectOIDOfThisTransaction;
                 newCi.GetCommitedZoneInfo().last = lastCommittedObjectOID;
             }
         }
         // Connect Unconnected zone to connected zone
         // make next oid of last committed object point to first
         // uncommitted object
         // make previous oid of first uncommitted object point to
         // last committed object
         if (lastCommittedObjectOID != null && newCi.GetUncommittedZoneInfo().HasObjects())
         {
             if (newCi.GetCommitedZoneInfo().HasObjects())
             {
                 // these 2 updates are executed directly without
                 // transaction, because
                 // We are in the commit process.
                 writer.UpdateNextObjectFieldOfObjectInfo(lastCommittedObjectOID, newCi.GetUncommittedZoneInfo
                                                              ().first, false);
                 writer.UpdatePreviousObjectFieldOfObjectInfo(newCi.GetUncommittedZoneInfo().first
                                                              , lastCommittedObjectOID, false);
             }
             else
             {
                 // Committed zone has 0 object
                 writer.UpdatePreviousObjectFieldOfObjectInfo(newCi.GetUncommittedZoneInfo().first
                                                              , null, false);
             }
         }
         // The number of committed objects must be updated with the number
         // of the last committed CI because a transaction may have been
         // committed changing this number.
         // Notice that the setNbObjects receive the full CommittedCIZoneInfo
         // object
         // because it will set the number of objects and the number of
         // deleted objects
         newCi.GetCommitedZoneInfo().SetNbObjects(lastCommittedCI.GetCommitedZoneInfo());
         // and don't forget to set the deleted objects
         // This sets the number of objects, the first object OID and the
         // last object OID
         newCi = BuildClassInfoForCommit(newCi);
         writer.UpdateInstanceFieldsOfClassInfo(newCi, false);
         if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
         {
             NeoDatis.Tool.DLogger.Debug("Analysing class " + newCi.GetFullClassName());
             NeoDatis.Tool.DLogger.Debug("\t-Commited CI   = " + newCi);
             NeoDatis.Tool.DLogger.Debug("\t-connect last commited object with oid " + lastCommittedObjectOID
                                         + " to first uncommited object " + newCi.GetUncommittedZoneInfo().first);
             NeoDatis.Tool.DLogger.Debug("\t-Commiting new Number of objects = " + newCi.GetNumberOfObjects
                                             ());
         }
     }
     sessionMetaModel.ResetChangedClasses();
     // To guarantee integrity after commit, the meta model is set to null
     // If the user continues using odb instance after commit the meta model
     // will be lazy-reloaded. Only for Client Server mode
     if (!isLocal)
     {
         session.SetMetaModel(null);
     }
 }
예제 #9
0
 public virtual void AddUniqueIndexOn(string name, string[] indexFields, bool verbose
                                      )
 {
     storageEngine.AddIndexOn(classInfo.GetFullClassName(), name, indexFields, verbose
                              , false);
 }
예제 #10
0
 public virtual void AddClassInfo(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo
                                  )
 {
     classInfos[classInfo.GetFullClassName()] = classInfo;
 }
예제 #11
0
 public NonNativeObjectInfo(object @object, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                            info, NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo[] values, long[]
                            attributesIdentification, int[] attributeIds) : base(NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
                                                                                 .GetFromName(info.GetFullClassName()))
 {
     //new OdbArrayList<NonNativeObjectInfo>();
     this.@object         = @object;
     this.classInfo       = info;
     this.attributeValues = values;
     this.maxNbattributes = classInfo.GetMaxAttributeId();
     if (attributeValues == null)
     {
         this.attributeValues = new NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                [maxNbattributes];
     }
     this.objectHeader = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader(-1,
                                                                                   null, null, (classInfo != null ? classInfo.GetId() : null), attributesIdentification
                                                                                   , attributeIds);
     this.allNonNativeObjects = new NeoDatis.Tool.Wrappers.List.OdbArrayList <NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                              >();
 }
예제 #12
0
 public override string ToString()
 {
     System.Text.StringBuilder buffer = new System.Text.StringBuilder(classInfo.GetFullClassName
                                                                          ()).Append("(").Append(GetOid()).Append(")=");
     if (attributeValues == null)
     {
         buffer.Append("null attribute values");
         return(buffer.ToString());
     }
     for (int i = 0; i < attributeValues.Length; i++)
     {
         if (i != 0)
         {
             buffer.Append(",");
         }
         string attributeName = (classInfo != null ? (classInfo.GetAttributeInfo(i)).GetName
                                     () : "?");
         buffer.Append(attributeName).Append("=");
         object @object = attributeValues[i];
         if (@object == null)
         {
             buffer.Append(" null java object - should not happen , ");
         }
         else
         {
             NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
                                                                 .GetFromClass(attributeValues[i].GetType());
             if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeNullObjectInfo)
             {
                 buffer.Append("null");
                 continue;
             }
             if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeDeletedObjectInfo)
             {
                 buffer.Append("deleted object");
                 continue;
             }
             if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NativeObjectInfo)
             {
                 NeoDatis.Odb.Core.Layers.Layer2.Meta.NativeObjectInfo noi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NativeObjectInfo
                                                                              )@object;
                 buffer.Append(noi.ToString());
                 continue;
             }
             if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)
             {
                 NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                  )@object;
                 buffer.Append("@").Append(nnoi.GetClassInfo().GetFullClassName()).Append("(id=").
                 Append(nnoi.GetOid()).Append(")");
                 continue;
             }
             if (@object is NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectReference)
             {
                 buffer.Append(@object.ToString());
                 continue;
             }
             buffer.Append("@").Append(NeoDatis.Tool.Wrappers.OdbClassUtil.GetClassName(type.GetName
                                                                                            ()));
         }
     }
     return(buffer.ToString());
 }
예제 #13
0
 public virtual void DecreaseNbObjects()
 {
     nbObjects--;
     if (nbObjects < 0)
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
                                                    .AddParameter("nb objects is negative! in " + ci.GetFullClassName()));
     }
 }
예제 #14
0
        /// <summary>Execute query using index</summary>
        /// <param name="index"></param>
        /// <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> ExecuteUsingIndex <T>(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex
                                                               index, bool inMemory, int startIndex, int endIndex, bool returnObjects, NeoDatis.Odb.Core.Query.Execution.IMatchingObjectAction
                                                               queryResultAction)
        {
            // Index that have not been used yet do not have persister!
            if (index.GetBTree().GetPersister() == null)
            {
                index.GetBTree().SetPersister(new NeoDatis.Odb.Impl.Core.Btree.LazyODBBTreePersister
                                                  (storageEngine));
            }
            bool objectMatches = false;
            long nbObjects     = classInfo.GetNumberOfObjects();
            long btreeSize     = index.GetBTree().GetSize();

            // the two values should be equal
            if (nbObjects != btreeSize)
            {
                NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = storageEngine.GetSession(true
                                                                                             ).GetMetaModel().GetClassInfoFromId(index.GetClassInfoId());
                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.IndexIsCorrupted
                                                           .AddParameter(index.GetName()).AddParameter(ci.GetFullClassName()).AddParameter(
                                                               nbObjects).AddParameter(btreeSize));
            }
            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("loading " + nbObjects + " instance(s) of " + classInfo
                                            .GetFullClassName());
            }
            if (ExecuteStartAndEndOfQueryAction())
            {
                queryResultAction.Start();
            }
            PrepareQuery();
            if (query != null)
            {
                queryHasOrderBy = query.HasOrderBy();
            }
            NeoDatis.Btree.IBTree tree = index.GetBTree();
            bool isUnique = index.IsUnique();

            // Iterator iterator = new BTreeIterator(tree,
            // OrderByConstants.ORDER_BY_ASC);
            System.IComparable       key  = ComputeIndexKey(classInfo, index);
            System.Collections.IList list = null;
            // If index is unique, get the object
            if (isUnique)
            {
                NeoDatis.Btree.IBTreeSingleValuePerKey treeSingle = (NeoDatis.Btree.IBTreeSingleValuePerKey
                                                                     )tree;
                object o = treeSingle.Search(key);
                if (o != null)
                {
                    list = new System.Collections.ArrayList();
                    list.Add(o);
                }
            }
            else
            {
                NeoDatis.Btree.IBTreeMultipleValuesPerKey treeMultiple = (NeoDatis.Btree.IBTreeMultipleValuesPerKey
                                                                          )tree;
                list = treeMultiple.Search(key);
            }
            if (list != null)
            {
                System.Collections.IEnumerator iterator = list.GetEnumerator();
                while (iterator.MoveNext())
                {
                    NeoDatis.Odb.OID oid = (NeoDatis.Odb.OID)iterator.Current;
                    // FIXME Why calling this method
                    long position = objectReader.GetObjectPositionFromItsOid(oid, true, true);
                    orderByKey    = null;
                    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>());
        }
예제 #15
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>());
        }
        public virtual void DefragmentTo(string newFileName)
        {
            long start          = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs();
            long totalNbObjects = 0;

            NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine newStorage = NeoDatis.Odb.OdbConfiguration
                                                                        .GetCoreProvider().GetClientStorageEngine(new NeoDatis.Odb.Core.Layers.Layer3.IOFileParameter
                                                                                                                      (newFileName, true, baseIdentification.GetUserName(), baseIdentification.GetPassword
                                                                                                                          ()));
            NeoDatis.Odb.Objects <object> defragObjects = null;
            int j = 0;

            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
            // User classes
            System.Collections.IEnumerator iterator = GetMetaModel().GetUserClasses().GetEnumerator
                                                          ();
            while (iterator.MoveNext())
            {
                ci = (NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator.Current;
                if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                {
                    NeoDatis.Tool.DLogger.Debug("Reading " + ci.GetCommitedZoneInfo().GetNbObjects()
                                                + " objects of type " + ci.GetFullClassName());
                }
                defragObjects = GetObjects <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                        (ci.GetFullClassName()), true, -1, -1);
                while (defragObjects.HasNext())
                {
                    newStorage.Store(defragObjects.Next());
                    totalNbObjects++;
                    if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                    {
                        if (j % 10000 == 0)
                        {
                            NeoDatis.Tool.DLogger.Info("\n" + totalNbObjects + " objects saved.");
                        }
                    }
                    j++;
                }
            }
            // System classes
            iterator = GetMetaModel().GetSystemClasses().GetEnumerator();
            while (iterator.MoveNext())
            {
                ci = (NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator.Current;
                if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                {
                    NeoDatis.Tool.DLogger.Debug("Reading " + ci.GetCommitedZoneInfo().GetNbObjects()
                                                + " objects of type " + ci.GetFullClassName());
                }
                defragObjects = GetObjects <object>(new NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                        (ci.GetFullClassName()), true, -1, -1);
                while (defragObjects.HasNext())
                {
                    newStorage.Store(defragObjects.Next());
                    totalNbObjects++;
                    if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                    {
                        if (j % 10000 == 0)
                        {
                            NeoDatis.Tool.DLogger.Info("\n" + totalNbObjects + " objects saved.");
                        }
                    }
                    j++;
                }
            }
            newStorage.Commit();
            newStorage.Close();
            long time = NeoDatis.Tool.Wrappers.OdbTime.GetCurrentTimeInMs() - start;

            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Info("New storage " + newFileName + " created with " + totalNbObjects
                                           + " objects in " + time + " ms.");
            }
        }