Esempio n. 1
0
        public virtual void TestPerformanceOid()
        {
            var size   = 300000;
            var oidMap = new OdbHashMap <OID, string>();

            // OID
            var timeOidMapCreation = new StopWatch();

            timeOidMapCreation.Start();
            // Creates a hashmap with 100000 Longs
            for (var i = 0; i < size; i++)
            {
                oidMap.Add(OIDFactory.BuildObjectOID(i), i.ToString());
            }
            timeOidMapCreation.End();
            var timeOidMapGet = new StopWatch();

            timeOidMapGet.Start();
            // get all map elements
            for (var i = 0; i < size; i++)
            {
                AssertNotNull(oidMap[OIDFactory.BuildObjectOID(i)]);
            }
            timeOidMapGet.End();
            Println(size + " objects : OID Map creation=" + timeOidMapCreation.GetDurationInMiliseconds() + " - get=" +
                    timeOidMapGet.GetDurationInMiliseconds());
        }
Esempio n. 2
0
        /// <summary>
        ///   To detect if a class has cyclic reference
        /// </summary>
        /// <param name="alreadyVisitedClasses"> A dictionary containing all the already visited classes </param>
        /// <returns> true if this class info has cyclic references </returns>
        private bool HasCyclicReference(IDictionary <string, ClassInfo> alreadyVisitedClasses)
        {
            if (alreadyVisitedClasses[_fullClassName] != null)
            {
                return(true);
            }

            alreadyVisitedClasses.Add(_fullClassName, this);

            for (var i = 0; i < _attributes.Count; i++)
            {
                var classAttributeInfo = GetAttributeInfo(i);
                if (classAttributeInfo.IsNative())
                {
                    continue;
                }

                var localMap     = new OdbHashMap <string, ClassInfo>(alreadyVisitedClasses);
                var hasCyclicRef = classAttributeInfo.GetClassInfo().HasCyclicReference(localMap);
                if (hasCyclicRef)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        public virtual void TestPerformanceOid()
		{
			int size = 300000;
            OdbHashMap<OID,string> oidMap = new OdbHashMap<OID, string>();
			
			// OID
			NeoDatis.Tool.StopWatch timeOidMapCreation = new NeoDatis.Tool.StopWatch();
			timeOidMapCreation.Start();
			// Creates a hashmap with 100000 Longs
			for (int i = 0; i < size; i++)
			{
				oidMap.Add(NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(i), i.ToString());
			}
			timeOidMapCreation.End();
			NeoDatis.Tool.StopWatch timeOidMapGet = new NeoDatis.Tool.StopWatch();
			timeOidMapGet.Start();
			// get all map elements
			for (int i = 0; i < size; i++)
			{
				AssertNotNull(oidMap[NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(i)]);
			}
			timeOidMapGet.End();
			Println(size + " objects : OID Map creation=" + timeOidMapCreation.GetDurationInMiliseconds
				() + " - get=" + timeOidMapGet.GetDurationInMiliseconds());
		}
Esempio n. 4
0
 public LazyOdbBtreePersister(IStorageEngine engine)
 {
     _oids = new OdbHashMap <OID, object>();
     _modifiedObjectOids    = new OdbHashMap <object, int>();
     _modifiedObjectOidList = new OdbList <OID>(500);
     _engine = engine;
     _engine.AddCommitListener(this);
 }
Esempio n. 5
0
 public virtual void AddEntry(object key, object value)
 {
     if (map == null)
     {
         map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <object, object>();
     }
     map.Add(key, value);
 }
Esempio n. 6
0
 public MetaModel()
 {
     _rapidAccessForClassesByName = new OdbHashMap<Type, ClassInfo>(10);
     _rapidAccessForClassesByOid = new OdbHashMap<OID, ClassInfo>(10);
     _existingClasses = new List<Type>(10);
     _allClassInfos = new List<ClassInfo>();
     _changedClasses = new OdbHashMap<ClassInfo, ClassInfo>();
 }
Esempio n. 7
0
 public LazyOdbBtreePersister(IStorageEngine engine)
 {
     _oids = new OdbHashMap<OID, object>();
     _modifiedObjectOids = new OdbHashMap<object, int>();
     _modifiedObjectOidList = new OdbList<OID>(500);
     _engine = engine;
     _engine.AddCommitListener(this);
 }
Esempio n. 8
0
 public virtual void TestOIdInMap()
 {
     var oid1 = OIDFactory.BuildObjectOID(1);
     var oid2 = OIDFactory.BuildObjectOID(1);
     var map = new OdbHashMap<OID, string>();
     map.Add(oid1, "oid1");
     AssertNotNull(map[oid2]);
 }
Esempio n. 9
0
		public virtual void AddEntry(object key, object value)
		{
			if (map == null)
			{
				map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<object,object>();
			}
			map.Add(key, value);
		}
Esempio n. 10
0
 public MetaModel()
 {
     _rapidAccessForClassesByName = new OdbHashMap <Type, ClassInfo>(10);
     _rapidAccessForClassesByOid  = new OdbHashMap <OID, ClassInfo>(10);
     _existingClasses             = new List <Type>(10);
     _allClassInfos  = new List <ClassInfo>();
     _changedClasses = new OdbHashMap <ClassInfo, ClassInfo>();
 }
Esempio n. 11
0
 public virtual void AddEntry(object key, object value)
 {
     if (map == null)
     {
         map = new OdbHashMap <object, object>();
     }
     map.Add(key, value);
 }
Esempio n. 12
0
        public virtual void TestOIdInMap()
        {
            var oid1 = OIDFactory.BuildObjectOID(1);
            var oid2 = OIDFactory.BuildObjectOID(1);
            var map  = new OdbHashMap <OID, string>();

            map.Add(oid1, "oid1");
            AssertNotNull(map[oid2]);
        }
Esempio n. 13
0
        public virtual void TestInsertWithCommitsSimpleObject()
        {
            DeleteBase("commits");
            IOdb odb            = null;
            var  size           = 10000;
            var  commitInterval = 1000;

            try
            {
                odb = Open("commits");
                for (var i = 0; i < size; i++)
                {
                    odb.Store(new VO.Login.Function("function " + i));
                    if (i % commitInterval == 0)
                    {
                        odb.Commit();
                        Console.WriteLine(i);
                    }
                }
            }
            finally
            {
                // println("commiting "+i);
                odb.Close();
            }
            odb = Open("commits");
            var query     = odb.Query <VO.Login.Function>();
            var objects   = query.Execute <VO.Login.Function>();
            var nbObjects = objects.Count;
            var map       = new OdbHashMap <VO.Login.Function, int>();

            VO.Login.Function function = null;
            var j = 0;

            while (objects.HasNext())
            {
                function = objects.Next();
                var ii = map[function];
                if (ii != 0)
                {
                    Println(j + ":" + function.GetName() + " already exist at " + ii);
                }
                else
                {
                    map.Add(function, j);
                }
                j++;
            }
            odb.Close();
            DeleteBase("commits");
            Println("Nb objects=" + nbObjects);
            AssertEquals(size, nbObjects);
        }
		public override AbstractObjectInfo CreateCopy(IDictionary<OID, AbstractObjectInfo> cache, bool onlyData)
		{
            IDictionary<AbstractObjectInfo, AbstractObjectInfo> m = GetMap();
			IDictionary<AbstractObjectInfo,AbstractObjectInfo> newMap = new OdbHashMap<AbstractObjectInfo, AbstractObjectInfo>();
			System.Collections.IEnumerator iterator = m.Keys.GetEnumerator();
			while (iterator.MoveNext())
			{
				NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo keyAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
					)iterator.Current;
				NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo valueAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
					)m[keyAoi];
				// create copies
				keyAoi = keyAoi.CreateCopy(cache, onlyData);
				valueAoi = valueAoi.CreateCopy(cache, onlyData);
				newMap.Add(keyAoi, valueAoi);
			}
			MapObjectInfo moi = new MapObjectInfo(newMap, odbType, realMapClassName);
			return moi;
		}
        public override AbstractObjectInfo CreateCopy(IDictionary <OID, AbstractObjectInfo> cache, bool onlyData)
        {
            IDictionary <AbstractObjectInfo, AbstractObjectInfo> m      = GetMap();
            IDictionary <AbstractObjectInfo, AbstractObjectInfo> newMap = new OdbHashMap <AbstractObjectInfo, AbstractObjectInfo>();

            System.Collections.IEnumerator iterator = m.Keys.GetEnumerator();
            while (iterator.MoveNext())
            {
                NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo keyAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                                                                  )iterator.Current;
                NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo valueAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                                                                    )m[keyAoi];
                // create copies
                keyAoi   = keyAoi.CreateCopy(cache, onlyData);
                valueAoi = valueAoi.CreateCopy(cache, onlyData);
                newMap.Add(keyAoi, valueAoi);
            }
            MapObjectInfo moi = new MapObjectInfo(newMap, odbType, realMapClassName);

            return(moi);
        }
 private System.Collections.Generic.IDictionary<AbstractObjectInfo, AbstractObjectInfo> IntrospectGenericMap(
     System.Collections.Generic.IDictionary<object,object> map,
     bool introspect,
     IDictionary<object, NonNativeObjectInfo> alreadyReadObjects, IIntrospectionCallback callback)
 {
     System.Collections.Generic.IDictionary<AbstractObjectInfo, AbstractObjectInfo> mapCopy = new OdbHashMap<AbstractObjectInfo, AbstractObjectInfo>();
     System.Collections.Generic.ICollection<object> keySet = map.Keys;
     System.Collections.IEnumerator keys = keySet.GetEnumerator();
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ciKey = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ciValue = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoiForKey = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoiForValue = null;
     while (keys.MoveNext())
     {
         object key = keys.Current;
         object value = map[key];
         if (key != null)
         {
             ciKey = GetClassInfo(OdbClassUtil.GetFullName(key.GetType()));
             if (value != null)
             {
                 ciValue = GetClassInfo(OdbClassUtil.GetFullName(value.GetType()));
             }
             aoiForKey = GetObjectInfo(key, ciKey, introspect, alreadyReadObjects, callback);
             aoiForValue = GetObjectInfo(value, ciValue, introspect, alreadyReadObjects, callback);
             mapCopy.Add(aoiForKey, aoiForValue);
         }
     }
     return mapCopy;
 }
Esempio n. 17
0
 public virtual void SetMap(OdbHashMap<object, object> map)
 {
     this.map = map;
 }
Esempio n. 18
0
 public virtual void AddEntry(object key, object value)
 {
     if (map == null)
         map = new OdbHashMap<object, object>();
     map.Add(key, value);
 }
Esempio n. 19
0
 public Dictionnary(string name)
 {
     this.name = name;
     map = null;
 }
Esempio n. 20
0
        public virtual void TestPerformanceOid()
        {
            var size = 300000;
            var oidMap = new OdbHashMap<OID, string>();

            // OID
            var timeOidMapCreation = new StopWatch();
            timeOidMapCreation.Start();
            // Creates a hashmap with 100000 Longs
            for (var i = 0; i < size; i++)
                oidMap.Add(OIDFactory.BuildObjectOID(i), i.ToString());
            timeOidMapCreation.End();
            var timeOidMapGet = new StopWatch();
            timeOidMapGet.Start();
            // get all map elements
            for (var i = 0; i < size; i++)
                AssertNotNull(oidMap[OIDFactory.BuildObjectOID(i)]);
            timeOidMapGet.End();
            Println(size + " objects : OID Map creation=" + timeOidMapCreation.GetDurationInMiliseconds() + " - get=" +
                    timeOidMapGet.GetDurationInMiliseconds());
        }
Esempio n. 21
0
 public virtual void TestInsertWithCommitsSimpleObject()
 {
     DeleteBase("commits");
     IOdb odb = null;
     var size = 10000;
     var commitInterval = 1000;
     try
     {
         odb = Open("commits");
         for (var i = 0; i < size; i++)
         {
             odb.Store(new VO.Login.Function("function " + i));
             if (i % commitInterval == 0)
             {
                 odb.Commit();
                 Console.WriteLine(i);
             }
         }
     }
     finally
     {
         // println("commiting "+i);
         odb.Close();
     }
     odb = Open("commits");
     var query = odb.Query<VO.Login.Function>();
     var objects = query.Execute<VO.Login.Function>();
     var nbObjects = objects.Count;
     var map = new OdbHashMap<VO.Login.Function, int>();
     VO.Login.Function function = null;
     var j = 0;
     while (objects.HasNext())
     {
         function = objects.Next();
         var ii = map[function];
         if (ii != 0)
             Println(j + ":" + function.GetName() + " already exist at " + ii);
         else
             map.Add(function, j);
         j++;
     }
     odb.Close();
     DeleteBase("commits");
     Println("Nb objects=" + nbObjects);
     AssertEquals(size, nbObjects);
 }
Esempio n. 22
0
        /// <summary>
        ///   Build a meta representation of an object
        ///   <pre>warning: When an object has two fields with the same name
        ///        (a private field with the same name in a parent class, the deeper field (of the parent) is ignored!)</pre>
        /// </summary>
        /// <returns> The ObjectInfo </returns>
        private AbstractObjectInfo GetObjectInfoInternal(AbstractObjectInfo nnoi, object o, ClassInfo classInfo,
                                                         bool recursive,
                                                         IDictionary <object, NonNativeObjectInfo> alreadyReadObjects,
                                                         IIntrospectionCallback callback)
        {
            if (o == null)
            {
                return(NullNativeObjectInfo.GetInstance());
            }

            var clazz = o.GetType();
            var type  = OdbType.GetFromClass(clazz);

            if (type.IsNative())
            {
                return(GetNativeObjectInfoInternal(type, o, recursive, alreadyReadObjects, callback));
            }

            // sometimes the type.getName() may not match the ci.getClassName()
            // It happens when the attribute is an interface or superclass of the
            // real attribute class
            // In this case, ci must be updated to the real class info
            if (classInfo != null && !classInfo.FullClassName.Equals(OdbClassNameResolver.GetFullName(clazz)))
            {
                classInfo = GetClassInfo(clazz);
                nnoi      = null;
            }
            var mainAoi      = (NonNativeObjectInfo)nnoi;
            var isRootObject = false;

            if (alreadyReadObjects == null)
            {
                alreadyReadObjects = new OdbHashMap <object, NonNativeObjectInfo>();
                isRootObject       = true;
            }

            NonNativeObjectInfo cachedNnoi;

            alreadyReadObjects.TryGetValue(o, out cachedNnoi);

            if (cachedNnoi != null)
            {
                return(new ObjectReference(cachedNnoi));
            }

            if (callback != null)
            {
                callback.ObjectFound(o);
            }

            if (mainAoi == null)
            {
                mainAoi = BuildNnoi(o, classInfo);
            }

            alreadyReadObjects[o] = mainAoi;

            var fields = ClassIntrospector.GetAllFieldsFrom(clazz);

            foreach (var field in fields)
            {
                try
                {
                    var value       = field.GetValue(o);
                    var attributeId = classInfo.GetAttributeId(field.Name);
                    if (attributeId == -1)
                    {
                        throw new OdbRuntimeException(
                                  NDatabaseError.ObjectIntrospectorNoFieldWithName.AddParameter(classInfo.FullClassName).
                                  AddParameter(field.Name));
                    }

                    var valueType = OdbType.GetFromClass(value == null
                                                             ? field.FieldType
                                                             : value.GetType());
                    // for native fields
                    AbstractObjectInfo abstractObjectInfo;

                    if (valueType.IsNative())
                    {
                        abstractObjectInfo = GetNativeObjectInfoInternal(valueType, value, recursive, alreadyReadObjects,
                                                                         callback);
                        mainAoi.SetAttributeValue(attributeId, abstractObjectInfo);
                    }
                    else
                    {
                        // Non Native Objects
                        if (value == null)
                        {
                            var classInfo1 = GetClassInfo(field.GetType());

                            abstractObjectInfo = new NonNativeNullObjectInfo(classInfo1);
                            mainAoi.SetAttributeValue(attributeId, abstractObjectInfo);
                        }
                        else
                        {
                            var classInfo2 = GetClassInfo(value.GetType());
                            if (recursive)
                            {
                                abstractObjectInfo = GetObjectInfoInternal(null, value, classInfo2, true,
                                                                           alreadyReadObjects, callback);
                                mainAoi.SetAttributeValue(attributeId, abstractObjectInfo);
                            }
                            else
                            {
                                // When it is not recursive, simply add the object
                                // values.add(value);
                                throw new OdbRuntimeException(
                                          NDatabaseError.InternalError.AddParameter(
                                              "Should not enter here - ObjectIntrospector - 'simply add the object'"));
                            }
                        }
                    }
                }
                catch (ArgumentException e)
                {
                    throw new OdbRuntimeException(
                              NDatabaseError.InternalError.AddParameter("in getObjectInfoInternal"), e);
                }
                catch (MemberAccessException e)
                {
                    throw new OdbRuntimeException(NDatabaseError.InternalError.AddParameter("getObjectInfoInternal"), e);
                }
            }

            if (isRootObject)
            {
                alreadyReadObjects.Clear();
            }

            return(mainAoi);
        }
Esempio n. 23
0
        /// <summary>
        ///   To detect if a class has cyclic reference
        /// </summary>
        /// <param name="alreadyVisitedClasses"> A dictionary containing all the already visited classes </param>
        /// <returns> true if this class info has cyclic references </returns>
        private bool HasCyclicReference(IDictionary<string, ClassInfo> alreadyVisitedClasses)
        {
            if (alreadyVisitedClasses[_fullClassName] != null)
                return true;

            alreadyVisitedClasses.Add(_fullClassName, this);

            for (var i = 0; i < _attributes.Count; i++)
            {
                var classAttributeInfo = GetAttributeInfo(i);
                if (classAttributeInfo.IsNative())
                    continue;

                var localMap = new OdbHashMap<string, ClassInfo>(alreadyVisitedClasses);
                var hasCyclicRef = classAttributeInfo.GetClassInfo().HasCyclicReference(localMap);
                if (hasCyclicRef)
                    return true;
            }
            return false;
        }
Esempio n. 24
0
 public ObjectValues(int size)
 {
     _valuesByIndex = new object[size];
     _valuesByAlias = new OdbHashMap<string, object>();
 }
 private System.Collections.Generic.IDictionary <AbstractObjectInfo, AbstractObjectInfo> IntrospectGenericMap(
     System.Collections.Generic.IDictionary <object, object> map,
     bool introspect,
     IDictionary <object, NonNativeObjectInfo> alreadyReadObjects, IIntrospectionCallback callback)
 {
     System.Collections.Generic.IDictionary <AbstractObjectInfo, AbstractObjectInfo> mapCopy = new OdbHashMap <AbstractObjectInfo, AbstractObjectInfo>();
     System.Collections.Generic.ICollection <object> keySet = map.Keys;
     System.Collections.IEnumerator keys = keySet.GetEnumerator();
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo          ciKey       = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo          ciValue     = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoiForKey   = null;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoiForValue = null;
     while (keys.MoveNext())
     {
         object key   = keys.Current;
         object value = map[key];
         if (key != null)
         {
             ciKey = GetClassInfo(OdbClassUtil.GetFullName(key.GetType()));
             if (value != null)
             {
                 ciValue = GetClassInfo(OdbClassUtil.GetFullName(value.GetType()));
             }
             aoiForKey   = GetObjectInfo(key, ciKey, introspect, alreadyReadObjects, callback);
             aoiForValue = GetObjectInfo(value, ciValue, introspect, alreadyReadObjects, callback);
             mapCopy.Add(aoiForKey, aoiForValue);
         }
     }
     return(mapCopy);
 }
Esempio n. 26
0
        /// <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);
        }
Esempio n. 27
0
 internal AttributesCache()
 {
     AttributesByName = new OdbHashMap<string, ClassAttributeInfo>();
     AttributesById = new OdbHashMap<int, ClassAttributeInfo>();
 }
 public MyMapObject(string name)
 {
     this.name = name;
     map = new OdbHashMap<object, object>();
 }
Esempio n. 29
0
 internal AttributesCache()
 {
     AttributesByName = new OdbHashMap <string, ClassAttributeInfo>();
     AttributesById   = new OdbHashMap <int, ClassAttributeInfo>();
 }
Esempio n. 30
0
 public ObjectValues(int size)
 {
     _valuesByIndex = new object[size];
     _valuesByAlias = new OdbHashMap <string, object>();
 }
Esempio n. 31
0
 public Dictionnary(string name)
 {
     this.name = name;
     map       = null;
 }
Esempio n. 32
0
        /// <summary>
        ///   Build a meta representation of an object 
        ///   <pre>warning: When an object has two fields with the same name 
        ///        (a private field with the same name in a parent class, the deeper field (of the parent) is ignored!)</pre>
        /// </summary>
        /// <returns> The ObjectInfo </returns>
        private AbstractObjectInfo GetObjectInfoInternal(AbstractObjectInfo nnoi, object o, ClassInfo classInfo,
                                                         bool recursive,
                                                         IDictionary<object, NonNativeObjectInfo> alreadyReadObjects,
                                                         IIntrospectionCallback callback)
        {
            if (o == null)
                return NullNativeObjectInfo.GetInstance();

            var clazz = o.GetType();
            var type = OdbType.GetFromClass(clazz);
            if (type.IsNative())
                return GetNativeObjectInfoInternal(type, o, recursive, alreadyReadObjects, callback);

            // sometimes the type.getName() may not match the ci.getClassName()
            // It happens when the attribute is an interface or superclass of the
            // real attribute class
            // In this case, ci must be updated to the real class info
            if (classInfo != null && !classInfo.FullClassName.Equals(OdbClassNameResolver.GetFullName(clazz)))
            {
                classInfo = GetClassInfo(clazz);
                nnoi = null;
            }
            var mainAoi = (NonNativeObjectInfo) nnoi;
            var isRootObject = false;

            if (alreadyReadObjects == null)
            {
                alreadyReadObjects = new OdbHashMap<object, NonNativeObjectInfo>();
                isRootObject = true;
            }

            NonNativeObjectInfo cachedNnoi;
            alreadyReadObjects.TryGetValue(o, out cachedNnoi);

            if (cachedNnoi != null)
                return new ObjectReference(cachedNnoi);

            if (callback != null)
                callback.ObjectFound(o);

            if (mainAoi == null)
                mainAoi = BuildNnoi(o, classInfo);

            alreadyReadObjects[o] = mainAoi;
            
            var fields = ClassIntrospector.GetAllFieldsFrom(clazz);
            
            foreach (var field in fields)
            {
                try
                {
                    var value = field.GetValue(o);
                    var attributeId = classInfo.GetAttributeId(field.Name);
                    if (attributeId == -1)
                    {
                        throw new OdbRuntimeException(
                            NDatabaseError.ObjectIntrospectorNoFieldWithName.AddParameter(classInfo.FullClassName).
                                AddParameter(field.Name));
                    }

                    var valueType = OdbType.GetFromClass(value == null
                                                             ? field.FieldType
                                                             : value.GetType());
                    // for native fields
                    AbstractObjectInfo abstractObjectInfo;

                    if (valueType.IsNative())
                    {
                        abstractObjectInfo = GetNativeObjectInfoInternal(valueType, value, recursive, alreadyReadObjects,
                                                                         callback);
                        mainAoi.SetAttributeValue(attributeId, abstractObjectInfo);
                    }
                    else
                    {
                        // Non Native Objects
                        if (value == null)
                        {
                            var classInfo1 = GetClassInfo(field.GetType());

                            abstractObjectInfo = new NonNativeNullObjectInfo(classInfo1);
                            mainAoi.SetAttributeValue(attributeId, abstractObjectInfo);
                        }
                        else
                        {
                            var classInfo2 = GetClassInfo(value.GetType());
                            if (recursive)
                            {
                                abstractObjectInfo = GetObjectInfoInternal(null, value, classInfo2, true,
                                                                           alreadyReadObjects, callback);
                                mainAoi.SetAttributeValue(attributeId, abstractObjectInfo);
                            }
                            else
                            {
                                // When it is not recursive, simply add the object
                                // values.add(value);
                                throw new OdbRuntimeException(
                                    NDatabaseError.InternalError.AddParameter(
                                        "Should not enter here - ObjectIntrospector - 'simply add the object'"));
                            }
                        }
                    }
                }
                catch (ArgumentException e)
                {
                    throw new OdbRuntimeException(
                        NDatabaseError.InternalError.AddParameter("in getObjectInfoInternal"), e);
                }
                catch (MemberAccessException e)
                {
                    throw new OdbRuntimeException(NDatabaseError.InternalError.AddParameter("getObjectInfoInternal"), e);
                }
            }

            if (isRootObject)
                alreadyReadObjects.Clear();

            return mainAoi;
        }
Esempio n. 33
0
 public virtual void SetMap(OdbHashMap <object, object> map)
 {
     this.map = map;
 }
 public MyMapObject(string name)
 {
     this.name = name;
     map       = new OdbHashMap <object, object>();
 }