public async Task <int> GetValueSyncOrAsync(bool sync, CancellationToken token = default(CancellationToken)) { int result; if (_isDeferred) { if (sync) { result = _mainFuture.Value; } else { result = await _mainFuture.GetValueAsync(token); } } else { if (sync) { result = await _query.CountAsync(token); } else { result = _query.Count(); } } return(result); }
public async Task SecondLevelCacheWithMixedCacheRegionsFutureAsync() { using (ISession s = OpenSession()) using (ITransaction tx = s.BeginTransaction()) { User user = new User() { Name = "test" }; await(s.SaveAsync(user)); await(tx.CommitAsync()); } using (ISession s = OpenSession()) { // cacheable Future, not evaluated yet IFutureValue <User> userFuture = s.CreateCriteria <User>() .Add(Restrictions.NaturalId().Set("Name", "test")) .SetCacheable(true) .SetCacheRegion("region1") .FutureValue <User>(); // different cache-region causes batch to be non-cacheable int count = await(s.CreateCriteria <User>() .SetProjection(Projections.RowCount()) .SetCacheable(true) .SetCacheRegion("region2") .FutureValue <int>() .GetValueAsync()); Assert.That(await(userFuture.GetValueAsync()), Is.Not.Null); Assert.That(count, Is.EqualTo(1)); await(DeleteObjectsOutsideCacheAsync(s)); } using (ISession s = OpenSession()) { IFutureValue <User> userFuture = s.CreateCriteria <User>() .Add(Restrictions.NaturalId().Set("Name", "test")) .SetCacheable(true) .SetCacheRegion("region1") .FutureValue <User>(); int count = await(s.CreateCriteria <User>() .SetProjection(Projections.RowCount()) .SetCacheable(true) .SetCacheRegion("region2") .FutureValue <int>() .GetValueAsync()); Assert.That(await(userFuture.GetValueAsync()), Is.Null, "query results should not come from cache"); } }
private async Task <T> GetValueSyncOrAsync(bool sync, CancellationToken token = default(CancellationToken)) { T result; if (!_deferred) { CreateCriteriaOrFutures(); } if (_mainFuture != null) { if (_childFutures != null) { foreach (var cq in _childFutures) //we need to force execution: oracle client doesn't support multiple queries (for now) { if (sync) { cq.GetEnumerable(); } else { await cq.GetEnumerableAsync(token); } } } if (sync) { result = _mainFuture.Value; } else { result = await _mainFuture.GetValueAsync(token); } } else { if (sync) { result = _mainCriteria.UniqueResult <T>(); } else { result = await _mainCriteria.UniqueResultAsync <T>(token); } } if (_childNodesInfo != null) { NHUnitHelper.VisitNodes(result, _session, _childNodesInfo); } if (_unproxy) { return(NHUnitHelper.Unproxy(result, _session)); } return(result); }