This commit is contained in:
Looly
2019-10-29 19:53:17 +08:00
parent f9ee2af71c
commit e754ec3e86
45 changed files with 172 additions and 179 deletions

View File

@@ -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() {
}

View File

@@ -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();

View File

@@ -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关闭时关闭所有数据库连接

View File

@@ -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) {

View File

@@ -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));
});
}

View File

@@ -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