Implement isValid

This commit is contained in:
김선우
2025-02-09 17:28:32 +09:00
parent 4e067b2997
commit 968ae74810
2 changed files with 23 additions and 6 deletions

View File

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

View File

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