Closed JoyceLikeRose closed 3 years ago
你自己可以加上,检验没有问题,再合并到项目中去。
关于光连接池 我做了一个验证例子
分享测试性代码
public class SavePointTest {
public static void main(String[] ags) throws Exception {
testHikari();
testBeeCP();
}
private static void testHikari() throws Exception {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost/test");
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setUsername("root");
config.setPassword("");
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setConnectionTimeout(8000);
config.setConnectionTestQuery("select 1 from dual");
config.setAutoCommit(false);
HikariDataSource dataSource = new HikariDataSource(config);
Connection conn = dataSource.getConnection();
testSavepoint(conn, "Hikari");
conn = dataSource.getConnection();
conn.setAutoCommit(true);
conn.close();
}
private static void testBeeCP() throws Exception {
BeeDataSourceConfig config = new BeeDataSourceConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl("jdbc:mysql://localhost/test");
config.setUsername("root");
config.setPassword("");
config.setMaxActive(1);
config.setInitialSize(1);
config.setMaxWait(8000);
config.setDefaultAutoCommit(false);
BeeDataSource dataSource = new BeeDataSource(config);
Connection conn = dataSource.getConnection();
testSavepoint(conn, "BeeCP");
conn = dataSource.getConnection();
conn.setAutoCommit(true);
conn.close();
}
public static void testSavepoint(Connection conn, String dsName) throws SQLException {
Statement ptmt = null;
Savepoint save1 = null;
Savepoint save2 = null;
Savepoint save3 = null;
try {
conn.setAutoCommit(false);
ptmt = conn.createStatement();
ptmt.execute("insert into SAVE_POINT(DS_NAME) values('" + dsName + "_0')");
save1 = conn.setSavepoint("1");
ptmt.execute("insert into SAVE_POINT(DS_NAME) values('" + dsName + "_1')");
save2 = conn.setSavepoint("2");
ptmt.execute("insert into SAVE_POINT(DS_NAME) values('" + dsName + "_2')");
save3 = conn.setSavepoint("3");
ptmt.execute("insert into SAVE_POINT(DS_NAME) values('" + dsName + "_3')");
conn.rollback(save1);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ptmt != null)
ptmt.close();
if (conn != null)
conn.close();
}
}
}
执行前
执行后
BeeCP没有将rollback(SavePoint)方法与事务脏标记关联,因此运行上去代码是没有问题的,如果光连接池取消的话,上述代码是可以通过的。
我看到光连接池有支持,BeeCP没有,您能增加一下吗?