Beispiel #1
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);
        }
        protected AbstractObjectInfo(OdbType type)
        {
            if (type != null)
                OdbTypeId = type.Id;

            _odbType = type;
        }
Beispiel #3
0
        protected AbstractObjectInfo(OdbType type)
        {
            if (type != null)
            {
                OdbTypeId = type.Id;
            }

            _odbType = type;
        }
Beispiel #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);
        }
        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;
        }
Beispiel #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;
        }
Beispiel #7
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));
        }
Beispiel #8
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);
        }
Beispiel #9
0
 internal void SetAttributeType(OdbType attributeType)
 {
     _attributeType = attributeType;
 }
Beispiel #10
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());
        }
Beispiel #11
0
 private bool IsEquivalent(OdbType type2)
 {
     return(_id == IntegerId && type2._id == IntegerId);
 }
Beispiel #12
0
 public ArrayObjectInfo(IEnumerable array, OdbType type, int componentId) : base(array, type)
 {
     _realArrayComponentClassName = OdbType.DefaultArrayComponentClassName;
     _componentTypeId             = componentId;
 }
 internal void SetAttributeType(OdbType attributeType)
 {
     _attributeType = attributeType;
 }
Beispiel #14
0
 protected AbstractObjectInfo(int typeId)
 {
     OdbTypeId = typeId;
     _odbType  = OdbType.GetFromId(OdbTypeId);
 }
Beispiel #15
0
 protected NativeObjectInfo(object @object, OdbType odbType) : base(odbType)
 {
     TheObject = @object;
 }
 protected AbstractObjectInfo(int typeId)
 {
     OdbTypeId = typeId;
     _odbType = OdbType.GetFromId(OdbTypeId);
 }