mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 00:44:19 +01:00
Implement isValid
This commit is contained in:
@@ -205,14 +205,15 @@ public class JDBC4Connection extends LimboConnection {
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||
throws SQLException {
|
||||
return prepareStatement(sql, resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
throws SQLException {
|
||||
return prepareStatement(
|
||||
sql, resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(
|
||||
String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
checkOpen();
|
||||
checkCursor(resultSetType, resultSetConcurrency, resultSetHoldability);
|
||||
return new JDBC4PreparedStatement(this, sql);
|
||||
@@ -258,8 +259,13 @@ public class JDBC4Connection extends LimboConnection {
|
||||
|
||||
@Override
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
// TODO
|
||||
return false;
|
||||
if (isClosed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try (Statement statement = createStatement()) {
|
||||
return statement.execute("select 1;");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,4 +84,15 @@ class JDBC4ConnectionTest {
|
||||
connection.createStatement(
|
||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isValid_should_return_true_on_open_connection() throws SQLException {
|
||||
assertTrue(connection.isValid(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void isValid_should_return_false_on_closed_connection() throws SQLException {
|
||||
connection.close();
|
||||
assertFalse(connection.isValid(10));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user