Exemplo n.º 1
0
        private ICriteria EnsureCriteria(string associationPath, string alias)
        {
            ICriteria criteria;

            if ((criteria = currentCriteria.GetCriteriaByAlias(alias)) == null)
            {
                criteria = currentCriteria.CreateCriteria(associationPath, alias, JoinType.LeftOuterJoin);
            }
            return(criteria);
        }
Exemplo n.º 2
0
        public void TestGetCriteriaByAlias()
        {
            Person    personAlias = null;
            Person    fatherAlias = null;
            ICriteria criteria    = CreateSession()
                                    .CreateCriteria(typeof(Person), () => personAlias)
                                    .CreateAlias(() => personAlias.Father, () => fatherAlias);

            Assert.AreEqual("personAlias", criteria.GetCriteriaByAlias(() => personAlias).Alias);
            Assert.AreEqual("fatherAlias", criteria.GetCriteriaByAlias(() => fatherAlias).Alias);
        }
Exemplo n.º 3
0
        private static void SetJoinCriteria(ICriteria cr, Sort sort)
        {
            ICriteria crej = cr.GetCriteriaByAlias("ej");

            if (sort.Column == "d.Title")
            {
                ICriteria crd = cr.GetCriteriaByAlias("d");
                if (crej != null && crd == null)
                {
                    cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);
                }

                else if (crej == null && crd == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr   = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "es.Name")
            {
                ICriteria cres = cr.GetCriteriaByAlias("es");
                if (crej != null && cres == null)
                {
                    cr = crej.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                }

                else if (crej == null && cres == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr   = crej.CreateCriteria("ej.Employmentstatus", "es", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "dept.Name")
            {
                ICriteria crdept = cr.GetCriteriaByAlias("dept");
                if (crej != null && crdept == null)
                {
                    cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);
                }

                else if (crej == null && crdept == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr   = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);
                }
            }
        }
Exemplo n.º 4
0
        SqlString IProjection.ToSqlString(ICriteria criteria, Int32 position, ICriteriaQuery criteriaQuery, IDictionary <String, IFilter> enabledFilters)
        {
            var classMetadata = criteriaQuery.Factory.GetClassMetadata(this.rootEntity);
            var propertyNames = this.GetPropertyNames(classMetadata, criteriaQuery);
            var builder       = new SqlStringBuilder();

            for (var i = 0; i < propertyNames.Length; ++i)
            {
                var propertyName = propertyNames[i];
                var subcriteria  = criteria.GetCriteriaByAlias(this.alias);
                var columnName   = criteriaQuery.GetColumn(subcriteria, propertyName);

                builder.Add(columnName);
                builder.Add(" as ");
                builder.Add(propertyName);

                this.aliases.Add(propertyName);

                if (i < propertyNames.Length - 1)
                {
                    builder.Add(", ");
                }
            }
            return(builder.ToSqlString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Alows to get a sub criteria by alias.
        /// Will return null if the criteria does not exists
        /// </summary>
        /// <param name="criteria">criteria instance</param>
        /// <param name="alias">Lambda expression returning alias reference</param>
        /// <returns>The "sub criteria"</returns>
        public static ICriteria GetCriteriaByAlias(this ICriteria criteria,
                                                   Expression <Func <object> > alias)
        {
            string aliasContainer = ExpressionProcessor.FindMemberExpression(alias.Body);

            return(criteria.GetCriteriaByAlias(aliasContainer));
        }
        protected override Expression VisitEntity(EntityExpression expr)
        {
            if (_rootCriteria.GetCriteriaByAlias(expr.Alias) != null)
            {
                _transformer = new LinqJoinResultsTransformer(expr.Type);
            }

            return(expr);
        }
Exemplo n.º 7
0
        public DetachedCriteria GetCriteriaByAlias(string alias)
        {
            ICriteria tmpCrit = criteria.GetCriteriaByAlias(alias);

            if (tmpCrit == null)
            {
                return(null);
            }
            return(new DetachedCriteria(impl, tmpCrit));
        }
Exemplo n.º 8
0
 static void AddAlias(String path, ICriteria criteria)
 {
     String[] names = path.Split('.');
        for (int i = 0; i < names.Length - 1; i++)
        {
        if (criteria.GetCriteriaByAlias(names[i]) == null)
        {
            criteria.CreateAlias(names[i], names[i]);
        }
        }
 }
Exemplo n.º 9
0
 private static void SetJoinCriteria(ICriteria cr, Sort sort)
 {
     if (sort.Column == "e.Firstname")
     {
         ICriteria cre = cr.GetCriteriaByAlias("e");
         if (cre == null)
         {
             cr = cr.CreateCriteria("attendance.Employee", "e", JoinType.LeftOuterJoin);
         }
     }
 }
Exemplo n.º 10
0
 static void AddAlias(String path, ICriteria criteria)
 {
     String[] names = path.Split('.');
     for (int i = 0; i < names.Length - 1; i++)
     {
         if (criteria.GetCriteriaByAlias(names[i]) == null)
         {
             criteria.CreateAlias(names[i], names[i]);
         }
     }
 }
Exemplo n.º 11
0
        ///<summary>
        /// HQL 문을 생성한다.
        ///</summary>
        ///<exception cref="QueryException"></exception>
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
                                              IDictionary <string, IFilter> enabledFilters)
        {
            string    alias;
            Type      targetType;
            ICriteria aliasedCriteria;

            if (_propertyNameOrAlias.IsWhiteSpace())
            {
                alias = criteriaQuery.GetSQLAlias(criteria);
                string entityName = criteriaQuery.GetEntityName(criteria);
                targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco);
            }
            else if ((aliasedCriteria = criteria.GetCriteriaByAlias(_propertyNameOrAlias)) != null)
            {
                alias = criteriaQuery.GetSQLAlias(aliasedCriteria);
                string entityName = criteriaQuery.GetEntityName(aliasedCriteria);
                targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco);
            }
            else
            {
                alias = criteriaQuery.GetSQLAlias(criteria, _propertyNameOrAlias);
                var type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyNameOrAlias);

                if (!type.IsEntityType)
                {
                    throw new QueryException("Only entities can be used with an IsAExpression");
                }

                targetType = type.ReturnedClass;
            }

            if (!targetType.IsAssignableFrom(_entityClass))
            {
                return(new SqlString("1=0"));
            }

            var queryable = ObtainQueryable(criteriaQuery);
            var condition = queryable.WhereJoinFragment(alias, true, true);

            if (condition.IndexOfCaseInsensitive(" and ") == 0)
            {
                condition = condition.Substring(5);
            }

            return((condition.Length > 0) ? condition : new SqlString("1=1"));
        }
Exemplo n.º 12
0
        private static string IncluiSubcriteria(string column, ICriteria pCriteria)
        {
            string[]  Items     = column.Split('.');
            ICriteria lCriteria = pCriteria;

            for (int i = 0; i < Items.Length - 1; i++)
            {
                if (pCriteria.GetCriteriaByAlias(Items[i]) == null)
                {
                    lCriteria = lCriteria.CreateCriteria(Items[i], Items[i]);
                }
                else
                {
                    lCriteria = lCriteria.GetCriteriaByAlias(Items[i]);
                }
            }
            return(Items.Length > 1 ? Items[Items.Length - 2] + "." + Items[Items.Length - 1] : Items[Items.Length - 1]);
        }
Exemplo n.º 13
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery,
                                              IDictionary <string, IFilter> enabledFilters)
        {
            string    alias      = null;
            Type      targetType = null;
            ICriteria aliasedCriteria;

            if (string.IsNullOrEmpty(_alias))
            {
                alias = criteriaQuery.GetSQLAlias(criteria);
                string entityName = criteriaQuery.GetEntityName(criteria);
                targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco);
            }
            else if ((aliasedCriteria = criteria.GetCriteriaByAlias(_alias)) != null)
            {
                alias = criteriaQuery.GetSQLAlias(aliasedCriteria);
                string entityName = criteriaQuery.GetEntityName(aliasedCriteria);
                targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco);
            }

            if (targetType == null || !targetType.IsAssignableFrom(_entityClass))
            {
                return(new SqlString("1=0"));
            }

            IQueryable queryable = ObtainQueryable(criteriaQuery);
            string     condition = queryable.FilterFragment(alias, enabledFilters);

            if (condition.IndexOf(" and ", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                condition = condition.Substring(5);
            }

            if (condition == string.Empty)
            {
                condition = "1=1";
            }

            return(new SqlString(condition));
        }
Exemplo n.º 14
0
 internal static ICriteria BindCriteriaByAlias(this ICriteria criteria, string alias)
 {
     return(criteria.GetCriteriaByAlias(alias));
 }
Exemplo n.º 15
0
        private static void GetFilterCriteria(ICriteria cr, Dictionary <string, object> filters, Sort sort = null)
        {
            string employee          = Convert.ToString(filters["employee"]);
            string staff_id          = Convert.ToString(filters["staff_id"]);
            int    employment_status = (int)filters["employment_status"];
            int    designation       = (int)filters["designation"];
            int    dept = (int)filters["dept"];

            if (!string.IsNullOrEmpty(employee))
            {
                AbstractCriterion a1 = Restrictions.InsensitiveLike("employee.Firstname", employee, MatchMode.Anywhere);
                AbstractCriterion a2 = Restrictions.InsensitiveLike("employee.Middlename", employee, MatchMode.Anywhere);
                AbstractCriterion a3 = Restrictions.InsensitiveLike("employee.Lastname", employee, MatchMode.Anywhere);

                AbstractCriterion b1 = Restrictions.Or(a1, a2);
                AbstractCriterion b2 = Restrictions.Or(b1, a3);

                cr.Add(b2);
            }

            if (!string.IsNullOrEmpty(staff_id))
            {
                cr.Add(Restrictions.InsensitiveLike("employee.Staffid", staff_id, MatchMode.Anywhere));
            }

            if (employment_status != 0)
            {
                cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);
                cr = cr.CreateCriteria("ej.Employmentstatus", "es", JoinType.InnerJoin);
                cr.Add(Restrictions.Eq("es.Id", employment_status));
            }

            if (designation != 0)
            {
                ICriteria crej = cr.GetCriteriaByAlias("ej");
                if (crej == null)
                {
                    cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);
                }

                else
                {
                    cr = crej;
                }

                cr = cr.CreateCriteria("ej.Designation", "d", JoinType.InnerJoin);

                cr.Add(Restrictions.Eq("d.Id", designation));
            }

            if (dept != 0)
            {
                ICriteria crej = cr.GetCriteriaByAlias("ej");
                if (crej == null)
                {
                    cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);
                }

                else
                {
                    cr = crej;
                }

                cr = cr.CreateCriteria("ej.Department", "dept", JoinType.InnerJoin);

                cr.Add(Restrictions.Eq("dept.Id", dept));
            }

            if (sort != null)
            {
                SetJoinCriteria(cr, sort);
            }
        }
Exemplo n.º 16
0
 private static void SetJoinCriteria(ICriteria cr, Sort sort)
 {
     if (sort.Column == "e.Firstname")
     {
         ICriteria cre = cr.GetCriteriaByAlias("e");
         if (cre == null)
             cr = cr.CreateCriteria("attendance.Employee", "e", JoinType.LeftOuterJoin);
     }
 }
Exemplo n.º 17
0
        private static void GetFilterCriteria(ICriteria cr, Dictionary<string, object> filters, Sort sort = null)
        {
            string employee = Convert.ToString(filters["employee"]);
            string staff_id = Convert.ToString(filters["staff_id"]);
            int employment_status = (int)filters["employment_status"];
            int designation = (int)filters["designation"];
            int dept = (int)filters["dept"];

            if (!string.IsNullOrEmpty(employee))
            {
                AbstractCriterion a1 = Restrictions.InsensitiveLike("employee.Firstname", employee, MatchMode.Anywhere);
                AbstractCriterion a2 = Restrictions.InsensitiveLike("employee.Middlename", employee, MatchMode.Anywhere);
                AbstractCriterion a3 = Restrictions.InsensitiveLike("employee.Lastname", employee, MatchMode.Anywhere);

                AbstractCriterion b1 = Restrictions.Or(a1, a2);
                AbstractCriterion b2 = Restrictions.Or(b1, a3);

                cr.Add(b2);
            }

            if (!string.IsNullOrEmpty(staff_id))
                cr.Add(Restrictions.InsensitiveLike("employee.Staffid", staff_id, MatchMode.Anywhere));

            if (employment_status != 0)
            {
                cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);
                cr = cr.CreateCriteria("ej.Employmentstatus", "es", JoinType.InnerJoin);
                cr.Add(Restrictions.Eq("es.Id", employment_status));
            }

            if (designation != 0)
            {
                ICriteria crej = cr.GetCriteriaByAlias("ej");
                if (crej == null)
                    cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);

                else
                    cr = crej;

                cr = cr.CreateCriteria("ej.Designation", "d", JoinType.InnerJoin);

                cr.Add(Restrictions.Eq("d.Id", designation));
            }

            if (dept != 0)
            {
                ICriteria crej = cr.GetCriteriaByAlias("ej");
                if (crej == null)
                    cr = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.InnerJoin);

                else
                    cr = crej;

                cr = cr.CreateCriteria("ej.Department", "dept", JoinType.InnerJoin);

                cr.Add(Restrictions.Eq("dept.Id", dept));
            }

            if (sort != null)
                SetJoinCriteria(cr, sort);
        }
Exemplo n.º 18
0
        private static void SetJoinCriteria(ICriteria cr, Sort sort)
        {
            ICriteria crej = cr.GetCriteriaByAlias("ej");

            if (sort.Column == "d.Title")
            {
                ICriteria crd = cr.GetCriteriaByAlias("d");
                if (crej != null && crd == null)
                    cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);

                else if (crej == null && crd == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr = crej.CreateCriteria("ej.Designation", "d", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "es.Name")
            {
                ICriteria cres = cr.GetCriteriaByAlias("es");
                if (crej != null && cres == null)
                    cr = crej.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);

                else if (crej == null && cres == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr = crej.CreateCriteria("ej.Employmentstatus", "es", JoinType.LeftOuterJoin);
                }
            }

            if (sort.Column == "dept.Name")
            {
                ICriteria crdept = cr.GetCriteriaByAlias("dept");
                if (crej != null && crdept == null)
                    cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);

                else if (crej == null && crdept == null)
                {
                    crej = cr.CreateCriteria("employee.Employeejob", "ej", JoinType.LeftOuterJoin);
                    cr = crej.CreateCriteria("ej.Department", "dept", JoinType.LeftOuterJoin);
                }
            }
        }