Skip to content

Commit d425c15

Browse files
committed
#32 - Add detection of read-only errors that should reset the pool
1 parent 773ebdf commit d425c15

7 files changed

Lines changed: 95 additions & 61 deletions

File tree

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>io.ebean</groupId>
1212
<artifactId>ebean-datasource</artifactId>
13-
<version>4.7.4-SNAPSHOT</version>
13+
<version>4.8.1-SNAPSHOT</version>
1414

1515
<scm>
1616
<developerConnection>scm:git:git@github.com:ebean-orm/ebean-datasource.git</developerConnection>
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>io.ebean</groupId>
2424
<artifactId>ebean-datasource-api</artifactId>
25-
<version>4.7</version>
25+
<version>4.8</version>
2626
</dependency>
2727

2828
<dependency>
@@ -43,14 +43,14 @@
4343
<dependency>
4444
<groupId>io.ebean.test</groupId>
4545
<artifactId>ebean-test-docker</artifactId>
46-
<version>2.2.2</version>
46+
<version>3.1.5</version>
4747
<scope>test</scope>
4848
</dependency>
4949

5050
<dependency>
5151
<groupId>org.postgresql</groupId>
5252
<artifactId>postgresql</artifactId>
53-
<version>42.2.5</version>
53+
<version>42.2.11</version>
5454
<scope>test</scope>
5555
</dependency>
5656

src/main/java/io/ebean/datasource/pool/ConnectionPool.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,12 @@ private void returnTheConnection(PooledConnection pooledConnection, boolean forc
676676
}
677677
}
678678

679+
void returnConnectionReset(PooledConnection pooledConnection) {
680+
queue.returnPooledConnection(pooledConnection, true);
681+
logger.warn("Resetting DataSourcePool on read-only failure [{}]", name);
682+
reset();
683+
}
684+
679685
/**
680686
* Returns information describing connections that are currently being used.
681687
*/

src/main/java/io/ebean/datasource/pool/ExtendedPreparedStatement.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,59 +96,59 @@ public void close() {
9696
public void addBatch() throws SQLException {
9797
try {
9898
delegate.addBatch();
99-
} catch (SQLException e) {
100-
pooledConnection.markWithError();
101-
throw e;
99+
} catch (SQLException ex) {
100+
pooledConnection.markWithError(ex);
101+
throw ex;
102102
}
103103
}
104104

105105
@Override
106106
public void clearParameters() throws SQLException {
107107
try {
108108
delegate.clearParameters();
109-
} catch (SQLException e) {
110-
pooledConnection.markWithError();
111-
throw e;
109+
} catch (SQLException ex) {
110+
pooledConnection.markWithError(ex);
111+
throw ex;
112112
}
113113
}
114114

115115
@Override
116116
public boolean execute() throws SQLException {
117117
try {
118118
return delegate.execute();
119-
} catch (SQLException e) {
120-
pooledConnection.markWithError();
121-
throw e;
119+
} catch (SQLException ex) {
120+
pooledConnection.markWithError(ex);
121+
throw ex;
122122
}
123123
}
124124

125125
@Override
126126
public ResultSet executeQuery() throws SQLException {
127127
try {
128128
return delegate.executeQuery();
129-
} catch (SQLException e) {
130-
pooledConnection.markWithError();
131-
throw e;
129+
} catch (SQLException ex) {
130+
pooledConnection.markWithError(ex);
131+
throw ex;
132132
}
133133
}
134134

135135
@Override
136136
public int executeUpdate() throws SQLException {
137137
try {
138138
return delegate.executeUpdate();
139-
} catch (SQLException e) {
140-
pooledConnection.markWithError();
141-
throw e;
139+
} catch (SQLException ex) {
140+
pooledConnection.markWithError(ex);
141+
throw ex;
142142
}
143143
}
144144

145145
@Override
146146
public ResultSetMetaData getMetaData() throws SQLException {
147147
try {
148148
return delegate.getMetaData();
149-
} catch (SQLException e) {
150-
pooledConnection.markWithError();
151-
throw e;
149+
} catch (SQLException ex) {
150+
pooledConnection.markWithError(ex);
151+
throw ex;
152152
}
153153
}
154154

src/main/java/io/ebean/datasource/pool/ExtendedStatement.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ abstract class ExtendedStatement extends PreparedStatementDelegator {
4242
public Connection getConnection() throws SQLException {
4343
try {
4444
return delegate.getConnection();
45-
} catch (SQLException e) {
46-
pooledConnection.markWithError();
47-
throw e;
45+
} catch (SQLException ex) {
46+
pooledConnection.markWithError(ex);
47+
throw ex;
4848
}
4949
}
5050

@@ -56,9 +56,9 @@ public void addBatch(String sql) throws SQLException {
5656
try {
5757
pooledConnection.setLastStatement(sql);
5858
delegate.addBatch(sql);
59-
} catch (SQLException e) {
60-
pooledConnection.markWithError();
61-
throw e;
59+
} catch (SQLException ex) {
60+
pooledConnection.markWithError(ex);
61+
throw ex;
6262
}
6363
}
6464

@@ -70,9 +70,9 @@ public boolean execute(String sql) throws SQLException {
7070
try {
7171
pooledConnection.setLastStatement(sql);
7272
return delegate.execute(sql);
73-
} catch (SQLException e) {
74-
pooledConnection.markWithError();
75-
throw e;
73+
} catch (SQLException ex) {
74+
pooledConnection.markWithError(ex);
75+
throw ex;
7676
}
7777
}
7878

@@ -84,9 +84,9 @@ public ResultSet executeQuery(String sql) throws SQLException {
8484
try {
8585
pooledConnection.setLastStatement(sql);
8686
return delegate.executeQuery(sql);
87-
} catch (SQLException e) {
88-
pooledConnection.markWithError();
89-
throw e;
87+
} catch (SQLException ex) {
88+
pooledConnection.markWithError(ex);
89+
throw ex;
9090
}
9191
}
9292

@@ -98,9 +98,9 @@ public int executeUpdate(String sql) throws SQLException {
9898
try {
9999
pooledConnection.setLastStatement(sql);
100100
return delegate.executeUpdate(sql);
101-
} catch (SQLException e) {
102-
pooledConnection.markWithError();
103-
throw e;
101+
} catch (SQLException ex) {
102+
pooledConnection.markWithError(ex);
103+
throw ex;
104104
}
105105
}
106106

0 commit comments

Comments
 (0)