Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="persistentClass"></param>
        /// <param name="alias"></param>
        /// <returns></returns>
        public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
        {
            //TODO: add default capacity
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

            IType propertyType = AbstractCriterion.GetType(factory, persistentClass, _propertyName, aliasClasses);

            string[]    columnNames = AbstractCriterion.GetColumns(factory, persistentClass, _propertyName, alias, aliasClasses);
            Parameter[] parameters  = Parameter.GenerateParameters(factory, columnNames, propertyType);

            if (columnNames.Length != 1)
            {
                throw new HibernateException("insensitive like may only be used with single-column properties");
            }

            if (factory.Dialect is PostgreSQLDialect)
            {
                sqlBuilder.Add(columnNames[0]);
                sqlBuilder.Add(" ilike ");
            }
            else
            {
                sqlBuilder.Add(factory.Dialect.LowercaseFunction)
                .Add("(")
                .Add(columnNames[0])
                .Add(")")
                .Add(" like ");
            }

            sqlBuilder.Add(parameters[0]);

            return(sqlBuilder.ToSqlString());
        }
Esempio n. 2
0
        public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
        {
            //TODO: add default capacity
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

            string[] columnNames = AbstractCriterion.GetColumns(factory, persistentClass, _propertyName, alias, aliasClasses);


            bool opNeeded = false;

            for (int i = 0; i < columnNames.Length; i++)
            {
                if (opNeeded)
                {
                    sqlBuilder.Add(" or ");
                }
                opNeeded = true;

                sqlBuilder.Add(columnNames[i])
                .Add(" is not null");
            }

            if (columnNames.Length > 1)
            {
                sqlBuilder.Insert(0, "(");
                sqlBuilder.Add(")");
            }

            return(sqlBuilder.ToSqlString());
        }
Esempio n. 3
0
 /// <summary>
 /// Render the SQL fragment
 /// </summary>
 /// <param name="sessionFactory"></param>
 /// <param name="persistentClass"></param>
 /// <param name="alias"></param>
 /// <returns></returns>
 public string ToSqlString(ISessionFactoryImplementor sessionFactory, System.Type persistentClass, string alias)
 {
     string[] columns = AbstractCriterion.GetColumns(sessionFactory, persistentClass, _propertyName, alias, emptyMap);
     if (columns.Length != 1)
     {
         throw new HibernateException("Cannot order by multi-column property: " + _propertyName);
     }
     return(columns[0] + (_ascending ? " asc" : " desc"));
 }
Esempio n. 4
0
        /// <summary>
        /// Converts the SimpleExpression to a <see cref="SqlString"/>.
        /// </summary>
        /// <param name="factory">The ISessionFactory that contains the mapping for the Type.</param>
        /// <param name="persistentClass">The Class the Expression is being built for.</param>
        /// <param name="alias">The alias to use for the table.</param>
        /// <returns>A SqlString that contains a valid Sql fragment.</returns>
        public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
        {
            string[] columnNames  = AbstractCriterion.GetColumns(factory, persistentClass, _propertyName, alias, aliasClasses);
            IType    propertyType = AbstractCriterion.GetType(factory, persistentClass, _propertyName, aliasClasses);

            if (propertyType.IsPersistentCollectionType)
            {
                throw new QueryException(string.Format(
                                             "cannot use collection property ({0}.{1}) directly in a criterion,"
                                             + " use ICriteria.CreateCriteria instead",
                                             persistentClass.FullName, _propertyName));
            }

            Parameter[] parameters = Parameter.GenerateParameters(factory, columnNames, propertyType);

            if (_ignoreCase)
            {
                if (columnNames.Length != 1)
                {
                    throw new HibernateException(
                              "case insensitive expression may only be applied to single-column properties: " +
                              _propertyName);
                }

                return(new SqlStringBuilder(6)
                       .Add(factory.Dialect.LowercaseFunction)
                       .Add(StringHelper.OpenParen)
                       .Add(columnNames[0])
                       .Add(StringHelper.ClosedParen)
                       .Add(Op)
                       .Add(parameters[0])
                       .ToSqlString());
            }
            else
            {
                //TODO: add default capacity
                SqlStringBuilder sqlBuilder = new SqlStringBuilder(4 * columnNames.Length);

                for (int i = 0; i < columnNames.Length; i++)
                {
                    if (i > 0)
                    {
                        sqlBuilder.Add(" and ");
                    }

                    sqlBuilder.Add(columnNames[i])
                    .Add(Op)
                    .Add(parameters[i]);
                }
                return(sqlBuilder.ToSqlString());
            }
        }
Esempio n. 5
0
        public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
        {
            if (_values.Length == 0)
            {
                // "something in ()" is always false
                return(new SqlString("1=0"));
            }

            //TODO: add default capacity
            SqlStringBuilder result = new SqlStringBuilder();

            IType propertyType = AbstractCriterion.GetType(factory, persistentClass, _propertyName, aliasClasses);

            SqlType[] columnSqlTypes = propertyType.SqlTypes(factory);
            string[]  columnNames    = AbstractCriterion.GetColumns(factory, persistentClass, _propertyName, alias, aliasClasses);

            // Generate SqlString of the form:
            // columnName1 in (values) and columnName2 in (values) and ...

            for (int columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
            {
                string  columnName    = columnNames[columnIndex];
                SqlType columnSqlType = columnSqlTypes[columnIndex];

                if (columnIndex > 0)
                {
                    result.Add(" and ");
                }

                result
                .Add(columnName)
                .Add(" in (");

                Parameter[] valueParameters = GenerateValueParameters(columnName, columnSqlType, _values.Length);
                for (int i = 0; i < valueParameters.Length; i++)
                {
                    if (i > 0)
                    {
                        result.Add(StringHelper.CommaSpace);
                    }
                    result.Add(valueParameters[i]);
                }

                result.Add(")");
            }

            return(result.ToSqlString());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="persistentClass"></param>
        /// <param name="alias"></param>
        /// <returns></returns>
        public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
        {
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

            string[] columnNames      = AbstractCriterion.GetColumns(factory, persistentClass, _lhsPropertyName, alias, aliasClasses);
            string[] otherColumnNames = AbstractCriterion.GetColumns(factory, persistentClass, _rhsPropertyName, alias, aliasClasses);

            string result = string.Join(
                " and ",
                StringHelper.Add(columnNames, Op, otherColumnNames)
                );

            if (columnNames.Length > 1)
            {
                result = StringHelper.OpenParen + result + StringHelper.ClosedParen;
            }

            return(new SqlString(result));
            //TODO: get SQL rendering out of this package!
        }
Esempio n. 7
0
        public override SqlString ToSqlString(ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses)
        {
            //TODO: add a default capacity
            SqlStringBuilder sqlBuilder = new SqlStringBuilder();

            IType propertyType = AbstractCriterion.GetType(factory, persistentClass, _propertyName, aliasClasses);

            string[] columnNames = AbstractCriterion.GetColumns(factory, persistentClass, _propertyName, alias, aliasClasses);

            Parameter[] loParameters = Parameter.GenerateParameters(
                factory,
                StringHelper.Suffix(columnNames, "_lo"),
                propertyType);

            Parameter[] hiParameters = Parameter.GenerateParameters(
                factory,
                StringHelper.Suffix(columnNames, "_hi"),
                propertyType);

            bool andNeeded = false;

            for (int i = 0; i < columnNames.Length; i++)
            {
                if (andNeeded)
                {
                    sqlBuilder.Add(" AND ");
                }
                andNeeded = true;

                sqlBuilder.Add(columnNames[i])
                .Add(" between ")
                .Add(loParameters[i])
                .Add(" and ")
                .Add(hiParameters[i]);
            }

            return(sqlBuilder.ToSqlString());
        }