public void CachedResults_binary_formatter_can_serialize()
        {
            var tableMetadata = new[]
            {
                new ColumnMetadata("age", "int", typeof(System.Int32))
            };

            var cachedResults = new CachedResults(tableMetadata, new List <object[]> {
                new object[] { 105 }
            }, 1);
            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, cachedResults);
                stream.Seek(0L, SeekOrigin.Begin);
                var deserialized = (CachedResults)formatter.Deserialize(stream);

                Assert.Equal(1, deserialized.RecordsAffected);
                Assert.Equal("age", deserialized.TableMetadata.Single().Name);
                Assert.Equal("int", deserialized.TableMetadata.Single().DataTypeName);
                Assert.Equal(typeof(System.Int32), deserialized.TableMetadata.Single().DataType);
                Assert.Equal(105, deserialized.Results[0][0]);
            }
        }
Beispiel #2
0
        private DbDataReader HandleCaching(DbDataReader reader, string key, List <object[]> queryResults)
        {
            var cachedResults =
                new CachedResults(
                    GetTableMetadata(reader), queryResults, reader.RecordsAffected);

            int minCacheableRows, maxCachableRows;

            _cachingPolicy.GetCacheableRows(_commandTreeFacts.AffectedEntitySets, out minCacheableRows,
                                            out maxCachableRows);

            if (IsQueryAlwaysCached || (queryResults.Count >= minCacheableRows && queryResults.Count <= maxCachableRows))
            {
                TimeSpan       slidingExpiration;
                DateTimeOffset absoluteExpiration;
                _cachingPolicy.GetExpirationTimeout(_commandTreeFacts.AffectedEntitySets, out slidingExpiration,
                                                    out absoluteExpiration);

                _cacheTransactionHandler.PutItem(
                    Transaction,
                    key,
                    cachedResults,
                    _commandTreeFacts.AffectedEntitySets.Select(s => s.Name),
                    slidingExpiration,
                    absoluteExpiration,
                    DbConnection);
            }

            return(new CachingReader(cachedResults));
        }
Beispiel #3
0
        public CachingReader(CachedResults cachedResults)
        {
            Debug.Assert(cachedResults != null, "cachedResults is null");

            _tableMetadata        = cachedResults.TableMetadata;
            _recordsAffected      = cachedResults.RecordsAffected;
            _resultRowsEnumerator = cachedResults.Results.GetEnumerator();
            _state = State.BOF;
        }
Beispiel #4
0
        internal CachingReader(CachedResults cachedResults)
        {
            Debug.Assert(cachedResults != null, "cachedResults is null");

            _tableMetadata = cachedResults.TableMetadata;
            _recordsAffected = cachedResults.RecordsAffected;
            _resultRowsEnumerator = cachedResults.Results.GetEnumerator();
            _state = State.BOF;
        }
        public void CachedResults_properties_set_correctly()
        {
            var tableMetadata = new ColumnMetadata[0];
            var results = new List<object[]>();

            var cachedResults = new CachedResults(tableMetadata, results, 42);

            Assert.Same(tableMetadata, cachedResults.TableMetadata);
            Assert.Same(results, cachedResults.Results);
            Assert.Equal(42, cachedResults.RecordsAffected);
        }
        public void CachedResults_properties_set_correctly()
        {
            var tableMetadata = new ColumnMetadata[0];
            var results       = new List <object[]>();

            var cachedResults = new CachedResults(tableMetadata, results, 42);

            Assert.Same(tableMetadata, cachedResults.TableMetadata);
            Assert.Same(results, cachedResults.Results);
            Assert.Equal(42, cachedResults.RecordsAffected);
        }
Beispiel #7
0
        private DbDataReader HandleCaching(DbDataReader reader, string key, List<object[]> queryResults)
        {
            var cachedResults =
                new CachedResults(
                    GetTableMetadata(reader), queryResults, reader.RecordsAffected);

            int minCacheableRows, maxCachableRows;
            _cachingPolicy.GetCacheableRows(_commandTreeFacts.AffectedEntitySets, out minCacheableRows,
                out maxCachableRows);

            if (IsQueryAlwaysCached || (queryResults.Count >= minCacheableRows && queryResults.Count <= maxCachableRows))
            {
                TimeSpan slidingExpiration;
                DateTimeOffset absoluteExpiration;
                _cachingPolicy.GetExpirationTimeout(_commandTreeFacts.AffectedEntitySets, out slidingExpiration,
                    out absoluteExpiration);

                _cacheTransactionHandler.PutItem(
                    Transaction,
                    key,
                    cachedResults,
                    _commandTreeFacts.AffectedEntitySets.Select(s => s.Name),
                    slidingExpiration,
                    absoluteExpiration);
            }

            return new CachingReader(cachedResults);
        }