Example #1
0
		/// <summary>Performance test.</summary>
		/// <remarks>Performance test. Using ID or long in hash map</remarks>
		public virtual void TestPerformanceLong()
		{
			int size = 300000;
			System.Collections.IDictionary longMap = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
				();
			// LONG
			NeoDatis.Tool.StopWatch timeLongMapCreation = new NeoDatis.Tool.StopWatch();
			timeLongMapCreation.Start();
			// Creates a hashmap with 100000 Longs
			for (int i = 0; i < size; i++)
			{
				longMap.Add(System.Convert.ToInt64(i), i.ToString());
			}
			timeLongMapCreation.End();
			NeoDatis.Tool.StopWatch timeLongMapGet = new NeoDatis.Tool.StopWatch();
			timeLongMapGet.Start();
			// get all map elements
			for (int i = 0; i < size; i++)
			{
				AssertNotNull(longMap[System.Convert.ToInt64(i)]);
			}
			timeLongMapGet.End();
			Println(size + " objects : Long Map creation=" + timeLongMapCreation.GetDurationInMiliseconds
				() + " - get=" + timeLongMapGet.GetDurationInMiliseconds());
		}
Example #2
0
		/// <summary>Performance test.</summary>
		/// <remarks>Performance test. Using ID or long in hash map</remarks>
		public virtual void TestPerformanceOid()
		{
			int size = 300000;
			System.Collections.IDictionary oidMap = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
				();
			// 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());
		}
Example #3
0
        public virtual void Test1()
		{
			if (!isLocal)
			{
				return;
			}
			NeoDatis.Odb.ODB odb = Open("t-school.neodatis");
			// List students by name
			SchoolNativeQueryStudent natQuery = new SchoolNativeQueryStudent("Brenna", 23);
			NeoDatis.Odb.Objects<Student> students = odb.GetObjects<Student>(natQuery);
			SchoolSimpleNativeQueryStudent sNatQuery = new SchoolSimpleNativeQueryStudent("Brenna");
			students = odb.GetObjects<Student>(sNatQuery);
			// list disciplines of one teacher by semester
			SchoolNativeQueryTeacher natQuery2 = new SchoolNativeQueryTeacher
				("Jeremias");
			NeoDatis.Odb.Objects<History> historys = odb.GetObjects<History>(natQuery2);
			System.Collections.Hashtable listDiscipline = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<string,Discipline>();
			for (System.Collections.IEnumerator iter = historys.GetEnumerator(); iter.MoveNext
				(); )
			{
				History h = (History)iter
					.Current;
				listDiscipline.Add(h.GetDiscipline().GetName(), h.GetDiscipline());
			}
			odb.Close();
		}
Example #4
0
		public virtual void TestOIdInMap()
		{
			NeoDatis.Odb.OID oid1 = NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(1);
			NeoDatis.Odb.OID oid2 = NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(1);
			System.Collections.IDictionary map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap();
			map.Add(oid1, "oid1");
			AssertNotNull(map[oid2]);
		}
Example #5
0
        public virtual void TestInsertWithCommitsSimpleObject()
		{
			DeleteBase("commits");
			NeoDatis.Odb.ODB odb = null;
			int size = isLocal ? 10000 : 3000;
			int commitInterval = 1000;
			try
			{
				odb = Open("commits");
				for (int i = 0; i < size; i++)
				{
					odb.Store(new NeoDatis.Odb.Test.VO.Login.Function("function " + i));
					if (i % commitInterval == 0)
					{
						odb.Commit();
                        Console.WriteLine(i);
					}
				}
			}
			finally
			{
				// println("commiting "+i);
				odb.Close();
			}
			odb = Open("commits");
			NeoDatis.Odb.Objects<Function> objects = odb.GetObjects<Function>();
			int nbObjects = objects.Count;
            NeoDatis.Tool.Wrappers.Map.OdbHashMap<Function,int> map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<Function,int>();
			NeoDatis.Odb.Test.VO.Login.Function function = null;
			int j = 0;
			while (objects.HasNext())
			{
				function = (NeoDatis.Odb.Test.VO.Login.Function)objects.Next();
				int ii = (int)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);
		}
Example #6
0
		public virtual void Test1WithoutWeak()
		{
			int size = 40000;
			System.Collections.IDictionary map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap();
			for (int i = 0; i < size; i++)
			{
				object o = GetSimpleObjectInstance(i);
				if (i % 50000 == 0)
				{
					NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory(string.Empty + i, true);
				}
				map.Add(o, o);
			}
			Println("Test 1 ok");
			Println("Map size " + map.Count);
		}
		public LazyODBBTreePersister(NeoDatis.Odb.Core.Layers.Layer3.IStorageEngine engine
			)
		{
			// See the map strategy performance test at
			// test/org.neodatis.odb.test.performance.TestMapPerf
			// TODO create a boolean value to know if data must be saved on update or
			// only at the end
			oids = new System.Collections.Generic.Dictionary<NeoDatis.Odb.OID, object>();
			modifiedObjectOids = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<object, int>();
			modifiedObjectOidList = new NeoDatis.Tool.Wrappers.List.OdbArrayList<NeoDatis.Odb.OID
				>(500);
			this.engine = engine;
			this.engine.AddCommitListener(this);
			smap = oids;
			smodifiedObjects = modifiedObjectOids;
		}
Example #8
0
		/// <summary>Loading x objects, x/2 are modified, using strategy 2</summary>
		public virtual void Test2()
		{
			NeoDatis.Tool.StopWatch stopWatch = new NeoDatis.Tool.StopWatch();
			stopWatch.Start();
			System.Collections.IDictionary objects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
				();
			NeoDatis.Odb.Test.VO.Login.Function f = null;
			NeoDatis.Odb.OID oid = null;
			NeoDatis.Odb.Test.Performance.ObjectWrapper ow = null;
			int i = 0;
			for (i = 0; i < size; i++)
			{
				f = new NeoDatis.Odb.Test.VO.Login.Function("function " + i);
				oid = NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(i);
				objects.Add(oid, new NeoDatis.Odb.Test.Performance.ObjectWrapper(f, false));
				if (i < size / 2)
				{
					ow = (NeoDatis.Odb.Test.Performance.ObjectWrapper)objects[oid];
					ow.SetModified(true);
				}
				if (i % 10000 == 0)
				{
					NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("put i", false);
				}
			}
			i = 0;
			int nbModified = 0;
			// Now get all modified objects
			System.Collections.IEnumerator iterator = objects.Keys.GetEnumerator();
			while (iterator.MoveNext())
			{
				oid = (NeoDatis.Odb.OID)iterator.Current;
				ow = (NeoDatis.Odb.Test.Performance.ObjectWrapper)objects[oid];
				if (ow.IsModified())
				{
					nbModified++;
				}
				if (i % 10000 == 0)
				{
					NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("get i", false);
				}
				i++;
			}
			stopWatch.End();
			Println("time for 1 map =" + stopWatch.GetDurationInMiliseconds());
			AssertEquals(size / 2, nbModified);
		}
Example #9
0
        public virtual void Test1()
        {
            NeoDatis.Tool.StopWatch stopWatch = new NeoDatis.Tool.StopWatch();
            stopWatch.Start();
            System.Collections.IDictionary loadedObjects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
                                                               ();
            System.Collections.IDictionary modifiedObjects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
                                                                 ();
            NeoDatis.Odb.Test.VO.Login.Function f = null;
            NeoDatis.Odb.OID oid = null;
            for (int i = 0; i < size; i++)
            {
                f   = new NeoDatis.Odb.Test.VO.Login.Function("function " + i);
                oid = NeoDatis.Odb.Core.Oid.OIDFactory.BuildObjectOID(i);
                loadedObjects.Add(oid, f);
                if (i < size / 2)
                {
                    modifiedObjects.Add(oid, f);
                }
                if (i % 10000 == 0)
                {
                    NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("put i", false);
                }
            }
            int j          = 0;
            int nbModified = 0;

            // Now get all modified objects
            System.Collections.IEnumerator iterator = modifiedObjects.Keys.GetEnumerator();
            while (iterator.MoveNext())
            {
                oid = (NeoDatis.Odb.OID)iterator.Current;
                object o = modifiedObjects[oid];
                if (j % 10000 == 0)
                {
                    NeoDatis.Odb.Impl.Tool.MemoryMonitor.DisplayCurrentMemory("get i", false);
                }
                j++;
                nbModified++;
            }
            stopWatch.End();
            Println("time for 2 maps =" + stopWatch.GetDurationInMiliseconds());
            AssertEquals(size / 2, nbModified);
        }
Example #10
0
 public virtual void SetMap(NeoDatis.Tool.Wrappers.Map.OdbHashMap <object, object>
                            map)
 {
     this.map = map;
 }
Example #11
0
 public MyMapObject(string name)
 {
     this.name = name;
     this.map  = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <object, object>();
 }
		public DefaultObjectValues(int size)
		{
			valuesByIndex = new object[size];
			valuesByAlias = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<string, object>();
		}
        /// <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>
        /// <param name="o"></param>
        /// <param name="ci"></param>
        /// <param name="recursive"></param>
        /// <returns>The ObjectInfo</returns>
        protected virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo GetObjectInfoInternal
            (NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo nnoi, object o, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
            ci, bool recursive, System.Collections.Generic.IDictionary <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                        > alreadyReadObjects, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback
            callback)
        {
            object value = null;

            if (o == null)
            {
                return(NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo.GetInstance());
            }
            System.Type clazz = o.GetType();
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
                                                                .GetFromClass(clazz);
            string className = OdbClassUtil.GetFullName(clazz);

            if (type.IsNative())
            {
                return(GetNativeObjectInfoInternal(type, o, recursive, alreadyReadObjects,
                                                   callback));
            }
            // sometimes the clazz.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 (ci != null && !clazz.FullName.Equals(ci.GetFullClassName()))
            {
                ci   = GetClassInfo(className);
                nnoi = null;
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo mainAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                )nnoi;
            bool isRootObject = false;

            if (alreadyReadObjects == null)
            {
                alreadyReadObjects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                >();
                isRootObject = true;
            }
            if (o != null)
            {
                NonNativeObjectInfo cachedNnoi = null;
                alreadyReadObjects.TryGetValue(o, out cachedNnoi);

                if (cachedNnoi != null)
                {
                    ObjectReference or = new ObjectReference(cachedNnoi);
                    return(or);
                }
                if (callback != null)
                {
                    callback.ObjectFound(o);
                }
            }
            if (mainAoi == null)
            {
                mainAoi = BuildNnoi(o, ci, null, null, null, alreadyReadObjects);
            }
            alreadyReadObjects[o] = mainAoi;
            NeoDatis.Tool.Wrappers.List.IOdbList <System.Reflection.FieldInfo> fields = classIntrospector.GetAllFields(className);
            NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo            aoi    = null;
            int attributeId = -1;

            // For all fields
            for (int i = 0; i < fields.Count; i++)
            {
                System.Reflection.FieldInfo field = fields[i];
                try
                {
                    value       = field.GetValue(o);
                    attributeId = ci.GetAttributeId(field.Name);
                    if (attributeId == -1)
                    {
                        throw new ODBRuntimeException(NeoDatisError.ObjectIntrospectorNoFieldWithName.AddParameter(ci.GetFullClassName()).AddParameter(field.Name));
                    }
                    ODBType valueType = null;
                    if (value == null)
                    {
                        // If value is null, take the type from the field type
                        // declared in the class
                        valueType = ODBType.GetFromClass(field.FieldType);
                    }
                    else
                    {
                        // Else take the real attribute type!
                        valueType = ODBType.GetFromClass(value.GetType());
                    }
                    // for native fields
                    if (valueType.IsNative())
                    {
                        aoi = GetNativeObjectInfoInternal(valueType, value, recursive, alreadyReadObjects, callback);
                        mainAoi.SetAttributeValue(attributeId, aoi);
                    }
                    else
                    {
                        //callback.objectFound(value);
                        // Non Native Objects
                        if (value == null)
                        {
                            ClassInfo clai = GetClassInfo(OdbClassUtil.GetFullName(field.GetType()));

                            aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeNullObjectInfo(clai);
                            mainAoi.SetAttributeValue(attributeId, aoi);
                        }
                        else
                        {
                            ClassInfo clai = GetClassInfo(OdbClassUtil.GetFullName(value.GetType()));
                            if (recursive)
                            {
                                aoi = GetObjectInfoInternal(null, value, clai, recursive, alreadyReadObjects, callback
                                                            );
                                mainAoi.SetAttributeValue(attributeId, aoi);
                            }
                            else
                            {
                                // When it is not recursive, simply add the object
                                // values.add(value);
                                throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
                                                                           .AddParameter("Should not enter here - ObjectIntrospector - 'simply add the object'"
                                                                                         ));
                            }
                        }
                    }
                }
                catch (System.ArgumentException e)
                {
                    throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
                                                               .AddParameter("in getObjectInfoInternal"), e);
                }
                catch (System.MemberAccessException e)
                {
                    throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
                                                               .AddParameter("getObjectInfoInternal"), e);
                }
            }
            if (isRootObject)
            {
                alreadyReadObjects.Clear();
                alreadyReadObjects = null;
            }
            return(mainAoi);
        }
Example #14
0
 public DefaultObjectValues(int size)
 {
     valuesByIndex = new object[size];
     valuesByAlias = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <string, object>();
 }
		public GetDependentObjectIntrospectingCallback()
		{
			objects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<object, object>();
		}
		public virtual void SetMap(NeoDatis.Tool.Wrappers.Map.OdbHashMap<object, object> 
			map)
		{
			this.map = map;
		}
 public SessionMetaModel() : base()
 {
     changedClasses = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                                 , NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo>();
 }
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="System.TypeLoadException"></exception>
		public virtual void LoadWriteActionsBackwards(string filename, bool apply)
		{
			int executedWriteAction = 0;
			if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
			{
				NeoDatis.Tool.DLogger.Debug("Load write actions of " + filename);
			}
			NeoDatis.Odb.Core.Transaction.IWriteAction wa = null;
			try
			{
				CheckFileAccess(false, filename);
				fsi.UseBuffer(true);
				fsi.SetReadPosition(0);
				isCommited = fsi.ReadByte() == 1;
				creationDateTime = fsi.ReadLong();
				System.Collections.Generic.IDictionary<long, long> writtenPositions = null;
				if (apply)
				{
					writtenPositions = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<long, long>();
				}
				long position = System.Convert.ToInt64(-1);
				int i = numberOfWriteActions;
				long previousWriteActionPosition = fsi.GetLength();
				while (i > 0)
				{
					// Sets the position 8 bytes backwards
					fsi.SetReadPosition(previousWriteActionPosition - NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
						.Long.GetSize());
					// And then the read a long, this will be the previous write
					// action position
					previousWriteActionPosition = fsi.ReadLong();
					// Then sets the read position to read the write action
					fsi.SetReadPosition(previousWriteActionPosition);
					wa = NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction.Read(fsi, i + 1);
					if (apply)
					{
						position = wa.GetPosition();
						if (writtenPositions[position] != null)
						{
							// It has already been written something more recent at
							// this position, do not write again
							i--;
							continue;
						}
						wa.ApplyTo(fsiToApplyWriteActions, i + 1);
						writtenPositions.Add(position, position);
						executedWriteAction++;
					}
					else
					{
						AddWriteAction(wa, false);
					}
					i--;
				}
				if (apply)
				{
					fsiToApplyWriteActions.Flush();
					if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
					{
						NeoDatis.Tool.DLogger.Debug("Total Write actions : " + i + " / position cache = "
							 + writtenPositions.Count);
					}
					NeoDatis.Tool.DLogger.Info("Total write actions = " + numberOfWriteActions + " : executed = "
						 + executedWriteAction);
					writtenPositions.Clear();
					writtenPositions = null;
				}
			}
			finally
			{
			}
		}
		/// <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 NeoDatis.Tool.Wrappers.List.IOdbList<string> GetAllInvolvedFields
			()
		{
			NeoDatis.Tool.Wrappers.List.IOdbList<string> l = new NeoDatis.Tool.Wrappers.List.OdbArrayList
				<string>();
			// To check field duplicity
			System.Collections.Generic.IDictionary<string, string> map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
				<string, string>();
			l.AddAll(base.GetAllInvolvedFields());
			if (!l.IsEmpty())
			{
				for (int i = 0; i < l.Count; i++)
				{
					map.Add(l[i], l[i]);
				}
			}
			System.Collections.Generic.IEnumerator<NeoDatis.Odb.Core.Query.Execution.IQueryFieldAction
				> iterator = objectActions.GetEnumerator();
			NeoDatis.Odb.Core.Query.Execution.IQueryFieldAction oa = null;
			string name = null;
			while (iterator.MoveNext())
			{
				oa = iterator.Current;
				if (oa.GetType() != typeof(NeoDatis.Odb.Impl.Core.Query.Values.CountAction))
				{
					name = oa.GetAttributeName();
					if (!map.ContainsKey(name))
					{
						l.Add(name);
						map.Add(name, name);
					}
				}
			}
			if (hasGroupBy)
			{
				for (int i = 0; i < groupByFieldList.Length; i++)
				{
					name = groupByFieldList[i];
					if (!map.ContainsKey(name))
					{
						l.Add(name);
						map.Add(name, name);
					}
				}
			}
			if (HasOrderBy())
			{
				for (int i = 0; i < orderByFields.Length; i++)
				{
					name = orderByFields[i];
					if (!map.ContainsKey(name))
					{
						l.Add(name);
						map.Add(name, name);
					}
				}
			}
			map.Clear();
			map = null;
			return l;
		}
		/// <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>
		/// <param name="o"></param>
		/// <param name="ci"></param>
		/// <param name="recursive"></param>
		/// <returns>The ObjectInfo</returns>
		protected virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo GetObjectInfoInternal
			(NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo nnoi, object o, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
			 ci, bool recursive, System.Collections.Generic.IDictionary<object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
			> alreadyReadObjects, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback
			 callback)
		{
			object value = null;
			if (o == null)
			{
				return NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo.GetInstance();
			}
			System.Type clazz = o.GetType();
			NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
				.GetFromClass(clazz);
			string className = OdbClassUtil.GetFullName(clazz);
			if (type.IsNative())
			{
				return GetNativeObjectInfoInternal(type, o, recursive, alreadyReadObjects, 
					callback);
			}
			// sometimes the clazz.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 (ci != null && !clazz.FullName.Equals(ci.GetFullClassName()))
			{
				ci = GetClassInfo(className);
				nnoi = null;
			}
			NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo mainAoi = (NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
				)nnoi;
			bool isRootObject = false;
			if (alreadyReadObjects == null)
			{
				alreadyReadObjects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
					>();
				isRootObject = true;
			}
			if (o != null)
			{
                NonNativeObjectInfo cachedNnoi = null;
                alreadyReadObjects.TryGetValue(o, out cachedNnoi);
				
                if (cachedNnoi != null)
				{
					ObjectReference or = new ObjectReference(cachedNnoi);
					return or;
				}
				if (callback != null)
				{
					callback.ObjectFound(o);
				}
			}
			if (mainAoi == null)
			{
				mainAoi = BuildNnoi(o, ci, null, null, null, alreadyReadObjects);
			}
			alreadyReadObjects[o] = mainAoi;
			NeoDatis.Tool.Wrappers.List.IOdbList<System.Reflection.FieldInfo> fields = classIntrospector.GetAllFields(className);
			NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null;
			int attributeId = -1;
			// For all fields
			for (int i = 0; i < fields.Count; i++)
			{
				System.Reflection.FieldInfo field = fields[i];
				try
				{
					value = field.GetValue(o);
					attributeId = ci.GetAttributeId(field.Name);
					if (attributeId == -1)
					{
						throw new ODBRuntimeException(NeoDatisError.ObjectIntrospectorNoFieldWithName.AddParameter(ci.GetFullClassName()).AddParameter(field.Name));
					}
					ODBType valueType = null;
					if (value == null)
					{
						// If value is null, take the type from the field type
						// declared in the class
						valueType = ODBType.GetFromClass(field.FieldType);
					}
					else
					{
						// Else take the real attribute type!
						valueType = ODBType.GetFromClass(value.GetType());
					}
					// for native fields
					if (valueType.IsNative())
					{
						aoi = GetNativeObjectInfoInternal(valueType, value, recursive, alreadyReadObjects, callback);
						mainAoi.SetAttributeValue(attributeId, aoi);
					}
					else
					{
						//callback.objectFound(value);
						// Non Native Objects
						if (value == null)
						{
                            ClassInfo clai = GetClassInfo(OdbClassUtil.GetFullName(field.GetType()));

							aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeNullObjectInfo(clai);
							mainAoi.SetAttributeValue(attributeId, aoi);
						}
						else
						{
                            ClassInfo clai = GetClassInfo(OdbClassUtil.GetFullName(value.GetType()));
							if (recursive)
							{
								aoi = GetObjectInfoInternal(null, value, clai, recursive, alreadyReadObjects, callback
									);
								mainAoi.SetAttributeValue(attributeId, aoi);
							}
							else
							{
								// When it is not recursive, simply add the object
								// values.add(value);
								throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
									.AddParameter("Should not enter here - ObjectIntrospector - 'simply add the object'"
									));
							}
						}
					}
				}
				catch (System.ArgumentException e)
				{
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
						.AddParameter("in getObjectInfoInternal"), e);
				}
				catch (System.MemberAccessException e)
				{
					throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.InternalError
						.AddParameter("getObjectInfoInternal"), e);
				}
			}
			if (isRootObject)
			{
				alreadyReadObjects.Clear();
				alreadyReadObjects = null;
			}
			return mainAoi;
		}
		public MyMapObject(string name)
		{
			this.name = name;
			this.map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<object, object>();
		}
Example #22
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 NeoDatis.Tool.Wrappers.List.IOdbList <string> GetAllInvolvedFields
            ()
        {
            NeoDatis.Tool.Wrappers.List.IOdbList <string> l = new NeoDatis.Tool.Wrappers.List.OdbArrayList
                                                              <string>();
            // To check field duplicity
            System.Collections.Generic.IDictionary <string, string> map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
                                                                          <string, string>();
            l.AddAll(base.GetAllInvolvedFields());
            if (!l.IsEmpty())
            {
                for (int i = 0; i < l.Count; i++)
                {
                    map.Add(l[i], l[i]);
                }
            }
            System.Collections.Generic.IEnumerator <NeoDatis.Odb.Core.Query.Execution.IQueryFieldAction
                                                    >           iterator = objectActions.GetEnumerator();
            NeoDatis.Odb.Core.Query.Execution.IQueryFieldAction oa       = null;
            string name = null;

            while (iterator.MoveNext())
            {
                oa = iterator.Current;
                if (oa.GetType() != typeof(NeoDatis.Odb.Impl.Core.Query.Values.CountAction))
                {
                    name = oa.GetAttributeName();
                    if (!map.ContainsKey(name))
                    {
                        l.Add(name);
                        map.Add(name, name);
                    }
                }
            }
            if (hasGroupBy)
            {
                for (int i = 0; i < groupByFieldList.Length; i++)
                {
                    name = groupByFieldList[i];
                    if (!map.ContainsKey(name))
                    {
                        l.Add(name);
                        map.Add(name, name);
                    }
                }
            }
            if (HasOrderBy())
            {
                for (int i = 0; i < orderByFields.Length; i++)
                {
                    name = orderByFields[i];
                    if (!map.ContainsKey(name))
                    {
                        l.Add(name);
                        map.Add(name, name);
                    }
                }
            }
            map.Clear();
            map = null;
            return(l);
        }
Example #23
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="System.TypeLoadException"></exception>
        public virtual void LoadWriteActionsBackwards(string filename, bool apply)
        {
            int executedWriteAction = 0;

            if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
            {
                NeoDatis.Tool.DLogger.Debug("Load write actions of " + filename);
            }
            NeoDatis.Odb.Core.Transaction.IWriteAction wa = null;
            try
            {
                CheckFileAccess(false, filename);
                fsi.UseBuffer(true);
                fsi.SetReadPosition(0);
                isCommited       = fsi.ReadByte() == 1;
                creationDateTime = fsi.ReadLong();
                System.Collections.Generic.IDictionary <long, long> writtenPositions = null;
                if (apply)
                {
                    writtenPositions = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <long, long>();
                }
                long position = System.Convert.ToInt64(-1);
                int  i        = numberOfWriteActions;
                long previousWriteActionPosition = fsi.GetLength();
                while (i > 0)
                {
                    // Sets the position 8 bytes backwards
                    fsi.SetReadPosition(previousWriteActionPosition - NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
                                        .Long.GetSize());
                    // And then the read a long, this will be the previous write
                    // action position
                    previousWriteActionPosition = fsi.ReadLong();
                    // Then sets the read position to read the write action
                    fsi.SetReadPosition(previousWriteActionPosition);
                    wa = NeoDatis.Odb.Impl.Core.Transaction.DefaultWriteAction.Read(fsi, i + 1);
                    if (apply)
                    {
                        position = wa.GetPosition();
                        if (writtenPositions[position] != null)
                        {
                            // It has already been written something more recent at
                            // this position, do not write again
                            i--;
                            continue;
                        }
                        wa.ApplyTo(fsiToApplyWriteActions, i + 1);
                        writtenPositions.Add(position, position);
                        executedWriteAction++;
                    }
                    else
                    {
                        AddWriteAction(wa, false);
                    }
                    i--;
                }
                if (apply)
                {
                    fsiToApplyWriteActions.Flush();
                    if (NeoDatis.Odb.OdbConfiguration.IsDebugEnabled(LogId))
                    {
                        NeoDatis.Tool.DLogger.Debug("Total Write actions : " + i + " / position cache = "
                                                    + writtenPositions.Count);
                    }
                    NeoDatis.Tool.DLogger.Info("Total write actions = " + numberOfWriteActions + " : executed = "
                                               + executedWriteAction);
                    writtenPositions.Clear();
                    writtenPositions = null;
                }
            }
            finally
            {
            }
        }
Example #24
0
		public virtual System.Collections.Generic.IDictionary<string, object> GetHistory(
			)
		{
			System.Collections.Generic.IDictionary<string, object> map = new NeoDatis.Tool.Wrappers.Map.OdbHashMap
				<string, object>();
			NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
			System.Collections.Generic.IEnumerator<NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
				> iterator = allClassInfos.GetEnumerator();
			while (iterator.MoveNext())
			{
				ci = iterator.Current;
				map.Add(ci.GetFullClassName(), ci.GetHistory());
			}
			return map;
		}
		public SessionMetaModel() : base()
		{
			changedClasses = new NeoDatis.Tool.Wrappers.Map.OdbHashMap<NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
				, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo>();
		}
 public GetDependentObjectIntrospectingCallback()
 {
     objects = new NeoDatis.Tool.Wrappers.Map.OdbHashMap <object, object>();
 }