Exemplo n.º 1
0
        /// <summary>
        /// 转换为HQL字符串
        /// </summary>
        /// <returns></returns>
        public string ToHql()
        {
            var paramName = string.Format("{0}{1}", PropertyName.Trim().Replace('.', '_'), random.Next(1000));

            switch (Operator)
            {
            case Operator.Equals:
                return(string.Format("{0} = :{1}", PropertyName, paramName));

            case Operator.Like:
                return(string.Format("{0} LIKE '%'||:{1}||'%'", PropertyName, paramName));

            case Operator.LessThan:
                return(string.Format("{0} < :{1}", PropertyName, paramName));

            case Operator.LessThanOrEquals:
                return(string.Format("{0} <= :{1}", PropertyName, paramName));

            case Operator.GreaterThan:
                return(string.Format("{0} > :{1}", PropertyName, paramName));

            case Operator.GreaterThanOrEquals:
                return(string.Format("{0} >= :{1}", PropertyName, paramName));

            default:
                throw new ArgumentOutOfRangeException(string.Format("不支持的操作符 {0}", Operator));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 转换为HQL字符串
        /// </summary>
        /// <returns></returns>
        public string ToHql()
        {
            var paramName = string.Format("{0}{1}", PropertyName.Trim().Replace('.', '_'), random.Next());

            switch (Operator)
            {
            case Operator.In:
                return(string.Format("{0} IN (:{1})", PropertyName, paramName));

            default:
                throw new ArgumentOutOfRangeException(string.Format("不支持的操作符 {0}", Operator));
            }
        }
Exemplo n.º 3
0
        private bool DoesVirtualPropertyHaveSetter()
        {
            if (this.ClassDef == null)
            {
                return(false);
            }
            string       virtualPropName = PropertyName.Trim('-');
            PropertyInfo propertyInfo    =
                ReflectionUtilities.GetPropertyInfo(this.ClassDef.ClassType, virtualPropName);
            bool virtualPropertySetExists = propertyInfo != null && propertyInfo.CanWrite;

            return(virtualPropertySetExists);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 转换为HQL字符串
        /// </summary>
        /// <returns></returns>
        public string ToHql()
        {
            var paramName1 = string.Format("{0}{1}", PropertyName.Trim().Replace('.', '_'), random.Next());
            var paramName2 = string.Format("{0}{1}", PropertyName.Trim().Replace('.', '_'), random.Next());

            switch (Operator)
            {
            case Operator.BetweenAnd:
                return(string.Format("{0} BETWEEN :{1} AND :{2}", PropertyName, paramName1, paramName2));

            default:
                throw new ArgumentOutOfRangeException(string.Format("不支持的操作符", Operator));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets value to cached property
        /// </summary>
        /// <param name="aObject">
        /// Object where property resides <see cref="System.Object"/>
        /// </param>
        /// <param name="aProperty">
        /// Property name <see cref="System.String"/>
        /// </param>
        /// <param name="aValue">
        /// New value <see cref="System.Object"/>
        /// </param>
        /// <returns>
        /// true if successful, false if not <see cref="System.Boolean"/>
        /// </returns>
        public bool SetValue(object aObject, string aProperty, object aValue)
        {
            bool startMethod = false;

            if (IsCached == true)
            {
                if (aProperty == PropertyName)
                {
                    startMethod = true;
                }
            }
            else
            {
                if (IsCompatible(aObject) == true)
                {
                    if (PropertyName.Trim() == aProperty.Trim())
                    {
                        startMethod = IsCached;
                    }
                }
            }
            // Start copying data
            if (startMethod == true)
            {
                if (IsProperty == true)
                {
                    return(ConnectionProvider.SetPropertyValue(aObject, propInfo, aValue));
                }
                if (IsVirtualProperty == true)
                {
                    propVirtual.Value = aValue;
                    return(true);
                }
                if (IsDataRowField == true)
                {
                    return(DatabaseProvider.SetValue(aObject, propColumn, aValue));
                }
                throw new ExceptionCachedPropertySetValueFailed(this);
            }
            else
            {
                // If method arrived here then this is not a valid cache for that property
                // fallback creates temporary cache and sets new value trough it
                return(CachedProperty.UncachedSetValue(aObject, aProperty, aValue));
            }
            return(false);
        }