Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,11 @@ void updateSession(StatementClient client)
}
}

void removePreparedStatement(String name)
{
preparedStatements.remove(name);
}

WarningsManager getWarningsManager()
{
return warningsManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class PrestoPreparedStatement
public void close()
throws SQLException
{
super.execute(format("DEALLOCATE PREPARE %s", statementName));
optionalConnection().ifPresent(x -> x.removePreparedStatement(statementName));
super.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ protected final PrestoConnection connection()
return connection;
}

protected final Optional<PrestoConnection> optionalConnection()
{
return Optional.ofNullable(connection.get());
}

private void closeResultSet()
throws SQLException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,17 @@ private void assertParameter(Object expectedValue, int expectedSqlType, Binder b
}
}

@Test
public void testCloseIdempotency()
throws Exception
{
try (Connection connection = createConnection()) {
PreparedStatement statement = connection.prepareStatement("SELECT 123");
statement.close();
statement.close();
}
}

private interface Binder
{
void bind(PreparedStatement ps, int i)
Expand Down