zoukankan      html  css  js  c++  java
  • Spring.net--很棒的事务处理

    1--Case

    比如t_Order订单表1,t_OrderDetail订单明细表2

    下一张订单会往表1插入一条数据,表2会插入多行数据

    使用Spring.net事务管理

    例如

    ---Order---订单主信息-------

    public class OrderBIL

    {

          private void InsertOrderHeader(Order order)

      {

              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插入数据失败

    -----------好的东东下回分解--------------------------------------------------------

      

  • 相关阅读:
    Java ConcurrentModificationException 异常分析与解决方案
    android studio 怎么做屏幕适配?
    java Class.getSimpleName() 的用法
    LeetCode——Remove Element
    用WidgeDuino创建一个SCADA(监控与数据採集)系统
    【Oracle】OCR的备份和恢复之导出导入
    Java大数类介绍
    POJ 1113 Wall 凸包
    OPENCV中滑动条的使用
    Android
  • 原文地址:https://www.cnblogs.com/meilibao/p/3472808.html
Copyright © 2011-2022 走看看