Commit 99297dde by s_guodong

update-多数据源切换

parent d9de10b4
...@@ -1509,8 +1509,6 @@ public class Platform { ...@@ -1509,8 +1509,6 @@ public class Platform {
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
if (db != null) { if (db != null) {
ctx.storeData("LastDB." + Platform.getModuleRoot(), db); ctx.storeData("LastDB." + Platform.getModuleRoot(), db);
DynamicDataSourceContextHolder.setDataSourceType(db);
} }
} }
...@@ -1589,7 +1587,6 @@ public class Platform { ...@@ -1589,7 +1587,6 @@ public class Platform {
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
String tableName = MdaUtils.getTableNameFromSQL(sql); String tableName = MdaUtils.getTableNameFromSQL(sql);
String tableDB = Platform.getTableDB(tableName); String tableDB = Platform.getTableDB(tableName);
// Platform.setDefaultDB(tableDB);
DynamicDataSourceContextHolder.setDataSourceType(tableDB); DynamicDataSourceContextHolder.setDataSourceType(tableDB);
ctx.getDaoSession().dbExecuteSQL(sql); ctx.getDaoSession().dbExecuteSQL(sql);
} }
...@@ -1641,7 +1638,7 @@ public class Platform { ...@@ -1641,7 +1638,7 @@ public class Platform {
//取得上下文 //取得上下文
IContext ctx = MdaEnv.getContext(); IContext ctx = MdaEnv.getContext();
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
String db = (String) Platform.getStoredData("DefaultDB." + Platform.getModuleRoot().getClass() + MdaEnv.getLoginUser()); String db = (String) Platform.getStoredData("DefaultDB." + Platform.getModuleRoot());
if (db == null) { if (db == null) {
//从前手交易获取默认数据库 //从前手交易获取默认数据库
String caller = (String) ctx.restoreData(ctx.getTransName() + ".caller"); String caller = (String) ctx.restoreData(ctx.getTransName() + ".caller");
...@@ -1702,8 +1699,7 @@ public class Platform { ...@@ -1702,8 +1699,7 @@ public class Platform {
IContext ctx = MdaEnv.getContext(); IContext ctx = MdaEnv.getContext();
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
if (db != null) { if (db != null) {
ctx.storeData("DefaultDB." + Platform.getModuleRoot().getClass() + MdaEnv.getLoginUser(), db); ctx.storeData("DefaultDB." + Platform.getModuleRoot(), db);
DynamicDataSourceContextHolder.setDataSourceType(db);
log.debug("{}", "DefaultDB change to " + db); log.debug("{}", "DefaultDB change to " + db);
} }
} }
...@@ -1780,7 +1776,6 @@ public class Platform { ...@@ -1780,7 +1776,6 @@ public class Platform {
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
// 切换数据源 // 切换数据源
String moduleDB = Platform.getModuleDB(module); String moduleDB = Platform.getModuleDB(module);
//Platform.setDefaultDB(moduleDB);
DynamicDataSourceContextHolder.setDataSourceType(moduleDB); DynamicDataSourceContextHolder.setDataSourceType(moduleDB);
ctx.getDaoSession().dbRead(module, arguments); ctx.getDaoSession().dbRead(module, arguments);
} }
...@@ -1884,7 +1879,6 @@ public class Platform { ...@@ -1884,7 +1879,6 @@ public class Platform {
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
// 切换数据源 // 切换数据源
String db = Platform.getModuleListsDB(lists); String db = Platform.getModuleListsDB(lists);
// Platform.setDefaultDB(db);
DynamicDataSourceContextHolder.setDataSourceType(db); DynamicDataSourceContextHolder.setDataSourceType(db);
ctx.getDaoSession().dbReadset(lists, maxSize, whereClause, datas); ctx.getDaoSession().dbReadset(lists, maxSize, whereClause, datas);
} }
...@@ -2019,7 +2013,6 @@ public class Platform { ...@@ -2019,7 +2013,6 @@ public class Platform {
ctx.setErrorCode(NO_ERROR); ctx.setErrorCode(NO_ERROR);
String tableName = MdaUtils.getTableNameFromSQL(sql); String tableName = MdaUtils.getTableNameFromSQL(sql);
String tableDB = Platform.getTableDB(tableName); String tableDB = Platform.getTableDB(tableName);
// Platform.setDefaultDB(tableDB);
DynamicDataSourceContextHolder.setDataSourceType(tableDB); DynamicDataSourceContextHolder.setDataSourceType(tableDB);
ctx.getDaoSession().dbExecuteSQL(sql, value); ctx.getDaoSession().dbExecuteSQL(sql, value);
} }
......
...@@ -3,6 +3,7 @@ package com.brilliance.mda.runtime.mda.driver; ...@@ -3,6 +3,7 @@ package com.brilliance.mda.runtime.mda.driver;
import com.brilliance.mda.runtime.annotation.Transaction; import com.brilliance.mda.runtime.annotation.Transaction;
import com.brilliance.mda.runtime.mda.*; import com.brilliance.mda.runtime.mda.*;
import com.brilliance.mda.runtime.mda.impl.EnvConfig; import com.brilliance.mda.runtime.mda.impl.EnvConfig;
import com.brilliance.mda.runtime.request.BaseVO;
import java.util.*; import java.util.*;
...@@ -17,6 +18,7 @@ public class MdaContext implements IContext { ...@@ -17,6 +18,7 @@ public class MdaContext implements IContext {
private transient final ILocker locker; private transient final ILocker locker;
private Map<String, Object> params = new HashMap<String, Object>(); private Map<String, Object> params = new HashMap<String, Object>();
private Map<String, Object> globleParams = new HashMap<String, Object>();
private String displayStr; private String displayStr;
private transient IRuleEmitter emmiter; private transient IRuleEmitter emmiter;
...@@ -206,11 +208,28 @@ public class MdaContext implements IContext { ...@@ -206,11 +208,28 @@ public class MdaContext implements IContext {
} }
public Object restoreData(String key) { public Object restoreData(String key) {
return this.params.get(key); Object o = this.params.get(key);
if (o == null && key.startsWith("DefaultDB.")) {
IContext ctx = MdaEnv.getContext();
BaseVO baseVO = (BaseVO) ctx.restoreData(IContext.DISPLAY_KEY);
if (baseVO != null) {
String substring = key.substring(0, key.indexOf("@"));
return this.globleParams.get(substring + baseVO.getPageId());
}
}
return o;
} }
@Override @Override
public void storeData(String key, Object data) { public void storeData(String key, Object data) {
if (key.startsWith("DefaultDB.")) {
IContext ctx = MdaEnv.getContext();
BaseVO baseVO = (BaseVO) ctx.restoreData(IContext.DISPLAY_KEY);
if (baseVO != null) {
String substring = key.substring(0, key.indexOf("@"));
this.globleParams.put(substring + baseVO.getPageId(), data);
}
}
this.params.put(key, data); this.params.put(key, data);
} }
...@@ -349,7 +368,7 @@ public class MdaContext implements IContext { ...@@ -349,7 +368,7 @@ public class MdaContext implements IContext {
@Override @Override
public void resetParams(Map<String, Object> params) { public void resetParams(Map<String, Object> params) {
// this.params.clear(); this.params.clear();
if (params != null) if (params != null)
this.params.putAll(params); this.params.putAll(params);
} }
......
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