예제 #1
0
 protected DetachedCriteria Limit(DetachedCriteria criteria, int start, int max)
 {
     if (start >= 1)
     {
         criteria.SetFirstResult(start);
     }
     if (max >= 0)
     {
         criteria.SetMaxResults(max);
     }
     return(criteria);
 }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <param name="matchLoginId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IList <User> FindUsersByLoginId(string matchLoginId, int pageIndex, int pageSize)
        {
            DetachedCriteria ica = CreateDetachedCriteria();

            if (!String.IsNullOrEmpty(matchLoginId))
            {
                ica.Add(Restrictions.InsensitiveLike(LoginProperty, matchLoginId + "%"));
            }

            return
                (ica.SetMaxResults(pageSize).SetFirstResult(pageIndex * pageSize).GetExecutableCriteria(CurrentSession)
                 .List <User>());
        }
예제 #3
0
        /// <summary>
        /// Current Criteria의 Paging 설정을 수행한다.
        /// </summary>
        /// <param name="firstResult">결과 Set의 첫번째 인덱스</param>
        /// <param name="maxResults">결과 Set의 최대 레코드 수 (0 이하이면 설정하지 않는다.)</param>
        /// <returns>Current instance of CriteriaBatch</returns>
        public CriteriaBatch Paging(int firstResult, int maxResults)
        {
            if (firstResult >= 0)
            {
                _currentCriteria.SetFirstResult(firstResult);
            }

            if (maxResults > 0)
            {
                _currentCriteria.SetMaxResults(maxResults);
            }

            return(this);
        }
 /// <summary>
 /// Adds paging to the DetachedCriteria based on the given parameters.
 /// </summary>
 /// <param name="criteria"></param>
 /// <param name="pageSize"></param>
 /// <param name="pageNumber"></param>
 /// <returns></returns>
 public static DetachedCriteria ApplyPaging(this DetachedCriteria criteria, int?pageSize, int?pageNumber)
 {
     if (pageSize.HasValue)
     {
         criteria.SetMaxResults(pageSize.Value);
     }
     if (pageNumber.HasValue)
     {
         if (!pageSize.HasValue)
         {
             throw new ArgumentException("Unable to determine the object to return for the given page number when the pagesize is unknown.");
         }
         criteria.SetFirstResult(pageSize.Value * (pageNumber.Value - 1));
     }
     return(criteria);
 }
        private IList <RegistrationInformation> AcceptPaginator(DetachedCriteria criteria, ISession session)
        {
            var countSubquery = CriteriaTransformer.TransformToRowCount(criteria);

            _lastRowsCount = countSubquery.GetExecutableCriteria(session).UniqueResult <int>();

            if (CurrentPage > 0)
            {
                criteria.SetFirstResult(CurrentPage * PageSize);
            }

            criteria.SetMaxResults(PageSize);

            ApplySort(criteria);

            return(criteria.GetExecutableCriteria(session).ToList <RegistrationInformation>().ToList());
        }
        private IList <DocumentLog> AcceptPaginator(ISession session, DetachedCriteria criteria, bool forExport = false)
        {
            var countQuery = CriteriaTransformer.TransformToRowCount(criteria);

            if (OnlyNoParsed && !forExport)
            {
                if (CurrentPage > 0)
                {
                    criteria.SetFirstResult(CurrentPage * PageSize);
                }

                criteria.SetMaxResults(PageSize);
            }

            RowsCount = countQuery.GetExecutableCriteria(session).UniqueResult <int>();
            return(criteria.GetExecutableCriteria(session).ToList <DocumentLog>());
        }
        /// <summary>
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="relative"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IList <PersonalMessage> GetChat(User owner, User relative, DateTime?lastGetLastTime, int pageIndex,
                                               int pageSize)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (relative == null)
            {
                throw new ArgumentNullException("relative");
            }
            IProjection receiverProperty  = ReceiverProperty;
            IProjection publisherProperty = PublisherProperty;
            IProjection deleteProperty    = CreateDeleteStatus;

            var receive = new Disjunction();

            receive.Add(
                (new Conjunction())
                .Add(Restrictions.Eq(receiverProperty, owner))
                .Add(Restrictions.Not(Restrictions.Eq(deleteProperty, PersonalMessageStatus.Receiver)))
                );
            receive.Add(Restrictions.Eq(receiverProperty, relative));


            var publisher = new Disjunction();

            publisher.Add(
                (new Conjunction()).Add(Restrictions.Eq(publisherProperty, owner))
                .Add(Restrictions.Not(Restrictions.Eq(deleteProperty, PersonalMessageStatus.Publisher)))
                );
            publisher.Add(Restrictions.Eq(publisherProperty, relative));

            DetachedCriteria deach = CreateDetachedCriteria()
                                     .Add(receive)
                                     .Add(publisher);

            if (lastGetLastTime != null)
            {
                deach.Add(Restrictions.Gt(CreateTimeProperty, lastGetLastTime.Value));
            }
            return
                (deach.SetMaxResults(pageSize).SetFirstResult(pageIndex * pageSize)
                 .AddOrder(Order.Desc(CreateTimeProperty))
                 .GetExecutableCriteria(CurrentSession).List <PersonalMessage>());
        }
예제 #8
0
        /// <summary>
        /// <paramref name="criteria"/>에 해당하는 엔티티가 존재하는지 검사합니다. 하나라도 있으면 True, 없으면 False
        /// </summary>
        public static bool ExistsStateless <T>(this DetachedCriteria criteria, ISession session) where T : IDataObject
        {
            criteria.ShouldNotBeNull("criteria");
            session.ShouldNotBeNull("session");

            var result = false;

            NHWith.StatelessSessionNoTransaction(session,
                                                 stateless => {
                result =
                    criteria
                    .SetMaxResults(1)
                    .GetExecutableCriteria(stateless)
                    .List <T>()
                    .Any();
            });

            return(result);
        }
 public NHibernateDynamicQueryGenerator <EntityType> SetMaxResults(int maxResults)
 {
     query.SetMaxResults(maxResults);
     return(this);
 }
 public ICriteria SetMaxResults(int maxResults)
 {
     return(detachedCriteria.SetMaxResults(maxResults).Adapt(session));
 }
예제 #11
0
 public CriteriaBatch Paging(int firstResult, int maxResults)
 {
     currentCriteria.SetFirstResult(firstResult);
     currentCriteria.SetMaxResults(maxResults);
     return(this);
 }
예제 #12
0
        /// <summary>
        ///     Builds a <see cref="DetachedCriteria" /> from the given <see cref="IMorphableFlowQuery" /> query.
        /// </summary>
        /// <param name="query">
        ///     The query from which to build a <see cref="ICriteria" />.
        /// </param>
        /// <typeparam name="TSource">
        ///     The <see cref="System.Type" /> of the underlying entity for the given query.
        /// </typeparam>
        /// <returns>
        ///     The built <see cref="DetachedCriteria" />.
        /// </returns>
        public virtual DetachedCriteria Build <TSource>(IMorphableFlowQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            DetachedCriteria criteria = DetachedCriteria.For <TSource>(query.Alias);

            foreach (Join join in query.Joins)
            {
                criteria.CreateAlias(join.Property, join.Alias, join.JoinType, join.WithClause);
            }

            foreach (ICriterion criterion in query.Criterions)
            {
                criteria.Add(criterion);
            }

            foreach (Lock queryLock in query.Locks)
            {
                if (queryLock.Alias == null)
                {
                    criteria.SetLockMode(queryLock.LockMode);
                }
                else
                {
                    criteria.SetLockMode(queryLock.Alias, queryLock.LockMode);
                }
            }

            bool skips = query.ResultsToSkip.HasValue && query.ResultsToSkip.Value > 0;

            if (skips)
            {
                criteria.SetFirstResult(query.ResultsToSkip.Value);
            }

            bool takes = query.ResultsToTake.HasValue && query.ResultsToTake.Value > 0;

            if (takes)
            {
                criteria.SetMaxResults(query.ResultsToTake.Value);
            }

            if (query.IsCacheable)
            {
                criteria.SetCacheable(true);

                if (query.CacheMode.HasValue)
                {
                    criteria.SetCacheMode(query.CacheMode.Value);
                }

                if (!string.IsNullOrEmpty(query.CacheRegion))
                {
                    criteria.SetCacheRegion(query.CacheRegion);
                }
            }

            criteria
            .SetProjection
            (
                GetProjection(query)
            );

            if (query.ResultTransformer != null)
            {
                criteria.SetResultTransformer(query.ResultTransformer);
            }

            if (query.Orders.Count > 0 && (skips || takes))
            {
                foreach (OrderByStatement statement in query.Orders)
                {
                    if (statement.IsBasedOnSource)
                    {
                        criteria.AddOrder(statement.Order);
                    }
                }
            }

            return(criteria);
        }