/// <summary> /// /// </summary> /// <param name="sql">SQL语句</param> /// <param name="parameters">查询参数</param> /// <param name="hints">指令的扩展属性</param> /// <param name="operationType">操作类型,读写分离,默认从master库读取</param> /// <returns>DataSet</returns> /// <exception cref="DalException">数据访问框架异常</exception> public DataSet SelectDataSet(String sql, StatementParameterCollection parameters, IDictionary hints, OperationType operationType) { try { DataSet dataSet; if (!IsShardEnabled) { Statement statement = SqlBuilder.GetSqlStatement(LogicDbName, ShardingStrategy, sql, parameters, hints, operationType).Single(); AddSqlToExtendParams(statement, hints); dataSet = DatabaseBridge.Instance.ExecuteDataSet(statement); } else { var statements = ShardingUtil.GetShardStatement(LogicDbName, ShardingStrategy, null, hints, newHints => ShardingUtil.GetQueryStatement(LogicDbName, sql, ShardingStrategy, parameters, newHints, operationType), SqlStatementType.SELECT); dataSet = ShardingExecutor.ExecuteShardingDataSet(statements); } return(dataSet); } catch (Exception ex) { throw; } finally { } }
/// <summary> /// /// </summary> /// <param name="sql">SQL语句</param> /// <param name="parameters">查询参数</param> /// <param name="hints">指令的扩展属性</param> /// <param name="operationType">操作类型,读写分离,默认从master库读取</param> /// <returns>DataSet</returns> /// <exception cref="DalException">数据访问框架异常</exception> public DataSet SelectDataSet(String sql, StatementParameterCollection parameters, IDictionary hints, OperationType operationType) { if (!IsShardEnabled) { Statement statement = SqlBuilder.GetSqlStatement(LogicDbName, ShardingStrategy, sql, parameters, hints, operationType).Single(); AddSqlToExtendParams(statement, hints); try { var dataSet = DatabaseBridge.Instance.ExecuteDataSet(statement); return(dataSet); } finally { RunTimeDetail runTimeDetail = new RunTimeDetail { DbName = statement.DbName, Duration = statement.Duration, Server = statement.HostName }; if (hints != null) { hints.Add(DALExtStatementConstant.EXCUTE_TIME, new List <RunTimeDetail> { runTimeDetail }); } } } else { var statements = ShardingUtil.GetShardStatement(LogicDbName, ShardingStrategy, null, hints, newHints => ShardingUtil.GetQueryStatement(LogicDbName, sql, ShardingStrategy, parameters, newHints, operationType), SqlStatementType.SELECT); try { var dataSet = ShardingExecutor.ExecuteShardingDataSet(statements); return(dataSet); } finally { var runTimeList = new List <RunTimeDetail>(); foreach (var statement in statements) { RunTimeDetail runTimeDetail = new RunTimeDetail { DbName = statement.DbName, Duration = statement.Duration, Server = statement.HostName }; runTimeList.Add(runTimeDetail); } if (hints != null) { hints.Add(DALExtStatementConstant.EXCUTE_TIME, runTimeList); } } } }