示例#1
0
        public void CreateTableDataLoader_ShouldReturnEntityObjectDataLoaderWrapper()
        {
            // Setup
            var sut = CreateSut();

            // Exercise
            ITableDataLoader actual = sut.CreateTableDataLoader(BuildTestModelTableDescription());

            // Verify outcome
            Assert.NotNull(actual);
            Assert.IsAssignableFrom <EntityObjectDataLoaderWrapper>(actual);
        }
示例#2
0
        public void CreateTableDataLoader_NotBindedTableDescription_ShouldReturnEmptyTableDataLoader()
        {
            // Setup
            var sut = CreateSut();

            // Exercise
            ITableDataLoader actual = sut.CreateTableDataLoader(BuildTestModel2TableDescription());

            // Verify outcome
            Assert.NotNull(actual);
            Assert.IsAssignableFrom <EmptyTableDataLoader>(actual);
        }
        /// <summary>
        ///     Creates a proxy for the global table data cache.
        /// </summary>
        /// <param name="table"> The table metadata. </param>
        /// <returns> The proxy for the cache. </returns>
        private CachingTableDataLoader CreateCachedData(TableDescription table)
        {
            if (this.wrappedTableDataLoaderFactory == null)
            {
                this.wrappedTableDataLoaderFactory =
                    this.wrappedDataLoader.CreateTableDataLoaderFactory();
            }

            ITableDataLoader wrappedTableDataLoader =
                this.wrappedTableDataLoaderFactory.CreateTableDataLoader(table);

            return(new CachingTableDataLoader(wrappedTableDataLoader));
        }
示例#4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CachingTableDataLoader" /> class.
        /// </summary>
        /// <param name="tableDataLoader">
        ///     The table data loader that is used to retrieve the data.
        /// </param>
        public CachingTableDataLoader(ITableDataLoader tableDataLoader)
        {
            IEnumerable <object[]> data;

            if (tableDataLoader != null)
            {
                data = tableDataLoader.GetData();
            }
            else
            {
                data = Enumerable.Empty <object[]>();
            }

            this.data = data.ToArray();
        }
示例#5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CachingTableDataLoader" /> class.
        /// </summary>
        /// <param name="tableDataLoader">
        ///     The table data loader that is used to retrieve the data.
        /// </param>
        public CachingTableDataLoader(ITableDataLoader tableDataLoader)
        {
            IEnumerable<object[]> data;

            if (tableDataLoader != null)
            {
                data = tableDataLoader.GetData();
            }
            else
            {
                data = Enumerable.Empty<object[]>();
            }

            this.data = data.ToArray();
        }
示例#6
0
        /// <summary>
        ///     Loads the table data from the specified table data loader and materializes it
        ///     bases on the specified metadata.
        /// </summary>
        /// <param name="loaderFactory"> The loader factory. </param>
        /// <param name="table"> The table metadata. </param>
        /// <returns> The materialized data. </returns>
        public static IEnumerable <object> Load(
            ITableDataLoaderFactory loaderFactory,
            DbTableInfo table)
        {
            List <ColumnDescription> columns = new List <ColumnDescription>();

            PropertyInfo[]          properties = table.EntityType.GetProperties();
            Func <object, object>[] converters = new Func <object, object> [properties.Length];

            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo property = properties[i];
                Type         type     = property.PropertyType;

                // TODO: external
                if (type == typeof(NMemory.Data.Timestamp))
                {
                    converters[i] = ConvertTimestamp;
                    type          = typeof(byte[]);
                }
                else if (type == typeof(NMemory.Data.Binary))
                {
                    converters[i] = ConvertBinary;
                    type          = typeof(byte[]);
                }

                ColumnDescription column = new ColumnDescription(property.Name, type);
                columns.Add(column);
            }

            TableDescription tableDescription =
                new TableDescription(table.TableName, columns);

            ITableDataLoader loader = loaderFactory.CreateTableDataLoader(tableDescription);

            // Prefetch require info/object to increase performance
            Func <object[], object> initializer = table.EntityInitializer;
            int columnCount = columns.Count;

            // Single array to spare GC
            object[] entityProperties = null;

            foreach (object[] data in loader.GetData())
            {
                if (entityProperties == null)
                {
                    // Initialize at the first element
                    entityProperties = new object[data.Length];
                }

                for (int i = 0; i < columnCount; i++)
                {
                    object propertyValue = data[i];

                    // Use converter if required
                    Func <object, object> converter = converters[i];
                    if (converter != null)
                    {
                        propertyValue = converter.Invoke(propertyValue);
                    }

                    entityProperties[i] = propertyValue;
                }

                yield return(initializer.Invoke(entityProperties));
            }
        }