Skip to content
Merged
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 @@ -187,10 +187,11 @@ public void setAutoCommit(boolean autoCommit)
throws SQLException
{
checkOpen();
boolean wasAutoCommit = this.autoCommit.getAndSet(autoCommit);
boolean wasAutoCommit = this.autoCommit.get();
if (autoCommit && !wasAutoCommit) {
commit();
}
this.autoCommit.set(autoCommit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,85 @@ public void teardownServer()
public void testCommit()
throws SQLException
{
try (Connection connection = createConnection()) {
connection.setAutoCommit(false);
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE test_commit (x bigint)");
try {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to see in github, but the only thing that's changed about this test is that it's wrapped in an extra try so I could put a finally at the end to drop the table.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A neat trick is to take the url in the browser and add the query parameter ?w=1, which will cause whitespaces to be ignored. e.g. https://github.com/prestodb/presto/pull/23453/files?w=1

try (Connection connection = createConnection()) {
connection.setAutoCommit(false);
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE test_commit (x bigint)");
}

try (Connection otherConnection = createConnection()) {
assertThat(listTables(otherConnection)).doesNotContain("test_commit");
}

connection.commit();
}

try (Connection otherConnection = createConnection()) {
assertThat(listTables(otherConnection)).doesNotContain("test_commit");
try (Connection connection = createConnection()) {
assertThat(listTables(connection)).contains("test_commit");
}
}
finally {
try (Connection connection = createConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE test_commit");
}
}
}
}

@Test
public void testAutoCommit()
throws SQLException
{
try {
try (Connection connection = createConnection()) {
connection.setAutoCommit(true);
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE test_autocommit (x bigint)");
}
}

connection.commit();
try (Connection connection = createConnection()) {
assertThat(listTables(connection)).contains("test_autocommit");
}
}
finally {
try (Connection connection = createConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE test_autocommit");
}
}
}
}

try (Connection connection = createConnection()) {
assertThat(listTables(connection)).contains("test_commit");
@Test
public void testResetAutoCommit()
throws SQLException
{
try {
try (Connection connection = createConnection()) {
connection.setAutoCommit(false);
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE TABLE test_reset_autocommit (x bigint)");
}

try (Connection otherConnection = createConnection()) {
assertThat(listTables(otherConnection)).doesNotContain("test_reset_autocommit");
}
connection.setAutoCommit(true);
}

try (Connection connection = createConnection()) {
assertThat(listTables(connection)).contains("test_reset_autocommit");
}
}
finally {
try (Connection connection = createConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("DROP TABLE test_reset_autocommit");
}
}
}
}

Expand Down