示例#1
0
        internal IndexManager(IStorageEngine storageEngine, ClassInfo classInfo)
        {
            _storageEngine = storageEngine;
            _classInfo = classInfo;

            _reflectionService = DependencyContainer.Resolve<IReflectionService>();
        }
 public CriteriaQueryExecutionPlan(ClassInfo classInfo, SodaQuery query)
 {
     _classInfo = classInfo;
     _query = query;
     ((IInternalQuery) _query).SetExecutionPlan(this);
     Init();
 }
示例#3
0
        public int[] GetOrderByAttributeIds(ClassInfo classInfo, IInternalQuery query)
        {
            var fieldNames = query.GetOrderByFieldNames();
            var fieldIds = new int[fieldNames.Count];

            for (var i = 0; i < fieldNames.Count; i++)
                fieldIds[i] = classInfo.GetAttributeId(fieldNames[i]);

            return fieldIds;
        }
        internal ClassAttributeInfo(int attributeId, string name, Type nativeClass, string fullClassName, ClassInfo info)
        {
            _id = attributeId;
            _name = name;
            SetFullClassName(fullClassName);
            
            if (nativeClass != null)
            {
                _attributeType = OdbType.GetFromClass(nativeClass);
            }
            else
            {
                if (fullClassName != null)
                    _attributeType = OdbType.GetFromName(fullClassName);
            }

            _classInfo = info;
            _isIndex = false;
        }
示例#5
0
        internal ClassAttributeInfo(int attributeId, string name, Type nativeClass, string fullClassName, ClassInfo info)
        {
            _id   = attributeId;
            _name = name;
            SetFullClassName(fullClassName);

            if (nativeClass != null)
            {
                _attributeType = OdbType.GetFromClass(nativeClass);
            }
            else
            {
                if (fullClassName != null)
                {
                    _attributeType = OdbType.GetFromName(fullClassName);
                }
            }

            _classInfo = info;
            _isIndex   = false;
        }
示例#6
0
 internal ClassAttributeInfo(int attributeId, string name, string fullClassName, ClassInfo info)
     : this(attributeId, name, null, fullClassName, info)
 {
 }
示例#7
0
 public NonNativeObjectInfo(object @object, ClassInfo info)
     : this(@object, info, null, null, null)
 {
 }
示例#8
0
        /// <summary>
        ///   Write the class info header to the database file
        /// </summary>
        /// <param name="classInfo"> The class info to be written </param>
        /// <param name="position"> The position at which it must be written </param>
        /// <param name="writeInTransaction"> true if the write must be done in transaction, false to write directly </param>
        private void WriteClassInfoHeader(ClassInfo classInfo, long position, bool writeInTransaction)
        {
            var classId = classInfo.ClassInfoId;
            if (classId == null)
            {
                classId = _idManager.GetNextClassId(position);
                classInfo.ClassInfoId = classId;
            }
            else
                _idManager.UpdateClassPositionForId(classId, position, true);

            FileSystemProcessor.FileSystemInterface.SetWritePosition(position, writeInTransaction);
            if (OdbConfiguration.IsLoggingEnabled())
            {
                var positionAsString = position.ToString();
                DLogger.Debug("ObjectWriter: Writing new Class info header at " + positionAsString + " : " + classInfo);
            }

            // Real value of block size is only known at the end of the writing
            FileSystemProcessor.FileSystemInterface.WriteInt(0, writeInTransaction);
            FileSystemProcessor.FileSystemInterface.WriteByte(BlockTypes.BlockTypeClassHeader, writeInTransaction);
            FileSystemProcessor.FileSystemInterface.WriteByte(2, writeInTransaction);
            FileSystemProcessor.FileSystemInterface.WriteLong(classId.ObjectId, writeInTransaction); //class id

            FileSystemProcessor.WriteOid(classInfo.PreviousClassOID, writeInTransaction);

            FileSystemProcessor.WriteOid(classInfo.NextClassOID, writeInTransaction);

            FileSystemProcessor.FileSystemInterface.WriteLong(classInfo.CommitedZoneInfo.GetNumberbOfObjects(), writeInTransaction); //class nb objects

            FileSystemProcessor.WriteOid(classInfo.CommitedZoneInfo.First, writeInTransaction);

            FileSystemProcessor.WriteOid(classInfo.CommitedZoneInfo.Last, writeInTransaction);

            // FIXME : append extra info if not empty (.net compatibility)
            FileSystemProcessor.FileSystemInterface.WriteString(classInfo.FullClassName, writeInTransaction);
            FileSystemProcessor.FileSystemInterface.WriteInt(classInfo.MaxAttributeId, writeInTransaction);

            if (classInfo.AttributesDefinitionPosition != -1)
            {
                FileSystemProcessor.FileSystemInterface.WriteLong(classInfo.AttributesDefinitionPosition, writeInTransaction); //class att def pos
            }
            else
            {
                // todo check this
                FileSystemProcessor.FileSystemInterface.WriteLong(-1, writeInTransaction); //class att def pos
            }

            var blockSize = (int) (FileSystemProcessor.FileSystemInterface.GetPosition() - position);
            FileSystemProcessor.WriteBlockSizeAt(position, blockSize, writeInTransaction, classInfo);
        }
示例#9
0
        /// <summary>
        ///   Shift all unconnected infos to connected (committed) infos
        /// </summary>
        /// <param name="classInfo"> </param>
        /// <returns> The updated class info </returns>
        private static ClassInfo BuildClassInfoForCommit(ClassInfo classInfo)
        {
            var nbObjects = classInfo.NumberOfObjects;
            classInfo.CommitedZoneInfo.SetNbObjects(nbObjects);

            if (classInfo.CommitedZoneInfo.First == null)
            {
                // nothing to change
                classInfo.CommitedZoneInfo.First = classInfo.UncommittedZoneInfo.First;
            }

            if (classInfo.UncommittedZoneInfo.Last != null)
                classInfo.CommitedZoneInfo.Last = classInfo.UncommittedZoneInfo.Last;

            classInfo.UncommittedZoneInfo.Reset();

            return classInfo;
        }
示例#10
0
        public ClassInfo AddClass(ClassInfo newClassInfo, bool addDependentClasses)
        {
            var classInfo = _session.GetMetaModel().GetClassInfo(newClassInfo.FullClassName, false);
            if (classInfo != null && classInfo.Position != -1)
                return classInfo;

            return PersistClass(newClassInfo, -1, true, addDependentClasses);
        }
示例#11
0
        /// <summary>
        ///   Write the class info body to the database file.
        /// </summary>
        /// <remarks>
        ///   Write the class info body to the database file. TODO Check if we really must recall the writeClassInfoHeader
        /// </remarks>
        private void WriteClassInfoBody(ClassInfo classInfo, long position, bool writeInTransaction)
        {
            if (OdbConfiguration.IsLoggingEnabled())
            {
                var positionAsString = position.ToString();
                DLogger.Debug("ObjectWriter: Writing new Class info body at " + positionAsString + " : " + classInfo);
            }
            // updates class info
            classInfo.AttributesDefinitionPosition = position;
            // FIXME : change this to write only the position and not the whole
            // header
            WriteClassInfoHeader(classInfo, classInfo.Position, writeInTransaction);
            FileSystemProcessor.FileSystemInterface.SetWritePosition(position, writeInTransaction);
            // block definition
            FileSystemProcessor.FileSystemInterface.WriteInt(0, writeInTransaction);
            FileSystemProcessor.FileSystemInterface.WriteByte(BlockTypes.BlockTypeClassBody, writeInTransaction);
            // number of class attributes
            FileSystemProcessor.FileSystemInterface.WriteLong(classInfo.Attributes.Count, writeInTransaction);
            
            foreach (var classAttributeInfo in classInfo.Attributes)
                FileSystemProcessor.WriteClassAttributeInfo(_storageEngine, classAttributeInfo, writeInTransaction);

            var blockSize = (int) (FileSystemProcessor.FileSystemInterface.GetPosition() - position);
            FileSystemProcessor.WriteBlockSizeAt(position, blockSize, writeInTransaction, classInfo);
        }
示例#12
0
 public void AddClassInfo(ClassInfo classInfo)
 {
     _classInfosByType.Add(classInfo.UnderlyingType, classInfo);
 }
示例#13
0
 internal ClassAttributeInfo(int attributeId, string name, string fullClassName, ClassInfo info)
     : this(attributeId, name, null, fullClassName, info)
 {
 }
示例#14
0
 public EnumNativeObjectInfo(ClassInfo classInfo, string enumName) : base(enumName, OdbType.EnumId)
 {
     _enumClassInfo = classInfo;
 }
示例#15
0
 /// <summary>
 ///   Updates pointers of objects, Only changes uncommitted info pointers
 /// </summary>
 /// <param name="objectInfo"> The meta representation of the object being inserted </param>
 /// <param name="classInfo"> The class of the object being inserted </param>
 public void ManageNewObjectPointers(NonNativeObjectInfo objectInfo, ClassInfo classInfo)
 {
     var cache = _storageEngine.GetSession().GetCache();
     var isFirstUncommitedObject = !classInfo.UncommittedZoneInfo.HasObjects();
     // if it is the first uncommitted object
     if (isFirstUncommitedObject)
     {
         classInfo.UncommittedZoneInfo.First = objectInfo.GetOid();
         var lastCommittedObjectOid = classInfo.CommitedZoneInfo.Last;
         if (lastCommittedObjectOid != null)
         {
             // Also updates the last committed object next object oid in
             // memory to connect the committed
             // zone with unconnected for THIS transaction (only in memory)
             var oih = cache.GetObjectInfoHeaderByOid(lastCommittedObjectOid, true);
             oih.SetNextObjectOID(objectInfo.GetOid());
             // And sets the previous oid of the current object with the last
             // committed oid
             objectInfo.SetPreviousInstanceOID(lastCommittedObjectOid);
         }
     }
     else
     {
         // Gets the last object, updates its (next object)
         // pointer to the new object and updates the class info 'last
         // uncommitted object
         // oid' field
         var oip = classInfo.LastObjectInfoHeader;
         if (oip == null)
         {
             throw new OdbRuntimeException(
                 NDatabaseError.InternalError.AddParameter("last OIP is null in manageNewObjectPointers oid=" +
                                                          objectInfo.GetOid()));
         }
         if (oip.GetNextObjectOID() != objectInfo.GetOid())
         {
             oip.SetNextObjectOID(objectInfo.GetOid());
             // Here we are working in unconnected zone, so this
             // can be done without transaction: actually
             // write in database file
             UpdateNextObjectFieldOfObjectInfo(oip.GetOid(), oip.GetNextObjectOID(), false);
             objectInfo.SetPreviousInstanceOID(oip.GetOid());
             // Resets the class info oid: In some case,
             // (client // server) it may be -1.
             oip.SetClassInfoId(classInfo.ClassInfoId);
             // object info oip has been changed, we must put it
             // in the cache to turn this change available for current
             // transaction until the commit
             _storageEngine.GetSession().GetCache().AddObjectInfoOfNonCommitedObject(oip);
         }
     }
     // always set the new last object oid and the number of objects
     classInfo.UncommittedZoneInfo.Last = objectInfo.GetOid();
     classInfo.UncommittedZoneInfo.IncreaseNbObjects();
     // Then updates the last info pointers of the class info
     // with this new created object
     // At this moment, the objectInfo.getHeader() do not have the
     // attribute ids.
     // but later in this code, the attributes will be set, so the class
     // info also will have them
     classInfo.LastObjectInfoHeader = objectInfo.GetHeader();
     // // Saves the fact that something has changed in the class (number of
     // objects and/or last object oid)
     _storageEngine.GetSession().GetMetaModel().AddChangedClass(classInfo);
 }
示例#16
0
        /// <summary>
        ///   PersistTo a single class info - This method is used by the XML Importer.
        /// </summary>
        /// <remarks>
        ///   PersistTo a single class info - This method is used by the XML Importer.
        /// </remarks>
        private ClassInfo PersistClass(ClassInfo newClassInfo, int lastClassInfoIndex, bool addClass,
                                              bool addDependentClasses)
        {
            var metaModel = _session.GetMetaModel();
            var classInfoId = newClassInfo.ClassInfoId;
            if (classInfoId == null)
            {
                classInfoId = GetIdManager().GetNextClassId(-1);
                newClassInfo.ClassInfoId = classInfoId;
            }
            var writePosition = FileSystemProcessor.FileSystemInterface.GetAvailablePosition();
            newClassInfo.Position = writePosition;
            GetIdManager().UpdateClassPositionForId(classInfoId, writePosition, true);

            #region Logging

            if (OdbConfiguration.IsLoggingEnabled())
            {
                var writePositionAsString = writePosition.ToString();
                DLogger.Debug(
                    string.Format("ObjectWriter: Persisting class into database : {0} with oid {1} at pos ",
                                  newClassInfo.FullClassName, classInfoId) + writePositionAsString);

                var numberOfAttributesAsString = newClassInfo.NumberOfAttributes.ToString();
                DLogger.Debug("ObjectWriter: class " + newClassInfo.FullClassName + " has " + numberOfAttributesAsString + " attributes");
            }

            #endregion

            // The class info oid is created in ObjectWriter.writeClassInfoHeader
            if (metaModel.GetNumberOfClasses() > 0 && lastClassInfoIndex != -2)
            {
                var lastClassinfo = lastClassInfoIndex == -1
                                        ? metaModel.GetLastClassInfo()
                                        : metaModel.GetClassInfo(lastClassInfoIndex);

                lastClassinfo.NextClassOID = newClassInfo.ClassInfoId;

                #region Logging

                if (OdbConfiguration.IsLoggingEnabled())
                {
                    var positionAsString = lastClassinfo.Position.ToString();
                    var classOffsetAsString = StorageEngineConstant.ClassOffsetNextClassPosition.ToString();
                    DLogger.Debug("ObjectWriter: changing next class oid. of class info " + lastClassinfo.FullClassName + "@ " +
                                  positionAsString + " + offset " + classOffsetAsString +
                                  string.Format(" to {0}({1})", newClassInfo.ClassInfoId, newClassInfo.FullClassName));
                }

                #endregion

                FileSystemProcessor.FileSystemInterface.SetWritePosition(lastClassinfo.Position + StorageEngineConstant.ClassOffsetNextClassPosition,
                                      true);

                FileSystemProcessor.FileSystemInterface.WriteLong(newClassInfo.ClassInfoId.ObjectId, true); // next class oid

                newClassInfo.PreviousClassOID = lastClassinfo.ClassInfoId;
            }

            if (addClass)
                metaModel.AddClass(newClassInfo);

            // updates number of classes
            FileSystemProcessor.WriteNumberOfClasses(metaModel.GetNumberOfClasses(), true);
            // If it is the first class , updates the first class OID
            if (newClassInfo.PreviousClassOID == null)
                FileSystemProcessor.WriteFirstClassInfoOID(newClassInfo.ClassInfoId, true);

            // Writes the header of the class - out of transaction (FIXME why out of
            // transaction)
            WriteClassInfoHeader(newClassInfo, writePosition, false);

            if (addDependentClasses)
            {
                var dependingAttributes = newClassInfo.GetAllNonNativeAttributes();

                UpdateClass(dependingAttributes, metaModel);
            }

            WriteClassInfoBody(newClassInfo, FileSystemProcessor.FileSystemInterface.GetAvailablePosition(), true);
            return newClassInfo;
        }
示例#17
0
 internal void SetClassInfo(ClassInfo classInfo)
 {
     _classInfo = classInfo;
 }
示例#18
0
 public PendingReading(int id, ClassInfo ci, OID attributeOID)
 {
     _id = id;
     _ci = ci;
     _attributeOID = attributeOID;
 }
示例#19
0
 internal void SetClassInfo(ClassInfo classInfo)
 {
     _classInfo = classInfo;
 }
示例#20
0
        public void UpdateClassInfo(ClassInfo classInfo, bool writeInTransaction)
        {
            // first check dependent classes
            var dependingAttributes = classInfo.GetAllNonNativeAttributes();
            var metaModel = _session.GetMetaModel();

            UpdateClass(dependingAttributes, metaModel);

            // To force the rewrite of class info body
            classInfo.AttributesDefinitionPosition = -1;
            var newCiPosition = FileSystemProcessor.FileSystemInterface.GetAvailablePosition();
            classInfo.Position = newCiPosition;
            WriteClassInfoHeader(classInfo, newCiPosition, writeInTransaction);
            WriteClassInfoBody(classInfo, FileSystemProcessor.FileSystemInterface.GetAvailablePosition(), writeInTransaction);
        }
示例#21
0
        public ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
        {
            string             attributeName;
            ClassAttributeInfo cai1;
            ClassAttributeInfo cai2;

            var result = new ClassInfoCompareResult(FullClassName);
            IOdbList <ClassAttributeInfo> attributesToRemove = new OdbList <ClassAttributeInfo>(10);
            IOdbList <ClassAttributeInfo> attributesToAdd    = new OdbList <ClassAttributeInfo>(10);

            var attributesCount = _attributes.Count;

            for (var id = 0; id < attributesCount; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai1 = _attributes[id];
                if (cai1 == null)
                {
                    continue;
                }
                attributeName = cai1.GetName();
                cai2          = newCI.GetAttributeInfoFromId(cai1.GetId());
                if (cai2 == null)
                {
                    result.AddCompatibleChange(string.Format("Field '{0}' has been removed", attributeName));
                    if (update)
                    {
                        // Simply remove the attribute from meta-model
                        attributesToRemove.Add(cai1);
                    }
                }
                else
                {
                    if (!OdbType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
                    {
                        result.AddIncompatibleChange(
                            string.Format("Type of Field '{0}' has changed : old='{1}' - new='{2}'", attributeName,
                                          cai1.GetFullClassname(), cai2.GetFullClassname()));
                    }
                }
            }

            var nbNewAttributes = newCI._attributes.Count;

            for (var id = 0; id < nbNewAttributes; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai2 = newCI._attributes[id];
                if (cai2 == null)
                {
                    continue;
                }
                attributeName = cai2.GetName();
                cai1          = GetAttributeInfoFromId(cai2.GetId());
                if (cai1 == null)
                {
                    result.AddCompatibleChange("Field '" + attributeName + "' has been added");
                    if (update)
                    {
                        // Sets the right id of attribute
                        cai2.SetId(MaxAttributeId + 1);
                        MaxAttributeId++;
                        // Then adds the new attribute to the meta-model
                        attributesToAdd.Add(cai2);
                    }
                }
            }
            _attributes.RemoveAll(attributesToRemove);
            _attributes.AddAll(attributesToAdd);
            FillAttributesMap();
            return(result);
        }
示例#22
0
        /// <summary>
        ///   Updates the instance related field of the class info into the database file Updates the number of objects, the first object oid and the next class oid
        /// </summary>
        /// <param name="classInfo"> The class info to be updated </param>
        /// <param name="writeInTransaction"> To specify if it must be part of a transaction @ </param>
        public void UpdateInstanceFieldsOfClassInfo(ClassInfo classInfo, bool writeInTransaction)
        {
            var currentPosition = FileSystemInterface.GetPosition();

            var position = classInfo.Position + StorageEngineConstant.ClassOffsetClassNbObjects;
            FileSystemInterface.SetWritePosition(position, writeInTransaction);
            var nbObjects = classInfo.NumberOfObjects;
            FileSystemInterface.WriteLong(nbObjects, writeInTransaction); //class info update nb objects
            WriteOid(classInfo.CommitedZoneInfo.First, writeInTransaction); // class info update first obj oid
            WriteOid(classInfo.CommitedZoneInfo.Last, writeInTransaction); // class info update last obj oid
            
            FileSystemInterface.SetWritePosition(currentPosition, writeInTransaction);
        }
示例#23
0
        /// <summary>
        ///   Read the class info header with the specific oid
        /// </summary>
        /// <returns> The read class info object @ </returns>
        public ClassInfo ReadClassInfoHeader(OID classInfoOid)
        {
            if (OdbConfiguration.IsLoggingEnabled())
                DLogger.Debug("FileSystemReader: Reading new Class info Header with oid " + classInfoOid);
            var classInfoPosition = GetObjectPositionFromItsOid(classInfoOid, true, true);
            _fsi.SetReadPosition(classInfoPosition);
            var blockSize = _fsi.ReadInt();
            var blockType = _fsi.ReadByte();
            if (!BlockTypes.IsClassHeader(blockType))
            {
                throw new OdbRuntimeException(
                    NDatabaseError.WrongTypeForBlockType.AddParameter("Class Header").AddParameter(blockType).
                        AddParameter(classInfoPosition));
            }
            //class info category, to remove
            _fsi.ReadByte();

            var classInfoId = OIDFactory.BuildClassOID(_fsi.ReadLong());
            var previousClassOID = ReadOid();
            var nextClassOID = ReadOid();
            var nbObjects = _fsi.ReadLong();
            var originalZoneInfoFirst = ReadOid();
            var originalZoneInfoLast = ReadOid();
            var fullClassName = _fsi.ReadString();
            var maxAttributeId = _fsi.ReadInt();
            var attributesDefinitionPosition = _fsi.ReadLong();

            var classInfo = new ClassInfo(fullClassName)
            {
                Position = classInfoPosition,
                ClassInfoId = classInfoId,
                PreviousClassOID = previousClassOID,
                NextClassOID = nextClassOID,
                MaxAttributeId = maxAttributeId,
                AttributesDefinitionPosition = attributesDefinitionPosition
            };

            classInfo.OriginalZoneInfo.SetNbObjects(nbObjects);
            classInfo.OriginalZoneInfo.First = originalZoneInfoFirst;
            classInfo.OriginalZoneInfo.Last = originalZoneInfoLast;
            classInfo.CommitedZoneInfo.SetBasedOn(classInfo.OriginalZoneInfo);

            // FIXME Convert block size to long ??
            var realBlockSize = (int)(_fsi.GetPosition() - classInfoPosition);
            if (blockSize != realBlockSize)
            {
                throw new OdbRuntimeException(
                    NDatabaseError.WrongBlockSize.AddParameter(blockSize).AddParameter(realBlockSize).AddParameter(
                        classInfoPosition));
            }
            return classInfo;
        }
示例#24
0
文件: MetaModel.cs 项目: Myvar/Eclang
 /// <summary>
 ///   Saves the fact that something has changed in the class (number of objects or last object oid)
 /// </summary>
 public void AddChangedClass(ClassInfo classInfo)
 {
     _changedClasses[classInfo] = classInfo;
     _hasChanged = true;
 }