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); }
/// <summary>Checks if something in the Map has changed, if yes, stores the change</summary> /// <param name="nnoi1"> /// The first Object meta representation (nnoi = /// NonNativeObjectInfo) /// </param> /// <param name="nnoi2">The second object meta representation</param> /// <param name="fieldIndex">The field index that this map represents</param> /// <param name="moi1">The Meta representation of the map 1 (moi = MapObjectInfo)</param> /// <param name="moi2">The Meta representation of the map 2</param> /// <param name="objectRecursionLevel"></param> /// <returns>true if the 2 map representations are different</returns> private bool ManageMapChanges(NonNativeObjectInfo nnoi1, NonNativeObjectInfo nnoi2, int fieldId , MapObjectInfo moi1, MapObjectInfo moi2, int objectRecursionLevel) { if (true) { return true; } IDictionary<AbstractObjectInfo , AbstractObjectInfo> map1 = moi1.GetMap(); IDictionary<AbstractObjectInfo , AbstractObjectInfo> map2 = moi2.GetMap(); if (map1.Count != map2.Count) { System.Text.StringBuilder buffer = new System.Text.StringBuilder(); buffer.Append("Map size has changed oldsize=").Append(map1.Count).Append("/newsize=" ).Append(map2.Count); StoreChangedObject(nnoi1, nnoi2, fieldId, moi1, moi2, buffer.ToString(), objectRecursionLevel ); return true; } IEnumerator<AbstractObjectInfo > keys1 = map1.Keys.GetEnumerator(); IEnumerator<AbstractObjectInfo > keys2 = map2.Keys.GetEnumerator(); AbstractObjectInfo key1 = null; AbstractObjectInfo key2 = null; AbstractObjectInfo value1 = null; AbstractObjectInfo value2 = null; int index = 0; while (keys1.MoveNext()) { keys2.MoveNext(); key1 = keys1.Current; key2 = keys2.Current; bool keysHaveChanged = this.HasChanged(key1, key2, objectRecursionLevel); if (keysHaveChanged) { StoreChangedObject(nnoi1, nnoi2, fieldId, key1, key2, "Map key index " + index + " has changed", objectRecursionLevel); return true; } value1 = map1[key1]; value2 = map2[key2]; bool valuesHaveChanged = this.HasChanged(value1, value2, objectRecursionLevel); if (valuesHaveChanged) { StoreChangedObject(nnoi1, nnoi2, fieldId, value1, value2, "Map value index " + index + " has changed", objectRecursionLevel); return true; } index++; } return false; }
protected virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo GetNativeObjectInfoInternal (NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type, object o, bool recursive , System.Collections.Generic.IDictionary <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo > alreadyReadObjects, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback callback) { NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null; if (type.IsAtomicNative()) { if (o == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo(type.GetId()); } else { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.AtomicNativeObjectInfo(o, type .GetId()); } } else { if (type.IsCollection()) { aoi = IntrospectCollection((System.Collections.ICollection)o, recursive, alreadyReadObjects , type, callback); } else { if (type.IsArray()) { if (o == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo(null); } else { // Gets the type of the elements of the array string realArrayClassName = OdbClassUtil.GetFullName(o.GetType().GetElementType()); NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo aroi = null; if (recursive) { aroi = IntrospectArray(o, recursive, alreadyReadObjects, type, callback); } else { aroi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo((object[])o ); } aroi.SetRealArrayComponentClassName(realArrayClassName); aoi = aroi; } } else { if (type.IsMap()) { if (o == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.MapObjectInfo(null, type, type.GetDefaultInstanciationClass ().FullName); } else { MapObjectInfo moi = null; string realMapClassName = OdbClassUtil.GetFullName(o.GetType()); bool isGeneric = o.GetType().IsGenericType; if (isGeneric) { moi = new MapObjectInfo(IntrospectGenericMap((System.Collections.Generic.IDictionary <object, object>)o, recursive, alreadyReadObjects, callback), type, realMapClassName); } else { moi = new MapObjectInfo(IntrospectNonGenericMap((System.Collections.IDictionary)o, recursive, alreadyReadObjects, callback), type, realMapClassName); } if (realMapClassName.IndexOf("$") != -1) { moi.SetRealMapClassName(OdbClassUtil.GetFullName(type.GetDefaultInstanciationClass())); } aoi = moi; } } else { if (type.IsEnum()) { System.Enum enumObject = (System.Enum)o; if (enumObject == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo(type.GetSize( )); } else { Type t = enumObject.GetType(); string enumClassName = enumObject == null ? null : OdbClassUtil.GetFullName(enumObject.GetType()); // Here we must check if the enum is already in the meta model. Enum must be stored in the meta // model to optimize its storing as we need to keep track of the enum class // for each enum stored. So instead of storing the enum class name, we can store enum class id, a long // instead of the full enum class name string NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = GetClassInfo(enumClassName); string enumValue = enumObject == null ? null : enumObject.ToString(); aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.EnumNativeObjectInfo(ci, enumValue ); } } } } } } return(aoi); }
public virtual object BuildGenericMapInstance(MapObjectInfo mapObjectInfo, Type t) { System.Collections.Generic.IDictionary<AbstractObjectInfo, AbstractObjectInfo> map = mapObjectInfo.GetMap(); Type genericType = t.GetGenericTypeDefinition(); object newMap = null; try { newMap = System.Activator.CreateInstance(t); } catch (System.Exception e) { Console.WriteLine(e); throw new ODBRuntimeException(NeoDatisError.MapInstanciationError.AddParameter(map.GetType().FullName), e); } int i = 0; System.Collections.Generic.IEnumerator<AbstractObjectInfo> iterator = map.Keys.GetEnumerator(); AbstractObjectInfo key = null; MethodInfo method = t.GetMethod("Add", t.GetGenericArguments()); while (iterator.MoveNext()) { key = iterator.Current; object realKey = BuildOneInstance(key); object realValue = BuildOneInstance(map[key]); method.Invoke(newMap, new object[] { realKey, realValue }); } return newMap; }
public virtual IDictionary BuildNonGenericMapInstance(MapObjectInfo mapObjectInfo, Type t) { System.Collections.Generic.IDictionary<AbstractObjectInfo,AbstractObjectInfo> map = mapObjectInfo.GetMap(); IDictionary newMap; try { newMap = (IDictionary) System.Activator.CreateInstance(t); } catch (System.Exception e) { throw new ODBRuntimeException(NeoDatisError.MapInstanciationError.AddParameter(map.GetType().FullName),e); } int i = 0; System.Collections.Generic.IEnumerator<AbstractObjectInfo> iterator = map.Keys.GetEnumerator(); AbstractObjectInfo key = null; while (iterator.MoveNext()) { key = iterator.Current; object realKey = BuildOneInstance(key); object realValue = BuildOneInstance(map[key]); newMap[realKey] = realValue; } return newMap; }
public virtual object BuildMapInstance(MapObjectInfo moi) { Type t = classPool.GetClass(moi.GetRealMapClassName()); if (t.IsGenericType) { return BuildGenericMapInstance(moi, t); } else { return BuildNonGenericMapInstance(moi,t); } }
protected virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo GetNativeObjectInfoInternal (NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type, object o, bool recursive , System.Collections.Generic.IDictionary<object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo > alreadyReadObjects, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback callback) { NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null; if (type.IsAtomicNative()) { if (o == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo(type.GetId()); } else { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.AtomicNativeObjectInfo(o, type .GetId()); } } else { if (type.IsCollection()) { aoi = IntrospectCollection((System.Collections.ICollection)o, recursive, alreadyReadObjects , type, callback); } else { if (type.IsArray()) { if (o == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo(null); } else { // Gets the type of the elements of the array string realArrayClassName = OdbClassUtil.GetFullName(o.GetType().GetElementType()); NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo aroi = null; if (recursive) { aroi = IntrospectArray(o, recursive, alreadyReadObjects, type, callback); } else { aroi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo((object[])o ); } aroi.SetRealArrayComponentClassName(realArrayClassName); aoi = aroi; } } else { if (type.IsMap()) { if (o == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.MapObjectInfo(null, type, type.GetDefaultInstanciationClass ().FullName); } else { MapObjectInfo moi = null; string realMapClassName = OdbClassUtil.GetFullName(o.GetType()); bool isGeneric = o.GetType().IsGenericType; if (isGeneric) { moi = new MapObjectInfo(IntrospectGenericMap((System.Collections.Generic.IDictionary<object,object>)o, recursive, alreadyReadObjects, callback), type, realMapClassName); } else { moi = new MapObjectInfo(IntrospectNonGenericMap((System.Collections.IDictionary)o, recursive, alreadyReadObjects, callback), type, realMapClassName); } if (realMapClassName.IndexOf("$") != -1) { moi.SetRealMapClassName(OdbClassUtil.GetFullName(type.GetDefaultInstanciationClass())); } aoi = moi; } } else { if (type.IsEnum()) { System.Enum enumObject = (System.Enum)o; if (enumObject == null) { aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NullNativeObjectInfo(type.GetSize( )); } else { Type t = enumObject.GetType(); string enumClassName = enumObject == null ? null : OdbClassUtil.GetFullName(enumObject.GetType()); // Here we must check if the enum is already in the meta model. Enum must be stored in the meta // model to optimize its storing as we need to keep track of the enum class // for each enum stored. So instead of storing the enum class name, we can store enum class id, a long // instead of the full enum class name string NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = GetClassInfo(enumClassName); string enumValue = enumObject == null ? null : enumObject.ToString(); aoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.EnumNativeObjectInfo(ci, enumValue ); } } } } } } return aoi; }