示例#1
0
        private static object BuildOneInstance(AtomicNativeObjectInfo objectInfo)
        {
            var odbTypeId = objectInfo.GetOdbTypeId();


            return(CheckIfNull(objectInfo, odbTypeId));
        }
示例#2
0
 public virtual void TestAtomicNativeCollectionDate()
 {
     var date = new DateTime();
     AtomicNativeObjectInfo anoi = null;
     anoi = new AtomicNativeObjectInfo(date, OdbType.DateId);
     var s = Serializer.ToString(anoi);
     // println(s);
     var anoi2 = (AtomicNativeObjectInfo) Serializer.FromOneString(s);
     AssertEquals(anoi, anoi2);
 }
示例#3
0
 public virtual void TestAtomicNativeCollectionBigDecimal()
 {
     var bd = Convert.ToDecimal("123456789.987654321", CultureInfo.InvariantCulture);
     AtomicNativeObjectInfo anoi = null;
     anoi = new AtomicNativeObjectInfo(bd, OdbType.BigDecimalId);
     var s = Serializer.ToString(anoi);
     // println(s);
     var anoi2 = (AtomicNativeObjectInfo) Serializer.FromOneString(s);
     AssertEquals(anoi, anoi2);
 }
示例#4
0
 public virtual void TestAtomicNativeCollectionInt()
 {
     var i = 123456789;
     AtomicNativeObjectInfo anoi = null;
     anoi = new AtomicNativeObjectInfo(i, OdbType.IntegerId);
     var s = Serializer.ToString(anoi);
     // println(s);
     var anoi2 = (AtomicNativeObjectInfo) Serializer.FromOneString(s);
     AssertEquals(anoi, anoi2);
 }
示例#5
0
 public virtual void TestAtomicNativeCollectionString()
 {
     var s1 = "ol√° chico";
     AtomicNativeObjectInfo anoi = null;
     anoi = new AtomicNativeObjectInfo(s1, OdbType.StringId);
     var s = Serializer.ToString(anoi);
     // println(s);
     var anoi2 = (AtomicNativeObjectInfo) Serializer.FromOneString(s);
     AssertEquals(anoi, anoi2);
 }
示例#6
0
 public virtual void TestAtomicNativeCollectionDouble()
 {
     var d = 123456789.789456123;
     AtomicNativeObjectInfo anoi = null;
     anoi = new AtomicNativeObjectInfo(d, OdbType.DoubleId);
     var s = Serializer.ToString(anoi);
     // println(s);
     var anoi2 = (AtomicNativeObjectInfo) Serializer.FromOneString(s);
     Assert.That(anoi.ToString(), Is.EqualTo(anoi2.ToString()));
 }
示例#7
0
        public virtual void TestAtomicNativeCollectionInt()
        {
            var i = 123456789;
            AtomicNativeObjectInfo anoi = null;

            anoi = new AtomicNativeObjectInfo(i, OdbType.IntegerId);
            var s = Serializer.ToString(anoi);
            // println(s);
            var anoi2 = (AtomicNativeObjectInfo)Serializer.FromOneString(s);

            AssertEquals(anoi, anoi2);
        }
示例#8
0
        public virtual void TestAtomicNativeCollectionDouble()
        {
            var d = 123456789.789456123;
            AtomicNativeObjectInfo anoi = null;

            anoi = new AtomicNativeObjectInfo(d, OdbType.DoubleId);
            var s = Serializer.ToString(anoi);
            // println(s);
            var anoi2 = (AtomicNativeObjectInfo)Serializer.FromOneString(s);

            Assert.That(anoi.ToString(), Is.EqualTo(anoi2.ToString()));
        }
示例#9
0
        public virtual void TestAtomicNativeCollectionDate()
        {
            var date = new DateTime();
            AtomicNativeObjectInfo anoi = null;

            anoi = new AtomicNativeObjectInfo(date, OdbType.DateId);
            var s = Serializer.ToString(anoi);
            // println(s);
            var anoi2 = (AtomicNativeObjectInfo)Serializer.FromOneString(s);

            AssertEquals(anoi, anoi2);
        }
示例#10
0
        public virtual void TestAtomicNativeCollectionBigDecimal()
        {
            var bd = Convert.ToDecimal("123456789.987654321", CultureInfo.InvariantCulture);
            AtomicNativeObjectInfo anoi = null;

            anoi = new AtomicNativeObjectInfo(bd, OdbType.BigDecimalId);
            var s = Serializer.ToString(anoi);
            // println(s);
            var anoi2 = (AtomicNativeObjectInfo)Serializer.FromOneString(s);

            AssertEquals(anoi, anoi2);
        }
示例#11
0
        public virtual void TestAtomicNativeCollectionString()
        {
            var s1 = "ol√° chico";
            AtomicNativeObjectInfo anoi = null;

            anoi = new AtomicNativeObjectInfo(s1, OdbType.StringId);
            var s = Serializer.ToString(anoi);
            // println(s);
            var anoi2 = (AtomicNativeObjectInfo)Serializer.FromOneString(s);

            AssertEquals(anoi, anoi2);
        }
示例#12
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);
        }
示例#13
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;
        }
示例#14
0
        private static ArrayObjectInfo IntropectAtomicNativeArray(object array, OdbType type)
        {
            var length    = ((Array)array).GetLength(0);
            var arrayCopy = new object[length];

            for (var i = 0; i < length; i++)
            {
                var o = ((Array)array).GetValue(i);
                if (o != null)
                {
                    // If object is not null, try to get the exact type
                    var typeId = OdbType.GetFromClass(o.GetType()).Id;
                    var atomicNativeObjectInfo = new AtomicNativeObjectInfo(o, typeId);
                    arrayCopy[i] = atomicNativeObjectInfo;
                }
                else
                {
                    // Else take the declared type
                    arrayCopy[i] = new NullNativeObjectInfo(type.Id);
                }
            }

            return(new ArrayObjectInfo(arrayCopy, OdbType.Array, type.Id));
        }
示例#15
0
        private static ArrayObjectInfo IntropectAtomicNativeArray(object array, OdbType type)
        {
            var length = ((Array) array).GetLength(0);
            var arrayCopy = new object[length];
            for (var i = 0; i < length; i++)
            {
                var o = ((Array) array).GetValue(i);
                if (o != null)
                {
                    // If object is not null, try to get the exact type
                    var typeId = OdbType.GetFromClass(o.GetType()).Id;
                    var atomicNativeObjectInfo = new AtomicNativeObjectInfo(o, typeId);
                    arrayCopy[i] = atomicNativeObjectInfo;
                }
                else
                {
                    // Else take the declared type
                    arrayCopy[i] = new NullNativeObjectInfo(type.Id);
                }
            }

            return new ArrayObjectInfo(arrayCopy, OdbType.Array, type.Id);
        }
示例#16
0
        public override AbstractObjectInfo CreateCopy(IDictionary<OID, AbstractObjectInfo> cache, bool onlyData)
        {
            var array = GetArray();
            var length = array.Length;

            var atomicNativeObjectInfos = new AtomicNativeObjectInfo[length];
            for (var i = 0; i < length; i++)
            {
                var aoi = (AbstractObjectInfo) array[i];
                atomicNativeObjectInfos[i] = aoi.CreateCopy(cache, onlyData) as AtomicNativeObjectInfo;
            }

            var arrayOfAoi = new ArrayObjectInfo(atomicNativeObjectInfos);
            arrayOfAoi.SetRealArrayComponentClassName(_realArrayComponentClassName);
            arrayOfAoi.SetComponentTypeId(_componentTypeId);

            return arrayOfAoi;
        }
示例#17
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;
            }
            }
        }