示例#1
0
 public virtual void AddAttribute(ClassAttributeInfo
                                  cai)
 {
     cai.SetId(maxAttributeId++);
     attributes.Add(cai);
     attributesByName.Add(cai.GetName(), cai);
 }
示例#2
0
        /// <summary>To detect if a class has cyclic reference</summary>
        /// <param name="alreadyVisitedClasses">A hashmap containg all the already visited classes
        ///     </param>
        /// <returns>true if this class info has cyclic references</returns>
        private bool HasCyclicReference(System.Collections.Generic.IDictionary <string, ClassInfo
                                                                                > alreadyVisitedClasses)
        {
            ClassAttributeInfo cai = null;
            bool hasCyclicRef      = false;

            if (alreadyVisitedClasses[fullClassName] != null)
            {
                return(true);
            }
            System.Collections.Generic.IDictionary <string, ClassInfo
                                                    > localMap = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <string, ClassInfo
                                                                                                            >();
            alreadyVisitedClasses.Add(fullClassName, this);
            for (int i = 0; i < attributes.Count; i++)
            {
                cai = GetAttributeInfo(i);
                if (!cai.IsNative())
                {
                    localMap = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <string, ClassInfo
                                                                          >(alreadyVisitedClasses);
                    hasCyclicRef = cai.GetClassInfo().HasCyclicReference(localMap);
                    if (hasCyclicRef)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#3
0
                                                             > GetAllNonNativeAttributes()
        {
            NeoDatis.Tool.Wrappers.List.IOdbList <ClassAttributeInfo
                                                  > result = new NeoDatis.Tool.Wrappers.List.OdbArrayList <ClassAttributeInfo
                                                                                                           >(attributes.Count);
            ClassAttributeInfo cai = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                cai = attributes[i];
                if (!cai.IsNative() || cai.GetAttributeType().IsEnum())
                {
                    result.Add(cai);
                }
                else
                {
                    if (cai.GetAttributeType().IsArray() && !cai.GetAttributeType().GetSubType().IsNative
                            ())
                    {
                        result.Add(new ClassAttributeInfo(-1, "subtype"
                                                          , cai.GetAttributeType().GetSubType().GetName(), null));
                    }
                }
            }
            return(result);
        }
示例#4
0
        public virtual int GetAttributeId(string name)
        {
            ClassAttributeInfo cai = attributesByName[name
                                     ];

            if (cai == null)
            {
                return(-1);
            }
            return(cai.GetId());
        }
示例#5
0
        private void FillAttributesMap()
        {
            ClassAttributeInfo cai = null;

            if (attributesByName == null)
            {
                attributesByName = new OdbHashMap <string, ClassAttributeInfo>();
                attributesById   = new OdbHashMap <int, ClassAttributeInfo>();
            }
            // attributesMap.clear();
            for (int i = 0; i < attributes.Count; i++)
            {
                cai = attributes[i];
                attributesByName[cai.GetName()] = cai;
                attributesById[cai.GetId()]     = cai;
            }
        }
示例#6
0
 public override string ToString()
 {
     System.Text.StringBuilder buffer = new System.Text.StringBuilder();
     buffer.Append(" [ ").Append(fullClassName).Append(" - id=").Append(id);
     buffer.Append(" - previousClass=").Append(previousClassOID).Append(" - nextClass="
                                                                        ).Append(nextClassOID).Append(" - attributes=(");
     // buffer.append(" | position=").append(position);
     // buffer.append(" | class=").append(className).append(" | attributes=[");
     if (attributes != null)
     {
         for (int i = 0; i < attributes.Count; i++)
         {
             ClassAttributeInfo cai = (ClassAttributeInfo
                                       )attributes[i];
             buffer.Append(cai.GetName()).Append(",");
         }
     }
     else
     {
         buffer.Append("not yet defined");
     }
     buffer.Append(") ]");
     return(buffer.ToString());
 }
示例#7
0
 public virtual void RemoveAttribute(ClassAttributeInfo
                                     cai)
 {
     attributes.Remove(cai);
     attributesByName.Remove(cai.GetName());
 }
示例#8
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);
        }