Skip to content

Commit 2444e20

Browse files
committed
#65 - isClose() on IDLE connection throws SQLException - Flyway is using isClosed()
1 parent e290571 commit 2444e20

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ public void setTransactionIsolation(int level) throws SQLException {
524524
}
525525
}
526526

527+
@Override
528+
public boolean isClosed() throws SQLException {
529+
return status == STATUS_IDLE ? true : connection.isClosed();
530+
}
531+
527532
//
528533
//
529534
// Simple wrapper methods which pass a method call onto the acutal
@@ -601,14 +606,6 @@ public SQLWarning getWarnings() throws SQLException {
601606
return connection.getWarnings();
602607
}
603608

604-
@Override
605-
public boolean isClosed() throws SQLException {
606-
if (status == STATUS_IDLE) {
607-
throw new SQLException(IDLE_CONNECTION_ACCESSED_ERROR + "isClosed()");
608-
}
609-
return connection.isClosed();
610-
}
611-
612609
@Override
613610
public boolean isReadOnly() throws SQLException {
614611
if (status == STATUS_IDLE) {

ebean-datasource/src/test/java/io/ebean/datasource/pool/ConnectionPoolTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
1313

14-
public class ConnectionPoolTest {
14+
class ConnectionPoolTest {
1515

1616
private ConnectionPool pool;
1717

@@ -20,7 +20,6 @@ public class ConnectionPoolTest {
2020
}
2121

2222
private ConnectionPool createPool() {
23-
2423
DataSourceConfig config = new DataSourceConfig();
2524
config.setUrl("jdbc:h2:mem:tests");
2625
config.setUsername("sa");
@@ -32,13 +31,12 @@ private ConnectionPool createPool() {
3231
}
3332

3433
@AfterEach
35-
public void after() {
34+
void after() {
3635
pool.shutdown();
3736
}
3837

3938
@Test
40-
public void getConnection_expect_poolGrowsAboveMin() throws SQLException {
41-
39+
void getConnection_expect_poolGrowsAboveMin() throws SQLException {
4240
Connection con1 = pool.getConnection();
4341
Connection con2 = pool.getConnection();
4442

@@ -68,8 +66,7 @@ public void getConnection_expect_poolGrowsAboveMin() throws SQLException {
6866
}
6967

7068
@Test
71-
public void getConnection_explicitUserPassword() throws SQLException {
72-
69+
void getConnection_explicitUserPassword() throws SQLException {
7370
Connection connection = pool.getConnection("sa", "");
7471
PreparedStatement statement = connection.prepareStatement("create user testing password '123'");
7572
statement.execute();
@@ -81,8 +78,7 @@ public void getConnection_explicitUserPassword() throws SQLException {
8178
}
8279

8380
@Test
84-
public void unwrapConnection() throws SQLException {
85-
81+
void unwrapConnection() throws SQLException {
8682
Connection connection = pool.getConnection();
8783
Connection underlying = connection.unwrap(Connection.class);
8884

@@ -91,8 +87,7 @@ public void unwrapConnection() throws SQLException {
9187
}
9288

9389
@Test
94-
public void getDelegate() throws SQLException {
95-
90+
void getDelegate() throws SQLException {
9691
Connection connection = pool.getConnection();
9792
PooledConnection pc = (PooledConnection)connection;
9893
Connection underlying = pc.delegate();
@@ -102,7 +97,16 @@ public void getDelegate() throws SQLException {
10297
}
10398

10499
@Test
105-
public void testSchemaSwitch() throws SQLException {
100+
void isClosed_afterClose() throws SQLException {
101+
Connection connection = pool.getConnection();
102+
assertThat(connection.isClosed()).isFalse();
103+
104+
connection.close();
105+
assertThat(connection.isClosed()).isTrue();
106+
}
107+
108+
@Test
109+
void testSchemaSwitch() throws SQLException {
106110
Connection conn = pool.getConnection();
107111
Statement stmt = conn.createStatement();
108112
stmt.executeUpdate("CREATE SCHEMA TENANT_1");

0 commit comments

Comments
 (0)