提交 cdcdbbc0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Cluster: The SQL statement SET AUTOCOMMIT FALSE doesn't work. This limitation is…

Cluster: The SQL statement SET AUTOCOMMIT FALSE doesn't work. This limitation is now documented. Issue 259.
上级 e9df482d
......@@ -373,6 +373,10 @@ When using the cluster modes, result sets are read fully in memory by the client
there is no problem if the server dies that executed the query. Result sets must fit in memory
on the client side.
</p>
<p>
The SQL statement <code>SET AUTOCOMMIT FALSE</code> is not supported in the cluster mode.
To disable autocommit, the method <code>Connection.setAutoCommit(false)</code> needs to be called.
</p>
<h2 id="two_phase_commit">Two Phase Commit</h2>
<p>
......
......@@ -18,7 +18,12 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Connection pool / DataSource: a NullPointerException was thrown when
<ul><li>The Shell tool can now enable, disable, and display the current autocommit mode.
</li><li>There is a limitation in the cluster mode:
The SQL statement SET AUTOCOMMIT FALSE doesn't work.
To disable autocommit, the method Connection.setAutoCommit(false) needs to be called.
This is now documented. See also issue 259.
</li><li>Connection pool / DataSource: a NullPointerException was thrown when
using a database URL that doesn't start with "jdbc:h2:".
</li><li>Using the java.sql.Blob or java.sql.Clob interfaces could throw the wrong
exception after the object was closed.
......
......@@ -35,11 +35,57 @@ public class TestCluster extends TestBase {
}
public void test() throws Exception {
testRollback();
testCase();
testCreateClusterAtRuntime();
testStartStopCluster();
}
private void testRollback() throws SQLException {
if (config.memory || config.networked || config.cipher != null) {
return;
}
int port1 = 9191, port2 = 9192;
String serverList = "localhost:" + port1 + ",localhost:" + port2;
deleteFiles();
org.h2.Driver.load();
String user = getUser(), password = getPassword();
Connection conn;
Statement stat;
ResultSet rs;
String url1 = "jdbc:h2:tcp://localhost:" + port1 + "/test";
String url2 = "jdbc:h2:tcp://localhost:" + port2 + "/test";
String urlCluster = "jdbc:h2:tcp://" + serverList + "/test";
Server n1 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port1, "-baseDir", getBaseDir() + "/node1").start();
Server n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2 , "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, "-user", user, "-password", password, "-serverList",
serverList);
conn = DriverManager.getConnection(urlCluster, user, password);
stat = conn.createStatement();
assertTrue(conn.getAutoCommit());
stat.execute("create table test(id int, name varchar)");
assertTrue(conn.getAutoCommit());
stat.execute("set autocommit false");
// issue 259
// assertFalse(conn.getAutoCommit());
conn.setAutoCommit(false);
assertFalse(conn.getAutoCommit());
stat.execute("insert into test values(1, 'Hello')");
stat.execute("rollback");
rs = stat.executeQuery("select * from test order by id");
assertFalse(rs.next());
conn.close();
n1.stop();
n2.stop();
deleteFiles();
}
private void testCase() throws SQLException {
if (config.memory || config.networked || config.cipher != null) {
return;
......@@ -52,6 +98,8 @@ public class TestCluster extends TestBase {
String user = getUser(), password = getPassword();
Connection conn;
Statement stat;
ResultSet rs;
String url1 = "jdbc:h2:tcp://localhost:" + port1 + "/test";
String url2 = "jdbc:h2:tcp://localhost:" + port2 + "/test";
String urlCluster = "jdbc:h2:tcp://" + serverList + "/test";
......@@ -73,6 +121,9 @@ public class TestCluster extends TestBase {
stat.execute("insert into test values(2)");
assertFalse(conn.getAutoCommit());
conn.rollback();
rs = stat.executeQuery("select * from test order by name");
assertTrue(rs.next());
assertFalse(rs.next());
conn.close();
// stop server 2, and test if only one server is available
......@@ -80,7 +131,7 @@ public class TestCluster extends TestBase {
conn = DriverManager.getConnection(urlCluster, user, password);
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from test");
rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
conn.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论