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

Auto-Reconnect

上级 3d7f8f3a
......@@ -6,14 +6,13 @@
*/
package org.h2.result;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.h2.constant.ErrorCode;
import org.h2.engine.SessionInterface;
import org.h2.jdbc.JdbcConnection;
import org.h2.message.Message;
import org.h2.util.JdbcUtils;
import org.h2.util.ObjectArray;
......@@ -28,8 +27,7 @@ import org.h2.value.ValueNull;
*/
public class UpdatableRow {
private final SessionInterface session;
private final Connection conn;
private final JdbcConnection conn;
private final DatabaseMetaData meta;
private final ResultInterface result;
private final int columnCount;
......@@ -44,13 +42,11 @@ public class UpdatableRow {
*
* @param conn the database connection
* @param result the result
* @param session the session
*/
public UpdatableRow(Connection conn, ResultInterface result, SessionInterface session) throws SQLException {
public UpdatableRow(JdbcConnection conn, ResultInterface result) throws SQLException {
this.conn = conn;
this.meta = conn.getMetaData();
this.result = result;
this.session = session;
columnCount = result.getVisibleColumnCount();
for (int i = 0; i < columnCount; i++) {
String t = result.getTableName(i);
......@@ -197,7 +193,7 @@ public class UpdatableRow {
Value[] newRow = new Value[columnCount];
for (int i = 0; i < columnCount; i++) {
int type = result.getColumnType(i);
newRow[i] = DataType.readValue(session, rs, i + 1, type);
newRow[i] = DataType.readValue(conn.getSession(), rs, i + 1, type);
}
return newRow;
}
......
......@@ -963,9 +963,9 @@ public class DataType {
public static Object convertTo(SessionInterface session, JdbcConnection conn, Value v, Class paramClass)
throws SQLException {
if (paramClass == java.sql.Blob.class) {
return new JdbcBlob(session, conn, v, 0);
return new JdbcBlob(conn, v, 0);
} else if (paramClass == Clob.class) {
return new JdbcClob(session, conn, v, 0);
return new JdbcClob(conn, v, 0);
} else {
throw Message.getUnsupportedException();
}
......
......@@ -8,9 +8,11 @@ package org.h2.test.unit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.jdbc.JdbcConnection;
import org.h2.test.TestBase;
/**
......@@ -28,9 +30,36 @@ public class TestFileLockSerialized extends TestBase {
}
public void test() throws Exception {
testKillWriter();
testConcurrentReadWrite();
}
private void testKillWriter() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + baseDir + "/fileLockSerialized";
String writeUrl = url + ";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0";
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)");
((JdbcConnection) conn).setPowerOffCount(1);
try {
stat.execute("insert into test values(1)");
fail();
} catch (SQLException e) {
// ignore
}
Connection conn2 = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat2 = conn2.createStatement();
stat2.execute("insert into test values(1)");
printResult(stat2, "select * from test");
// TODO support long running queries
conn2.close();
}
private void testConcurrentReadWrite() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + baseDir + "/fileLockSerialized";
......@@ -45,7 +74,7 @@ public class TestFileLockSerialized extends TestBase {
stat.execute("create table test(id int primary key)");
Connection conn3 = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat3 = conn3.createStatement();
PreparedStatement prep3 = conn3.prepareStatement("insert into test values(?)");
Connection conn2 = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat2 = conn2.createStatement();
......@@ -57,7 +86,8 @@ public class TestFileLockSerialized extends TestBase {
trace("insert row 1");
stat.execute("insert into test values(1)");
trace("insert row 2");
stat3.execute("insert into test values(2)");
prep3.setInt(1, 2);
prep3.execute();
printResult(stat2, "select * from test");
printResult(stat2, "select * from temp");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论