コード例 #1
0
 public virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo BuildNnoi
     (object o, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo classInfo, NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
     [] values, long[] attributesIdentification, int[] attributeIds, System.Collections.Generic.IDictionary
     <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo> alreadyReadObjects
     )
 {
     NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo nnoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                         (o, classInfo, values, attributesIdentification, attributeIds);
     if (storageEngine != null)
     {
         // for unit test purpose
         NeoDatis.Odb.Core.Transaction.ICache cache = storageEngine.GetSession(true).GetCache
                                                          ();
         // Check if object is in the cache, if so sets its oid
         NeoDatis.Odb.OID oid = cache.GetOid(o, false);
         if (oid != null)
         {
             nnoi.SetOid(oid);
             // Sets some values to the new header to keep track of the infos
             // when
             // executing NeoDatis without closing it, just committing.
             // Bug reported by Andy
             NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = cache.GetObjectInfoHeaderFromOid
                                                                             (oid, true);
             nnoi.GetHeader().SetObjectVersion(oih.GetObjectVersion());
             nnoi.GetHeader().SetUpdateDate(oih.GetUpdateDate());
             nnoi.GetHeader().SetCreationDate(oih.GetCreationDate());
         }
     }
     return(nnoi);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
        public override void SetMetaModel(NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel
                                          metaModel2)
        {
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci        = null;
            NeoDatis.Odb.Core.Layers.Layer2.Meta.MetaModel metaModel = new NeoDatis.Odb.Core.Layers.Layer2.Meta.SessionMetaModel
                                                                           ();
            GetSession(true).SetMetaModel(metaModel);
            // Just add the classes
            System.Collections.IEnumerator iterator = metaModel2.GetAllClasses().GetEnumerator
                                                          ();
            while (iterator.MoveNext())
            {
                this.GetMetaModel().AddClass((NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator
                                             .Current);
            }
            // Now persists classes
            iterator = metaModel.GetAllClasses().GetEnumerator();
            int i = 0;

            while (iterator.MoveNext())
            {
                ci = (NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo)iterator.Current;
                if (ci.GetPosition() == -1)
                {
                    objectWriter.PersistClass(ci, (i == 0 ? -2 : i - 1), false, false);
                }
                i++;
            }
        }
コード例 #4
0
 public NeoDatisStoredClass(ClassInfo ci, NeoDatisLocalConnection connection)
 {
     this.ci = ci;
     this.connection = connection;
     Name = ci.GetFullClassName();
     var classAttributeInfos = ci.GetAttributes();
     fields = classAttributeInfos.Select(cai => (Field) new NeoDatisField() {Name = cai.GetName(), DataType = cai.GetAttributeType().GetName()}).ToList();
 }
コード例 #5
0
 public virtual NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo GetMetaRepresentation
     (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)
 {
     return(GetObjectInfo(o, ci, recursive, alreadyReadObjects, callback));
 }
コード例 #6
0
        private NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo IntrospectCollection
            (System.Collections.ICollection collection, bool introspect, System.Collections.Generic.IDictionary
            <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo> alreadyReadObjects
            , NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback
            callback)
        {
            if (collection == null)
            {
                return(new NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo());
            }
            // A collection that contain all meta representations of the collection
            // objects
            System.Collections.Generic.ICollection <NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                                    > collectionCopy = new System.Collections.Generic.List <NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                                                                                            >(collection.Count);
            // A collection to keep references all all non native objects of the
            // collection
            // This will be used later to get all non native objects contained in an
            // object
            System.Collections.Generic.ICollection <NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                    > nonNativesObjects = new System.Collections.Generic.List <NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                                               >(collection.Count);
            NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null;
            System.Collections.IEnumerator iterator = collection.GetEnumerator();
            while (iterator.MoveNext())
            {
                object o = iterator.Current;
                NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
                // Null objects are not inserted in list
                if (o != null)
                {
                    ci  = GetClassInfo(OdbClassUtil.GetFullName(o.GetType()));
                    aoi = GetObjectInfo(o, ci, introspect, alreadyReadObjects, callback);
                    collectionCopy.Add(aoi);
                    if (aoi.IsNonNativeObject())
                    {
                        // o is not null, call the callback with it
                        //callback.objectFound(o);
                        // This is a non native object
                        nonNativesObjects.Add((NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)aoi
                                              );
                    }
                }
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo coi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo
                                                                                (collectionCopy, nonNativesObjects);
            string realCollectionClassName = OdbClassUtil.GetFullName(collection.GetType());

            if (realCollectionClassName.IndexOf("$") != -1)
            {
                coi.SetRealCollectionClassName(type.GetDefaultInstanciationClass().FullName);
            }
            else
            {
                coi.SetRealCollectionClassName(realCollectionClassName);
            }
            return(coi);
        }
コード例 #7
0
 /// <summary>Reconnect an object to the current session.</summary>
 /// <remarks>
 /// Reconnect an object to the current session. It connects the object and
 /// all the dependent objects (Objects accessible from the object graph of the
 /// root object
 /// </remarks>
 public override void Reconnect(object @object)
 {
     if (@object == null)
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.ReconnectCanReconnectNullObject
                                                    );
     }
     NeoDatis.Odb.Core.Transaction.ICrossSessionCache crossSessionCache = NeoDatis.Odb.Impl.Core.Transaction.CacheFactory
                                                                          .GetCrossSessionCache(GetBaseIdentification().GetIdentification());
     NeoDatis.Odb.OID oid = crossSessionCache.GetOid(@object);
     //in some situation the user can control the disconnect and reconnect
     //so before throws an exception test if in the current session
     //there is the object on the cache
     if (oid == null)
     {
         throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CrossSessionCacheNullOidForObject
                                                    .AddParameter(@object));
     }
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ObjectInfoHeader oih = objectReader.ReadObjectInfoHeaderFromOid
                                                                     (oid, false);
     GetSession(true).AddObjectToCache(oid, @object, oih);
     // Retrieve Dependent Objects
     NeoDatis.Odb.Impl.Core.Layers.Layer1.Introspector.GetDependentObjectIntrospectingCallback
         getObjectsCallback = new NeoDatis.Odb.Impl.Core.Layers.Layer1.Introspector.GetDependentObjectIntrospectingCallback
                                  ();
     NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = GetSession(true).GetMetaModel
                                                             ().GetClassInfoFromId(oih.GetClassInfoId());
     objectIntrospector.GetMetaRepresentation(@object, ci, true, null, getObjectsCallback
                                              );
     System.Collections.Generic.ICollection <object> dependentObjects = getObjectsCallback
                                                                        .GetObjects();
     System.Collections.Generic.IEnumerator <object> iterator = dependentObjects.GetEnumerator
                                                                    ();
     while (iterator.MoveNext())
     {
         object o = iterator.Current;
         if (o != null)
         {
             oid = crossSessionCache.GetOid(o);
             if (oid == null)
             {
                 throw new NeoDatis.Odb.ODBRuntimeException(NeoDatis.Odb.Core.NeoDatisError.CrossSessionCacheNullOidForObject
                                                            .AddParameter(o));
             }
             oih = objectReader.ReadObjectInfoHeaderFromOid(oid, false);
             GetSession(true).AddObjectToCache(oid, o, oih);
         }
     }
 }
コード例 #8
0
 public override System.IComparable ComputeIndexKey(NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo
                                                    ci, NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfoIndex index)
 {
     NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery q = (NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery
                                                              )query;
     NeoDatis.Odb.Core.Layers.Layer2.Meta.AttributeValuesMap values = q.GetCriteria().
                                                                      GetValues();
     // if values.hasOid() is true, this means that we are working of the full object,
     // the index key is then the oid and not the object itself
     if (values.HasOid())
     {
         return(new NeoDatis.Odb.Core.Query.SimpleCompareKey(values.GetOid()));
     }
     return(NeoDatis.Odb.Core.Query.Execution.IndexTool.ComputeKey(classInfo, index, (
                                                                       NeoDatis.Odb.Impl.Core.Query.Criteria.CriteriaQuery)query));
 }
コード例 #9
0
        private NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo IntrospectArray(object
                                                                                     array, bool introspect, System.Collections.Generic.IDictionary <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                                                                                     > alreadyReadObjects, NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType valueType, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback
                                                                                     callback)
        {
            int length = NeoDatis.Tool.Wrappers.OdbReflection.GetArrayLength(array);

            System.Type elementType = array.GetType().GetElementType();
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type = NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType
                                                                .GetFromClass(elementType);
            if (type.IsAtomicNative())
            {
                return(IntropectAtomicNativeArray(array, type));
            }
            if (!introspect)
            {
                return(new NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo((object[])array));
            }
            object[] arrayCopy = new object[length];
            for (int i = 0; i < length; i++)
            {
                object o = NeoDatis.Tool.Wrappers.OdbReflection.GetArrayElement(array, i);
                NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
                if (o != null)
                {
                    ci = GetClassInfo(OdbClassUtil.GetFullName(o.GetType()));
                    NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = GetObjectInfo(o, ci
                                                                                                , introspect, alreadyReadObjects, callback);
                    arrayCopy[i] = aoi;
                }
                else
                {
                    arrayCopy[i] = new NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeNullObjectInfo();
                }
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo arrayOfAoi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.ArrayObjectInfo
                                                                                  (arrayCopy, valueType, type.GetId());
            return(arrayOfAoi);
        }
コード例 #10
0
		/// <summary>
		/// Saves the fact that something has changed in the class (number of objects
		/// or last object oid)
		/// </summary>
		/// <param name="classInfo"></param>
		/// <param name="uci"></param>
		public override void AddChangedClass(ClassInfo classInfo)
		{
            changedClasses[classInfo] = classInfo;
			SetHasChanged(true);
		}
コード例 #11
0
        public virtual ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
        {
            string             attributeName = null;
            ClassAttributeInfo cai1          = null;
            ClassAttributeInfo cai2          = null;

            Meta.ClassInfoCompareResult result = new ClassInfoCompareResult(GetFullClassName());
            bool isCompatible = true;
            IOdbList <ClassAttributeInfo> attributesToRemove = new OdbArrayList <ClassAttributeInfo>(10);
            IOdbList <ClassAttributeInfo> attributesToAdd    = new OdbArrayList <ClassAttributeInfo>(10);
            int nbAttributes = attributes.Count;

            for (int id = 0; id < nbAttributes; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai1 = attributes[id];
                if (cai1 == null)
                {
                    continue;
                }
                attributeName = cai1.GetName();
                cai2          = newCI.GetAttributeInfoFromId(cai1.GetId());
                if (cai2 == null)
                {
                    result.AddCompatibleChange("Field '" + attributeName + "' has been removed");
                    if (update)
                    {
                        // Simply remove the attribute from meta-model
                        attributesToRemove.Add(cai1);
                    }
                }
                else
                {
                    if (!ODBType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
                    {
                        result.AddIncompatibleChange("Type of Field '" + attributeName + "' has changed : old='"
                                                     + cai1.GetFullClassname() + "' - new='" + cai2.GetFullClassname() + "'");
                        isCompatible = false;
                    }
                }
            }
            int nbNewAttributes = newCI.attributes.Count;

            for (int id = 0; id < nbNewAttributes; id++)
            {
                // !!!WARNING : ID start with 1 and not 0
                cai2 = newCI.attributes[id];
                if (cai2 == null)
                {
                    continue;
                }
                attributeName = cai2.GetName();
                cai1          = GetAttributeInfoFromId(cai2.GetId());
                if (cai1 == null)
                {
                    result.AddCompatibleChange("Field '" + attributeName + "' has been added");
                    if (update)
                    {
                        // Sets the right id of attribute
                        cai2.SetId(maxAttributeId + 1);
                        maxAttributeId++;
                        // Then adds the new attribute to the meta-model
                        attributesToAdd.Add(cai2);
                    }
                }
            }
            attributes.RemoveAll(attributesToRemove);
            attributes.AddAll(attributesToAdd);
            FillAttributesMap();
            return(result);
        }
コード例 #12
0
		public virtual ClassInfo Duplicate(bool onlyData
			)
		{
			ClassInfo ci = new ClassInfo
				(fullClassName);
			ci.extraInfo = extraInfo;
			ci.SetAttributes(attributes);
			ci.SetClassCategory(classCategory);
			ci.SetMaxAttributeId(maxAttributeId);
			if (onlyData)
			{
				return ci;
			}
			ci.SetAttributesDefinitionPosition(attributesDefinitionPosition);
			ci.SetBlockSize(blockSize);
			ci.SetExtraInfo(extraInfo);
			ci.SetId(id);
			ci.SetPreviousClassOID(previousClassOID);
			ci.SetNextClassOID(nextClassOID);
			ci.SetLastObjectInfoHeader(lastObjectInfoHeader);
			ci.SetPosition(position);
			ci.SetIndexes(indexes);
			return ci;
		}
コード例 #13
0
		public virtual ClassInfoCompareResult ExtractDifferences(ClassInfo newCI, bool update)
		{
			string attributeName = null;
			ClassAttributeInfo cai1 = null;
			ClassAttributeInfo cai2 = null;
			Meta.ClassInfoCompareResult result = new ClassInfoCompareResult(GetFullClassName());
			bool isCompatible = true;
			IOdbList<ClassAttributeInfo> attributesToRemove = new OdbArrayList<ClassAttributeInfo>(10);
			IOdbList<ClassAttributeInfo> attributesToAdd = new OdbArrayList<ClassAttributeInfo>(10);
			int nbAttributes = attributes.Count;
			for (int id = 0; id < nbAttributes; id++)
			{
				// !!!WARNING : ID start with 1 and not 0
				cai1 = attributes[id];
				if (cai1 == null)
				{
					continue;
				}
				attributeName = cai1.GetName();
				cai2 = newCI.GetAttributeInfoFromId(cai1.GetId());
				if (cai2 == null)
				{
					result.AddCompatibleChange("Field '" + attributeName + "' has been removed");
					if (update)
					{
						// Simply remove the attribute from meta-model
						attributesToRemove.Add(cai1);
					}
				}
				else
				{
					if (!ODBType.TypesAreCompatible(cai1.GetAttributeType(), cai2.GetAttributeType()))
					{
						result.AddIncompatibleChange("Type of Field '" + attributeName + "' has changed : old='"
							 + cai1.GetFullClassname() + "' - new='" + cai2.GetFullClassname() + "'");
						isCompatible = false;
					}
				}
			}
			int nbNewAttributes = newCI.attributes.Count;
			for (int id = 0; id < nbNewAttributes; id++)
			{
				// !!!WARNING : ID start with 1 and not 0
				cai2 = newCI.attributes[id];
				if (cai2 == null)
				{
					continue;
				}
				attributeName = cai2.GetName();
				cai1 = GetAttributeInfoFromId(cai2.GetId());
				if (cai1 == null)
				{
					result.AddCompatibleChange("Field '" + attributeName + "' has been added");
					if (update)
					{
						// Sets the right id of attribute
						cai2.SetId(maxAttributeId + 1);
						maxAttributeId++;
						// Then adds the new attribute to the meta-model
						attributesToAdd.Add(cai2);
					}
				}
			}
			attributes.RemoveAll(attributesToRemove);
			attributes.AddAll(attributesToAdd);
			FillAttributesMap();
			return result;
		}
コード例 #14
0
 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);
 }
コード例 #15
0
				/// <summary> </summary>
				/// <param name="clazz">The class to instrospect
				/// </param>
				/// <param name="recursive">If true, goes does the hierarchy to try to analyse all classes
				/// </param>
				/// <param name="A">map with classname that are being introspected, to avoid recursive calls
				/// 
				/// </param>
				/// <returns>
				/// </returns>
				private ClassInfoList InternalIntrospect(System.Type clazz, bool recursive, ClassInfoList classInfoList)
				{
					if (classInfoList != null)
					{
						ClassInfo existingCi = (ClassInfo) classInfoList.GetClassInfoWithName(OdbClassUtil.GetFullName( clazz));
						if (existingCi != null)
						{
							return classInfoList;
						}
					}
					
		            ClassInfo classInfo = new ClassInfo(OdbClassUtil.GetFullName(clazz));
		            classInfo.SetClassCategory( GetClassCategory(OdbClassUtil.GetFullName(clazz)) );
					if (classInfoList == null)
					{
						classInfoList = new ClassInfoList(classInfo);
					}
					else
					{
						classInfoList.AddClassInfo(classInfo);
					}
					
					// Field[] fields = clazz.getDeclaredFields();
					//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
					//m by cristi
		            IOdbList<FieldInfo> fields = GetAllFields(OdbClassUtil.GetFullName(clazz));
					IOdbList<ClassAttributeInfo> attributes = new OdbArrayList<ClassAttributeInfo>(fields.Count);
					
					ClassInfo ci = null;
					for (int i = 0; i < fields.Count; i++)
					{
						System.Reflection.FieldInfo field = (System.Reflection.FieldInfo) fields[i];
                        //Console.WriteLine("Field " + field.Name + " , type = " + field.FieldType);
						if (!ODBType.GetFromClass(field.FieldType).IsNative())
						{
							if (recursive)
							{
								classInfoList = InternalIntrospect(field.FieldType, recursive, classInfoList);
		                        ci = classInfoList.GetClassInfoWithName(OdbClassUtil.GetFullName(field.FieldType));
							}
							else
							{
		                        ci = new ClassInfo(OdbClassUtil.GetFullName(field.FieldType));
							}
						}
						else
						{
							ci = null;
						}
						attributes.Add(new ClassAttributeInfo((i + 1), field.Name, field.FieldType, OdbClassUtil.GetFullName(field.FieldType), ci));
					}
					classInfo.SetAttributes( attributes );
					classInfo.SetMaxAttributeId( fields.Count);
					return classInfoList;
				}
コード例 #16
0
				/// <summary>Builds a class info from a class and an existing class info
				/// 
				/// <pre>
				/// The existing class info is used to make sure that fields with the same name will have
				/// the same id
				/// </pre>
				/// 
				/// </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>
				public ClassInfo GetClassInfo(System.String fullClassName, ClassInfo existingClassInfo)
				{
					
					
					ClassInfo classInfo = new ClassInfo(fullClassName);
					classInfo.SetClassCategory( GetClassCategory(fullClassName) );
		;
					IOdbList<FieldInfo> fields = GetAllFields(fullClassName);
					IOdbList<ClassAttributeInfo> attributes = new OdbArrayList<ClassAttributeInfo>(fields.Count);
			
					int attributeId = - 1;
					int maxAttributeId = existingClassInfo.GetMaxAttributeId();
					ClassInfo ci = null;
					for (int i = 0; i < fields.Count; i++)
					{
						FieldInfo field = fields[i];
						// Gets the attribute id from the existing class info
						attributeId = existingClassInfo.GetAttributeId(field.Name);
						if (attributeId == - 1)
						{
							maxAttributeId++;
							// The attibute with field.getName() does not exist in existing class info
							//  create a new id
							attributeId = maxAttributeId;
						}
						if (!ODBType.GetFromClass(field.FieldType).IsNative())
						{
							ci = new ClassInfo(OdbClassUtil.GetFullName(field.FieldType));
						}
						else
						{
							ci = null;
						}
						
						attributes.Add(new ClassAttributeInfo(attributeId, field.Name, field.FieldType, OdbClassUtil.GetFullName(field.FieldType), ci));
					}
					classInfo.SetAttributes( attributes );
					classInfo.SetMaxAttributeId( maxAttributeId);
					return classInfo;
				}
コード例 #17
0
 /// <summary>
 /// Saves the fact that something has changed in the class (number of objects
 /// or last object oid)
 /// </summary>
 /// <param name="classInfo"></param>
 /// <param name="uci"></param>
 public override void AddChangedClass(ClassInfo classInfo)
 {
     changedClasses[classInfo] = classInfo;
     SetHasChanged(true);
 }
コード例 #18
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>
        /// <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);
        }