Beispiel #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));
        }
Beispiel #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);
        }
        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);
        }
        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);
        }
 private static object CheckIfDecimal(AbstractObjectInfo objectInfo, int odbTypeId)
 {
     return odbTypeId == OdbType.DecimalId
                ? Decimal.Parse(objectInfo.GetObject().ToString(), NumberStyles.Any)
                : CheckIfCharacter(objectInfo, odbTypeId);
 }
        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);
        }
        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 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);
        }
        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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
0
 private static object CheckIfDate(AbstractObjectInfo objectInfo, int odbTypeId)
 {
     return odbTypeId == OdbType.DateId ? objectInfo.GetObject() : CheckIfLong(objectInfo, odbTypeId);
 }
Beispiel #13
0
 private static object CheckIfNull(AbstractObjectInfo objectInfo, int odbTypeId)
 {
     return odbTypeId == OdbType.NullId ? null : CheckIfString(objectInfo, odbTypeId);
 }
Beispiel #14
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;
        }
Beispiel #15
0
 public void SetAttributeValue(int attributeId, AbstractObjectInfo aoi)
 {
     _attributeValues[attributeId - 1] = aoi;
 }
Beispiel #16
0
 /// <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;
 }