这里对这种方式在进行行为抽象。
大致如下:
大致这样,具体要扩展的话,可以在详细点。
测试如下:
Code
[TestMethod]
public void TestExecutor()
{
IDbExecutor exec1 = ExecutorHelper.CreateExecutor(ExecutorType.NonQueryExecutor);
IDbExecutor exec2 = ExecutorHelper.CreateExecutor(ExecutorType.NonQueryExecutor);
exec1.SetTextCommand("insert into dept(name) values('one');");
exec2.SetTextCommand("insert into dep(name) values('two');");
ExecutorHelper.TranstactExecute();
for (int i = 0; i < 1000; i++)
{
IDbExecutor exec3 = ExecutorHelper.CreateExecutor(ExecutorType.DataReaderExecutor);
exec3.SetTextCommand("select * from dept;");
ExecutorHelper.Execute();
IDataReader dr = exec3.Result as IDataReader;
using (dr)
{
if (dr.Read()) { }
}
}
IDbExecutor exec4 = ExecutorHelper.CreateExecutor(ExecutorType.DataSetExecutor);
exec4.SetTextCommand("select * from dept;");
ExecutorHelper.Execute();
DataSet ds = exec4.Result as DataSet;
Assert.AreEqual(3,ds.Tables[0].Rows.Count);
}
[TestMethod]
public void TestExecutor()
{
IDbExecutor exec1 = ExecutorHelper.CreateExecutor(ExecutorType.NonQueryExecutor);
IDbExecutor exec2 = ExecutorHelper.CreateExecutor(ExecutorType.NonQueryExecutor);
exec1.SetTextCommand("insert into dept(name) values('one');");
exec2.SetTextCommand("insert into dep(name) values('two');");
ExecutorHelper.TranstactExecute();
for (int i = 0; i < 1000; i++)
{
IDbExecutor exec3 = ExecutorHelper.CreateExecutor(ExecutorType.DataReaderExecutor);
exec3.SetTextCommand("select * from dept;");
ExecutorHelper.Execute();
IDataReader dr = exec3.Result as IDataReader;
using (dr)
{
if (dr.Read()) { }
}
}
IDbExecutor exec4 = ExecutorHelper.CreateExecutor(ExecutorType.DataSetExecutor);
exec4.SetTextCommand("select * from dept;");
ExecutorHelper.Execute();
DataSet ds = exec4.Result as DataSet;
Assert.AreEqual(3,ds.Tables[0].Rows.Count);
}
文件下载:/Files/bmrxntfj/Bmrxntfj.Data.rar