This commit is contained in:
Looly
2020-04-04 01:34:54 +08:00
parent 6b13cb5263
commit 24a300e348
36 changed files with 228 additions and 380 deletions

View File

@@ -1,16 +1,5 @@
package cn.hutool.db;
import java.io.Closeable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import cn.hutool.db.dialect.Dialect;
@@ -22,6 +11,11 @@ import cn.hutool.log.LogFactory;
import cn.hutool.log.level.Level;
import cn.hutool.setting.Setting;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
/**
* 数据库操作工具类
*
@@ -156,31 +150,12 @@ public final class DbUtil {
*
* @param objsToClose 需要关闭的对象
*/
@SuppressWarnings("ConstantConditions")
public static void close(Object... objsToClose) {
for (Object obj : objsToClose) {
if (obj instanceof AutoCloseable) {
IoUtil.close((AutoCloseable) obj);
} else if (obj instanceof Closeable) {
IoUtil.close((Closeable) obj);
} else {
try {
if (obj != null) {
if (obj instanceof ResultSet) {
((ResultSet) obj).close();
} else if (obj instanceof Statement) {
((Statement) obj).close();
} else if (obj instanceof PreparedStatement) {
((PreparedStatement) obj).close();
} else if (obj instanceof Connection) {
((Connection) obj).close();
} else {
log.warn("Object {} not a ResultSet or Statement or PreparedStatement or Connection!", obj.getClass().getName());
}
}
} catch (SQLException e) {
// ignore
}
log.warn("Object {} not a ResultSet or Statement or PreparedStatement or Connection!", obj.getClass().getName());
}
}
}

View File

@@ -1,13 +1,5 @@
package cn.hutool.db;
import java.io.Closeable;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
import javax.sql.DataSource;
import cn.hutool.core.lang.func.VoidFunc0;
import cn.hutool.core.lang.func.VoidFunc1;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.dialect.Dialect;
@@ -17,6 +9,12 @@ import cn.hutool.db.sql.Wrapper;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import javax.sql.DataSource;
import java.io.Closeable;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
/**
* 数据库SQL执行会话<br>
* 会话通过共用Connection而可以实现JDBC事务<br>
@@ -246,7 +244,7 @@ public class Session extends AbstractDb implements Closeable {
}
/**
* 在事务中执行操作,通过实现{@link VoidFunc0}接口的call方法执行多条SQL语句从而完成事务
* 在事务中执行操作,通过实现{@link VoidFunc1}接口的call方法执行多条SQL语句从而完成事务
*
* @param func 函数抽象在函数中执行多个SQL操作多个操作会被合并为同一事务
* @throws SQLException SQL异常
@@ -264,7 +262,7 @@ public class Session extends AbstractDb implements Closeable {
}
/**
* 在事务中执行操作,通过实现{@link VoidFunc0}接口的call方法执行多条SQL语句从而完成事务
* 在事务中执行操作,通过实现{@link VoidFunc1}接口的call方法执行多条SQL语句从而完成事务
*
* @param func 函数抽象在函数中执行多个SQL操作多个操作会被合并为同一事务
* @since 3.2.3

View File

@@ -148,7 +148,6 @@ public class HandleHelper {
* @since 3.3.1
*/
public static <T extends Entity> T handleRow(T row, int columnCount, ResultSetMetaData meta, ResultSet rs, boolean withMetaInfo) throws SQLException {
String columnLabel;
int type;
for (int i = 1; i <= columnCount; i++) {
type = meta.getColumnType(i);

View File

@@ -353,17 +353,6 @@ public class MongoDS implements Closeable {
log.debug("MongoDB connectionsPerHost: {}", connectionsPerHost);
}
// multiplier for connectionsPerHost for # of threads that can block if connectionsPerHost is 10, and threadsAllowedToBlockForConnectionMultiplier is 5, then 50 threads can block more than
// that and an exception will be throw --int
Integer threadsAllowedToBlockForConnectionMultiplier = setting.getInt(group + "threadsAllowedToBlockForConnectionMultiplier");
if (StrUtil.isBlank(group) == false && threadsAllowedToBlockForConnectionMultiplier == null) {
threadsAllowedToBlockForConnectionMultiplier = setting.getInt("threadsAllowedToBlockForConnectionMultiplier");
}
if (threadsAllowedToBlockForConnectionMultiplier != null) {
builder.threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);
log.debug("MongoDB threadsAllowedToBlockForConnectionMultiplier: {}", threadsAllowedToBlockForConnectionMultiplier);
}
// 被阻塞线程从连接池获取连接的最长等待时间ms --int
Integer connectTimeout = setting.getInt(group + "connectTimeout");
if (StrUtil.isBlank(group) == false && connectTimeout == null) {