Пример #1
0
        protected AbstractObjectInfo(OdbType type)
        {
            if (type != null)
                OdbTypeId = type.Id;

            _odbType = type;
        }
Пример #2
0
        public static bool TypesAreCompatible(OdbType type1, OdbType type2)
        {
            if (type1 == null || type2 == null)
            {
                return(false);
            }

            if (type1.IsArray() && type2.IsArray())
            {
                return(TypesAreCompatible(type1.SubType, type2.SubType));
            }

            if (type1.Name.Equals(type2.Name))
            {
                return(true);
            }

            if (type1.IsEnum() && type2.IsEnum())
            {
                return(type1.GetNativeClass() == type2.GetNativeClass());
            }

            if (type1.IsNative() && type2.IsNative())
            {
                return(type1.IsEquivalent(type2));
            }

            if (type1.IsNonNative() && type2.IsNonNative())
            {
                return((type1.GetNativeClass() == type2.GetNativeClass()) ||
                       (type1.GetNativeClass().IsAssignableFrom(type2.GetNativeClass())));
            }

            return(false);
        }
Пример #3
0
        protected AbstractObjectInfo(OdbType type)
        {
            if (type != null)
            {
                OdbTypeId = type.Id;
            }

            _odbType = type;
        }
Пример #4
0
        private NonNativeObjectInfo(object @object, ClassInfo info, AbstractObjectInfo[] values,
                                    long[] attributesIdentification, int[] attributeIds)
            : base(OdbType.GetFromName(info.FullClassName))
        {
            _theObject       = @object;
            _classInfo       = info;
            _attributeValues = values;
            _maxNbattributes = _classInfo.MaxAttributeId;

            if (_attributeValues == null)
            {
                _attributeValues = new AbstractObjectInfo[_maxNbattributes];
            }

            _objectHeader = new ObjectInfoHeader(-1, null, null, (_classInfo != null
                                                                      ? _classInfo.ClassInfoId
                                                                      : null), attributesIdentification, attributeIds);
        }
Пример #5
0
        private AbstractObjectInfo GetNativeObjectInfoInternal(OdbType type, object o, bool recursive,
                                                               IDictionary<object, NonNativeObjectInfo>
                                                                   alreadyReadObjects, IIntrospectionCallback callback)
        {
            AbstractObjectInfo aoi = null;
            if (type.IsAtomicNative())
            {
                if (o == null)
                    aoi = new NullNativeObjectInfo(type.Id);
                else
                    aoi = new AtomicNativeObjectInfo(o, type.Id);
            }
            else if (type.IsArray())
            {
                if (o == null)
                    aoi = new ArrayObjectInfo(null);
                else
                {
                    // Gets the type of the elements of the array
                    var realArrayClassName = OdbClassNameResolver.GetFullName(o.GetType().GetElementType());
                    var arrayObjectInfo = recursive
                                              ? IntrospectArray(o, alreadyReadObjects, type, callback)
                                              : new ArrayObjectInfo((object[]) o);

                    arrayObjectInfo.SetRealArrayComponentClassName(realArrayClassName);
                    aoi = arrayObjectInfo;
                }
            }
            else if (type.IsEnum())
            {
                var enumObject = (Enum) o;
                
                // Here we must check if the enum is already in the meta model. Enum must be stored in the meta
                // model to optimize its storing as we need to keep track of the enum class
                // for each enum stored. So instead of storing the enum class name, we can store enum class id, a long
                // instead of the full enum class name string
                var classInfo = GetClassInfo(enumObject.GetType());
                var enumValue = enumObject.ToString();
                aoi = new EnumNativeObjectInfo(classInfo, enumValue);
            }

            return aoi;
        }
Пример #6
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;
        }
Пример #7
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;
        }
Пример #8
0
        public static OdbType GetFromClass(Type clazz)
        {
            if (clazz.IsEnum)
            {
                return(new OdbType(Enum._isPrimitive, EnumId, OdbClassNameResolver.GetFullName(clazz), 0));
            }

            var className = OdbClassNameResolver.GetFullName(clazz);

            // First check if it is a 'default type'
            OdbType odbType;
            var     success = TypesByName.TryGetValue(className, out odbType);

            if (success)
            {
                return(odbType);
            }

            // Then check if it is a 'non default type'
            success = CacheOfTypesByName.TryGetValue(className, out odbType);
            if (success)
            {
                return(odbType);
            }

            if (clazz.IsArray)
            {
                var type = new OdbType(Array._isPrimitive, ArrayId, Array.Name, 0)
                {
                    _subType = GetFromClass(clazz.GetElementType())
                };

                return(CacheOfTypesByName.GetOrAdd(className, type));
            }

            var nonNative = new OdbType(NonNative._isPrimitive, NonNativeId, className, 0);

            return(CacheOfTypesByName.GetOrAdd(className, nonNative));
        }
Пример #9
0
 private bool IsEquivalent(OdbType type2)
 {
     return(_id == IntegerId && type2._id == IntegerId);
 }
Пример #10
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);
        }
Пример #11
0
 internal void SetAttributeType(OdbType attributeType)
 {
     _attributeType = attributeType;
 }
Пример #12
0
        public static OdbType GetFromClass(Type clazz)
        {
            if (clazz.IsEnum)
                return new OdbType(Enum._isPrimitive, EnumId, OdbClassNameResolver.GetFullName(clazz), 0);

            var className = OdbClassNameResolver.GetFullName(clazz);

            // First check if it is a 'default type'
            OdbType odbType;
            var success = TypesByName.TryGetValue(className, out odbType);
            if (success)
                return odbType;

            // Then check if it is a 'non default type'
            success = CacheOfTypesByName.TryGetValue(className, out odbType);
            if (success)
                return odbType;

            if (clazz.IsArray)
            {
                var type = new OdbType(Array._isPrimitive, ArrayId, Array.Name, 0)
                               {_subType = GetFromClass(clazz.GetElementType())};

                return CacheOfTypesByName.GetOrAdd(className, type);
            }

            var nonNative = new OdbType(NonNative._isPrimitive, NonNativeId, className, 0);
            return CacheOfTypesByName.GetOrAdd(className, nonNative);
        }
Пример #13
0
 protected AbstractObjectInfo(int typeId)
 {
     OdbTypeId = typeId;
     _odbType = OdbType.GetFromId(OdbTypeId);
 }
Пример #14
0
 public ArrayObjectInfo(IEnumerable array, OdbType type, int componentId) : base(array, type)
 {
     _realArrayComponentClassName = OdbType.DefaultArrayComponentClassName;
     _componentTypeId = componentId;
 }
Пример #15
0
 protected AbstractObjectInfo(int typeId)
 {
     OdbTypeId = typeId;
     _odbType  = OdbType.GetFromId(OdbTypeId);
 }
Пример #16
0
        private static ArrayObjectInfo IntropectAtomicNativeArray(object array, OdbType type)
        {
            var length = ((Array) array).GetLength(0);
            var arrayCopy = new object[length];
            for (var i = 0; i < length; i++)
            {
                var o = ((Array) array).GetValue(i);
                if (o != null)
                {
                    // If object is not null, try to get the exact type
                    var typeId = OdbType.GetFromClass(o.GetType()).Id;
                    var atomicNativeObjectInfo = new AtomicNativeObjectInfo(o, typeId);
                    arrayCopy[i] = atomicNativeObjectInfo;
                }
                else
                {
                    // Else take the declared type
                    arrayCopy[i] = new NullNativeObjectInfo(type.Id);
                }
            }

            return new ArrayObjectInfo(arrayCopy, OdbType.Array, type.Id);
        }
Пример #17
0
        private ArrayObjectInfo IntrospectArray(object array,
                                                IDictionary<object, NonNativeObjectInfo> alreadyReadObjects,
                                                OdbType odbType, IIntrospectionCallback callback)
        {
            var length = ((Array) array).GetLength(0);
            var elementType = array.GetType().GetElementType();
            var type = OdbType.GetFromClass(elementType);

            if (type.IsAtomicNative())
                return IntropectAtomicNativeArray(array, type);

            var arrayCopy = new object[length];
            for (var i = 0; i < length; i++)
            {
                var o = ((Array) array).GetValue(i);
                if (o != null)
                {
                    var classInfo = GetClassInfo(o.GetType());
                    var abstractObjectInfo = GetObjectInfo(o, classInfo, true, alreadyReadObjects, callback);
                    arrayCopy[i] = abstractObjectInfo;
                }
                else
                    arrayCopy[i] = NullNativeObjectInfo.GetInstance();
            }

            return new ArrayObjectInfo(arrayCopy, odbType, type.Id);
        }
Пример #18
0
        public static bool TypesAreCompatible(OdbType type1, OdbType type2)
        {
            if (type1 == null || type2 == null)
                return false;

            if (type1.IsArray() && type2.IsArray())
                return TypesAreCompatible(type1.SubType, type2.SubType);

            if (type1.Name.Equals(type2.Name))
                return true;

            if (type1.IsEnum() && type2.IsEnum())
                return type1.GetNativeClass() == type2.GetNativeClass();

            if (type1.IsNative() && type2.IsNative())
                return type1.IsEquivalent(type2);

            if (type1.IsNonNative() && type2.IsNonNative())
                return (type1.GetNativeClass() == type2.GetNativeClass()) ||
                       (type1.GetNativeClass().IsAssignableFrom(type2.GetNativeClass()));

            return false;
        }
Пример #19
0
        public override string ToString()
        {
            var buffer = new StringBuilder(_classInfo.FullClassName).Append("(").Append(GetOid()).Append(")=");

            if (_attributeValues == null)
            {
                buffer.Append("null attribute values");
                return(buffer.ToString());
            }

            for (var i = 0; i < _attributeValues.Length; i++)
            {
                if (i != 0)
                {
                    buffer.Append(",");
                }

                var attributeName = (_classInfo != null
                                         ? (_classInfo.GetAttributeInfo(i)).GetName()
                                         : "?");

                buffer.Append(attributeName).Append("=");
                object @object = _attributeValues[i];

                if (@object == null)
                {
                    buffer.Append(" null object - should not happen , ");
                }
                else
                {
                    var type = OdbType.GetFromClass(_attributeValues[i].GetType());
                    if (@object is NonNativeNullObjectInfo)
                    {
                        buffer.Append("null");
                        continue;
                    }
                    if (@object is NonNativeDeletedObjectInfo)
                    {
                        buffer.Append("deleted object");
                        continue;
                    }
                    var noi = @object as NativeObjectInfo;
                    if (noi != null)
                    {
                        buffer.Append(noi);
                        continue;
                    }
                    var nnoi = @object as NonNativeObjectInfo;
                    if (nnoi != null)
                    {
                        buffer.Append("@").Append(nnoi.GetClassInfo().FullClassName).Append("(id=").Append(
                            nnoi.GetOid()).Append(")");
                        continue;
                    }
                    if (@object is ObjectReference)
                    {
                        buffer.Append(@object);
                        continue;
                    }
                    buffer.Append("@").Append(OdbClassNameResolver.GetClassName(type.Name));
                }
            }

            return(buffer.ToString());
        }
Пример #20
0
 private bool IsEquivalent(OdbType type2)
 {
     return (_id == IntegerId && type2._id == IntegerId);
 }
Пример #21
0
 public ArrayObjectInfo(IEnumerable array, OdbType type, int componentId) : base(array, type)
 {
     _realArrayComponentClassName = OdbType.DefaultArrayComponentClassName;
     _componentTypeId             = componentId;
 }
Пример #22
0
 internal void SetAttributeType(OdbType attributeType)
 {
     _attributeType = attributeType;
 }