예제 #1
0
        private void StoreChangedObject(NonNativeObjectInfo aoi1, NonNativeObjectInfo aoi2, int fieldId,
                                        AbstractObjectInfo oldValue, AbstractObjectInfo newValue, string message,
                                        int objectRecursionLevel)
        {
            if (aoi1 == null || aoi2 == null)
            {
                return;
            }

            if (aoi1.GetOid() != null && aoi1.GetOid().Equals(aoi2.GetOid()))
            {
                _changedObjectMetaRepresentations.Add(aoi2);
                _changes.Add(new ChangedObjectInfo(aoi1.GetClassInfo(), aoi2.GetClassInfo(), fieldId, oldValue,
                                                   newValue, message, objectRecursionLevel));
                // also the max recursion level
                if (objectRecursionLevel > _maxObjectRecursionLevel)
                {
                    _maxObjectRecursionLevel = objectRecursionLevel;
                }
                _nbChanges++;
            }
            else
            {
                _newObjects.Add(aoi2.GetObject());
                _nbChanges++;
            }
        }
예제 #2
0
        private static bool ClassAreCompatible(AbstractObjectInfo value1, AbstractObjectInfo value2)
        {
            var clazz1 = value1.GetType();
            var clazz2 = value2.GetType();

            return(clazz1 == clazz2);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public virtual object BuildGenericCollectionInstance(CollectionObjectInfo coi, Type t)
        {
            Type   genericType   = t.GetGenericTypeDefinition();
            object newCollection = null;

            try
            {
                newCollection = System.Activator.CreateInstance(t);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
                throw new ODBRuntimeException(NeoDatisError.CollectionInstanciationError.AddParameter(coi.GetRealCollectionClassName()));
            }
            System.Collections.IEnumerator iterator = coi.GetCollection().GetEnumerator();
            AbstractObjectInfo             aoi      = null;
            MethodInfo method = t.GetMethod("Add");

            while (iterator.MoveNext())
            {
                aoi = (AbstractObjectInfo)iterator.Current;
                if (!aoi.IsDeletedObject())
                {
                    method.Invoke(newCollection, new object[] { BuildOneInstance(aoi) });
                }
            }
            return(newCollection);
        }
예제 #6
0
        private static object CheckIfOid(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            long l;

            if (odbTypeId == OdbType.ObjectOidId)
            {
                if (objectInfo.GetObject() is long)
                {
                    l = (long)objectInfo.GetObject();
                }
                else
                {
                    var oid = (OID)objectInfo.GetObject();
                    l = oid.ObjectId;
                }

                return(OIDFactory.BuildObjectOID(l));
            }

            if (odbTypeId == OdbType.ClassOidId)
            {
                if (objectInfo.GetObject() is long)
                {
                    l = (long)objectInfo.GetObject();
                }
                else
                {
                    l = Convert.ToInt64(objectInfo.GetObject().ToString());
                }
                return(OIDFactory.BuildClassOID(l));
            }

            return(ThrowIfNotFound(odbTypeId));
        }
        /// <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);
        }
        /// <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);
        }
예제 #9
0
 public virtual bool Match(AbstractObjectInfo
                           aoi)
 {
     if (criterion == null)
     {
         return(true);
     }
     return(criterion.Match(aoi));
 }
        private void StoreArrayChange(NonNativeObjectInfo
                                      nnoi, int arrayAttributeId, int arrayIndex, AbstractObjectInfo
                                      value, bool supportInPlaceUpdate)
        {
            nbChanges++;
            ArrayModifyElement ame = new ArrayModifyElement
                                         (nnoi, arrayAttributeId, arrayIndex, value, supportInPlaceUpdate);

            arrayChanges.Add(ame);
        }
예제 #11
0
 public ChangedObjectInfo(ClassInfo oldCi, ClassInfo newCi, int fieldIndex, AbstractObjectInfo oldValue,
                          AbstractObjectInfo newValue, string message, int objectRecursionLevel)
 {
     _oldCi = oldCi;
     _newCi = newCi;
     _fieldIndex = fieldIndex;
     _oldValue = oldValue;
     _newValue = newValue;
     _message = message;
     _objectRecursionLevel = objectRecursionLevel;
 }
예제 #12
0
 private bool HasChanged(AbstractObjectInfo aoi1, AbstractObjectInfo aoi2, int objectRecursionLevel)
 {
     // If one is null and the other not
     if (aoi1.IsNull() != aoi2.IsNull())
         return true;
     if (aoi1.IsNonNativeObject() && aoi2.IsNonNativeObject())
         return HasChanged((NonNativeObjectInfo) aoi1, (NonNativeObjectInfo) aoi2, objectRecursionLevel + 1);
     if (aoi1.IsNative() && aoi2.IsNative())
         return HasChanged((NativeObjectInfo) aoi1, (NativeObjectInfo) aoi2);
     return false;
 }
예제 #13
0
 public ChangedObjectInfo(ClassInfo oldCi, ClassInfo newCi, int fieldIndex, AbstractObjectInfo oldValue,
                          AbstractObjectInfo newValue, string message, int objectRecursionLevel)
 {
     _oldCi                = oldCi;
     _newCi                = newCi;
     _fieldIndex           = fieldIndex;
     _oldValue             = oldValue;
     _newValue             = newValue;
     _message              = message;
     _objectRecursionLevel = objectRecursionLevel;
 }
예제 #14
0
        private static object CheckIfBool(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.BooleanId)
            {
                if (objectInfo.GetObject() is bool)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToBoolean(objectInfo.GetObject().ToString()));
            }

            return(CheckIfByte(objectInfo, odbTypeId));
        }
예제 #15
0
        private object BuildOneInstance(AbstractObjectInfo objectInfo)
        {
            if (objectInfo.IsNull())
            {
                return(null);
            }

            var instance = objectInfo.GetType() == typeof(NonNativeObjectInfo)
                               ? BuildOneInstance((NonNativeObjectInfo)objectInfo)
                               : BuildOneInstance((NativeObjectInfo)objectInfo);

            return(instance);
        }
예제 #16
0
        private static object CheckIfCharacter(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.CharacterId)
            {
                if (objectInfo.GetObject() is char)
                {
                    return(objectInfo.GetObject());
                }
                return(objectInfo.GetObject().ToString()[0]);
            }

            return(CheckIfOid(objectInfo, odbTypeId));
        }
예제 #17
0
        private AbstractObjectInfo GetNativeObjectInfoInternal(OdbType type, object o, bool recursive,
                                                               IDictionary <object, NonNativeObjectInfo>
                                                               alreadyReadObjects, IIntrospectionCallback callback)
        {
            AbstractObjectInfo aoi = null;

            if (type.IsAtomicNative())
            {
                if (o == null)
                {
                    aoi = new NullNativeObjectInfo(type.Id);
                }
                else
                {
                    aoi = new AtomicNativeObjectInfo(o, type.Id);
                }
            }
            else if (type.IsArray())
            {
                if (o == null)
                {
                    aoi = new ArrayObjectInfo(null);
                }
                else
                {
                    // Gets the type of the elements of the array
                    var realArrayClassName = OdbClassNameResolver.GetFullName(o.GetType().GetElementType());
                    var arrayObjectInfo    = recursive
                                              ? IntrospectArray(o, alreadyReadObjects, type, callback)
                                              : new ArrayObjectInfo((object[])o);

                    arrayObjectInfo.SetRealArrayComponentClassName(realArrayClassName);
                    aoi = arrayObjectInfo;
                }
            }
            else if (type.IsEnum())
            {
                var enumObject = (Enum)o;

                // 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
                var classInfo = GetClassInfo(enumObject.GetType());
                var enumValue = enumObject.ToString();
                aoi = new EnumNativeObjectInfo(classInfo, enumValue);
            }

            return(aoi);
        }
예제 #18
0
        private NonNativeObjectInfo(object @object, ClassInfo info, AbstractObjectInfo[] values,
                                   long[] attributesIdentification, int[] attributeIds)
            : base(OdbType.GetFromName(info.FullClassName))
        {
            _theObject = @object;
            _classInfo = info;
            _attributeValues = values;
            _maxNbattributes = _classInfo.MaxAttributeId;

            if (_attributeValues == null)
                _attributeValues = new AbstractObjectInfo[_maxNbattributes];

            _objectHeader = new ObjectInfoHeader(-1, null, null, (_classInfo != null
                                                                      ? _classInfo.ClassInfoId
                                                                      : null), attributesIdentification, attributeIds);
        }
예제 #19
0
        public virtual object BuildNonGenericCollectionInstance(CollectionObjectInfo coi, Type t)
        {
            System.Collections.IList       newCollection = (System.Collections.IList)System.Activator.CreateInstance(classPool.GetClass(coi.GetRealCollectionClassName()));
            System.Collections.IEnumerator iterator      = coi.GetCollection().GetEnumerator();
            AbstractObjectInfo             aoi           = null;

            while (iterator.MoveNext())
            {
                aoi = (AbstractObjectInfo)iterator.Current;
                if (!aoi.IsDeletedObject())
                {
                    newCollection.Add(BuildOneInstance(aoi));
                }
            }
            return(newCollection);
        }
 private bool ClassAreCompatible(AbstractObjectInfo
                                 value1, AbstractObjectInfo value2)
 {
     System.Type clazz1 = value1.GetType();
     System.Type clazz2 = value2.GetType();
     if (clazz1 == clazz2)
     {
         return(true);
     }
     if ((clazz1 == typeof(NonNativeObjectInfo)) &&
         (clazz2 == typeof(NeoDatis.Odb.Core.Server.Layers.Layer2.Meta.ClientNonNativeObjectInfo
                           )))
     {
         return(true);
     }
     return(false);
 }
예제 #21
0
 private bool HasChanged(AbstractObjectInfo aoi1, AbstractObjectInfo aoi2, int objectRecursionLevel)
 {
     // If one is null and the other not
     if (aoi1.IsNull() != aoi2.IsNull())
     {
         return(true);
     }
     if (aoi1.IsNonNativeObject() && aoi2.IsNonNativeObject())
     {
         return(HasChanged((NonNativeObjectInfo)aoi1, (NonNativeObjectInfo)aoi2, objectRecursionLevel + 1));
     }
     if (aoi1.IsNative() && aoi2.IsNative())
     {
         return(HasChanged((NativeObjectInfo)aoi1, (NativeObjectInfo)aoi2));
     }
     return(false);
 }
예제 #22
0
        public virtual object BuildOneInstance(AbstractObjectInfo objectInfo)
        {
            object o = null;

            if (objectInfo is NonNativeNullObjectInfo)
            {
                return(null);
            }

            if (objectInfo.GetType() == typeof(NonNativeObjectInfo))
            {
                o = BuildOneInstance((NonNativeObjectInfo)objectInfo);
            }
            else
            {
                // instantiation cache is not used for native objects
                o = BuildOneInstance((NativeObjectInfo)objectInfo);
            }
            return(o);
        }
예제 #23
0
        private static object CheckIfFloatOrDouble(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.FloatId)
            {
                if (objectInfo.GetObject() is float)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToSingle(objectInfo.GetObject().ToString()));
            }

            if (odbTypeId == OdbType.DoubleId)
            {
                if (objectInfo.GetObject() is double)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToDouble(objectInfo.GetObject().ToString()));
            }

            return(CheckIfDecimal(objectInfo, odbTypeId));
        }
예제 #24
0
        private static object CheckIfLong(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.LongId)
            {
                if (objectInfo.GetObject() is long)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToInt64(objectInfo.GetObject().ToString()));
            }

            if (odbTypeId == OdbType.ULongId)
            {
                if (objectInfo.GetObject() is ulong)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToUInt64(objectInfo.GetObject().ToString()));
            }

            return(CheckIfInt(objectInfo, odbTypeId));
        }
예제 #25
0
        private static object CheckIfByte(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.ByteId)
            {
                if (objectInfo.GetObject() is byte)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToByte(objectInfo.GetObject().ToString()));
            }

            if (odbTypeId == OdbType.SByteId)
            {
                if (objectInfo.GetObject() is sbyte)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToSByte(objectInfo.GetObject().ToString()));
            }

            return(CheckIfShort(objectInfo, odbTypeId));
        }
예제 #26
0
        private static object CheckIfInt(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.IntegerId)
            {
                if (objectInfo.GetObject() is int)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToInt32(objectInfo.GetObject().ToString()));
            }

            if (odbTypeId == OdbType.UIntegerId)
            {
                if (objectInfo.GetObject() is uint)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToUInt32(objectInfo.GetObject().ToString()));
            }

            return(CheckIfBool(objectInfo, odbTypeId));
        }
예제 #27
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);
        }
예제 #28
0
        private static object CheckIfShort(AbstractObjectInfo objectInfo, int odbTypeId)
        {
            if (odbTypeId == OdbType.ShortId)
            {
                if (objectInfo.GetObject() is short)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToInt16(objectInfo.GetObject().ToString()));
            }

            if (odbTypeId == OdbType.UShortId)
            {
                if (objectInfo.GetObject() is ushort)
                {
                    return(objectInfo.GetObject());
                }
                return(Convert.ToUInt16(objectInfo.GetObject().ToString()));
            }

            return(CheckIfFloatOrDouble(objectInfo, odbTypeId));
        }
 private void StoreChangedObject(NonNativeObjectInfo
                                 aoi1, NonNativeObjectInfo aoi2, int fieldId
                                 , AbstractObjectInfo oldValue, AbstractObjectInfo
                                 newValue, string message, int objectRecursionLevel)
 {
     if (aoi1 != null && aoi2 != null)
     {
         if (aoi1.GetOid() != null && aoi1.GetOid().Equals(aoi2.GetOid()))
         {
             changedObjectMetaRepresentations.Add(aoi2);
             changes.Add(new ChangedObjectInfo(aoi1
                                               .GetClassInfo(), aoi2.GetClassInfo(), fieldId, oldValue, newValue, message, objectRecursionLevel
                                               ));
             // also the max recursion level
             if (objectRecursionLevel > maxObjectRecursionLevel)
             {
                 maxObjectRecursionLevel = objectRecursionLevel;
             }
             nbChanges++;
         }
         else
         {
             newObjects.Add(aoi2.GetObject());
             string fieldName = aoi1.GetClassInfo().GetAttributeInfoFromId(fieldId).GetName();
             // keep track of the position where the reference must be
             // updated - use aoi1 to get position, because aoi2 do not have position defined yet
             long positionToUpdateReference = aoi1.GetAttributeDefinitionPosition(fieldId);
             StoreNewObjectReference(positionToUpdateReference, aoi2, objectRecursionLevel, fieldName
                                     );
         }
     }
     else
     {
         //newObjectMetaRepresentations.add(aoi2);
         NeoDatis.Tool.DLogger.Info("Non native object with null object");
     }
 }
예제 #30
0
 public ChangedObjectInfo(ClassInfo oldCi, ClassInfo newCi, int fieldIndex, AbstractObjectInfo oldValue,
                          AbstractObjectInfo newValue, int objectRecursionLevel)
     : this(oldCi, newCi, fieldIndex, oldValue, newValue, null, objectRecursionLevel)
 {
 }
예제 #31
0
        private static bool ClassAreCompatible(AbstractObjectInfo value1, AbstractObjectInfo value2)
        {
            var clazz1 = value1.GetType();
            var clazz2 = value2.GetType();

            return clazz1 == clazz2;
        }
예제 #32
0
        public virtual object BuildOneInstance(NonNativeObjectInfo objectInfo)
        {
            ICache cache = GetSession().GetCache();

            // verify if the object is check to delete
            if (objectInfo.IsDeletedObject())
            {
                throw new ODBRuntimeException(NeoDatisError.ObjectIsMarkedAsDeletedForOid.AddParameter(objectInfo.GetOid()));
            }
            // Then check if object is in cache
            object o = cache.GetObjectWithOid(objectInfo.GetOid());

            if (o != null)
            {
                return(o);
            }
            Type instanceClazz = null;

            instanceClazz = classPool.GetClass(objectInfo.GetClassInfo().GetFullClassName());
            try
            {
                o = classIntrospector.NewInstanceOf(instanceClazz);
            }
            catch (System.Exception e)
            {
                throw new ODBRuntimeException(NeoDatisError.InstanciationError.AddParameter(objectInfo.GetClassInfo().GetFullClassName()), e);
            }
            // This can happen if ODB can not create the instance
            // TODO Check if returning null is correct
            if (o == null)
            {
                return(null);
            }
            // Keep the initial hash code. In some cases, when the class redefines
            // the hash code method
            // Hash code can return wrong values when attributes are not set (when
            // hash code depends on attribute values)
            // Hash codes are used as the key of the map,
            // So at the end of this method, if hash codes are different, object
            // will be removed from the cache and inserted back
            bool hashCodeIsOk    = true;
            int  initialHashCode = 0;

            try
            {
                initialHashCode = o.GetHashCode();
            }
            catch (System.Exception)
            {
                hashCodeIsOk = false;
            }
            // Adds this incomplete instance in the cache to manage cyclic reference
            if (hashCodeIsOk)
            {
                cache.AddObject(objectInfo.GetOid(), o, objectInfo.GetHeader());
            }
            ClassInfo            ci     = objectInfo.GetClassInfo();
            IOdbList <FieldInfo> fields = classIntrospector.GetAllFields(ci.GetFullClassName());

            FieldInfo          field = null;
            AbstractObjectInfo aoi   = null;
            object             value = null;

            for (int i = 0; i < fields.Count; i++)
            {
                field = fields[i];
                // Gets the id of this field
                int attributeId = ci.GetAttributeId(field.Name);
                if (OdbConfiguration.IsDebugEnabled(LogIdDebug))
                {
                    DLogger.Debug("getting field with name " + field.Name + ", attribute id is " + attributeId);
                }
                aoi = objectInfo.GetAttributeValueFromId(attributeId);
                // Check consistency
                // ensureClassCompatibily(field,
                // instanceInfo.getClassInfo().getAttributeinfo(i).getFullClassname());
                if (aoi != null && (!aoi.IsNull()))
                {
                    if (aoi.IsNative())
                    {
                        if (aoi.IsAtomicNativeObject())
                        {
                            if (aoi.IsNull())
                            {
                                value = null;
                            }
                            else
                            {
                                value = aoi.GetObject();
                            }
                        }
                        if (aoi.IsCollectionObject())
                        {
                            value = BuildCollectionInstance((CollectionObjectInfo)aoi);
                            // Manage a specific case of Set

                            /*
                             * if (typeof(Java.Util.Set).IsAssignableFrom(field.GetType()) && typeof(ICollection).IsAssignableFrom(value.GetType()))
                             * {
                             *      Java.Util.Set s = new Java.Util.HashSet();
                             *      s.AddAll((System.Collections.ICollection)value);
                             *      value = s;
                             * }*/
                        }
                        if (aoi.IsArrayObject())
                        {
                            value = BuildArrayInstance((ArrayObjectInfo)aoi);
                        }
                        if (aoi.IsMapObject())
                        {
                            value = BuildMapInstance((MapObjectInfo)aoi);
                        }
                        if (aoi.IsEnumObject())
                        {
                            value = BuildEnumInstance((EnumNativeObjectInfo)aoi, field.FieldType);
                        }
                    }
                    else
                    {
                        if (aoi.IsNonNativeObject())
                        {
                            if (aoi.IsDeletedObject())
                            {
                                if (NeoDatis.Odb.OdbConfiguration.DisplayWarnings())
                                {
                                    IError warning = NeoDatisError.AttributeReferencesADeletedObject
                                                     .AddParameter(objectInfo.GetClassInfo().GetFullClassName())
                                                     .AddParameter(objectInfo.GetOid()).AddParameter(field.Name);
                                    DLogger.Info(warning.ToString());
                                }
                                value = null;
                            }
                            else
                            {
                                value = BuildOneInstance((NonNativeObjectInfo)aoi);
                            }
                        }
                    }
                    if (value != null)
                    {
                        if (OdbConfiguration.IsDebugEnabled(LogIdDebug))
                        {
                            DLogger.Debug("Setting field " + field.Name + "(" + field.GetType().FullName + ") to " + value + " / " + value.GetType().FullName);
                        }
                        try
                        {
                            field.SetValue(o, value);
                        }
                        catch (System.Exception e)
                        {
                            throw new ODBRuntimeException(NeoDatisError.InstanceBuilderWrongObjectContainerType
                                                          .AddParameter(objectInfo.GetClassInfo().GetFullClassName())
                                                          .AddParameter(value.GetType().FullName).AddParameter(field.GetType().FullName), e);
                        }
                    }
                }
            }
            if (o != null && !OdbClassUtil.GetFullName(o.GetType()).Equals(objectInfo.GetClassInfo().GetFullClassName()))
            {
                new ODBRuntimeException(NeoDatisError.InstanceBuilderWrongObjectType
                                        .AddParameter(objectInfo.GetClassInfo().GetFullClassName())
                                        .AddParameter(o.GetType().FullName));
            }
            if (hashCodeIsOk || initialHashCode != o.GetHashCode())
            {
                // Bug (sf bug id=1875544 )detected by glsender
                // This can happen when an object has redefined its own hashcode
                // method and depends on the field values
                // Then, we have to remove object from the cache and re-insert to
                // correct map hash code
                cache.RemoveObjectWithOid(objectInfo.GetOid());
                // re-Adds instance in the cache
                cache.AddObject(objectInfo.GetOid(), o, objectInfo.GetHeader());
            }
            if (triggerManager != null)
            {
                triggerManager.ManageSelectTriggerAfter(objectInfo.GetClassInfo().GetFullClassName
                                                            (), objectInfo, objectInfo.GetOid());
            }
            if (OdbConfiguration.ReconnectObjectsToSession())
            {
                ICrossSessionCache crossSessionCache = CacheFactory.GetCrossSessionCache(engine.GetBaseIdentification().GetIdentification());
                crossSessionCache.AddObject(o, objectInfo.GetOid());
            }

            return(o);
        }
예제 #33
0
 public ChangedObjectInfo(ClassInfo oldCi, ClassInfo newCi, int fieldIndex, AbstractObjectInfo oldValue,
                          AbstractObjectInfo newValue, int objectRecursionLevel)
     : this(oldCi, newCi, fieldIndex, oldValue, newValue, null, objectRecursionLevel)
 {
 }
예제 #34
0
        private void StoreChangedObject(NonNativeObjectInfo aoi1, NonNativeObjectInfo aoi2, int fieldId,
                                        AbstractObjectInfo oldValue, AbstractObjectInfo newValue, string message,
                                        int objectRecursionLevel)
        {
            if (aoi1 == null || aoi2 == null) 
                return;

            if (aoi1.GetOid() != null && aoi1.GetOid().Equals(aoi2.GetOid()))
            {
                _changedObjectMetaRepresentations.Add(aoi2);
                _changes.Add(new ChangedObjectInfo(aoi1.GetClassInfo(), aoi2.GetClassInfo(), fieldId, oldValue,
                                                   newValue, message, objectRecursionLevel));
                // also the max recursion level
                if (objectRecursionLevel > _maxObjectRecursionLevel)
                    _maxObjectRecursionLevel = objectRecursionLevel;
                _nbChanges++;
            }
            else
            {
                _newObjects.Add(aoi2.GetObject());
                _nbChanges++;
            }
        }
예제 #35
0
 public bool HasChanged(AbstractObjectInfo aoi1, AbstractObjectInfo aoi2)
 {
     return(HasChanged(aoi1, aoi2, -1));
 }
예제 #36
0
        /// <summary>
        ///   Used to change the value of an attribute
        /// </summary>
        /// <param name="attributeName"> </param>
        /// <param name="aoi"> </param>
        public void SetValueOf(string attributeName, AbstractObjectInfo aoi)
        {
            var isRelation = attributeName.IndexOf(".", StringComparison.Ordinal) != -1;

            if (!isRelation)
            {
                var attributeId = GetClassInfo().GetAttributeId(attributeName);
                SetAttributeValue(attributeId, aoi);
                return;
            }

            var firstDotIndex = attributeName.IndexOf(".", StringComparison.Ordinal);

            var nnoi = GetNonNativeObjectInfo(attributeName, firstDotIndex);

            if (nnoi != null)
            {
                var beginIndex = firstDotIndex + 1;
                nnoi.SetValueOf(attributeName.Substring(beginIndex, attributeName.Length - beginIndex), aoi);
            }

            throw new OdbRuntimeException(
                NDatabaseError.ClassInfoDoNotHaveTheAttribute.AddParameter(GetClassInfo().FullClassName).
                    AddParameter(attributeName));
        }
예제 #37
0
        /// <summary>
        ///   Create a copy oh this meta object
        /// </summary>
        /// <param name="cache"> </param>
        /// <param name="onlyData"> if true, only copy attributes values </param>
        /// <returns> </returns>
        public override AbstractObjectInfo CreateCopy(IDictionary<OID, AbstractObjectInfo> cache, bool onlyData)
        {
            NonNativeObjectInfo nnoi;

            if (_objectHeader.GetOid() != null && cache.ContainsKey(_objectHeader.GetOid()))
            {
                nnoi = (NonNativeObjectInfo) cache[_objectHeader.GetOid()];
                if (nnoi != null)
                    return nnoi;
            }

            if (_theObject == null)
                return new NonNativeNullObjectInfo(_classInfo);

            if (onlyData)
            {
                var oih = new ObjectInfoHeader();
                nnoi = new NonNativeObjectInfo(_theObject, _classInfo, null, oih.GetAttributesIdentification(),
                                               oih.GetAttributeIds());
            }
            else
            {
                nnoi = new NonNativeObjectInfo(_theObject, _classInfo, null, _objectHeader.GetAttributesIdentification(),
                                               _objectHeader.GetAttributeIds());

                nnoi.GetHeader().SetOid(GetHeader().GetOid());
            }

            var newAttributeValues = new AbstractObjectInfo[_attributeValues.Length];

            for (var i = 0; i < _attributeValues.Length; i++)
                newAttributeValues[i] = _attributeValues[i].CreateCopy(cache, onlyData);

            nnoi._attributeValues = newAttributeValues;

            if (_objectHeader.GetOid() != null)
                cache.Add(_objectHeader.GetOid(), nnoi);

            return nnoi;
        }
예제 #38
0
        /// <summary>
        ///   Build a meta representation of an object 
        ///   <pre>warning: When an object has two fields with the same name 
        ///        (a private field with the same name in a parent class, the deeper field (of the parent) is ignored!)</pre>
        /// </summary>
        /// <returns> The ObjectInfo </returns>
        private AbstractObjectInfo GetObjectInfoInternal(AbstractObjectInfo nnoi, object o, ClassInfo classInfo,
                                                         bool recursive,
                                                         IDictionary<object, NonNativeObjectInfo> alreadyReadObjects,
                                                         IIntrospectionCallback callback)
        {
            if (o == null)
                return NullNativeObjectInfo.GetInstance();

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

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

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

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

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

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

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

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

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

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

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

            if (isRootObject)
                alreadyReadObjects.Clear();

            return mainAoi;
        }
예제 #39
0
        /// <summary>
        ///   Build a meta representation of an object
        ///   <pre>warning: When an object has two fields with the same name
        ///        (a private field with the same name in a parent class, the deeper field (of the parent) is ignored!)</pre>
        /// </summary>
        /// <returns> The ObjectInfo </returns>
        private AbstractObjectInfo GetObjectInfoInternal(AbstractObjectInfo nnoi, object o, ClassInfo classInfo,
                                                         bool recursive,
                                                         IDictionary <object, NonNativeObjectInfo> alreadyReadObjects,
                                                         IIntrospectionCallback callback)
        {
            if (o == null)
            {
                return(NullNativeObjectInfo.GetInstance());
            }

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

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

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

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

            NonNativeObjectInfo cachedNnoi;

            alreadyReadObjects.TryGetValue(o, out cachedNnoi);

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

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

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

            alreadyReadObjects[o] = mainAoi;

            var fields = ClassIntrospector.GetAllFieldsFrom(clazz);

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

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

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

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

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

            return(mainAoi);
        }
예제 #40
0
 public void SetAttributeValue(int attributeId, AbstractObjectInfo aoi)
 {
     _attributeValues[attributeId - 1] = aoi;
 }
예제 #41
0
 public bool HasChanged(AbstractObjectInfo aoi1, AbstractObjectInfo aoi2)
 {
     return HasChanged(aoi1, aoi2, -1);
 }