MyPDO 2.0 支持业务逻辑层事务

类别:.NET开发 点击:0 评论:0 推荐:

MyPDO 2.0 支持业务逻辑层事务

下载 http://free.ys168.com/?yu-nan88

文件 Trans1.cs

using System;

using NUnit.Framework;
using MyPDO.DataAccess;

namespace TestData
{
 /// <summary>
 /// Trans1 的摘要说明。
 /// </summary>
 [TestFixture]
 public class Trans1
 {
  public Trans1()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
   DBA = new DataAccessor();
   DBA.ConnectString = "data source=10.10.35.30;initial catalog=TradeCityT;persist security info=False;user id=sa;pwd=lee;"; //"Provider=SQLOLEDB;data source=10.10.25.63;initial catalog=Master;user id=zha;Password=123;";
   DBA.ConnectType = MyPDO.ConnectType.SqlDataDriver;
   DBA.Open(); 
  }
  private MyPDO.DataAccess.DataAccessor DBA;
 
  public MyPDO.DataAccess.DataAccessor Data
  {
   get{return DBA;}
   set{DBA = value;}
  }

  [SetUp]
  public void SetUp()
  {   
   //this.ConnectString = "data source=10.10.35.37;initial catalog=TradeCityT;persist security info=False;user id=sa;pwd=123;";
   //this.ConnectType = MyPDO.ConnectType.SqlDataDriver;
   
   Assert.IsTrue(DBA.IsOpen,"DBA closed");
  }
  public int Insert()
  {
   string str = "INSERT INTO t_base_manager(ManagerCode, State2) values('TEST1',1)";
   DBA.CommandText = str;
   int i = DBA.ExecuteCommand(false);
   Assert.IsTrue(i == 1);
   return i;
  }

 }
}

文件 Trans2.cs

using System;

using NUnit.Framework;
using MyPDO.DataAccess;

namespace TestData
{
 /// <summary>
 /// Trans1 的摘要说明。
 /// </summary>
 [TestFixture]
 public class Trans2
 {
  public Trans2()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //

   DBA = new DataAccessor();
   DBA.ConnectString = "data source=10.10.35.30;initial catalog=TradeCityT;persist security info=False;user id=sa;pwd=lee;"; //"Provider=SQLOLEDB;data source=10.10.25.63;initial catalog=Master;user id=zha;Password=123;";
   DBA.ConnectType = MyPDO.ConnectType.SqlDataDriver;
   DBA.Open(); 

  }
  private MyPDO.DataAccess.DataAccessor DBA;

  public MyPDO.DataAccess.DataAccessor Data
  {
   get{return DBA;}
   set{DBA = value;}
  }
  [SetUp]
  public void SetUp()
  {   
   //this.ConnectString = "data source=10.10.35.37;initial catalog=TradeCityT;persist security info=False;user id=sa;pwd=123;";
   //this.ConnectType = MyPDO.ConnectType.SqlDataDriver;
   
   Assert.IsTrue(DBA.IsOpen,"DBA closed");
  }
  public int Insert()
  {
   //DBA.AutoCommit = false;
   string str = "INSERT INTO t_base_manager(ManagerCode, State) values('TEST2_1',1)";
   DBA.CommandText = str;
   int i = this.insert();
   if (i==1)
   {
    str = "INSERT INTO t_base_manager(ManagerCode, State) values('TEST2_2',1)";
    DBA.CommandText = str;
    i += this.insert();
   }
   Assert.IsTrue(2 ==i);
   //if(i==2)
   // DBA.CommitTrans();
   //else
   // DBA.RollbackTrans();
   return i;
  }
  private int insert()
  {    
   int i = DBA.ExecuteCommand(false);
   Assert.IsTrue(i == 1);
   return i;
  }
 }
}

文件 TestData.cs

using System;

using NUnit.Framework;
using MyPDO.DataAccess;


namespace TestData
{
 /// <summary>
 /// TestData 的摘要说明。
 /// </summary>
 [TestFixture]
 public class TestData
 {
  public TestData()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }
  private MyPDO.DataAccess.DataAccessor DBA;

  [SetUp]
  public void SetUp()
  {   
   //this.ConnectString = "data source=10.10.35.37;initial catalog=TradeCityT;persist security info=False;user id=sa;pwd=123;";
   //this.ConnectType = MyPDO.ConnectType.SqlDataDriver;

   DBA = new DataAccessor();
   DBA.ConnectString = "data source=10.10.35.30;initial catalog=TradeCityT;persist security info=False;user id=sa;pwd=lee;"; //"Provider=SQLOLEDB;data source=10.10.25.63;initial catalog=Master;user id=zha;Password=123;";
   DBA.ConnectType = MyPDO.ConnectType.SqlDataDriver;
   DBA.Open(); 
   Assert.IsTrue(DBA.IsOpen,"DBA closed");
  }
 

  [Test]
  public void Trans_Test()
  {
   string str = "INSERT INTO t_base_manager(ManagerCode, State) values('TEST3',1)";
   
   DBA.AutoCommit = false;
   DBA.CommandText = str;
   int i = DBA.ExecuteCommand(false);

   Assert.IsTrue(i==1);

   if(i ==1)
   {

    Console.Write(i.ToString() + "\n");

    Trans2 ts2 = new  Trans2();
    ts2.Data = DBA;
    i +=ts2.Insert();

    Console.Write(i.ToString() + "\n");

    Assert.IsTrue(i==3);
    if(i==3)
    {
     Trans1 ts1 = new Trans1();
     ts1.Data = DBA;
     i += ts1.Insert();

     Console.Write(i.ToString() + "\n");

    }
   }

   if(i==4)
    DBA.CommitTrans();
   else
    DBA.RollbackTrans();

   Console.Write(i.ToString()+ "\n");


  }
 }
}

本文地址:http://com.8s8s.com/it/it41210.htm