Commit d7974868 by gechengyang

提交数据库配置初始化模板mybatis.properties

parent 4255bc56
......@@ -185,6 +185,7 @@ public class Acdopn extends AbstractTransaction{
//Object resMsg = MdaUtils.invoke("com.brilliance.eibs.main.Client","scall","w414","w414",new Object[]{yymap});
Object resMsg = new ResultMsg();
Map retMap=new HashMap();
retMap.put("code","000000");
ResultMsg retMsg= (ResultMsg) resMsg;
retMsg.setContent(retMap);
resMsg=retMsg;
......
......@@ -8,6 +8,7 @@ import com.brilliance.mda.runtime.mda.impl.Argument;
import com.brilliance.mda.runtime.mda.impl.ModuleList;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.request.BaseVO;
import com.brilliance.mda.support.mybatis.config.MybatisDbUtil;
import com.brilliance.mda.support.mybatis.count.CounterService;
import com.brilliance.mda.support.mybatis.dync.mapper.DbExecuteMapper;
import com.github.pagehelper.PageHelper;
......@@ -71,6 +72,8 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
private static final String SQLID_SELECTBYID = "selectByInr";
private static final String SQLID_SELECTBYPRIMARYKEY = "selectByPrimaryKey";
private static boolean isMultiDb= MybatisDbUtil.isMultilDb();
@Autowired
CounterService counter;
......@@ -104,40 +107,50 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public <T extends IModule> int dbInsert(T module) {
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
String sqlId = getSqlId(module.getClass(), SQLID_INSERT);
return executeUpdate(sqlId, module);
}
@Override
public <T extends IModule> int dbUpdate(T module) {
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
String sqlId = getSqlId(module.getClass(), SQLID_UPDATE);
return executeUpdate(sqlId, module);
}
@Override
public <T extends IModule> int dbDelete(T module) {
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
String sqlId = getSqlId(module.getClass(), SQLID_DELETE);
return executeUpdate(sqlId, module);
}
@Override
public <T extends IModule> int dbDelete(T m, Argument... args) {
String moduleDB = MdaUtils.getModuleDB(m);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(m);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
Class<T> clazz = (Class<T>) m.getClass();
MybatisArgumentAdapter adapter = new MybatisArgumentAdapter(DELETE, clazz, args);
return executeUpdate(getSqlId(clazz, SQLID_DYNCDEL), adapter.getSqlParams());
}
public <T extends IModule> int dbDelete(T module, Serializable... id) {
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
Class<T> clazz = (Class<T>) module.getClass();
String sqlId = getSqlId(clazz, SQLID_DELBYIDS);
return executeUpdate(sqlId, Arrays.asList(id));
......@@ -154,8 +167,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public <T extends IModule> T dbRead(T module, Argument... args) {
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
MybatisArgumentAdapter adapter = new MybatisArgumentAdapter(SELECT, module.getClass(), args);
T entity = this.dyncReadOne(module.getClass(), adapter);
......@@ -167,8 +182,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public <T extends IModule> T dbReadByInr(T module, String inr) {
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleDB(module);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
Map<String, Object> dyncMap = new HashMap<>();
dyncMap.put("inr", inr);
T entity = this.dyncReadByInr(module.getClass(), dyncMap);
......@@ -197,9 +214,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public <T extends IModule> int dbReadset(IModuleList<T>[] lists, CacheOption cacheOption, String whereSql, Object[] param) {
String moduleDB = MdaUtils.getModuleListsDB(lists);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleListsDB(lists);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
if (cacheOption != null) {
IContext ctx = MdaEnv.getContext();
BaseVO baseVO = ctx.getVo();
......@@ -226,9 +244,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public <T extends IModule> int dbReadset(IModuleList<T> list, Argument... args) {
String moduleDB = MdaUtils.getModuleListDB(list);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
if(isMultiDb){
String moduleDB = MdaUtils.getModuleListDB(list);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
list.clear();
MybatisArgumentAdapter adapter = new MybatisArgumentAdapter(SELECT, list.getDataClass(), args);
List<T> result = this.dyncRead(list.getDataClass(), adapter);
......@@ -282,9 +301,10 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public <T extends IModule> int dbReadset(IModuleList<T> list, String whereSql, Object[] objects) {
if(isMultiDb){
String moduleDB = MdaUtils.getModuleListDB(list);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
}
list.clear();
MybatisArgumentAdapter adapter = new MybatisArgumentAdapter(SELECT, list.getDataClass(), whereSql, objects);
List<T> result = this.dyncRead(list.getDataClass(), adapter);
......@@ -307,10 +327,11 @@ public class MyBatisDaoSession extends AbstractDaoSession implements IDaoSession
@Override
public void dbExecuteSQL(String sql, Object... objects) {
String tableName = MdaUtils.getTableNameFromSQL(sql);
String tableDB = MdaUtils.getTableDB(tableName);
DynamicDataSourceContextHolder.setDataSourceType(tableDB);
if(isMultiDb){
String tableName = MdaUtils.getTableNameFromSQL(sql);
String tableDB = MdaUtils.getTableDB(tableName);
DynamicDataSourceContextHolder.setDataSourceType(tableDB);
}
Map<String, Object> map = new HashMap<>();
if (objects != null) {
sql = MybatisArgumentAdapter.convertPlaceHolder(sql, objects, map);
......
......@@ -6,11 +6,30 @@ import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class MybatisDbUtil {
private static Properties properties = new Properties();
static {
try {
InputStream inputStream = MybatisDbUtil.class.getResourceAsStream("/mybatis.properties");
properties.load(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static boolean isMultilDb() {
//不加/会从当前包进行寻找,加上/会从src开始找
String pro = properties.getProperty("multidb");
return pro == null ? false : Boolean.valueOf(pro);
}
// private static Map
static {
// PropertyUtils
}
public static void main(String[] args) throws IOException {
System.out.println(isMultilDb());
}
}
#数据库相关配置信息
dbinfo.multidb=false
dbinfo.name=ipsnew
\ No newline at end of file
#是否是多数据库true false
multidb=false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment