Beispiel #1
0
        protected override IPaginable <Foo> GetPaginableWithLikeRestriction(ISession session)
        {
            var query = new DetachedQuery("f where f.Name like :p1");

            query.SetString("p1", "N_%");
            return(new PaginableQuery <Foo>(session, query));
        }
        public void TransformingShouldDelayingParameterCopy()
        {
            var          originalQuery = new DetachedQuery("from Foo f where f.Name like :p1");
            IRowsCounter rc            = QueryRowsCounter.Transforming(originalQuery);

            originalQuery.SetString("p1", "%1_");

            SessionFactory.EncloseInTransaction(s => Assert.AreEqual(5, rc.GetRowsCount(s)));
        }
        public void RowsCountTransforming()
        {
            Assert.Throws <ArgumentNullException>(() => QueryRowsCounter.Transforming(null));

            var originalQuery = new DetachedQuery("from Foo f where f.Name like :p1");

            originalQuery.SetString("p1", "%1_");

            IRowsCounter rc = QueryRowsCounter.Transforming(originalQuery);

            SessionFactory.EncloseInTransaction(s => Assert.AreEqual(5, rc.GetRowsCount(s)));
        }
Beispiel #4
0
        public void RowsCountTransforming()
        {
            DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1");

            dq.SetString("p1", "%1_");
            IRowsCounter rc = QueryRowsCounter.Transforming(dq);

            using (ISession s = OpenSession())
            {
                Assert.AreEqual(5, rc.GetRowsCount(s));
            }
        }
Beispiel #5
0
        public void PaginableRowsCount()
        {
            DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1");

            dq.SetString("p1", "N_");
            using (ISession s = OpenSession())
            {
                IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(LastOpenedSession, dq);
                IList <Foo>      l  = fp.GetPage(5, 1);
                Assert.AreEqual(5, l.Count);
                Assert.AreEqual(10, ((IRowsCounter)fp).GetRowsCount(s));
            }
        }
        public void ShouldWorkAsPaginatorAndAsRowCounter()
        {
            var dq = new DetachedQuery("from Foo f where f.Name like :p1");

            dq.SetString("p1", "N_");
            using (ISession s = SessionFactory.OpenSession())
            {
                IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(s, dq);
                IList <Foo>      l  = fp.GetPage(5, 1);
                Assert.That(l.Count, Is.EqualTo(5));
                Assert.That(((IRowsCounter)fp).GetRowsCount(s), Is.EqualTo(10));
            }
        }
        public void Serializable()
        {
            DetachedQuery dq = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");

            dq.SetString("pn", "N2").SetString("pd", "D2");
            byte[] bytes = SerializationHelper.Serialize(dq);

            DetachedQuery dqs = (DetachedQuery)SerializationHelper.Deserialize(bytes);

            using (ISession s = OpenSession())
            {
                dqs.GetExecutableQuery(s).List();
            }
        }
Beispiel #8
0
        public void WithSelfCounter()
        {
            DetachedQuery dq = new DetachedQuery("from Foo f where f.Name like :p1");

            dq.SetString("p1", "%1_");
            IPaginable <Foo> fp = new PaginableRowsCounterQuery <Foo>(LastOpenedSession, dq);

            Paginator <Foo> ptor = new Paginator <Foo>(2, fp);

            Assert.IsTrue(ptor.AutoCalcPages);
            Assert.AreEqual(3, ptor.LastPageNumber);
            // check page 2
            IList <Foo> lpage = ptor.GetPage(2);

            Assert.AreEqual(2, lpage.Count);
            Assert.AreEqual(2, ptor.CurrentPageNumber);
            Assert.AreEqual("N12", lpage[0].Name);
            Assert.AreEqual("N13", lpage[1].Name);
        }
Beispiel #9
0
        public void PerformanceDiffSimplyQuery()
        {
            DateTime      sDQStart = DateTime.Now;
            DetachedQuery dq       = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");

            dq.SetString("pn", "N2").SetString("pd", "D2");
            using (ISession s = OpenSession())
            {
                IQuery q = dq.GetExecutableQuery(s);
            }
            DateTime sDQStop = DateTime.Now;

            DateTime sQStart = DateTime.Now;

            using (ISession s = OpenSession())
            {
                IQuery q = s.CreateQuery("from Foo f where f.Name=:pn and f.Description=:pd").SetString("pn", "N2").SetString("pd", "D2");
            }
            DateTime sQStop = DateTime.Now;

            Console.WriteLine("DetachedQueryCycle={0} QueryCycl={1}  Diff={2}", sDQStop - sDQStart, sQStop - sQStart,
                              (sDQStop - sDQStart) - (sQStop - sQStart));
        }
        public void ExecutableQuery()
        {
            // Simply fetch
            IDetachedQuery dq = new DetachedQuery("from Foo");

            using (ISession s = OpenSession())
            {
                IQuery q = dq.GetExecutableQuery(s);
                IList  l = q.List();
                Assert.AreEqual(totalFoo, l.Count);
            }

            // With Typed Parameters
            dq = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");
            dq.SetString("pn", "N2").SetString("pd", "D2");
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(1, l.Count);
                Assert.AreEqual("N2", l[0].Name);
                Assert.AreEqual("D2", l[0].Description);
            }

            // With UnTyped Parameters
            dq = new DetachedQuery("from Foo f where f.Name=:pn and f.Description=:pd");
            dq.SetParameter("pn", "N2").SetParameter("pd", "D2");
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(1, l.Count);
                Assert.AreEqual("N2", l[0].Name);
                Assert.AreEqual("D2", l[0].Description);
            }

            // With UnTyped Parameter List
            dq = new DetachedQuery("from Foo f where f.IntValue in (:pn)");
            dq.SetParameterList("pn", new int[] { 2, 3 });
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(2, l.Count);

                Assert.True(l.Contains(new Foo("N2", "D2")));
                Assert.True(l.Contains(new Foo("N3", "D3")));
            }

            // Pagination
            dq = new DetachedQuery("from Foo f order by f.IntValue");
            dq.SetFirstResult(0).SetMaxResults(2);
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(2, l.Count);
                Assert.AreEqual("N0", l[0].Name);
                Assert.AreEqual("N1", l[1].Name);
            }
            dq.SetFirstResult(2).SetMaxResults(1);
            using (ISession s = OpenSession())
            {
                IQuery      q = dq.GetExecutableQuery(s);
                IList <Foo> l = q.List <Foo>();
                Assert.AreEqual(1, l.Count);
                Assert.AreEqual("N2", l[0].Name);
            }
        }