示例#1
0
        /// <summary>
        /// 填充字类列表
        /// </summary>
        /// <param name="pks">ID集合</param>
        /// <param name="fatherInfo">父表对应类的信息</param>
        /// <param name="dicElement">元素</param>
        /// <param name="mappingInfo">当前父表对应属性的映射信息</param>
        private static void FillParent(object pk, EntityInfoHandle fatherInfo,
                                       EntityMappingInfo mappingInfo, string propertyName, EntityBase sender)
        {
            DBInfo          db       = fatherInfo.DBInfo;
            DataBaseOperate oper     = fatherInfo.DBInfo.DefaultOperate;
            BQLDbBase       dao      = new BQLDbBase(oper);
            ScopeList       lstScope = new ScopeList();

            sender.OnFillParent(propertyName, lstScope);
            lstScope.AddEqual(mappingInfo.TargetProperty.PropertyName, pk);
            IDataReader reader = dao.QueryReader(lstScope, fatherInfo.EntityType);

            try
            {
                //获取子表的get列表
                List <EntityPropertyInfo> lstParamNames = CacheReader.GenerateCache(reader, fatherInfo);//创建一个缓存数值列表
                while (reader.Read())
                {
                    object newObj = fatherInfo.CreateSelectProxyInstance();
                    mappingInfo.SetValue(sender, newObj);
                    CacheReader.FillObjectFromReader(reader, lstParamNames, newObj, db);
                }
                sender.OnPropertyUpdated(mappingInfo.PropertyName);
            }
            finally
            {
                reader.Close();
                oper.AutoClose();
            }
        }
示例#2
0
        /// <summary>
        /// 检查表信息
        /// </summary>
        /// <param name="info">数据库</param>
        /// <param name="lstTableInfos">需要检查的表</param>
        /// <returns></returns>
        public static List <string> CheckTable(DBInfo info, List <KeyWordTableParamItem> lstTableInfos)
        {
            List <KeyWordTableParamItem> tableInfos = FilterDistinct(lstTableInfos);


            List <DBTableInfo>           tables       = GetAllTables(info);
            BQLDbBase                    db           = new BQLDbBase(info.CreateOperate());
            List <KeyWordTableParamItem> lstNotExists = new List <KeyWordTableParamItem>();
            List <KeyWordTableParamItem> lstExists    = new List <KeyWordTableParamItem>();

            FilteExistsTable(tableInfos, tables, lstExists, lstNotExists);

            List <string> lstRet = new List <string>();


            CreateTableSQL(lstRet, info, lstNotExists);

            foreach (KeyWordTableParamItem existsTable in lstExists)
            {
                CheckTableStruct(lstRet, info, existsTable);
            }
            foreach (KeyWordTableParamItem table in tableInfos)
            {
                CheckRelation(lstRet, info, table);
            }

            IDBAdapter idb = info.CurrentDbAdapter;

            foreach (KeyWordTableParamItem table in tableInfos)
            {
                foreach (EntityParam prm in table.PrimaryParam)
                {
                    //创建逐渐序列(暂时只有Oracle)
                    if (prm.Identity && IsIdentityType(prm.SqlType))
                    {
                        string seqName = idb.GetDefaultSequenceName(table.TableName, prm.ParamName);
                        if (!string.IsNullOrEmpty(seqName))
                        {
                            string seqSql = idb.GetSequenceInit(seqName, prm, info.DefaultOperate);

                            if (!string.IsNullOrEmpty(seqSql))
                            {
                                lstRet.Add(seqSql);
                            }
                        }
                    }
                }
            }
            return(lstRet);
        }
示例#3
0
        /// <summary>
        /// 填充字类列表
        /// </summary>
        /// <param name="pks">ID集合</param>
        /// <param name="childHandle">子元素的信息句柄</param>
        /// <param name="mappingInfo">映射信息</param>
        /// <param name="dicElement">元素</param>
        /// <param name="propertyName">属性名</param>
        /// <param name="curObjs"></param>
        /// <param name="filter"></param>
        private static void FillChilds(Queue <object> pks, EntityInfoHandle childHandle, EntityMappingInfo mappingInfo,
                                       Dictionary <string, List <object> > dicEntity, string propertyName, Queue <object> curObjs, ScopeList filter)
        {
            DBInfo                    db            = childHandle.DBInfo;
            DataBaseOperate           oper          = childHandle.DBInfo.DefaultOperate;
            BQLDbBase                 dao           = new BQLDbBase(oper);
            Queue <object>            needCollect   = null;
            List <EntityPropertyInfo> lstParamNames = null;

            try
            {
                while (pks.Count > 0)
                {
                    needCollect = GetCurPks(pks);
                    FillChildReader(needCollect, mappingInfo, dicEntity, dao, ref lstParamNames, db, curObjs, filter);
                }
            }
            finally
            {
                oper.AutoClose();
            }
        }
示例#4
0
        /// <summary>
        /// 填充字类列表
        /// </summary>
        /// <param name="pks">ID集合</param>
        /// <param name="childHandle">子元素的信息句柄</param>
        /// <param name="mappingInfo">映射信息</param>
        /// <param name="dicElement">元素</param>
        private static void FillChilds(object pk, EntityInfoHandle childHandle, EntityMappingInfo mappingInfo,
                                       EntityBase sender, string propertyName)
        {
            EntityInfoHandle childInfo = mappingInfo.TargetProperty.BelongInfo;
            DBInfo           db        = childInfo.DBInfo;
            DataBaseOperate  oper      = childHandle.DBInfo.DefaultOperate;
            BQLDbBase        dao       = new BQLDbBase(oper);
            ScopeList        lstScope  = new ScopeList();

            sender.OnFillChild(propertyName, lstScope);
            lstScope.AddEqual(mappingInfo.TargetProperty.PropertyName, pk);


            IDataReader reader = dao.QueryReader(lstScope, childInfo.EntityType);

            try
            {
                string fullName  = mappingInfo.TargetProperty.BelongInfo.EntityType.FullName;
                Type   childType = mappingInfo.TargetProperty.BelongInfo.EntityType;

                //获取子表的get列表
                List <EntityPropertyInfo> lstParamNames = CacheReader.GenerateCache(reader, childInfo);//创建一个缓存数值列表
                IList lst = (IList)mappingInfo.GetValue(sender);
                while (reader.Read())
                {
                    object obj = childInfo.CreateSelectProxyInstance();
                    //string fk = reader[mappingInfo.TargetProperty.ParamName].ToString();
                    CacheReader.FillObjectFromReader(reader, lstParamNames, obj, db);
                    lst.Add(obj);
                }
            }
            finally
            {
                reader.Close();
                oper.AutoClose();
            }
        }
示例#5
0
        /// <summary>
        /// 查询并填充子类信息
        /// </summary>
        /// <param name="pks"></param>
        /// <param name="mappingInfo"></param>
        /// <param name="dicEntity"></param>
        /// <param name="dao"></param>
        /// <param name="lstParamNames"></param>
        /// <param name="db"></param>
        /// <param name="curObjs"></param>
        /// <param name="filter"></param>
        private static void FillChildReader(Queue <object> pks, EntityMappingInfo mappingInfo, Dictionary <string, List <object> > dicEntity, BQLDbBase dao,
                                            ref List <EntityPropertyInfo> lstParamNames, DBInfo db, Queue <object> curObjs, ScopeList filter)
        {
            EntityInfoHandle childInfo = mappingInfo.TargetProperty.BelongInfo;
            string           fullName  = mappingInfo.TargetProperty.BelongInfo.EntityType.FullName;
            Type             childType = mappingInfo.TargetProperty.BelongInfo.EntityType;
            List <object>    senders   = null;

            while (pks.Count > 0)
            {
                Queue <object> searchPks = GetSearchPKs(pks);
                if (searchPks.Count <= 0)
                {
                    break;
                }

                ScopeList lstScope = new ScopeList();
                lstScope.AddScopeList(filter);
                lstScope.AddIn(mappingInfo.TargetProperty.PropertyName, searchPks);
                using (IDataReader reader = dao.QueryReader(lstScope, childInfo.EntityType))
                {
                    //获取子表的get列表
                    if (lstParamNames == null)
                    {
                        lstParamNames = CacheReader.GenerateCache(reader, childInfo);//创建一个缓存数值列表
                    }


                    while (reader.Read())
                    {
                        string fk = reader[mappingInfo.TargetProperty.ParamName].ToString();
                        if (!dicEntity.TryGetValue(fk, out senders))
                        {
                            continue;
                        }
                        object obj = childInfo.CreateSelectProxyInstance();

                        if (curObjs != null)
                        {
                            curObjs.Enqueue(obj);
                        }
                        CacheReader.FillObjectFromReader(reader, lstParamNames, obj, db);

                        foreach (object sender in senders)
                        {
                            if (mappingInfo.IsParent)
                            {
                                mappingInfo.SetValue(sender, obj);
                            }
                            else
                            {
                                IList lst = (IList)mappingInfo.GetValue(sender);
                                lst.Add(obj);
                            }
                        }
                    }
                }
            }
        }