private ClassInfo GetClassInfo(string fullClassName
                                       )
        {
            if (ODBType.GetFromName(fullClassName).IsNative())
            {
                return(null);
            }
            ISession  session   = storageEngine.GetSession(true);
            MetaModel metaModel = session.GetMetaModel();

            if (metaModel.ExistClass(fullClassName))
            {
                return(metaModel.GetClassInfo(fullClassName, true));
            }
            ClassInfo     ci     = null;
            ClassInfoList ciList = null;

            ciList = classIntrospector.Introspect(fullClassName, true);
            // to enable junit tests
            if (storageEngine != null)
            {
                storageEngine.AddClasses(ciList);
                // For client Server : reset meta model
                if (!storageEngine.IsLocal())
                {
                    metaModel = session.GetMetaModel();
                }
            }
            else
            {
                metaModel.AddClasses(ciList);
            }
            ci = metaModel.GetClassInfo(fullClassName, true);
            return(ci);
        }
Ejemplo n.º 2
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);
        }
        /// <summary>Checks if something in the Arary 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 collection represents</param>
        /// <param name="aoi1">The Meta representation of the array 1 (aoi = ArraybjectInfo)</param>
        /// <param name="aoi2">The Meta representation of the array 2</param>
        /// <param name="objectRecursionLevel"></param>
        /// <returns>true if the 2 array representations are different</returns>
        private bool ManageArrayChanges(NonNativeObjectInfo
                                        nnoi1, NonNativeObjectInfo nnoi2, int fieldId
                                        , ArrayObjectInfo aoi1, ArrayObjectInfo
                                        aoi2, int objectRecursionLevel)
        {
            object[] array1 = aoi1.GetArray();
            object[] array2 = aoi2.GetArray();
            if (array1.Length != array2.Length)
            {
                System.Text.StringBuilder buffer = new System.Text.StringBuilder();
                buffer.Append("Array size has changed oldsize=").Append(array1.Length).Append("/newsize="
                                                                                              ).Append(array2.Length);
                StoreChangedObject(nnoi1, nnoi2, fieldId, aoi1, aoi2, buffer.ToString(), objectRecursionLevel
                                   );
                supportInPlaceUpdate = false;
                return(true);
            }
            AbstractObjectInfo value1 = null;
            AbstractObjectInfo value2 = null;
            // check if this array supports in place update
            bool localSupportInPlaceUpdate = ODBType.HasFixSize
                                                 (aoi2.GetComponentTypeId());
            int  index      = 0;
            bool hasChanged = false;

            try
            {
                for (int i = 0; i < array1.Length; i++)
                {
                    value1 = (AbstractObjectInfo)array1[i];
                    value2 = (AbstractObjectInfo)array2[i];
                    bool localHasChanged = this.HasChanged(value1, value2, objectRecursionLevel);
                    if (localHasChanged)
                    {
                        StoreArrayChange(nnoi1, fieldId, i, value2, localSupportInPlaceUpdate);
                        if (localSupportInPlaceUpdate)
                        {
                            hasChanged = true;
                        }
                        else
                        {
                            hasChanged = true;
                            return(hasChanged);
                        }
                    }
                    index++;
                }
            }
            finally
            {
                if (hasChanged && !localSupportInPlaceUpdate)
                {
                    supportInPlaceUpdate = false;
                }
            }
            return(hasChanged);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>Builds an instance of an array</summary>
        public virtual object BuildArrayInstance(ArrayObjectInfo aoi)
        {
            // first check if array element type is native (int,short, for example)
            ODBType type = ODBType.GetFromName(aoi.GetRealArrayComponentClassName());

            System.Type arrayClazz = type.GetNativeClass();
            object      array      = System.Array.CreateInstance(arrayClazz, aoi.GetArray().Length);

            object             o    = null;
            AbstractObjectInfo aboi = null;

            for (int i = 0; i < aoi.GetArrayLength(); i++)
            {
                aboi = (AbstractObjectInfo)aoi.GetArray()[i];
                if (aboi != null && !aboi.IsDeletedObject() && !aboi.IsNull())
                {
                    o = BuildOneInstance(aboi);
                    ((Array)array).SetValue(o, i);
                }
            }
            return(array);
        }
 public ClassAttributeInfo(int attributeId, string name, System.Type nativeClass,
                           string fullClassName, ClassInfo info) : base
         ()
 {
     //private transient static int nb=0;
     this.id          = attributeId;
     this.name        = name;
     this.nativeClass = nativeClass;
     SetFullClassName(fullClassName);
     if (nativeClass != null)
     {
         attributeType = ODBType.GetFromClass(nativeClass
                                              );
     }
     else
     {
         if (fullClassName != null)
         {
             attributeType = ODBType.GetFromName(fullClassName);
         }
     }
     classInfo = info;
     isIndex   = false;
 }
		public ArrayObjectInfo(object[] array, ODBType type, int componentId) : base(array, type)
		{
			realArrayComponentClassName = ODBType.DefaultArrayComponentClassName;
			componentTypeId = componentId;
		}
        /// <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);
        }
Ejemplo n.º 9
0
        public virtual object BuildOneInstance(AtomicNativeObjectInfo objectInfo)
        {
            int  odbTypeId = objectInfo.GetOdbTypeId();
            long l         = -1;

            switch (odbTypeId)
            {
            case ODBType.NullId:
            {
                return(null);
            }

            case ODBType.StringId:
            {
                return(objectInfo.GetObject());
            }

            case ODBType.DateId:
            {
                return(objectInfo.GetObject());
            }

            case ODBType.LongId:
            case ODBType.NativeLongId:
            {
                if (objectInfo.GetObject().GetType() == typeof(System.Int64))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToInt64(objectInfo.GetObject().ToString()));
            }

            case ODBType.IntegerId:
            case ODBType.NativeIntId:
            {
                if (objectInfo.GetObject().GetType() == typeof(int))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToInt32(objectInfo.GetObject().ToString()));
            }

            case ODBType.BooleanId:
            case ODBType.NativeBooleanId:
            {
                if (objectInfo.GetObject().GetType() == typeof(bool))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToBoolean(objectInfo.GetObject().ToString()));
            }

            case ODBType.ByteId:
            case ODBType.NativeByteId:
            {
                if (objectInfo.GetObject().GetType() == typeof(byte))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToByte(objectInfo.GetObject().ToString()));
            }

            case ODBType.ShortId:
            case ODBType.NativeShortId:
            {
                if (objectInfo.GetObject().GetType() == typeof(short))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToInt16(objectInfo.GetObject().ToString()));
            }

            case ODBType.FloatId:
            case ODBType.NativeFloatId:
            {
                if (objectInfo.GetObject().GetType() == typeof(float))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToSingle(objectInfo.GetObject().ToString()));
            }

            case ODBType.DoubleId:
            case ODBType.NativeDoubleId:
            {
                if (objectInfo.GetObject().GetType() == typeof(double))
                {
                    return(objectInfo.GetObject());
                }
                return(System.Convert.ToDouble(objectInfo.GetObject().ToString()));
            }

            case NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType.BigDecimalId:
            {
                return(System.Decimal.Parse(objectInfo.GetObject().ToString(), System.Globalization.NumberStyles.Any));
            }

            case NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType.BigIntegerId:
            {
                return(System.Decimal.Parse(objectInfo.GetObject().ToString(), System.Globalization.NumberStyles.Any));
            }

            case ODBType.CharacterId:
            case ODBType.NativeCharId:
            {
                if (objectInfo.GetObject().GetType() == typeof(char))
                {
                    return(objectInfo.GetObject());
                }
                return(objectInfo.GetObject().ToString()[0]);
            }

            case ODBType.ObjectOidId:
            {
                if (objectInfo.GetObject().GetType() == typeof(long))
                {
                    l = (long)objectInfo.GetObject();
                }
                else
                {
                    OID oid = (OID)objectInfo.GetObject();
                    l = oid.GetObjectId();
                }
                return(OIDFactory.BuildObjectOID(l));
            }

            case ODBType.ClassOidId:
            {
                if (objectInfo.GetObject().GetType() == typeof(long))
                {
                    l = (long)objectInfo.GetObject();
                }
                else
                {
                    l = System.Convert.ToInt64(objectInfo.GetObject().ToString());
                }
                return(OIDFactory.BuildClassOID(l));
            }

            default:
            {
                throw new ODBRuntimeException(NeoDatisError.InstanceBuilderNativeTypeInCollectionNotSupported
                                              .AddParameter(ODBType.GetNameFromId(odbTypeId)));
                break;
            }
            }
        }
Ejemplo n.º 10
0
        public virtual object BuildOneInstance(NativeObjectInfo objectInfo)
        {
            if (objectInfo.IsAtomicNativeObject())
            {
                return(BuildOneInstance((AtomicNativeObjectInfo)objectInfo));
            }
            if (objectInfo.IsCollectionObject())
            {
                CollectionObjectInfo coi = (CollectionObjectInfo)objectInfo;
                object value             = BuildCollectionInstance(coi);

                /* Manage a specific case of Set
                 * if (typeof(Java.Util.Set).IsAssignableFrom(value.GetType()) && typeof(System.Collections.ICollection).IsAssignableFrom(value.GetType()))
                 * {
                 *      Java.Util.Set s = new Java.Util.HashSet();
                 *      s.AddAll((System.Collections.ICollection)value);
                 *      value = s;
                 * }
                 */
                return(value);
            }
            if (objectInfo.IsArrayObject())
            {
                return(BuildArrayInstance((ArrayObjectInfo)objectInfo));
            }
            if (objectInfo.IsMapObject())
            {
                return(BuildMapInstance((MapObjectInfo)objectInfo));
            }
            if (objectInfo.IsNull())
            {
                return(null);
            }
            throw new ODBRuntimeException(NeoDatisError.InstanceBuilderNativeType.AddParameter(ODBType.GetNameFromId(objectInfo.GetOdbTypeId())));
        }
Ejemplo n.º 11
0
 public ArrayObjectInfo(object[] array, ODBType type, int componentId) : base(array, type)
 {
     realArrayComponentClassName = ODBType.DefaultArrayComponentClassName;
     componentTypeId             = componentId;
 }
Ejemplo n.º 12
0
        /// <summary>Store an object with the specific id</summary>
        /// <param name="oid"></param>
        /// <param name="@object"></param>
        /// <returns></returns>
        /// <></>
        protected virtual NeoDatis.Odb.OID InternalStore(OID oid, object o)
        {
            if (GetSession(true).IsRollbacked())
            {
                throw new ODBRuntimeException(NeoDatisError.OdbHasBeenRollbacked.AddParameter(GetBaseIdentification().ToString()));
            }
            if (o == null)
            {
                throw new ODBRuntimeException(NeoDatisError.OdbCanNotStoreNullObject);
            }
            Type clazz = o.GetType();

            if (ODBType.IsNative(clazz))
            {
                throw new ODBRuntimeException(NeoDatisError.OdbCanNotStoreNativeObjectDirectly
                                              .AddParameter(clazz.FullName).AddParameter(ODBType.GetFromClass(clazz).GetName()).AddParameter(clazz.FullName));
            }
            // The object must be transformed into meta representation
            ClassInfo ci        = null;
            string    className = OdbClassUtil.GetFullName(clazz);

            // first checks if the class of this object already exist in the
            // metamodel
            if (GetMetaModel().ExistClass(className))
            {
                ci = GetMetaModel().GetClassInfo(className, true);
            }
            else
            {
                ClassInfoList ciList = classIntrospector.Introspect(o.GetType(), true);
                // All new classes found
                objectWriter.AddClasses(ciList);
                ci = ciList.GetMainClassInfo();
            }
            // first detects if we must perform an insert or an update
            // If object is in the cache, we must perform an update, else an insert
            bool   mustUpdate = false;
            ICache cache      = GetSession(true).GetCache();

            if (o != null)
            {
                OID cacheOid = cache.IdOfInsertingObject(o);
                if (cacheOid != null)
                {
                    return(cacheOid);
                }
                // throw new ODBRuntimeException("Inserting meta representation of
                // an object without the object itself is not yet supported");
                mustUpdate = cache.ExistObject(o);
            }
            // The introspection callback is used to execute some specific task (like calling trigger, for example) while introspecting the object
            IIntrospectionCallback callback = introspectionCallbackForInsert;

            if (mustUpdate)
            {
                callback = introspectionCallbackForUpdate;
            }
            // Transform the object into an ObjectInfo
            NonNativeObjectInfo nnoi = (NonNativeObjectInfo)objectIntrospector.GetMetaRepresentation(o, ci, true, null, callback);

            // During the introspection process, if object is to be updated, then the oid has been set
            mustUpdate = nnoi.GetOid() != null;
            if (mustUpdate)
            {
                return(objectWriter.UpdateNonNativeObjectInfo(nnoi, false));
            }
            return(objectWriter.InsertNonNativeObject(oid, nnoi, true));
        }