mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
b405b2526d
commit
3da217a627
@ -49,7 +49,17 @@ public class SettingConfigParser implements ConfigParser {
|
|||||||
* @return SettingConfigParser
|
* @return SettingConfigParser
|
||||||
*/
|
*/
|
||||||
public static SettingConfigParser of() {
|
public static SettingConfigParser of() {
|
||||||
return new SettingConfigParser(null);
|
return of(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建默认配置解析器
|
||||||
|
*
|
||||||
|
* @param setting 配置文件
|
||||||
|
* @return SettingConfigParser
|
||||||
|
*/
|
||||||
|
public static SettingConfigParser of(final Setting setting) {
|
||||||
|
return new SettingConfigParser(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Setting setting;
|
private final Setting setting;
|
||||||
@ -128,7 +138,7 @@ public class SettingConfigParser implements ConfigParser {
|
|||||||
|
|
||||||
// SQL日志
|
// SQL日志
|
||||||
final SqlLogFilter sqlLogFilter = getSqlLogFilter(setting);
|
final SqlLogFilter sqlLogFilter = getSqlLogFilter(setting);
|
||||||
if(null != sqlLogFilter){
|
if (null != sqlLogFilter) {
|
||||||
dbConfig.addSqlFilter(sqlLogFilter);
|
dbConfig.addSqlFilter(sqlLogFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +183,7 @@ public class SettingConfigParser implements ConfigParser {
|
|||||||
private static SqlLogFilter getSqlLogFilter(final Setting setting) {
|
private static SqlLogFilter getSqlLogFilter(final Setting setting) {
|
||||||
// 初始化SQL显示
|
// 初始化SQL显示
|
||||||
final boolean isShowSql = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_SQL), false);
|
final boolean isShowSql = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_SQL), false);
|
||||||
if(!isShowSql){
|
if (!isShowSql) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import org.dromara.hutool.core.io.IoUtil;
|
|||||||
import org.dromara.hutool.core.lang.Singleton;
|
import org.dromara.hutool.core.lang.Singleton;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.map.SafeConcurrentHashMap;
|
import org.dromara.hutool.core.map.SafeConcurrentHashMap;
|
||||||
import org.dromara.hutool.core.spi.SpiUtil;
|
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
import org.dromara.hutool.db.config.ConfigParser;
|
import org.dromara.hutool.db.config.ConfigParser;
|
||||||
import org.dromara.hutool.db.config.DbConfig;
|
import org.dromara.hutool.db.config.DbConfig;
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.db.sql;
|
package org.dromara.hutool.db.sql;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import org.dromara.hutool.core.text.StrUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL排序对象
|
* SQL排序对象
|
||||||
* @author Looly
|
* @author Looly
|
||||||
@ -30,6 +30,9 @@ public class Order implements Serializable{
|
|||||||
private Direction direction;
|
private Direction direction;
|
||||||
|
|
||||||
//---------------------------------------------------------- Constructor start
|
//---------------------------------------------------------- Constructor start
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*/
|
||||||
public Order() {
|
public Order() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package org.dromara.hutool.db;
|
|||||||
|
|
||||||
import org.dromara.hutool.core.lang.Console;
|
import org.dromara.hutool.core.lang.Console;
|
||||||
import org.dromara.hutool.db.config.DbConfig;
|
import org.dromara.hutool.db.config.DbConfig;
|
||||||
|
import org.dromara.hutool.db.config.SettingConfigParser;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -28,4 +29,22 @@ public class IssueI8UTGPTest {
|
|||||||
|
|
||||||
Assertions.assertTrue(isFilterValid.get());
|
Assertions.assertTrue(isFilterValid.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void customSqlLogTest2() {
|
||||||
|
final AtomicBoolean isFilterValid = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
final DbConfig dbConfig = SettingConfigParser.of().parse("test");
|
||||||
|
dbConfig.addSqlFilter((conn, boundSql, returnGeneratedKey) -> {
|
||||||
|
isFilterValid.set(true);
|
||||||
|
Console.log("Custom log: {}", boundSql.getSql());
|
||||||
|
});
|
||||||
|
|
||||||
|
final Db db = Db.of(dbConfig);
|
||||||
|
|
||||||
|
final List<Entity> find = db.query("select * from user where age = ?", 18);
|
||||||
|
Assertions.assertEquals("王五", find.get(0).get("name"));
|
||||||
|
|
||||||
|
Assertions.assertTrue(isFilterValid.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user