コード例 #1
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));
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
 private static object CheckIfDecimal(AbstractObjectInfo objectInfo, int odbTypeId)
 {
     return odbTypeId == OdbType.DecimalId
                ? Decimal.Parse(objectInfo.GetObject().ToString(), NumberStyles.Any)
                : CheckIfCharacter(objectInfo, odbTypeId);
 }
コード例 #5
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #6
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #7
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #8
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;
        }
コード例 #9
0
 public void SetAttributeValue(int attributeId, AbstractObjectInfo aoi)
 {
     _attributeValues[attributeId - 1] = aoi;
 }
コード例 #10
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
 private static object CheckIfDate(AbstractObjectInfo objectInfo, int odbTypeId)
 {
     return odbTypeId == OdbType.DateId ? objectInfo.GetObject() : CheckIfLong(objectInfo, odbTypeId);
 }
コード例 #11
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
 private static object CheckIfNull(AbstractObjectInfo objectInfo, int odbTypeId)
 {
     return odbTypeId == OdbType.NullId ? null : CheckIfString(objectInfo, odbTypeId);
 }
コード例 #12
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        private object BuildOneInstance(AbstractObjectInfo objectInfo)
        {
            if (objectInfo.IsNull())
                return null;

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

            return instance;
        }
コード例 #13
0
ファイル: ObjectWriter.cs プロジェクト: spolnik/ndatabase
 /// <summary>
 ///   This method is used to store the object : natibe or non native and return a number : - The position of the object if it is a native object - The oid (as a negative number) if it is a non native object
 /// </summary>
 /// <param name="aoi"> </param>
 /// <returns> </returns>
 /// <exception cref="System.Exception">System.Exception</exception>
 private long InternalStoreObjectWrapper(AbstractObjectInfo aoi)
 {
     if (aoi.IsNative())
         return InternalStoreObject((NativeObjectInfo) aoi);
     if (aoi.IsNonNativeObject())
     {
         var oid = StoreObject(null, (NonNativeObjectInfo) aoi);
         return -oid.ObjectId;
     }
     // Object references are references to object already stored.
     // But in the case of map, the reference can appear before the real
     // object (as order may change)
     // If objectReference.getOid() is null, it is the case. In this case,
     // We take the object being referenced and stores it directly.
     var objectReference = (ObjectReference) aoi;
     if (objectReference.GetOid() == null)
     {
         var oid = StoreObject(null, objectReference.GetNnoi());
         return -oid.ObjectId;
     }
     return -objectReference.GetOid().ObjectId;
 }
コード例 #14
0
 public void SetAttributeValue(int attributeId, AbstractObjectInfo aoi)
 {
     _attributeValues[attributeId - 1] = aoi;
 }
コード例 #15
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #16
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #17
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #18
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #19
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        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);
        }
コード例 #20
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;
        }
コード例 #21
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));
        }