Ejemplo n.º 1
0
		public virtual ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
		{
			string attributeName = null;
			ClassAttributeInfo cai1 = null;
			ClassAttributeInfo cai2 = null;
			Meta.ClassInfoCompareResult result = new ClassInfoCompareResult(GetFullClassName());
			bool isCompatible = true;
			IOdbList<ClassAttributeInfo> attributesToRemove = new OdbArrayList<ClassAttributeInfo>(10);
			IOdbList<ClassAttributeInfo> attributesToAdd = new OdbArrayList<ClassAttributeInfo>(10);
			int nbAttributes = attributes.Count;
			for (int id = 0; id < nbAttributes; 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("Field '" + attributeName + "' has been removed");
					if (update)
					{
						// Simply remove the attribute from meta-model
						attributesToRemove.Add(cai1);
					}
				}
				else
				{
					if (!ODBType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
					{
						result.AddIncompatibleChange("Type of Field '" + attributeName + "' has changed : old='"
							 + cai1.GetFullClassname() + "' - new='" + cai2.GetFullClassname() + "'");
						isCompatible = false;
					}
				}
			}
			int nbNewAttributes = newCI.attributes.Count;
			for (int 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;
		}
Ejemplo n.º 2
0
        public virtual ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
        {
            string             attributeName = null;
            ClassAttributeInfo cai1          = null;
            ClassAttributeInfo cai2          = null;

            Meta.ClassInfoCompareResult result = new ClassInfoCompareResult(GetFullClassName());
            bool isCompatible = true;
            IOdbList <ClassAttributeInfo> attributesToRemove = new OdbArrayList <ClassAttributeInfo>(10);
            IOdbList <ClassAttributeInfo> attributesToAdd    = new OdbArrayList <ClassAttributeInfo>(10);
            int nbAttributes = attributes.Count;

            for (int id = 0; id < nbAttributes; 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("Field '" + attributeName + "' has been removed");
                    if (update)
                    {
                        // Simply remove the attribute from meta-model
                        attributesToRemove.Add(cai1);
                    }
                }
                else
                {
                    if (!ODBType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
                    {
                        result.AddIncompatibleChange("Type of Field '" + attributeName + "' has changed : old='"
                                                     + cai1.GetFullClassname() + "' - new='" + cai2.GetFullClassname() + "'");
                        isCompatible = false;
                    }
                }
            }
            int nbNewAttributes = newCI.attributes.Count;

            for (int 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);
        }