add query method

This commit is contained in:
Looly 2020-01-11 19:37:36 +08:00
parent 33c3d12cbb
commit cc74ae34a2
5 changed files with 30 additions and 3 deletions

View File

@ -18,6 +18,8 @@
* 【core 】 QrCodeUtil增加背景透明支持pr#89@Gitee
* 【core 】 增加农历ChineseDatepr#90@Gitee
* 【core 】 ZipUtil增加zip方法写出到流issue#I17SCT@Gitee
* 【db 】 Db.use().query的方法中增加Map参数接口issue#709@Github
* 【db 】 getDialect使用数据源作为锁issue#720@Github
### Bug修复
* 【core 】 修复NumberUtil.mul中null的结果错误问题issue#I17Y4J@Gitee

View File

@ -45,6 +45,7 @@ public class AsymmetricCrypto extends AbstractAsymmetricCrypto<AsymmetricCrypto>
*
* @param algorithm {@link SymmetricAlgorithm}
*/
@SuppressWarnings("RedundantCast")
public AsymmetricCrypto(AsymmetricAlgorithm algorithm) {
this(algorithm, (byte[]) null, (byte[]) null);
}
@ -54,6 +55,7 @@ public class AsymmetricCrypto extends AbstractAsymmetricCrypto<AsymmetricCrypto>
*
* @param algorithm 算法
*/
@SuppressWarnings("RedundantCast")
public AsymmetricCrypto(String algorithm) {
this(algorithm, (byte[]) null, (byte[]) null);
}

View File

@ -5,6 +5,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
@ -154,6 +155,27 @@ public abstract class AbstractDb implements Serializable {
}
}
/**
* 支持占位符的查询例如select * from table where field1=:name1
*
* @param <T> 结果集需要处理的对象类型
* @param sql 查询语句使用参数名占位符例如:name
* @param rsh 结果集处理对象
* @param paramMap 参数
* @return 结果对象
* @throws SQLException SQL执行异常
* @since 5.1.1
*/
public <T> T query(String sql, RsHandler<T> rsh, Map<String, Object> paramMap) throws SQLException {
Connection conn = null;
try {
conn = this.getConnection();
return SqlExecutor.query(conn, sql, rsh, paramMap);
} finally {
this.closeConnection(conn);
}
}
/**
* 执行非查询语句<br>
* 语句包括 插入更新删除

View File

@ -55,7 +55,6 @@ public class DialectFactory {
public final static String DRIVER_DM7 = "dm.jdbc.driver.DmDriver";
private static Map<DataSource, Dialect> dialectPool = new ConcurrentHashMap<>();
private static final Object lock = new Object();
private DialectFactory() {
}
@ -153,7 +152,9 @@ public class DialectFactory {
public static Dialect getDialect(DataSource ds) {
Dialect dialect = dialectPool.get(ds);
if(null == dialect) {
synchronized (lock) {
// 数据源作为锁的意义在于不同数据源不会导致阻塞相同数据源获取方言时可保证互斥
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (ds) {
dialect = dialectPool.get(ds);
if(null == dialect) {
dialect = newDialect(ds);

View File

@ -220,7 +220,7 @@ public class SqlExecutor {
}
/**
* 执行查询语句<br>
* 执行查询语句例如select * from table where field1=:name1 <br>
* 此方法不会关闭Connection
*
* @param <T> 处理结果类型