remove show sql for group

This commit is contained in:
Looly 2021-06-17 19:19:37 +08:00
parent 5302edf980
commit 757bfdc723
4 changed files with 48 additions and 10 deletions

View File

@ -3,10 +3,11 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.2 (2021-06-16)
# 5.7.2 (2021-06-17)
### 🐣新特性
* 【core 】 增加UserPassAuthenticator
* 【db 】 获取分组数据源时,移除公共属性项
### 🐞Bug修复
* 【db 】 修复Oracle下别名错误造成的SQL语法啊错误issue#I3VTQW@Gitee

View File

@ -5,6 +5,7 @@ import cn.hutool.core.io.IoUtil;
import cn.hutool.db.dialect.Dialect;
import cn.hutool.db.dialect.DialectFactory;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.db.sql.SqlLog;
import cn.hutool.log.Log;
import cn.hutool.log.level.Level;
import cn.hutool.setting.Setting;
@ -168,17 +169,31 @@ public final class DbUtil {
}
/**
* 从配置文件中读取SQL打印选项
* 移除配置文件中的Show SQL相关配置项<br>
* 此方法用于移除用户配置在分组下的配置项目
*
* @param setting 配置项
* @since 5.7.2
*/
public static void removeShowSqlParams(Setting setting){
setting.remove(SqlLog.KEY_SHOW_SQL);
setting.remove(SqlLog.KEY_FORMAT_SQL);
setting.remove(SqlLog.KEY_SHOW_PARAMS);
setting.remove(SqlLog.KEY_SQL_LEVEL);
}
/**
* 从配置文件中读取SQL打印选项读取后会去除相应属性
*
* @param setting 配置文件
* @since 4.1.7
*/
public static void setShowSqlGlobal(Setting setting) {
// 初始化SQL显示
final boolean isShowSql = Convert.toBool(setting.remove("showSql"), false);
final boolean isFormatSql = Convert.toBool(setting.remove("formatSql"), false);
final boolean isShowParams = Convert.toBool(setting.remove("showParams"), false);
String sqlLevelStr = setting.remove("sqlLevel");
final boolean isShowSql = Convert.toBool(setting.remove(SqlLog.KEY_SHOW_SQL), false);
final boolean isFormatSql = Convert.toBool(setting.remove(SqlLog.KEY_FORMAT_SQL), false);
final boolean isShowParams = Convert.toBool(setting.remove(SqlLog.KEY_SHOW_PARAMS), false);
String sqlLevelStr = setting.remove(SqlLog.KEY_SQL_LEVEL);
if (null != sqlLevelStr) {
sqlLevelStr = sqlLevelStr.toUpperCase();
}

View File

@ -116,6 +116,11 @@ public abstract class AbstractDSFactory extends DSFactory {
if (StrUtil.isBlank(url)) {
throw new DbRuntimeException("No JDBC URL for group: [{}]", group);
}
// 移除用户可能误加入的show sql配置项
// issue#I3VW0R@Gitee
DbUtil.removeShowSqlParams(config);
// 自动识别Driver
String driver = config.getAndRemoveStr(KEY_ALIAS_DRIVER);
if (StrUtil.isBlank(driver)) {

View File

@ -6,13 +6,30 @@ import cn.hutool.log.level.Level;
/**
* SQL在日志中打印配置
*
*
* @author looly
* @since 4.1.0
*/
public enum SqlLog {
INSTANCE;
/**
* 配置文件中配置属性名是否显示SQL
*/
public static final String KEY_SHOW_SQL = "showSql";
/**
* 配置文件中配置属性名是否格式化SQL
*/
public static final String KEY_FORMAT_SQL = "formatSql";
/**
* 配置文件中配置属性名是否显示参数
*/
public static final String KEY_SHOW_PARAMS = "showParams";
/**
* 配置文件中配置属性名显示的日志级别
*/
public static final String KEY_SQL_LEVEL = "sqlLevel";
private final static Log log = LogFactory.get();
/** 是否debugSQL */
@ -23,10 +40,10 @@ public enum SqlLog {
private boolean showParams;
/** 默认日志级别 */
private Level level = Level.DEBUG;
/**
* 设置全局配置是否通过debug日志显示SQL
*
*
* @param isShowSql 是否显示SQL
* @param isFormatSql 是否格式化显示的SQL
* @param isShowParams 是否打印参数