/**
* Copyright 2018 人人开源 https://www.renren.io
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.epmet.service;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.dao.SysUserDao;
import com.epmet.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 测试多数据源
*
* @author Mark sunlightcs@gmail.com
* @since 1.0.0
*/
@Service
public class DynamicDataSourceTestService extends DynamicService {
@Autowired
private SysUserDao sysUserDao;
@Transactional
public void updateUser(Long id){
SysUserEntity user = new SysUserEntity();
user.setId(id);
user.setMobile("13500000000");
sysUserDao.updateById(user);
}
@DataSource("slave1")
@Transactional
public void updateUserBySlave1(Long id){
SysUserEntity user = new SysUserEntity();
user.setId(id);
user.setMobile("13500000001");
sysUserDao.updateById(user);
}
@DataSource("slave2")
@Transactional
public void updateUserBySlave2(Long id){
SysUserEntity user = new SysUserEntity();
user.setId(id);
user.setMobile("13500000002");
sysUserDao.updateById(user);
//测试事物
int i = 1/0;
}
}