Exemplo n.º 1
0
        internal static EntityPropertyInfo Get(PropertyInfo property)
        {
            EntityPropertyInfo ep = new EntityPropertyInfo();

            object[] arrAttr = property.GetCustomAttributes(typeof(ValidationAttribute), true);
            foreach (Object at in arrAttr)
            {
                ep.ValidationAttributes.Add(at as ValidationAttribute);
            }
            ep.SaveAttribute     = ReflectionUtil.GetAttribute(property, typeof(ColumnAttribute)) as ColumnAttribute;
            ep.LongTextAttribute = ReflectionUtil.GetAttribute(property, typeof(LongTextAttribute)) as LongTextAttribute;
            ep.DateTimeAttribute = ReflectionUtil.GetAttribute(property, typeof(DateTimeAttribute)) as DateTimeAttribute;
            ep.MoneyAttribute    = ReflectionUtil.GetAttribute(property, typeof(MoneyAttribute)) as MoneyAttribute;
            ep.DecimalAttribute  = ReflectionUtil.GetAttribute(property, typeof(DecimalAttribute)) as DecimalAttribute;
            ep.DefaultAttribute  = ReflectionUtil.GetAttribute(property, typeof(DefaultAttribute)) as DefaultAttribute;
            ep.Property          = property;
            ep.Name     = property.Name;
            ep.Type     = property.PropertyType;
            ep.SaveToDB = !property.IsDefined(typeof(NotSaveAttribute), false);
            if (property.PropertyType is IList)
            {
                ep.IsList   = true;
                ep.SaveToDB = false;
            }
            return(ep);
        }
Exemplo n.º 2
0
        public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result )
        {
            Object obj = target.get( info.Name );

            Boolean isNull = false;
            if (info.Type == typeof( String )) {
                if (obj == null) {
                    isNull = true;
                }
                else if (strUtil.IsNullOrEmpty( obj.ToString() )) {
                    isNull = true;
                }
            }
            else if (obj == null) {
                isNull = true;
            }

            if (isNull) {
                if (strUtil.HasText( this.Message )) {
                    result.Add( this.Message );
                }
                else {
                    EntityInfo ei = Entity.GetInfo( target );
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add( str + "can not be null" );
                }
            }
        }
Exemplo n.º 3
0
 internal static void SetParameters(IDbCommand cmd, String action, IEntity obj, EntityInfo entityInfo)
 {
     for (int i = 0; i < entityInfo.SavedPropertyList.Count; i++)
     {
         EntityPropertyInfo info = entityInfo.SavedPropertyList[i];
         if (isContinue(action, info, entityInfo))
         {
             continue;
         }
         Object paramVal = obj.get(info.Name);
         if (paramVal == null && info.DefaultAttribute != null)
         {
             paramVal = info.DefaultAttribute.Value;
         }
         if (paramVal == null)
         {
             setDefaultValue(cmd, info, entityInfo);
         }
         else if (info.Type.IsSubclassOf(typeof(IEntity)) || MappingClass.Instance.ClassList.Contains(info.Type.FullName))
         {
             setEntityId(cmd, info, paramVal);
         }
         else
         {
             paramVal = DataFactory.SetParameter(cmd, info.ColumnName, paramVal);
             obj.set(info.Name, paramVal);
         }
     }
 }
Exemplo n.º 4
0
 private static Boolean checkLength( EntityPropertyInfo info )
 {
     if (info.SaveAttribute == null) return false;
     if (info.SaveAttribute.LengthSetted() == false) return false;
     if (info.Type != typeof( String )) return false;
     return true;
 }
Exemplo n.º 5
0
 //1029
 private static Boolean isSavedProperty(EntityPropertyInfo ep)
 {
     if (ep.SaveToDB)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
 internal void AddPropertyToHashtable(EntityPropertyInfo p)
 {
     _propertyHashTable[p.Name.ToLower()] = p;
     if (strUtil.HasText(p.ColumnName))
     {
         _propertyHashTableByColumn[p.ColumnName.ToLower()] = p;
     }
 }
Exemplo n.º 7
0
 protected override void addColumn_Int( StringBuilder sb, EntityPropertyInfo ep, String columnName )
 {
     sb.Append( columnName );
     if (ep.Property.IsDefined( typeof( TinyIntAttribute ), false )) {
         sb.Append( " tinyint unsigned default 0, " );
     }
     else {
         sb.Append( " int unsigned default 0, " );
     }
 }
Exemplo n.º 8
0
 private static Boolean isContinue(String action, EntityPropertyInfo info, EntityInfo entityInfo)
 {
     if (info.SaveToDB == false) return true;
     if (info.IsList) return true;
     if (info.Name.Equals("Id"))
     {
         if (action.Equals("update")) return true;
         if (action.Equals("insert") && entityInfo.Parent == null) return true;
     }
     return false;
 }
Exemplo n.º 9
0
 protected virtual void addColumn_ByColumnAttribute( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName )
 {
     if (ep.SaveAttribute.Length < 255) {
         addColumn_ShortText( sb, columnName, ep.SaveAttribute.Length );
     }
     else if ((ep.SaveAttribute.Length > 255) && (ep.SaveAttribute.Length < 4000)) {
         addColumn_MiddleText( entity, sb, ep, columnName );
     }
     else {
         addColumn_LongText( entity, sb, columnName );
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 根据属性的类型,比如BlogCategory,获取符合要求的第一个属性的名称
 /// </summary>
 /// <param name="propertyType"></param>
 /// <returns></returns>
 public String GetPropertyName(Type propertyType)
 {
     for (int i = 0; i < _savedPropertyList.Count; i++)
     {
         EntityPropertyInfo ep = _savedPropertyList[i] as EntityPropertyInfo;
         if (ep.Type.FullName == propertyType.FullName)
         {
             return(ep.Name);
         }
     }
     return(null);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 获取某个属性在数据库中对应的数据列名称
 /// </summary>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 public String GetColumnName(String propertyName)
 {
     for (int i = 0; i < _savedPropertyList.Count; i++)
     {
         EntityPropertyInfo ep = _savedPropertyList[i] as EntityPropertyInfo;
         if (ep.Name == propertyName)
         {
             return(ep.ColumnName);
         }
     }
     return(null);
 }
Exemplo n.º 12
0
 private static void setEntityPropertyValueById( IEntity obj, ObjectInfo state, EntityPropertyInfo property, int pid )
 {
     if (!property.IsAbstractEntity) {
         IEntity objValue = Entity.New( property.Type.FullName );
         objValue.Id = pid;
         // state
         //objValue.state = new ObjectInfo( property.Type ).Copy( state );
         IEntity objCache = ObjectPool.FindOne( property.Type, objValue.Id );
         if (objCache != null) {
             objValue = objCache;
         }
         obj.set( property.Name, objValue );
     }
 }
Exemplo n.º 13
0
        protected override void addColumn_Decimal( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName ) {
            if (ep.MoneyAttribute != null) {
                sb.Append( columnName );
                sb.Append( " currency default 0, " );
            }
            else {

                DecimalAttribute da = ep.DecimalAttribute;
                if (da == null) throw new Exception( "DecimalAttribute not found=" + entity.FullName + "_" + ep.Name );

                sb.Append( columnName );
                sb.Append( " decimal(" + da.Precision + "," + da.Scale + ") default 0, " );
            }
        }
Exemplo n.º 14
0
 internal EntityPropertyInfo FindRelationProperty(Type t)
 {
     if (_relationProperty == null)
     {
         for (int i = 0; i < EntityPropertyList.Count; i++)
         {
             EntityPropertyInfo info = EntityPropertyList[i];
             if (info.Type != t)
             {
                 _relationProperty = info;
             }
         }
     }
     return(_relationProperty);
 }
Exemplo n.º 15
0
        public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result )
        {
            if (!Regex.IsMatch( cvt.ToNotNull( target.get( info.Name ) ), this.Regexp, RegexOptions.Singleline )) {
                if (strUtil.HasText( this.Message )) {
                    result.Add( this.Message );
                }

                else {
                    EntityInfo ei = Entity.GetInfo( target );
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add( str + " is not match the format pattern : " + this.Regexp );
                }

            }
        }
Exemplo n.º 16
0
        // 是否在sql中选择当前属性的column
        private Boolean isAddColumn(String selectedProperty, EntityPropertyInfo ep)
        {
            //选择字符串和属性完全同名
            if (selectedProperty.Equals(ep.Name))
            {
                return(true);
            }

            //属性Member,selectProperty为Member.Name,只要前缀相同,即可选取属性的columnName
            if (ep.IsEntity && selectedProperty.StartsWith(ep.Name + "."))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 17
0
 private static Boolean checkLength(EntityPropertyInfo info)
 {
     if (info.SaveAttribute == null)
     {
         return(false);
     }
     if (info.SaveAttribute.LengthSetted() == false)
     {
         return(false);
     }
     if (info.Type != typeof(String))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 18
0
        public virtual void Validate(String action, Object target, String propertyName, Result result)
        {
            if (target == null)
            {
                return;
            }
            IEntity entity = target as IEntity;

            if (entity == null)
            {
                throw new NotImplementedException("NotNullAttribute can only implement to IEntity. Currenty object's type:" + target.GetType().FullName);
            }
            EntityPropertyInfo ep = Entity.GetInfo(entity).GetProperty(propertyName);

            Validate(action, entity, ep, result);
        }
Exemplo n.º 19
0
        public override void Validate( String action, IEntity target, EntityPropertyInfo info, Result result ) {
            Object obj = target.get( info.Name );

            EntityInfo ei = Entity.GetInfo( target );
            int count = getCount( action, target, ei, info, obj );

            if (count > 0) {
                if (strUtil.HasText( this.Message )) {
                    result.Add( this.Message );
                }

                else {
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add( str + " should be unique, but it has been in database" );
                }
            }
        }
Exemplo n.º 20
0
        public override void Validate(String action, IEntity target, EntityPropertyInfo info, Result result)
        {
            if (!Regex.IsMatch(cvt.ToNotNull(target.get(info.Name)), this.Regexp, RegexOptions.Singleline))
            {
                if (strUtil.HasText(this.Message))
                {
                    result.Add(this.Message);
                }

                else
                {
                    EntityInfo ei  = Entity.GetInfo(target);
                    String     str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add(str + " is not match the format pattern : " + this.Regexp);
                }
            }
        }
Exemplo n.º 21
0
        private static int getCount( String action, IEntity target, EntityInfo entityInfo, EntityPropertyInfo info, Object obj )
        {
            if (obj == null) return 1;

            String usql;
            IDatabaseDialect dialect = entityInfo.Dialect;
            if (action.Equals( "update" )) {
                usql = String.Format( "select count(Id) from {0} where Id<>{3} and {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter( info.Name ), target.Id );
            }
            else {
                usql = String.Format( "select count(Id) from {0} where {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter( info.Name ) );
            }

            logger.Info( LoggerUtil.SqlPrefix + " validate unique sql : " + usql );
            IDbCommand cmd = DataFactory.GetCommand( usql, DbContext.getConnection( entityInfo ) );
            DataFactory.SetParameter( cmd, info.ColumnName, obj );
            return cvt.ToInt( cmd.ExecuteScalar() );
        }
Exemplo n.º 22
0
        internal String GetRelationPropertyName(Type propertyType)
        {
            String name = null;

            for (int i = 0; i < _savedPropertyList.Count; i++)
            {
                EntityPropertyInfo ep = _savedPropertyList[i] as EntityPropertyInfo;
                if (ep.Type.FullName == propertyType.FullName)
                {
                    return(ep.Name);
                }
                if (propertyType.IsSubclassOf(ep.Type))
                {
                    name = ep.Name;
                }
            }
            return(name);
        }
Exemplo n.º 23
0
        public static Object Populate(IDataRecord rd, ObjectInfo state)
        {
            IEntity obj = Entity.New(state.EntityInfo.Type.FullName);

            // state
            //obj.state.Order = state.Order;

            for (int i = 0; i < rd.FieldCount; i++)
            {
                Object fdvalue = rd[i];

                if (fdvalue == null || fdvalue == DBNull.Value)
                {
                    continue;
                }

                EntityPropertyInfo ep = state.EntityInfo.GetPropertyByColumn(rd.GetName(i));
                if (ep == null)
                {
                    continue;
                }

                try {
                    if (ep.IsEntity || ep.IsAbstractEntity)
                    {
                        setEntityPropertyValueById(obj, state, ep, rd.GetInt32(i));
                    }
                    else
                    {
                        ep.SetValue(obj, getReaderValue(fdvalue, ep.Type));
                    }
                }
                catch (Exception ex) {
                    logger.Error(ex.Message + "=" + ep.Name + "_" + ep.Type);
                    logger.Error(ex.StackTrace);
                    throw ex;
                }
            }

            return(obj);
        }
Exemplo n.º 24
0
        public override void Validate(String action, IEntity target, EntityPropertyInfo info, Result result)
        {
            Object obj = target.get(info.Name);

            EntityInfo ei    = Entity.GetInfo(target);
            int        count = getCount(action, target, ei, info, obj);

            if (count > 0)
            {
                if (strUtil.HasText(this.Message))
                {
                    result.Add(this.Message);
                }

                else
                {
                    String str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add(str + " should be unique, but it has been in database");
                }
            }
        }
Exemplo n.º 25
0
 private static void setDefaultValue(IDbCommand cmd, EntityPropertyInfo info, EntityInfo entityInfo)
 {
     if (MappingClass.Instance.ClassList.Contains(info.Type.FullName))
     {
         DataFactory.SetParameter(cmd, info.ColumnName, -1);
     }
     else if (info.Type == typeof(DateTime))
     {
         if (entityInfo.DbType == DatabaseType.Access)
         {
             DataFactory.SetParameter(cmd, info.ColumnName, DateTime.Now.ToString());
         }
         else
         {
             DataFactory.SetParameter(cmd, info.ColumnName, DateTime.Now);
         }
     }
     else
     {
         DataFactory.SetParameter(cmd, info.ColumnName, "");
     }
 }
Exemplo n.º 26
0
 private static void setDefaultValue(IDbCommand cmd, EntityPropertyInfo info, EntityInfo entityInfo)
 {
     if (MappingClass.Instance.ClassList.Contains(info.Type.FullName))
     {
         DataFactory.SetParameter(cmd, info.ColumnName, -1);
     }
     else if (info.Type == typeof(DateTime))
     {
         if (entityInfo.DbType == DatabaseType.Access)
         {
             DataFactory.SetParameter(cmd, info.ColumnName, DateTime.Now.ToString());
         }
         else
         {
             DataFactory.SetParameter(cmd, info.ColumnName, DateTime.Now);
         }
     }
     else
     {
         DataFactory.SetParameter(cmd, info.ColumnName, "");
     }
 }
Exemplo n.º 27
0
 public static void CheckCountCache(String action, IEntity obj, EntityInfo entityInfo)
 {
     for (int i = 0; i < entityInfo.SavedPropertyList.Count; i++)
     {
         IEntity            container    = null;
         String             propertyName = null;
         EntityPropertyInfo info         = entityInfo.SavedPropertyList[i];
         if ((info.Name != "Id") && !(info.Name == "OID"))
         {
             ICacheAttribute attribute = ReflectionUtil.GetAttribute(info.Property, typeof(CacheCountAttribute)) as ICacheAttribute;
             if (attribute != null)
             {
                 container    = ReflectionUtil.GetPropertyValue(obj, info.Name) as IEntity;
                 propertyName = attribute.TargetPropertyName.Replace(" ", "");
             }
             if (container != null)
             {
                 String columnName = Entity.GetInfo(container).GetColumnName(propertyName);
                 setCountCacheBySql(container, columnName, action);
             }
         }
     }
 }
Exemplo n.º 28
0
 private static Boolean isContinue(String action, EntityPropertyInfo info, EntityInfo entityInfo)
 {
     if (info.SaveToDB == false)
     {
         return(true);
     }
     if (info.IsList)
     {
         return(true);
     }
     if (info.Name.Equals("Id"))
     {
         if (action.Equals("update"))
         {
             return(true);
         }
         if (action.Equals("insert") && entityInfo.Parent == null)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 29
0
        /// <summary>
        /// 根据类型Type,初始化EntityInfo;注意:因为不是从缓存中取,所以速度较慢
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        internal static EntityInfo GetByType(Type t)
        {
            EntityInfo info = new EntityInfo();

            info.Type     = t;
            info.Name     = t.Name;
            info.FullName = t.FullName;

            info.TableName = AddPrefixToTableName(GetTableName(t));
            info.Database  = GetDatabase(t);

            CheckCustomMapping(info);

            info.Label = GetTypeLabel(t);

            IList propertyList = ReflectionUtil.GetPropertyList(t);

            for (int i = 0; i < propertyList.Count; i++)
            {
                PropertyInfo       property = propertyList[i] as PropertyInfo;
                EntityPropertyInfo ep       = EntityPropertyInfo.Get(property);
                ep.ParentEntityInfo = info;

                if (!(!ep.SaveToDB || ep.IsList))
                {
                    info.SavedPropertyList.Add(ep);
                }
                info.PropertyListAll.Add(ep);
            }

            if (info.SavedPropertyList.Count == 1)
            {
                throw new Exception("class's properties have not been setted '[save]' attribute.");
            }

            return(info);
        }
Exemplo n.º 30
0
        public override void Validate(String action, IEntity target, EntityPropertyInfo info, Result result)
        {
            Object obj = target.get(info.Name);

            Boolean isNull = false;

            if (info.Type == typeof(String))
            {
                if (obj == null)
                {
                    isNull = true;
                }
                else if (strUtil.IsNullOrEmpty(obj.ToString()))
                {
                    isNull = true;
                }
            }
            else if (obj == null)
            {
                isNull = true;
            }

            if (isNull)
            {
                if (strUtil.HasText(this.Message))
                {
                    result.Add(this.Message);
                }
                else
                {
                    EntityInfo ei  = Entity.GetInfo(target);
                    String     str = "[" + ei.FullName + "] : property \"" + info.Name + "\" ";
                    result.Add(str + "can not be null");
                }
            }
        }
Exemplo n.º 31
0
        protected virtual void addColumn_MiddleText( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName ) {

            addColumn_ShortText( sb, columnName, ep.SaveAttribute.Length );
        }
Exemplo n.º 32
0
 private void addColumnSingle( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName ) {
     if (ep.Type == typeof(int) || ep.Type == typeof(long))
     {
         addColumn_Int(sb, entity, ep, columnName);
     }
     else if (ep.Type == typeof(bool))
     {
         addColumn_Boolean(sb, ep, columnName);
     }
     else if (ep.Type == typeof(DateTime))
     {
         addColumn_Time(sb, columnName);
     }
     else if (ep.Type == typeof(decimal))
     {
         addColumn_Decimal(entity, sb, ep, columnName);
     }
     else if (ep.Type == typeof(double))
     {
         addColumn_Double(entity, sb, columnName);
     }
     else if (ep.Type == typeof(float))
     {
         addColumn_Single(entity, sb, columnName);
     }
     else if (ep.Type == typeof(String))
     {
         addColumn_String(entity, sb, ep, columnName);
     }
     else if (ep.IsEntity)
     {
         addColumn_entity(sb, columnName);
     }
 }
Exemplo n.º 33
0
 protected virtual void addColumn_Boolean(StringBuilder sb, EntityPropertyInfo ep, String columnName)
 {
     sb.Append(columnName);
     sb.Append(" tinyint default 0, ");
 }
Exemplo n.º 34
0
 protected virtual void addColumn_String( EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName ) {
     if (ep.LongTextAttribute != null) {
         addColumn_LongText( entity, sb, columnName );
     }
     else if (ep.SaveAttribute != null) {
         addColumn_ByColumnAttribute( entity, sb, ep, columnName );
     }
     else {
         addColumn_ShortText( sb, columnName, 250 );
     }
 }
Exemplo n.º 35
0
 internal EntityPropertyInfo FindRelationProperty( Type t ) {
     if (_relationProperty == null) {
         for (int i = 0; i < EntityPropertyList.Count; i++) {
             EntityPropertyInfo info = EntityPropertyList[i];
             if (info.Type != t) {
                 _relationProperty = info;
             }
         }
     }
     return _relationProperty;
 }
Exemplo n.º 36
0
 protected virtual void addColumn_Int(StringBuilder sb, EntityInfo entity, EntityPropertyInfo ep, String columnName)
 {
     sb.Append( columnName );
     if (ep.Property.IsDefined( typeof( TinyIntAttribute ), false )) {
         sb.Append(" tinyint default 0, ");
     }
     else if (ep.Property.IsDefined(typeof(LongAttribute), false))
     {
         if (entity.DbType == DatabaseType.Access)
         {
             sb.Append(" double default 0, ");
         }
         else
         {
             sb.Append(" bigint default 0, ");
         }
     }
     else
     {
         sb.Append(" int default 0, ");
     }
 }
Exemplo n.º 37
0
 private static bool shouldPass(EntityPropertyInfo info)
 {
     if (info.Type == typeof(int)) return false;
     if (info.Type == typeof(string)) return false;
     if (info.Type == typeof(decimal)) return false;
     if (info.Type == typeof(DateTime)) return false;
     if (info.Type == typeof(bool)) return false;
     if (info.Type == typeof(double)) return false;
     if (info.IsEntity) return false;
     return true;
 }
Exemplo n.º 38
0
 internal void AddPropertyToHashtable( EntityPropertyInfo p ) {
     _propertyHashTable[p.Name.ToLower()] = p;
     if (strUtil.HasText(p.ColumnName))
     {
         _propertyHashTableByColumn[p.ColumnName.ToLower()] = p;
     }
 }
Exemplo n.º 39
0
 /// <summary>
 /// 可以扩展的验证方法
 /// </summary>
 /// <param name="action">当前操作:update或insert</param>
 /// <param name="target">需要验证的实体对象</param>
 /// <param name="info">当前属性信息</param>
 /// <param name="result">验证结果</param>
 public abstract void Validate(String action, IEntity target, EntityPropertyInfo info, Result result);
Exemplo n.º 40
0
        private static int getCount(String action, IEntity target, EntityInfo entityInfo, EntityPropertyInfo info, Object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            String           usql;
            IDatabaseDialect dialect = entityInfo.Dialect;

            if (action.Equals("update"))
            {
                usql = String.Format("select count(Id) from {0} where Id<>{3} and {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter(info.Name), target.Id);
            }
            else
            {
                usql = String.Format("select count(Id) from {0} where {1}={2}", entityInfo.TableName, info.ColumnName, dialect.GetParameter(info.Name));
            }

            logger.Info(LoggerUtil.SqlPrefix + " validate unique sql : " + usql);
            IDbCommand cmd = DataFactory.GetCommand(usql, DbContext.getConnection(entityInfo));

            DataFactory.SetParameter(cmd, info.ColumnName, obj);
            return(cvt.ToInt(cmd.ExecuteScalar()));
        }
Exemplo n.º 41
0
        // 示例:Member.Id=6 and Cat.Id>7
        // art.Find("Author=:author and Title=:title and Id>:id order by Id desc")
        public String processCondition(String conditionString, Dictionary <String, Object> paramMap, ref String joinTable)
        {
            //logger.Info( "conditionString=>" + conditionString );


            // 根据不同方言,替换参数,比如“Author=:author and Title=:title”需要替换成“Author=? and Title=?”
            foreach (String key in paramMap.Keys)
            {
                conditionString = conditionString.Replace(":" + key, _entityInfo.Dialect.GetParameter(key));
            }

            //如果是实体属性在设置条件,还要负责把 Member.Id=:mid 转换成 TMemberId=?:不联表查询
            // 1、当前实体具有的column : _entityInfo.ColumnList
            // 2、找到参数查询所对应的column
            if (isConditionHasEntity(conditionString))
            {
                //是否联表查询
                Boolean isJoinedQuery          = false;
                String  _join_condition        = "";
                int     _joined_Property_Count = 0;

                //  and (Member.Id=? and Cat.Name=?) order by Id desc
                List <String[]> items = SqlUtil.getEntityProperties(conditionString);
                foreach (String[] pair in items)
                {
                    String strItem = pair[0] + "." + pair[1];

                    if (!pair[1].ToLower().Equals("id"))
                    {
                        isJoinedQuery = true;
                    }

                    if (!isJoinedQuery)
                    {
                        conditionString = conditionString.Replace(strItem, _entityInfo.GetColumnName(pair[0]));
                    }
                    else
                    {
                        _joined_Property_Count += 1;

                        EntityPropertyInfo _e_p = _entityInfo.GetProperty(pair[0]);

                        EntityPropertyInfo _sub_p           = _e_p.EntityInfo.GetProperty(pair[1]);
                        String             subColumn        = (_sub_p == null ? pair[1] : _sub_p.ColumnName);
                        String             _sub_column_name = "t" + _joined_Property_Count + "." + subColumn;

                        // joinTable
                        joinTable += _e_p.EntityInfo.TableName + " t" + _joined_Property_Count + ",";

                        // replace entity property
                        conditionString  = conditionString.Replace(strItem, _sub_column_name);
                        _join_condition += "and t0." + _e_p.ColumnName + "=t" + _joined_Property_Count + ".Id ";
                    }
                }

                // add prefix "0" to all current entity property's column, especially in "order by id desc" etc.(=>order by t0.id desc)
                if (isJoinedQuery)
                {
                    conditionString = addJoinTablePrefix(conditionString, ' ');
                }

                //conditionString = _join_condition + conditionString;
                conditionString = conditionString.Trim();
                _join_condition = _join_condition.Trim();
                if (conditionString.StartsWith("and ") == false && _join_condition.EndsWith(" and") == false)
                {
                    conditionString = _join_condition + " and " + conditionString;
                }
                else
                {
                    conditionString = _join_condition + " " + conditionString;
                }
            }

            return(conditionString);
        }
Exemplo n.º 42
0
 /// <summary>
 /// 可以扩展的验证方法
 /// </summary>
 /// <param name="action">当前操作:update或insert</param>
 /// <param name="target">需要验证的实体对象</param>
 /// <param name="info">当前属性信息</param>
 /// <param name="result">验证结果</param>
 public abstract void Validate(String action, IEntity target, EntityPropertyInfo info, Result result);
Exemplo n.º 43
0
 internal static EntityPropertyInfo Get( PropertyInfo property ) {
     EntityPropertyInfo ep = new EntityPropertyInfo();
     object[] arrAttr = property.GetCustomAttributes( typeof( ValidationAttribute ), true );
     foreach (Object at in arrAttr) {
         ep.ValidationAttributes.Add( at as ValidationAttribute );
     }
     ep.SaveAttribute = ReflectionUtil.GetAttribute( property, typeof( ColumnAttribute ) ) as ColumnAttribute;
     ep.LongTextAttribute = ReflectionUtil.GetAttribute( property, typeof( LongTextAttribute ) ) as LongTextAttribute;
     ep.DateTimeAttribute = ReflectionUtil.GetAttribute(property, typeof(DateTimeAttribute)) as DateTimeAttribute;
     ep.MoneyAttribute = ReflectionUtil.GetAttribute( property, typeof( MoneyAttribute ) ) as MoneyAttribute;
     ep.DecimalAttribute = ReflectionUtil.GetAttribute( property, typeof( DecimalAttribute ) ) as DecimalAttribute;
     ep.DefaultAttribute = ReflectionUtil.GetAttribute( property, typeof( DefaultAttribute ) ) as DefaultAttribute;
     ep.Property = property;
     ep.Name = property.Name;
     ep.Type = property.PropertyType;
     ep.SaveToDB = !property.IsDefined( typeof( NotSaveAttribute ), false );
     if (property.PropertyType is IList) {
         ep.IsList = true;
         ep.SaveToDB = false;
     }
     return ep;
 }
Exemplo n.º 44
0
 private static void setEntityId(IDbCommand cmd, EntityPropertyInfo info, Object paramVal)
 {
     int id = ((IEntity)paramVal).Id;
     DataFactory.SetParameter(cmd, info.ColumnName, id);
 }
Exemplo n.º 45
0
        private static void setEntityId(IDbCommand cmd, EntityPropertyInfo info, Object paramVal)
        {
            int id = ((IEntity)paramVal).Id;

            DataFactory.SetParameter(cmd, info.ColumnName, id);
        }
Exemplo n.º 46
0
 private static void setEntityPropertyValueById(IEntity obj, ObjectInfo state, EntityPropertyInfo property, int pid)
 {
     if (!property.IsAbstractEntity)
     {
         IEntity objValue = Entity.New(property.Type.FullName);
         objValue.Id = pid;
         // state
         //objValue.state = new ObjectInfo( property.Type ).Copy( state );
         IEntity objCache = ObjectPool.FindOne(property.Type, objValue.Id);
         if (objCache != null)
         {
             objValue = objCache;
         }
         obj.set(property.Name, objValue);
     }
 }
Exemplo n.º 47
0
 //1029
 private static Boolean isSavedProperty(EntityPropertyInfo ep)
 {
     if (ep.SaveToDB) return true;
     return false;
 }
Exemplo n.º 48
0
 protected override void addColumn_MiddleText( EntityInfo entity, StringBuilder sb, EntityPropertyInfo temP, string columnName ) {
     addColumn_LongText( entity, sb, columnName );
 }
Exemplo n.º 49
0
        // 是否在sql中选择当前属性的column
        private Boolean isAddColumn( String selectedProperty, EntityPropertyInfo ep ) {

            //选择字符串和属性完全同名
            if (selectedProperty.Equals( ep.Name )) return true;

            //属性Member,selectProperty为Member.Name,只要前缀相同,即可选取属性的columnName
            if (ep.IsEntity && selectedProperty.StartsWith( ep.Name + "." )) return true;

            return false;
        }