mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -55,7 +55,7 @@ public class DialectFactory {
|
||||
public final static String DRIVER_DM7 = "dm.jdbc.driver.DmDriver";
|
||||
|
||||
private static Map<DataSource, Dialect> dialectPool = new ConcurrentHashMap<>();
|
||||
private static Object lock = new Object();
|
||||
private static final Object lock = new Object();
|
||||
|
||||
private DialectFactory() {
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ public class DriverUtil {
|
||||
}
|
||||
|
||||
Connection conn = null;
|
||||
String driver = null;
|
||||
String driver;
|
||||
try {
|
||||
try {
|
||||
conn = ds.getConnection();
|
||||
@@ -69,7 +69,7 @@ public class DriverUtil {
|
||||
* @throws DbRuntimeException SQL异常包装,获取元数据信息失败
|
||||
*/
|
||||
public static String identifyDriver(Connection conn) throws DbRuntimeException {
|
||||
String driver = null;
|
||||
String driver;
|
||||
DatabaseMetaData meta;
|
||||
try {
|
||||
meta = conn.getMetaData();
|
||||
|
@@ -12,7 +12,7 @@ import cn.hutool.log.StaticLog;
|
||||
public class GlobalDSFactory {
|
||||
|
||||
private static volatile DSFactory factory;
|
||||
private static Object lock = new Object();
|
||||
private static final Object lock = new Object();
|
||||
|
||||
/*
|
||||
* 设置在JVM关闭时关闭所有数据库连接
|
||||
|
@@ -37,7 +37,7 @@ public class ConcurentTest {
|
||||
ThreadUtil.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<Entity> find = null;
|
||||
List<Entity> find;
|
||||
try {
|
||||
find = db.find(CollectionUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
} catch (SQLException e) {
|
||||
|
@@ -33,23 +33,19 @@ public class MySQLTest {
|
||||
* 事务测试<br>
|
||||
* 更新三条信息,低2条后抛出异常,正常情况下三条都应该不变
|
||||
*
|
||||
* @throws SQLException
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
@Test(expected=SQLException.class)
|
||||
@Ignore
|
||||
public void txTest() throws SQLException {
|
||||
Db.use("mysql").tx(new VoidFunc1<Db>() {
|
||||
|
||||
@Override
|
||||
public void call(Db db) throws Exception {
|
||||
int update = db.update(Entity.create("user").set("text", "描述100"), Entity.create().set("id", 100));
|
||||
db.update(Entity.create("user").set("text", "描述101"), Entity.create().set("id", 101));
|
||||
if(1 == update) {
|
||||
// 手动指定异常,然后测试回滚触发
|
||||
throw new RuntimeException("Error");
|
||||
}
|
||||
db.update(Entity.create("user").set("text", "描述102"), Entity.create().set("id", 102));
|
||||
Db.use("mysql").tx(db -> {
|
||||
int update = db.update(Entity.create("user").set("text", "描述100"), Entity.create().set("id", 100));
|
||||
db.update(Entity.create("user").set("text", "描述101"), Entity.create().set("id", 101));
|
||||
if(1 == update) {
|
||||
// 手动指定异常,然后测试回滚触发
|
||||
throw new RuntimeException("Error");
|
||||
}
|
||||
db.update(Entity.create("user").set("text", "描述102"), Entity.create().set("id", 102));
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -1,14 +1,11 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.db.Db;
|
||||
import cn.hutool.db.Entity;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UpdateTest {
|
||||
|
||||
@@ -22,7 +19,7 @@ public class UpdateTest {
|
||||
/**
|
||||
* 对更新做单元测试
|
||||
*
|
||||
* @throws SQLException
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
|
Reference in New Issue
Block a user