zoukankan      html  css  js  c++  java
  • 更新多表配置事务采取事务下沉的方式

    1、dao层代码

     // 公司dao
     public interface ICompanyDao {
     		int updateCompany(UserDTO user);
     }
     // 用户dao
     public interface IUserDao {
     		int updateUser(UserDTO user);
     }

    2、事务层代码

    public interface TransactionalManage {
    
        boolean updateCompanyPeople(UserDTO user);
    }
    
    @Service("transactionalManage")
    public class TransactionalManageImpl implements TransactionalManage{
    	
       @Resource
        private ICompanyDao companyDao;
    
        @Resource
        private IUserDao userDao;
        
        @Override
        @Transactional
        public boolean updateCompanyPeople(UserDTO user) {
            int row = companyDao.updateCompany(user);
            if (row <= 0) {
                return false;
            }
            row = userDao.updateUser(user);
            if (row <= 0) {
                throw new BusinessException("updateCompanyPeople:更新失败。");
            }
            return true;
        }
    }
    

    3、service层代码

    public interface ICompanyPeopleService {
    
    	boolean updateCompanyPeople(UserDTO user);
    
    }
    
    @Service("companyPeopleService")
    public class CompanyPeopleServiceImpl implements ICompanyPeopleService {  
    
    private static final Logger LOGGER = LoggerFactory.getLogger(CompanyPeopleServiceImpl.class);
    
      @Resource
        private TransactionalManage transactionalManage;
        
        @Override
        public boolean updateCompanyPeople(UserDTO user) {
            boolean isSuccess = false;
            try {
                isSuccess = transactionalManage.updateCompanyPeople(user);
            } catch (BusinessException e) {
                LOGGER.error("updateCompanyPeople:数据更新失败。", e);
            }
            return isSuccess;
        }
    }
    

      

      

      

      

  • 相关阅读:
    数组名和指针区别(还有数组退化等)
    无法从“const char *”转换为“char *”
    c语言数组初始化问题
    c语言实现atoi和itoa函数。
    不使用临时变量交换两个整数
    hdu 1282回文数猜想
    Android仿WIN8系统磁贴点击下沉倾斜效果
    Android Studio使用心得
    处理json中影响解析的多余引號
    我也来开发2048之主界面设计
  • 原文地址:https://www.cnblogs.com/yiyibinbin/p/9473065.html
Copyright © 2011-2022 走看看