private static IEnumerable <Trigger> GetListOfTriggersFor(Type type,
                                                                  IDictionary <Type, IOdbList <Trigger> > listOfTriggers)
        {
            var listOfTriggersByClassName       = listOfTriggers[type];
            var listOfTriggersByAllClassTrigger = listOfTriggers[typeof(object)];

            if (listOfTriggersByAllClassTrigger != null)
            {
                var size = listOfTriggersByAllClassTrigger.Count;
                if (listOfTriggersByClassName != null)
                {
                    size = size + listOfTriggersByClassName.Count;
                }

                var listOfTriggersToReturn = new OdbList <Trigger>(size);

                if (listOfTriggersByClassName != null)
                {
                    listOfTriggersToReturn.AddRange(listOfTriggersByClassName);
                }

                listOfTriggersToReturn.AddRange(listOfTriggersByAllClassTrigger);
                return(listOfTriggersToReturn);
            }

            return(listOfTriggersByClassName);
        }
Exemple #2
0
        /// <summary>
        ///   Builds a class info from a class and an existing class info
        ///   The existing class info is used to make sure that fields with the same name will have the same id
        /// </summary>
        /// <param name="fullClassName"> The name of the class to get info </param>
        /// <param name="existingClassInfo"> </param>
        /// <returns> A ClassInfo - a meta representation of the class </returns>
        private static ClassInfo GetClassInfo(String fullClassName, ClassInfo existingClassInfo)
        {
            var type      = TypeResolutionUtils.ResolveType(fullClassName);
            var classInfo = new ClassInfo(type);

            var fields     = GetAllFieldsFrom(type);
            var attributes = new OdbList <ClassAttributeInfo>(fields.Count);

            var maxAttributeId = existingClassInfo.MaxAttributeId;

            foreach (var fieldInfo in fields)
            {
                // Gets the attribute id from the existing class info
                var attributeId = existingClassInfo.GetAttributeId(fieldInfo.Name);
                if (attributeId == -1)
                {
                    maxAttributeId++;
                    // The attribute with field.getName() does not exist in existing class info
                    //  create a new id
                    attributeId = maxAttributeId;
                }
                var fieldClassInfo = !OdbType.GetFromClass(fieldInfo.FieldType).IsNative()
                                         ? new ClassInfo(fieldInfo.FieldType)
                                         : null;

                attributes.Add(new ClassAttributeInfo(attributeId, fieldInfo.Name, fieldInfo.FieldType,
                                                      OdbClassNameResolver.GetFullName(fieldInfo.FieldType), fieldClassInfo));
            }

            classInfo.Attributes     = attributes;
            classInfo.MaxAttributeId = maxAttributeId;

            return(classInfo);
        }
Exemple #3
0
        public IEnumerable <ClassInfo> GetChangedClassInfo()
        {
            IOdbList <ClassInfo> list = new OdbList <ClassInfo>();

            list.AddAll(_changedClasses.Keys);

            return(new ReadOnlyCollection <ClassInfo>(list));
        }
Exemple #4
0
        /// <param name="type"> The class to introspect </param>
        /// <param name="recursive"> If true, goes does the hierarchy to try to analyze all classes </param>
        /// <param name="classInfoList"> map with class name that are being introspected, to avoid recursive calls </param>
        private static ClassInfoList InternalIntrospect(Type type, bool recursive, ClassInfoList classInfoList)
        {
            if (classInfoList != null)
            {
                var existingClassInfo = classInfoList.GetClassInfoBy(type);

                if (existingClassInfo != null)
                {
                    return(classInfoList);
                }
            }

            var classInfo = new ClassInfo(type);

            if (classInfoList == null)
            {
                classInfoList = new ClassInfoList(classInfo);
            }
            else
            {
                classInfoList.AddClassInfo(classInfo);
            }

            var fields     = GetAllFieldsFrom(type);
            var attributes = new OdbList <ClassAttributeInfo>(fields.Count);

            for (var i = 0; i < fields.Count; i++)
            {
                var field = fields[i];

                ClassInfo classInfoByName;

                if (OdbType.GetFromClass(field.FieldType).IsNative())
                {
                    classInfoByName = null;
                }
                else
                {
                    if (recursive)
                    {
                        classInfoList   = InternalIntrospect(field.FieldType, true, classInfoList);
                        classInfoByName = classInfoList.GetClassInfoBy(field.FieldType);
                    }
                    else
                    {
                        classInfoByName = new ClassInfo(field.FieldType);
                    }
                }

                attributes.Add(new ClassAttributeInfo((i + 1), field.Name, field.FieldType,
                                                      OdbClassNameResolver.GetFullName(field.FieldType), classInfoByName));
            }

            classInfo.Attributes     = attributes;
            classInfo.MaxAttributeId = fields.Count;

            return(classInfoList);
        }
        public override IOdbList<string> GetAllInvolvedFields()
        {
            var fields = new OdbList<string>(10);

            foreach (var constraint in Constraints)
                FilterOutDuplicates(((IInternalConstraint)constraint).GetAllInvolvedFields(), fields);

            return fields;
        }
Exemple #6
0
        public override IOdbList <string> GetAllInvolvedFields()
        {
            var fields = new OdbList <string>(10);

            foreach (var constraint in Constraints)
            {
                FilterOutDuplicates(((IInternalConstraint)constraint).GetAllInvolvedFields(), fields);
            }

            return(fields);
        }
Exemple #7
0
        private static IEnumerable <FieldInfo> FilterFields(ICollection <FieldInfo> fields)
        {
            var fieldsToRemove = new OdbList <FieldInfo>(fields.Count);

            foreach (var fieldInfo in fields)
            {
                if (fieldInfo.IsNotSerialized)
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else if (fieldInfo.FieldType == typeof(IntPtr))
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else if (fieldInfo.FieldType == typeof(UIntPtr))
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else if (fieldInfo.FieldType == typeof(void *))
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else if (fieldInfo.FieldType == typeof(Pointer))
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else if (fieldInfo.FieldType.FullName.StartsWith("System.Reflection.CerHashtable"))
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else if (fieldInfo.Name.StartsWith("this$"))
                {
                    fieldsToRemove.Add(fieldInfo);
                }
                else
                {
                    var oattr           = fieldInfo.GetCustomAttributes(true);
                    var isNonPersistent = oattr.OfType <NonPersistentAttribute>().Any();

                    if (isNonPersistent)
                    {
                        fieldsToRemove.Add(fieldInfo);
                    }
                }
            }

            foreach (var item in fieldsToRemove)
            {
                fields.Remove(item);
            }

            return(fields);
        }
        private static void AddTriggerFor <TTrigger>(Type type, TTrigger trigger,
                                                     IDictionary <Type, IOdbList <Trigger> > listOfTriggers)
            where TTrigger : Trigger
        {
            var triggers = listOfTriggers[type];

            if (triggers == null)
            {
                triggers = new OdbList <Trigger>();
                listOfTriggers.Add(type, triggers);
            }

            triggers.Add(trigger);
        }
Exemple #9
0
        public void Test_if_odb_list_is_properly_stored()
        {
            IOdbList<string> list = new OdbList<string> {"one", "two"};
            const string dbName = "list.ndb";

            OdbFactory.Delete(dbName);

            using (var odb = OdbFactory.Open(dbName))
            {
                odb.Store(list);
            }
            
            using (var odb = OdbFactory.Open(dbName))
            {
                var items = odb.Query<IOdbList<string>>().Execute<IOdbList<string>>().First();
                CollectionAssert.AreEqual(items, list);

                var items2 = odb.Query<OdbList<string>>().Execute<OdbList<string>>().First();
                CollectionAssert.AreEqual(items2, list);
            }
        }
Exemple #10
0
        public void Test_if_odb_list_is_properly_stored()
        {
            IOdbList <string> list = new OdbList <string> {
                "one", "two"
            };
            const string dbName = "list.ndb";

            OdbFactory.Delete(dbName);

            using (var odb = OdbFactory.Open(dbName))
            {
                odb.Store(list);
            }

            using (var odb = OdbFactory.Open(dbName))
            {
                var items = odb.Query <IOdbList <string> >().Execute <IOdbList <string> >().First();
                CollectionAssert.AreEqual(items, list);

                var items2 = odb.Query <OdbList <string> >().Execute <OdbList <string> >().First();
                CollectionAssert.AreEqual(items2, list);
            }
        }
Exemple #11
0
        /// <summary>
        ///   This method could be optimized, but it is only on Class creation, one time in the database life time...
        /// </summary>
        /// <remarks>
        ///   This method could be optimized, but it is only on Class creation, one time in the database life time...
        ///   This is used to get all (non native) attributes a class info have to store them in the meta model
        ///   before storing the class itself
        /// </remarks>
        internal IOdbList <ClassAttributeInfo> GetAllNonNativeAttributes()
        {
            IOdbList <ClassAttributeInfo> result = new OdbList <ClassAttributeInfo>(_attributes.Count);

            foreach (var classAttributeInfo in _attributes)
            {
                if (!classAttributeInfo.IsNative() || classAttributeInfo.GetAttributeType().IsEnum())
                {
                    result.Add(classAttributeInfo);
                }
                else
                {
                    if (classAttributeInfo.GetAttributeType().IsArray() &&
                        !classAttributeInfo.GetAttributeType().SubType.IsNative())
                    {
                        result.Add(new ClassAttributeInfo(-1, "subtype",
                                                          classAttributeInfo.GetAttributeType().SubType.Name, null));
                    }
                }
            }

            return(result);
        }
Exemple #12
0
        /// <summary>
        ///   This method could be optimized, but it is only on Class creation, one time in the database life time...
        /// </summary>
        /// <remarks>
        ///   This method could be optimized, but it is only on Class creation, one time in the database life time... 
        ///   This is used to get all (non native) attributes a class info have to store them in the meta model
        ///   before storing the class itself
        /// </remarks>
        internal IOdbList<ClassAttributeInfo> GetAllNonNativeAttributes()
        {
            IOdbList<ClassAttributeInfo> result = new OdbList<ClassAttributeInfo>(_attributes.Count);

            foreach (var classAttributeInfo in _attributes)
            {
                if (!classAttributeInfo.IsNative() || classAttributeInfo.GetAttributeType().IsEnum())
                    result.Add(classAttributeInfo);
                else
                {
                    if (classAttributeInfo.GetAttributeType().IsArray() &&
                        !classAttributeInfo.GetAttributeType().SubType.IsNative())
                        result.Add(new ClassAttributeInfo(-1, "subtype",
                                                          classAttributeInfo.GetAttributeType().SubType.Name, null));
                }
            }

            return result;
        }
        private static IEnumerable<FieldInfo> FilterFields(ICollection<FieldInfo> fields)
        {
            var fieldsToRemove = new OdbList<FieldInfo>(fields.Count);

            foreach (var fieldInfo in fields)
            {
                if (fieldInfo.IsNotSerialized)
                    fieldsToRemove.Add(fieldInfo);
                else if (fieldInfo.FieldType == typeof (IntPtr))
                    fieldsToRemove.Add(fieldInfo);
                else if (fieldInfo.FieldType == typeof (UIntPtr))
                    fieldsToRemove.Add(fieldInfo);
                else if (fieldInfo.FieldType == typeof (void*))
                    fieldsToRemove.Add(fieldInfo);
                else if (fieldInfo.FieldType == typeof (Pointer))
                    fieldsToRemove.Add(fieldInfo);
                else if (fieldInfo.FieldType.FullName.StartsWith("System.Reflection.CerHashtable"))
                    fieldsToRemove.Add(fieldInfo);
                else if (fieldInfo.Name.StartsWith("this$"))
                    fieldsToRemove.Add(fieldInfo);
                else
                {
                    var oattr = fieldInfo.GetCustomAttributes(true);
                    var isNonPersistent = oattr.OfType<NonPersistentAttribute>().Any();

                    if (isNonPersistent)
                        fieldsToRemove.Add(fieldInfo);
                }
            }

            foreach (var item in fieldsToRemove)
                fields.Remove(item);

            return fields;
        }
        /// <param name="type"> The class to introspect </param>
        /// <param name="recursive"> If true, goes does the hierarchy to try to analyze all classes </param>
        /// <param name="classInfoList"> map with class name that are being introspected, to avoid recursive calls </param>
        private static ClassInfoList InternalIntrospect(Type type, bool recursive, ClassInfoList classInfoList)
        {
            if (classInfoList != null)
            {
                var existingClassInfo = classInfoList.GetClassInfoBy(type);

                if (existingClassInfo != null)
                    return classInfoList;
            }

            var classInfo = new ClassInfo(type);

            if (classInfoList == null)
                classInfoList = new ClassInfoList(classInfo);
            else
                classInfoList.AddClassInfo(classInfo);

            var fields = GetAllFieldsFrom(type);
            var attributes = new OdbList<ClassAttributeInfo>(fields.Count);

            for (var i = 0; i < fields.Count; i++)
            {
                var field = fields[i];

                ClassInfo classInfoByName;

                if (OdbType.GetFromClass(field.FieldType).IsNative())
                {
                    classInfoByName = null;
                }
                else
                {
                    if (recursive)
                    {
                        classInfoList = InternalIntrospect(field.FieldType, true, classInfoList);
                        classInfoByName = classInfoList.GetClassInfoBy(field.FieldType);
                    }
                    else
                        classInfoByName = new ClassInfo(field.FieldType);
                }

                attributes.Add(new ClassAttributeInfo((i + 1), field.Name, field.FieldType,
                                                      OdbClassNameResolver.GetFullName(field.FieldType), classInfoByName));
            }

            classInfo.Attributes = attributes;
            classInfo.MaxAttributeId = fields.Count;

            return classInfoList;
        }
        /// <summary>
        ///   Builds a class info from a class and an existing class info 
        ///   The existing class info is used to make sure that fields with the same name will have the same id
        /// </summary>
        /// <param name="fullClassName"> The name of the class to get info </param>
        /// <param name="existingClassInfo"> </param>
        /// <returns> A ClassInfo - a meta representation of the class </returns>
        private static ClassInfo GetClassInfo(String fullClassName, ClassInfo existingClassInfo)
        {
            var type = TypeResolutionUtils.ResolveType(fullClassName);
            var classInfo = new ClassInfo(type);

            var fields = GetAllFieldsFrom(type);
            var attributes = new OdbList<ClassAttributeInfo>(fields.Count);

            var maxAttributeId = existingClassInfo.MaxAttributeId;
            foreach (var fieldInfo in fields)
            {
                // Gets the attribute id from the existing class info
                var attributeId = existingClassInfo.GetAttributeId(fieldInfo.Name);
                if (attributeId == - 1)
                {
                    maxAttributeId++;
                    // The attribute with field.getName() does not exist in existing class info
                    //  create a new id
                    attributeId = maxAttributeId;
                }
                var fieldClassInfo = !OdbType.GetFromClass(fieldInfo.FieldType).IsNative()
                                         ? new ClassInfo(fieldInfo.FieldType)
                                         : null;

                attributes.Add(new ClassAttributeInfo(attributeId, fieldInfo.Name, fieldInfo.FieldType,
                                                      OdbClassNameResolver.GetFullName(fieldInfo.FieldType), fieldClassInfo));
            }

            classInfo.Attributes = attributes;
            classInfo.MaxAttributeId = maxAttributeId;

            return classInfo;
        }
Exemple #16
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);
        }
Exemple #17
0
        public IEnumerable<ClassInfo> GetChangedClassInfo()
        {
            IOdbList<ClassInfo> list = new OdbList<ClassInfo>();
            list.AddAll(_changedClasses.Keys);

            return new ReadOnlyCollection<ClassInfo>(list);
        }
Exemple #18
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;
        }
        /// <summary>
        ///   Returns the list of involved fields for this query.
        /// </summary>
        /// <remarks>
        ///   Returns the list of involved fields for this query. List of String <pre>If query must return sum("value") and field("name"), involvedField will contain "value","name"</pre>
        /// </remarks>
        public override IOdbList <string> GetAllInvolvedFields()
        {
            IOdbList <string> list = new OdbList <string>();

            // To check field duplicity
            IDictionary <string, string> map = new OdbHashMap <string, string>();

            list.AddAll(base.GetAllInvolvedFields());

            if (!list.IsNullOrEmpty())
            {
                foreach (var value in list)
                {
                    map.Add(value, value);
                }
            }

            var    iterator = _objectActions.GetEnumerator();
            string name;

            while (iterator.MoveNext())
            {
                var queryFieldAction = iterator.Current;
                if (queryFieldAction is CountAction)
                {
                    continue;
                }

                name = queryFieldAction.GetAttributeName();
                if (map.ContainsKey(name))
                {
                    continue;
                }

                list.Add(name);
                map.Add(name, name);
            }

            if (_hasGroupBy)
            {
                foreach (var groupByField in _groupByFieldList)
                {
                    name = groupByField;

                    if (map.ContainsKey(name))
                    {
                        continue;
                    }

                    list.Add(name);
                    map.Add(name, name);
                }
            }

            if (HasOrderBy())
            {
                foreach (var field in OrderByFields)
                {
                    name = field;
                    if (map.ContainsKey(name))
                    {
                        continue;
                    }

                    list.Add(name);
                    map.Add(name, name);
                }
            }
            map.Clear();

            return(list);
        }
 public LazySimpleListFromOid(IStorageEngine engine, bool returnObjects)
 {
     _engine         = engine;
     _returnInstance = returnObjects;
     _oids           = new OdbList <OID>();
 }