1--Case.net
好比t_Order訂單表1,t_OrderDetail訂單明細表2事務
下一張訂單會往表1插入一條數據,表2會插入多行數據get
使用Spring.net事務管理string
例如it
---Order---訂單主信息-------io
public class OrderBILclass
{exception
private void InsertOrderHeader(Order order)im
{數據
OrderDAL.InsertOrderHeader(Order order);
}
}
public class OrderDAL
{
private void InsertOrderHeader(Order order)
{
string insertSQL="insert into Order(orderNo,CreateTime,Creator,CreatName,SupplierCode,SupplierName,ClientCode,ClientName)"
.........................as so on
}
}
--訂單明細表----OrderDetail-----
public class OrderDetailBIL
{
private void InsertOrderDetail(Order order)
{
OrderDetailDAL.InsertOrderDetail(Order order);
}
}
public class OrderDetailDAL
{
private void InsertOrderDetail(Order order)
{
string insertSQL="insert into Order(orderNo,CreateTime,Creator,CreatName,SupplierCode,SupplierName,ClientCode,ClientName)"
.........................as so on
}
}
public InterFace IOrderService
{
void CreateOrder(Order OrderHeader,OrderDetail orderDetail);
}
--Service 實現類
public class OrderManageSerivceIMPL:IOrderService
{
private void CreateOrder(Order OrderHeader,OrderDetail orderDetail)
{
OrderBIL.InsertOrderHeader(OrderHeader);
OrderDetailBIL.InsertOrderDetail(orderDetail);
}
}
public class OrderManageSerivceTransaction
{
public OrderManageSerivce OrderManageSerivce{
private void CreateOrder(Order OrderHeader,OrderDetail orderDetail)
{
OrderManageSerivce.CreateOrder(OrderHeader,orderDetail);
}
}
事務調用----
IOrderService orderService=(IOrderService)BeanFactory.getObject("OrderManageSerivceTransaction");
orderService.CreateOrder(OrderHeader,orderDetail);
---這個是Spring.net事務封裝整個過程
若是插入表1成功,表2不成功整個事務回滾--呵呵
若是在某一個類中使用了異常處理
好比:
public class OrderDetailBIL
{
private void InsertOrderDetail(Order order)
{
try{
OrderDetailDAL.InsertOrderDetail(Order order);
}
catch(exception ex)
{
case 1: throw new Exception(ex.Message);
case 2: Log.WriteInfo(ex.Message);
}
}
}
case 1: Spring事務運行到這的時候,將回滾
case 2: Spring事務不回滾--將回出現這樣狀況---表1插入數據成功,表2插入數據失敗
-----------好的東東下回分解--------------------------------------------------------