|
@@ -23,9 +23,11 @@ public class SqlInterceptor implements Interceptor {
|
|
|
StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
|
|
|
String sql = statementHandler.getBoundSql().getSql();
|
|
|
// 修改SQL语句
|
|
|
- String modifiedSql = modifySql(sql);
|
|
|
+ String modifiedSql = BeforeSQL(sql);
|
|
|
// 将修改后的SQL语句设置回StatementHandler
|
|
|
ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", modifiedSql);
|
|
|
+ invocation.proceed();
|
|
|
+ ReflectUtils.setFieldValue(statementHandler.getBoundSql(), "sql", sql);
|
|
|
return invocation.proceed();
|
|
|
}
|
|
|
|
|
@@ -42,9 +44,26 @@ public class SqlInterceptor implements Interceptor {
|
|
|
return "set schema " + SecurityUtils.getDatabaseName() + "; " + sql;
|
|
|
if (SecurityUtils.getDatabaseType().equals("mysql"))
|
|
|
return "USE `" + SecurityUtils.getDatabaseName() + "`; " + sql;
|
|
|
- return "";
|
|
|
+ return sql;
|
|
|
}
|
|
|
|
|
|
+ // 根据类型设置不同的选择数据源格式
|
|
|
+ private String BeforeSQL(String sql) {
|
|
|
+ try {
|
|
|
+ SecurityUtils.getDatabaseType();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (SecurityUtils.getDatabaseType().equals("sqlserver"))
|
|
|
+ return "USE `" + SecurityUtils.getDatabaseName() + "`; ";
|
|
|
+ if (SecurityUtils.getDatabaseType().equals("dm"))
|
|
|
+ return "set schema " + SecurityUtils.getDatabaseName() + "; ";
|
|
|
+ if (SecurityUtils.getDatabaseType().equals("mysql"))
|
|
|
+ return "USE `" + SecurityUtils.getDatabaseName() + "`; ";
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Object plugin(Object target) {
|
|
|
return Plugin.wrap(target, this);
|