コード例 #1
0
        public void TestPopulatesCriteriaCacheableCachRegionAndCacheModeProperly()
        {
            IImmediateFlowQuery <CacheableUser> query = Session.FlowQuery <CacheableUser>()
                                                        .Cacheable("Region1", CacheMode.Put);

            var criteria = (CriteriaImpl) new CriteriaBuilder()
                           .Build <CacheableUser, CacheableUser>
                           (
                QuerySelection.Create(query as IQueryableFlowQuery)
                           );

            Assert.That(criteria.Cacheable, Is.True);
            Assert.That(criteria.CacheRegion, Is.EqualTo("Region1"));

            Type type = typeof(CriteriaImpl);

            FieldInfo field = type.GetField("cacheMode", BindingFlags.Instance | BindingFlags.NonPublic);

            Assert.That(field, Is.Not.Null, "FieldInfo");

            object mode = field
                          .GetValue(criteria);

            Assert.That(mode, Is.EqualTo(CacheMode.Put));
        }
コード例 #2
0
        private Product LoadProductWithId(ITransaction transaction, int id)
        {
            var query = new SelectionQuery()
                        .From(QueryFrom.EntityType(typeof(Product)))
                        .Where(QueryCondition.Expression(ConditionExpr.Build().Field(typeof(Product), "ProductId").Eq().Value(id)))
                        .Select(QuerySelection.EntityType(typeof(Product))).ToList(transaction);

            return(query.First() as Product);
        }
コード例 #3
0
        public void TestPopulatesCriteriaCacheableProperly()
        {
            IImmediateFlowQuery <CacheableUser> query = Session.FlowQuery <CacheableUser>()
                                                        .Cacheable();

            var criteria = (CriteriaImpl) new CriteriaBuilder()
                           .Build <CacheableUser, CacheableUser>
                           (
                QuerySelection.Create(query as IQueryableFlowQuery)
                           );

            Assert.That(criteria.Cacheable, Is.True);
        }
コード例 #4
0
        public void ReadOnlyTrueIsPopulatedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .ReadOnly();

            var queryable = (IQueryableFlowQuery)query;

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create(queryable));

            Assert.That(criteria, Is.Not.Null);
            Assert.That(criteria.IsReadOnlyInitialized, Is.True, "Initialized");
            Assert.That(criteria.IsReadOnly, Is.True, "ReadOnly");
        }
コード例 #5
0
        public void CanCreateDelayedFlowQueryWithOptions()
        {
            FlowQueryOptions options = new FlowQueryOptions()
                                       .Add(c => c.SetMaxResults(5));

            IDelayedFlowQuery <UserEntity> q = Session.DelayedFlowQuery <UserEntity>(options);

            Assert.That(q, Is.Not.Null);

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create(q as IQueryableFlowQuery));

            Assert.That(criteria.GetRootEntityTypeIfAvailable(), Is.EqualTo(typeof(UserEntity)));
        }
コード例 #6
0
        public void SpecifiedTimeoutIsUsedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .Timeout(10);

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.Timeout, Is.EqualTo(10));
        }
コード例 #7
0
        public void CanCreateStatelessDelayedFlowQueryWithAlias()
        {
            UserEntity alias = null;

            Assert.That(() => StatelessSession.DelayedFlowQuery(() => alias), Throws.Nothing);

            IDelayedFlowQuery <UserEntity> query = StatelessSession.DelayedFlowQuery(() => alias);

            Assert.That(query != null);

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create(query as IQueryableFlowQuery));

            Assert.That(criteria.Alias, Is.EqualTo("alias"));
        }
コード例 #8
0
        public SimpleEntity RetrieveWithQuery(ITransaction tx)
        {
            ISelectionQuery query = new SelectionQuery()
                                    .From(QueryFrom.EntityType(typeof(SimpleEntity)))
                                    .Select(QuerySelection.EntityType(typeof(SimpleEntity)));

            var result = query.ToList(tx).FirstOrDefault();

            if (result == null)
            {
                return(null);
            }

            var retrieved = (SimpleEntity)result;

            return(retrieved);
        }
コード例 #9
0
        public void FetchSizeIsPopulatedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .FetchSize(10);

            var queryable = (IQueryableFlowQuery)query;

            Assert.That(queryable.FetchSizeValue, Is.EqualTo(10));

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.FetchSize, Is.EqualTo(10));
        }
コード例 #10
0
        public void CommentIsPopulatedOnCriteria()
        {
            const string Comment = "Should fetch all users";

            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .Comment(Comment);

            var queryable = (IQueryableFlowQuery)query;

            Assert.That(queryable.CommentValue, Is.EqualTo(Comment));

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.Comment, Is.EqualTo(Comment));
        }
コード例 #11
0
ファイル: LockTest.cs プロジェクト: niklaskallander/flowquery
        public void LocksArePopulatedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .Lock().Upgrade()
                                                     .Lock("user").Read()
                                                     .Lock("testAlias").Force();

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.LockModes.Keys, Contains.Item("this"));
            Assert.That(impl.LockModes.Keys, Contains.Item("user"));
            Assert.That(impl.LockModes.Keys, Contains.Item("testAlias"));

            Assert.That(impl.LockModes["this"], Is.EqualTo(LockMode.Upgrade));
            Assert.That(impl.LockModes["user"], Is.EqualTo(LockMode.Read));
            Assert.That(impl.LockModes["testAlias"], Is.EqualTo(LockMode.Force));
        }
コード例 #12
0
 /// <summary>
 ///     Populates the given <see cref="IResultStream{TDestination}" /> with the results of this query in a
 ///     streamed fashion.
 /// </summary>
 /// <param name="stream">
 ///     The <see cref="IResultStream{TDestination}" /> to stream the results into.
 /// </param>
 /// <typeparam name="TDestination">
 ///     The <see cref="System.Type" /> of the selection.
 /// </typeparam>
 protected virtual void SelectStream <TDestination>(IResultStream <TDestination> stream)
 {
     SelectionHelper.SelectStream <TSource, TDestination>(QuerySelection.Create(this), stream);
 }
コード例 #13
0
 public void QuerySelectionThrowsIfQueryIsNull()
 {
     Assert.That(() => QuerySelection.Create(null), Throws.InstanceOf <ArgumentNullException>());
 }
コード例 #14
0
 /// <summary>
 ///     Creates a wrapped selection.
 /// </summary>
 /// <typeparam name="TDestination">
 ///     The <see cref="System.Type" /> of the selection.
 /// </typeparam>
 /// <returns>
 ///     The created wrapped selection.
 /// </returns>
 protected virtual Func <TDestination> SelectValue <TDestination>()
 {
     return(SelectionHelper.SelectValue <TSource, TDestination>(QuerySelection.Create(this)));
 }
コード例 #15
0
 /// <summary>
 ///     Creates a <see cref="FlowQuerySelection{TDestination}" />.
 /// </summary>
 /// <typeparam name="TDestination">
 ///     The <see cref="System.Type" /> of the selection.
 /// </typeparam>
 /// <returns>
 ///     The created <see cref="FlowQuerySelection{TDestination}" />.
 /// </returns>
 protected virtual FlowQuerySelection <TDestination> SelectList <TDestination>()
 {
     return(SelectionHelper.SelectList <TSource, TDestination>(QuerySelection.Create(this)));
 }
コード例 #16
0
 /// <summary>
 ///     Creates a wrapped dictionary selection.
 /// </summary>
 /// <typeparam name="TKey">
 ///     The <see cref="System.Type" /> of the dictionary keys.
 /// </typeparam>
 /// <typeparam name="TValue">
 ///     The <see cref="System.Type" /> of the dictionary values.
 /// </typeparam>
 /// <returns>
 ///     The created wrapped dictionary selection.
 /// </returns>
 protected virtual Func <Dictionary <TKey, TValue> > SelectDictionary <TKey, TValue>()
 {
     return(SelectionHelper.SelectDictionary <TSource, TKey, TValue>(QuerySelection.Create(this)));
 }
コード例 #17
0
        private IList <IEntity> QueryTest(IList <IEntity> items)
        {
            var newList = new List <IEntity>();

            var sw = new Stopwatch();

            sw.Start();
            var tx = transactionFactory.CreateTransaction();

            for (int i = 0; i < items.Count; i++)
            {
                var item     = items[i];
                var itemType = item.GetType();

                if (itemType == typeof(Transaction))
                {
                    var trns   = (Transaction)item;
                    var loaded = new SelectionQuery()
                                 .From(QueryFrom.EntityType(item.GetType()))
                                 .Select(QuerySelection.EntityType(item.GetType()))
                                 .Where(QueryCondition.Expression(ConditionExpr.Build().Field(itemType, "TransactionId").Eq().Value(trns.TransactionId)))
                                 .ToList(tx).FirstOrDefault();
                    newList.Add((IEntity)loaded);
                }
                else if (itemType == typeof(Service))
                {
                    var svc    = (Service)item;
                    var loaded = new SelectionQuery()
                                 .From(QueryFrom.EntityType(item.GetType()))
                                 .Select(QuerySelection.EntityType(item.GetType()))
                                 .Where(QueryCondition.Expression(ConditionExpr.Build().Field(itemType, "ItemId").Eq().Value(svc.ItemId)))
                                 .ToList(tx).FirstOrDefault();
                    newList.Add((IEntity)loaded);
                }
                else if (itemType == typeof(Product))
                {
                    var product = (Product)item;
                    var loaded  = new SelectionQuery()
                                  .From(QueryFrom.EntityType(item.GetType()))
                                  .Select(QuerySelection.EntityType(item.GetType()))
                                  .Where(QueryCondition.Expression(ConditionExpr.Build().Field(itemType, "ItemId").Eq().Value(product.ItemId)))
                                  .ToList(tx).FirstOrDefault();
                    newList.Add((IEntity)loaded);
                }

                if (i % 100 == 0)
                {
                    tx.Close();
                    tx = transactionFactory.CreateTransaction();
                }
            }
            tx.Commit();
            tx.Close();
            sw.Stop();

            var speed = items.Count * 1000 / sw.ElapsedMilliseconds;

            LoggerManager.GetLogger(Assembly.GetExecutingAssembly(), typeof(NDbGatePerformanceCounter))
            .Log(typeof(NDbGatePerformanceCounter), Level.Warn, $"NDBGate Thread Query speed  {speed} entities/second", null);
            return(newList);
        }