コード例 #1
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;
        }
コード例 #2
0
ファイル: ArrayObjectInfo.cs プロジェクト: mrdotnet/NDatabase
        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);
        }
コード例 #3
0
ファイル: ArrayObjectInfo.cs プロジェクト: spolnik/ndatabase
        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;
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: InstanceBuilder.cs プロジェクト: spolnik/ndatabase
        private static object BuildOneInstance(AtomicNativeObjectInfo objectInfo)
        {
            var odbTypeId = objectInfo.GetOdbTypeId();
            

            return CheckIfNull(objectInfo, odbTypeId);
        }
コード例 #6
0
ファイル: ObjectWriter.cs プロジェクト: spolnik/ndatabase
        private long WriteAtomicNativeObject(AtomicNativeObjectInfo anoi, bool writeInTransaction,
                                                    int totalSpaceIfString = -1)
        {
            var startPosition = FileSystemProcessor.FileSystemInterface.GetPosition();
            var odbTypeId = anoi.GetOdbTypeId();
            WriteNativeObjectHeader(odbTypeId, anoi.IsNull(), BlockTypes.BlockTypeNativeObject, writeInTransaction);
            if (anoi.IsNull())
            {
                // Even if object is null, reserve space for to simplify/enable in
                // place update
                FileSystemProcessor.FileSystemInterface.EnsureSpaceFor(anoi.GetOdbType());
                return startPosition;
            }
            var @object = anoi.GetObject();
            switch (odbTypeId)
            {
                case OdbType.ByteId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteByte(((byte) @object), writeInTransaction);
                        break;
                    }

                case OdbType.SByteId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteSByte(((sbyte)@object), writeInTransaction);
                        break;
                    }

                case OdbType.BooleanId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteBoolean(((bool) @object), writeInTransaction);
                        break;
                    }

                case OdbType.CharacterId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteChar(((char) @object), writeInTransaction);
                        break;
                    }

                case OdbType.FloatId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteFloat(((float) @object), writeInTransaction);
                        break;
                    }

                case OdbType.DoubleId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteDouble(((double) @object), writeInTransaction);
                        break;
                    }

                case OdbType.IntegerId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteInt(((int) @object), writeInTransaction);
                        break;
                    }

                case OdbType.UIntegerId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteUInt(((uint)@object), writeInTransaction); // native attr
                        break;
                    }

                case OdbType.LongId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteLong(((long)@object), writeInTransaction); // native attr
                        break;
                    }

                case OdbType.ULongId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteULong(((ulong)@object), writeInTransaction); // native attr
                        break;
                    }

                case OdbType.ShortId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteShort(((short) @object), writeInTransaction);
                        break;
                    }

                case OdbType.UShortId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteUShort(((ushort)@object), writeInTransaction);
                        break;
                    }

                case OdbType.DecimalId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteBigDecimal((Decimal) @object, writeInTransaction);
                        break;
                    }

                case OdbType.DateId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteDate((DateTime) @object, writeInTransaction);
                        break;
                    }

                case OdbType.StringId:
                    {
                        FileSystemProcessor.FileSystemInterface.WriteString((string) @object, writeInTransaction, totalSpaceIfString);
                        break;
                    }

                case OdbType.OidId:
                    {
                        var oid = ((ObjectOID) @object).ObjectId;
                        FileSystemProcessor.FileSystemInterface.WriteLong(oid, writeInTransaction);
                        break;
                    }

                case OdbType.ObjectOidId:
                    {
                        var ooid = ((ObjectOID) @object).ObjectId;
                        FileSystemProcessor.FileSystemInterface.WriteLong(ooid, writeInTransaction);
                        break;
                    }

                case OdbType.ClassOidId:
                    {
                        var coid = ((ClassOID) @object).ObjectId;
                        FileSystemProcessor.FileSystemInterface.WriteLong(coid, writeInTransaction);
                        break;
                    }

                default:
                {
                    var typeId = odbTypeId.ToString();
                    var message = 
                        "native type with odb type id " + typeId + " (" + OdbType.GetNameFromId(odbTypeId) + ") for attribute ? is not suported";

                    throw new OdbRuntimeException(NDatabaseError.InternalError.AddParameter(message));
                }
            }
            return startPosition;
        }