Esempio n. 1
0
        public int Delete(TSearchCriteria[] criteria)
        {
            if (this.Context.ReadOnly)
            {
                throw new InvalidOperationException("Cannot delete via read-only persistence context.");
            }

            var query = new HqlQuery(string.Format("delete {0} x", typeof(TEntity).Name));

            var or = new HqlOr();

            foreach (var c in criteria)
            {
                var and = new HqlAnd(HqlCondition.FromSearchCriteria("x", c));
                if (and.Conditions.Count > 0)
                {
                    or.Conditions.Add(and);
                }
            }

            if (or.Conditions.Count > 0)
            {
                query.Conditions.Add(or);
            }


            return(ExecuteHqlDml(query));
        }
Esempio n. 2
0
        public long Count(TSearchCriteria[] criteria, EntityFindOptions options)
        {
            // cannot defer count queries, because we have no way of proxying the result
            // without changing the return type of this method
            if (options.Defer)
            {
                throw new NotSupportedException("Count queries do not support the 'defer' option.");
            }

            var query = new HqlQuery(string.Format("select count(*) from {0} x", typeof(TEntity).Name))
            {
                Cacheable = options.Cache
            };

            // for a "count" query, sort conditions that may be present in the
            // criteria object must be ignored- therefore, only the conditions are added to the query
            var or = new HqlOr();

            foreach (var c in criteria)
            {
                var and = new HqlAnd(HqlCondition.FromSearchCriteria("x", c));
                if (and.Conditions.Count > 0)
                {
                    or.Conditions.Add(and);
                }
            }

            if (or.Conditions.Count > 0)
            {
                query.Conditions.Add(or);
            }

            // expect exactly one integer result
            return(ExecuteHqlUnique <long>(query));
        }
Esempio n. 3
0
        private static HqlProjectionQuery BuildSentQuery(Notebox notebox, INoteboxQueryContext nqc, bool countQuery)
        {
            var query = GetBaseQuery(nqc, countQuery, "n", typeof(Note), SentItemProjection, SentItemsJoins);

            var or = new HqlOr();

            foreach (var criteria in notebox.GetInvariantCriteria(nqc))
            {
                var and = new HqlAnd();

                // for sent items, IsAcknowledged means fully acknowledged (all readers have acknowledged)
                and.Conditions.Add(new HqlCondition("n.IsFullyAcknowledged = ?", criteria.IsAcknowledged));

                if (criteria.SentByMe)
                {
                    and.Conditions.Add(new HqlCondition("n.Author = ?", nqc.Staff));
                }

                or.Conditions.Add(and);
            }
            query.Conditions.Add(or);
            query.Conditions.Add(new HqlCondition("n.HasPostings = ?", true));

            if (!countQuery)
            {
                query.Sorts.AddRange(SentItemOrdering);
            }

            return(query);
        }
Esempio n. 4
0
        private static HqlProjectionQuery BuildInboxQuery(Notebox notebox, INoteboxQueryContext nqc, bool countQuery)
        {
            var query = GetBaseQuery(nqc, countQuery, "np", typeof(NotePosting), InboxItemProjection, InboxItemsJoins);

            var or = new HqlOr();

            foreach (var criteria in notebox.GetInvariantCriteria(nqc))
            {
                var and = new HqlAnd();
                and.Conditions.Add(new HqlCondition("np.IsAcknowledged = ?", criteria.IsAcknowledged));

                if (criteria.SentToMe)
                {
                    and.Conditions.Add(new HqlCondition("np.Recipient = ?", nqc.Staff));
                }
                if (criteria.SentToGroupIncludingMe)
                {
                    and.Conditions.Add(new HqlCondition("np.Recipient = ?", nqc.StaffGroup));
                }

                or.Conditions.Add(and);
            }
            query.Conditions.Add(or);
            //query.Conditions.Add(ConditionMostRecentNote);

            if (!countQuery)
            {
                query.Sorts.AddRange(InboxItemOrdering);
            }

            return(query);
        }
        /// <summary>
        /// Adds the specified criteria to the specified query, pre-pending the specified qualifier.
        /// </summary>
        /// <param name="qualifier"></param>
        /// <param name="criteria"></param>
        /// <param name="query"></param>
        /// <param name="remapHqlExprFunction"></param>
        /// <remarks>
        /// All HQL dot expressions are passed through the <paramref name="remapHqlExprFunction"/>, allowing the expression
        /// to be modified prior to be added to the query.
        /// </remarks>
        public static void AddCriteriaToQuery(string qualifier, WorklistItemSearchCriteria[] criteria, HqlProjectionQuery query,
                                              Converter <string, string> remapHqlExprFunction)
        {
            var or = new HqlOr();

            foreach (var c in criteria)
            {
                if (c.IsEmpty)
                {
                    continue;
                }

                var conditions = HqlCondition.FromSearchCriteria(qualifier, c, remapHqlExprFunction);
                var and        = new HqlAnd(conditions);
                if (and.Conditions.Count > 0)
                {
                    or.Conditions.Add(and);
                }
            }

            if (or.Conditions.Count > 0)
            {
                query.Conditions.Add(or);
            }
        }
Esempio n. 6
0
        public IList <TEntity> Find(TSearchCriteria[] criteria, SearchResultPage page, EntityFindOptions options)
        {
            var query = new HqlProjectionQuery(new HqlFrom(typeof(TEntity).Name, "x"))
            {
                Page = page, Cacheable = options.Cache
            };

            // add fetch joins
            foreach (var fetchJoin in GetDefaultFetchJoins())
            {
                query.Froms[0].Joins.Add(new HqlJoin("x." + fetchJoin, null, HqlJoinMode.Inner, true));
            }

            // apply lock hint
            if (options.LockForUpdate)
            {
                query.SetLockMode("x", LockMode.Upgrade);
            }

            var or = new HqlOr();

            foreach (var c in criteria)
            {
                var and = new HqlAnd(HqlCondition.FromSearchCriteria("x", c));
                if (and.Conditions.Count > 0)
                {
                    or.Conditions.Add(and);
                }

                query.Sorts.AddRange(HqlSort.FromSearchCriteria("x", c));
            }

            if (or.Conditions.Count > 0)
            {
                query.Conditions.Add(or);
            }


            return(ExecuteHql <TEntity>(query, options.Defer));
        }