Exemple #1
0
        /// <summary>
        /// 使用一段sql,进行分页查询, 目前只支持sqlserver
        /// </summary>
        /// <param name="sqlText"></param>
        /// <param name="orderbyClause"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable Query(string sqlText, string orderbyClause, int pageIndex, int pageSize, ref int recordCount)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(sqlText, "sql");
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(orderbyClause, "orderbyClause");

            if (pageSize > 0 && pageIndex >= 0)
            {
                if (recordCount <= 0)
                {
                    CmdTextBeeCommand countBeeCommand = new CmdTextBeeCommand(this, "select count(1) as beecount from ( {0} )t".FormatWith(sqlText), null);

                    DataTable countTable = countBeeCommand.Excute <DataTable>();
                    if (countTable != null && countTable.Rows.Count == 1)
                    {
                        int.TryParse(countTable.Rows[0]["beecount"].ToString(), out recordCount);
                    }
                }
            }

            string sql = this.dbDriver.GetPagedSelectCmdText(sqlText, orderbyClause, pageIndex, pageSize);

            CmdTextBeeCommand queryBeeCommand = new CmdTextBeeCommand(this, sql, null);

            return(queryBeeCommand.Excute <DataTable>());
        }
Exemple #2
0
        public T InsertT <T>(string tableName, BeeDataAdapter dataAdapter, bool removeIdentity)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentNotNull(dataAdapter, "dataAdapter");

            if (removeIdentity)
            {
                TableSchema tableSchema = GetTableSchema(tableName);
                ThrowExceptionUtil.ArgumentConditionTrue(tableSchema != null, "tableName", "can not find table. Name:{0}".FormatWith(tableName));
                if (tableSchema.IdentityColumn != null)
                {
                    dataAdapter.RemoveKey(tableSchema.IdentityColumn.ColumnName);
                }
                else
                {
                    dataAdapter.RemoveKey(Constants.DefaultIdentityColumnName);
                }
            }

            T result = default(T);
            InsertBeeCommand insertBeeCommand =
                new InsertBeeCommand(this, tableName, dataAdapter, Constants.DefaultIdentityColumnName);

            result = insertBeeCommand.Excute <T>();

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 返回数据对应表所对应key的值。
        /// </summary>
        /// <param name="mappingName">数据对应表名</param>
        /// <param name="keyValue">对应表值, 可以多个值, 以,分割</param>
        /// <param name="valuePropertyName"></param>
        /// <returns></returns>
        public string Mapping(string mappingName, string keyValue, string keyPropertyName, string valuePropertyName)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(mappingName, "mappingName");

            List <string> list   = new List <string>();
            string        result = string.Empty;

            object cacheValue = GetCachedMappingValue(mappingName);

            if (cacheValue != null && !string.IsNullOrEmpty(keyValue))
            {
                string[]  array      = keyValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                DataTable tableValue = cacheValue as DataTable;
                if (tableValue != null)
                {
                    foreach (string itemValue in array)
                    {
                        result = GetDataTableValue(tableValue, itemValue, keyPropertyName, valuePropertyName);

                        list.Add(result);
                    }
                }
            }

            return(string.Join(",", list.ToArray()));
        }
Exemple #4
0
        public DataTable ExecuteCommandWhere(string cmdTextWithWhere, SqlCriteria sqlCriteria)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(cmdTextWithWhere, "cmdTextWithWhere");

            CmdTextWithWhereBeeCommand cmdTextBeeCommand = new CmdTextWithWhereBeeCommand(this, cmdTextWithWhere, sqlCriteria);

            return(cmdTextBeeCommand.Excute <DataTable>());
        }
Exemple #5
0
        /// <summary>
        /// sql文查询
        /// </summary>
        /// <param name="cmdText">sql文</param>
        /// <param name="dataAdapter">数据集</param>
        /// <returns>结果集</returns>
        public DataTable ExecuteCommand(string cmdText, BeeDataAdapter dataAdapter)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(cmdText, "cmdText");

            CmdTextBeeCommand cmdTextBeeCommand = new CmdTextBeeCommand(this, cmdText, dataAdapter);

            return(cmdTextBeeCommand.Excute <DataTable>());
        }
Exemple #6
0
        /// <summary>
        /// 调用存储过程。
        /// 一般不推荐返回值, 直接将该信息反映在结果集中更好。
        /// </summary>
        /// <param name="spName">存储过程名</param>
        /// <param name="dataAdapter">数据集</param>
        /// <returns>返回结果集</returns>
        public DataTable CallSP(string spName, BeeDataAdapter dataAdapter)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(spName, "spName");

            SPBeeCommand spBeeCommand = new SPBeeCommand(this, spName, dataAdapter);

            return(spBeeCommand.Excute <DataTable>());
        }
Exemple #7
0
        public IEnumerable <T> ExecuteDataReader <T>(string cmdText, BeeDataAdapter dataAdapter)
            where T : class
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(cmdText, "cmdText");

            CmdTextBeeCommand cmdTextBeeCommand = new CmdTextBeeCommand(this, cmdText, dataAdapter);

            return(cmdTextBeeCommand.DataRead <T>());
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="dataTable"></param>
        /// <param name="mapping"></param>
        /// <param name="notifyHandler"></param>
        /// <param name="notifyAfter"></param>
        public void SqlBulkCopy(string tableName, DataTable dataTable, Dictionary <string, string> mapping, SqlRowsCopiedEventHandler notifyHandler, int notifyAfter)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentConditionTrue(dataTable != null && dataTable.Rows.Count > 0, "dataTable", "data can not be null or empty");

            SqlServerBulkCopyCommand command = new SqlServerBulkCopyCommand(this, tableName, dataTable, mapping, notifyHandler, notifyAfter);

            command.Excute <int>();
        }
Exemple #9
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="sqlCriteria">条件集</param>
        public void Delete(string tableName, SqlCriteria sqlCriteria)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");

            DeleteBeeCommand deleteBeeCommand =
                new DeleteBeeCommand(this, tableName, sqlCriteria);

            deleteBeeCommand.Excute <int>();
        }
Exemple #10
0
        // Methods
        public UpdateBeeCommand(DbSession owner, string tableName, BeeDataAdapter data, SqlCriteria sqlCriteria)
            : base(owner, BeeDbCommandBehavior.NoQuery)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentConditionTrue(data != null && data.Count != 0, "data", "data should not be null or empty.");

            this.tableName   = tableName;
            this.dataAdapter = data;
            this.sqlCriteria = sqlCriteria;
        }
Exemple #11
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="dataAdapter">数据集</param>
        /// <param name="sqlCriteria">条件集</param>
        public void Update(string tableName, BeeDataAdapter dataAdapter, SqlCriteria sqlCriteria)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");
            ThrowExceptionUtil.ArgumentNotNull(dataAdapter, "dataAdapter");

            UpdateBeeCommand updateBeeCommand =
                new UpdateBeeCommand(this, tableName, dataAdapter, sqlCriteria);

            updateBeeCommand.Excute <int>();
        }
Exemple #12
0
        /// <summary>
        /// 注册数据源
        /// </summary>
        /// <param name="connectionName">连接字符串名</param>
        /// <param name="providerName">数据源名</param>
        /// <param name="connectionString">连接字符串</param>
        public static void Register(string connectionName,
                                    string providerName, string connectionString)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(connectionName, "connectionName");
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(providerName, "providerName");
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(connectionString, "connectionString");

            DbDriverFactory.Instance.RegisterDbDriver(connectionName, providerName, connectionString);

            InitDefaultDbSession();
        }
Exemple #13
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="selectClause">需要查询的字段集</param>
        /// <param name="sqlCriteria">条件集</param>
        /// <param name="orderbyClause">排序集</param>
        /// <param name="pageIndex">起始页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">结果集大小</param>
        /// <returns>结果集</returns>
        public DataTable Query(string tableName, string selectClause,
                               SqlCriteria sqlCriteria, string orderbyClause, int pageIndex, int pageSize, ref int recordCount)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty(tableName, "tableName");

            DataTable cacheData = CacheManager.Instance.GetEntity <DataTable>(Constants.DBTableCacheName.FormatWith(tableName));

            // 需要被缓存
            if (cacheData != null)
            {
                if (cacheData.Rows.Count == 0)
                {
                    QueryBeeCommand queryBeeCommand = new QueryBeeCommand(this, tableName, "*",
                                                                          null, orderbyClause, -1, -1);

                    cacheData = queryBeeCommand.Excute <DataTable>();
                    CacheManager.Instance.AddEntity <DataTable>(Constants.DBTableCacheName.FormatWith(tableName), cacheData, TimeSpan.MaxValue);
                }

                DataTable result = DataUtil.Query(cacheData, sqlCriteria, orderbyClause,
                                                  pageIndex, pageSize, ref recordCount);

                return(result);
            }
            else
            {
                QueryBeeCommand queryBeeCommand = new QueryBeeCommand(this, tableName, selectClause,
                                                                      sqlCriteria, orderbyClause, pageIndex, pageSize);

                DataTable result = queryBeeCommand.Excute <DataTable>();

                if (pageSize > 0 && pageIndex >= 0)
                {
                    if (recordCount <= 0)
                    {
                        QueryBeeCommand countBeeCommand = new QueryBeeCommand(this, tableName,
                                                                              "count(*) as beecount", sqlCriteria, null, -1, -1);
                        DataTable countTable = countBeeCommand.Excute <DataTable>();
                        if (countTable != null && countTable.Rows.Count == 1)
                        {
                            int.TryParse(countTable.Rows[0]["beecount"].ToString(), out recordCount);
                        }
                    }
                }
                else
                {
                    recordCount = result.Rows.Count;
                }

                return(result);
            }
        }
        public Criterion(string name, object value, CriterionType type, CriterionModel model)
        {
            ThrowExceptionUtil.ArgumentNotNullOrEmpty("name", name);

            // 若是Enum, 转换成数字匹配
            if (value is Enum)
            {
                value = (int)value;
            }

            this.leftExpression = name;
            this.value          = value;
            this.criterionType  = type;
            this.criterionModel = model;
        }
        public PropertySchema this[string propertyName]
        {
            get
            {
                ThrowExceptionUtil.ArgumentNotNullOrEmpty(propertyName, "propertyName");
                foreach (PropertySchema item in GetPropertyList())
                {
                    if (string.Compare(item.Name, propertyName, true) == 0)
                    {
                        return(item);
                    }
                }

                return(null);
            }
        }