Skip to content

Commit 4cdec8a

Browse files
committed
#8 - ENH: Support 3.1 API with read-only configuration support
1 parent 28a539d commit 4cdec8a

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010

1111
<artifactId>avaje-datasource</artifactId>
12-
<version>2.1.2-SNAPSHOT</version>
12+
<version>3.1.1-SNAPSHOT</version>
1313

1414
<scm>
1515
<developerConnection>scm:git:git@github.com:ebean-orm/avaje-datasource.git</developerConnection>
@@ -21,13 +21,13 @@
2121
<dependency>
2222
<groupId>org.avaje</groupId>
2323
<artifactId>avaje-datasource-api</artifactId>
24-
<version>1.1</version>
24+
<version>3.1</version>
2525
</dependency>
2626

2727
<dependency>
2828
<groupId>org.slf4j</groupId>
2929
<artifactId>slf4j-api</artifactId>
30-
<version>[1.7.12,)</version>
30+
<version>1.7.12</version>
3131
<scope>provided</scope>
3232
</dependency>
3333

src/main/java/org/avaje/datasource/pool/ConnectionPool.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public class ConnectionPool implements DataSourcePool {
9292
*/
9393
private final boolean autoCommit;
9494

95+
private final boolean readOnly;
96+
9597
/**
9698
* Max idle time in millis.
9799
*/
@@ -177,6 +179,7 @@ public ConnectionPool(String name, DataSourceConfig params) {
177179
this.poolListener = params.getListener();
178180

179181
this.autoCommit = params.isAutoCommit();
182+
this.readOnly = params.isReadOnly();
180183
this.transactionIsolation = params.getIsolationLevel();
181184

182185
this.maxInactiveMillis = 1000 * params.getMaxInactiveTimeSecs();
@@ -429,6 +432,9 @@ public Connection createUnpooledConnection() throws SQLException {
429432
Connection conn = DriverManager.getConnection(databaseUrl, connectionProps);
430433
conn.setAutoCommit(autoCommit);
431434
conn.setTransactionIsolation(transactionIsolation);
435+
if (readOnly) {
436+
conn.setReadOnly(readOnly);
437+
}
432438
return conn;
433439

434440
} catch (SQLException ex) {

src/main/java/org/avaje/datasource/pool/FreeConnectionBuffer.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FreeConnectionBuffer {
2222
/**
2323
* Buffer oriented for add and remove.
2424
*/
25-
private final LinkedList<PooledConnection> freeBuffer = new LinkedList<PooledConnection>();
25+
private final LinkedList<PooledConnection> freeBuffer = new LinkedList<>();
2626

2727
FreeConnectionBuffer() {
2828
}
@@ -61,12 +61,10 @@ PooledConnection remove() {
6161
void closeAll(boolean logErrors) {
6262

6363
// create a temporary list
64-
List<PooledConnection> tempList = new ArrayList<PooledConnection>(freeBuffer.size());
64+
List<PooledConnection> tempList = new ArrayList<>(freeBuffer.size());
6565

6666
// add all the connections into it
67-
for (PooledConnection c : freeBuffer) {
68-
tempList.add(c);
69-
}
67+
tempList.addAll(freeBuffer);
7068

7169
// clear the buffer (in case it takes some time to close these connections).
7270
freeBuffer.clear();

src/main/java/org/avaje/datasource/pool/PooledConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public class PooledConnection extends ConnectionDelegator {
127127
*/
128128
private boolean hadErrors;
129129

130+
private boolean resetAutoCommit;
131+
130132
/**
131133
* The last start time. When the connection was given to a thread.
132134
*/
@@ -484,8 +486,9 @@ public void close() throws SQLException {
484486

485487
try {
486488
// reset the autoCommit back if client code changed it
487-
if (connection.getAutoCommit() != pool.isAutoCommit()) {
489+
if (resetAutoCommit) {
488490
connection.setAutoCommit(pool.isAutoCommit());
491+
resetAutoCommit = false;
489492
}
490493
// Generally resetting Isolation level seems expensive.
491494
// Hence using resetIsolationReadOnlyRequired flag
@@ -769,6 +772,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
769772
}
770773
try {
771774
connection.setAutoCommit(autoCommit);
775+
resetAutoCommit = true;
772776
} catch (SQLException ex) {
773777
markWithError();
774778
throw ex;

0 commit comments

Comments
 (0)