/// <summary>
        /// Get the aliases of the columns constrained
        /// by this criterion (for use in ORDER BY clause).
        /// </summary>
        public string[] GetColumnAliasesUsingProjection(ICriteria subcriteria, string propertyName)
        {
            //first look for a reference to a projection alias
            IProjection projection = rootCriteria.Projection;

            string[] projectionColumns = projection == null ? null : projection.GetColumnAliases(propertyName, 0);

            if (projectionColumns == null)
            {
                //it does not refer to an alias of a projection,
                //look for a property
                try
                {
                    return(GetColumns(subcriteria, propertyName));
                }
                catch (HibernateException)
                {
                    //not found in inner query , try the outer query
                    if (outerQueryTranslator != null)
                    {
                        return(outerQueryTranslator.GetColumnAliasesUsingProjection(subcriteria, propertyName));
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                //it refers to an alias of a projection
                return(projectionColumns);
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Render the SQL fragment
		/// </summary>
		public virtual string ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
		{
			string[] columns = criteriaQuery.GetColumnAliasesUsingProjection(criteria, propertyName);

			StringBuilder fragment = new StringBuilder();

			ISessionFactoryImplementor factory = criteriaQuery.Factory;
			for (int i = 0; i < columns.Length; i++)
			{
				// TODO H3: bool lower = _ignoreCase && type.SqlTypes( factory )[ i ] == Types.VARCHAR
				bool lower = false;
				if (lower)
				{
					fragment.Append(factory.Dialect.LowercaseFunction)
						.Append('(');
				}
				fragment.Append(columns[i]);

				if (lower)
				{
					fragment.Append(')');
				}

				fragment.Append(ascending ? " asc" : " desc");

				if (i < columns.Length - 1)
				{
					fragment.Append(", ");
				}
			}

			return fragment.ToString();
		}
Ejemplo n.º 3
0
        private object[] GetColumnsOrAliases(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            var propName = propertyName ?? (projection as IPropertyProjection)?.PropertyName;

            return(propName != null
                                ? criteriaQuery.GetColumnAliasesUsingProjection(criteria, propName)
                                : CriterionUtil.GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Render the SQL fragment
        /// </summary>
        public virtual SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
        {
            if (projection != null)
            {
                SqlString sb        = new SqlString();
                SqlString produced  = this.projection.ToSqlString(criteria, 0, criteriaQuery, new Dictionary <string, IFilter>());
                SqlString truncated = NHibernate.Util.StringHelper.RemoveAsAliasesFromSql(produced);
                sb = sb.Append(truncated);
                sb = sb.Append(ascending ? " asc" : " desc");
                return(sb);
            }

            string[]   columns = criteriaQuery.GetColumnAliasesUsingProjection(criteria, propertyName);
            Type.IType type    = criteriaQuery.GetTypeUsingProjection(criteria, propertyName);

            StringBuilder fragment             = new StringBuilder();
            ISessionFactoryImplementor factory = criteriaQuery.Factory;

            for (int i = 0; i < columns.Length; i++)
            {
                bool lower = ignoreCase && IsStringType(type.SqlTypes(factory)[i]);

                if (lower)
                {
                    fragment.Append(factory.Dialect.LowercaseFunction)
                    .Append("(");
                }
                fragment.Append(columns[i]);

                if (lower)
                {
                    fragment.Append(")");
                }

                fragment.Append(ascending ? " asc" : " desc");

                if (i < columns.Length - 1)
                {
                    fragment.Append(", ");
                }
            }

            return(new SqlString(fragment.ToString()));
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Render the SQL fragment
		/// </summary>
		public virtual SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
		{
			if(projection!=null)
			{
				SqlString sb=new SqlString();
				SqlString produced = this.projection.ToSqlString(criteria, 0, criteriaQuery, new Dictionary<string, IFilter>());
				SqlString truncated = NHibernate.Util.StringHelper.RemoveAsAliasesFromSql(produced);
				sb = sb.Append(truncated);
				sb = sb.Append(ascending ? " asc" : " desc");
				return sb;
			}

			string[] columns = criteriaQuery.GetColumnAliasesUsingProjection(criteria, propertyName);

			StringBuilder fragment = new StringBuilder();

			ISessionFactoryImplementor factory = criteriaQuery.Factory;
			for (int i = 0; i < columns.Length; i++)
			{
				// TODO H3: bool lower = _ignoreCase && type.SqlTypes( factory )[ i ] == Types.VARCHAR
				bool lower = false;
				if (lower)
				{
					fragment.Append(factory.Dialect.LowercaseFunction)
						.Append("(");
				}
				fragment.Append(columns[i]);

				if (lower)
				{
					fragment.Append(")");
				}

				fragment.Append(ascending ? " asc" : " desc");

				if (i < columns.Length - 1)
				{
					fragment.Append(", ");
				}
			}

			return new SqlString(fragment.ToString());
		}