Skip to content

Commit c5550f3

Browse files
authored
Compile to Java 11, use System.Logger (#51)
* Compile to Java 11, use System.Logger * Oops, bump to java11-oss parent * Use correct log message format for System.Logger * Use correct log message format for System.Logger
1 parent c0d0242 commit c5550f3

17 files changed

Lines changed: 116 additions & 126 deletions

File tree

ebean-datasource-api/pom.xml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<artifactId>ebean-datasource-parent</artifactId>
55
<groupId>io.ebean</groupId>
6-
<version>7.6-SNAPSHOT</version>
6+
<version>8.0-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99

@@ -14,37 +14,12 @@
1414
<dependencies>
1515

1616
<dependency>
17-
<groupId>org.slf4j</groupId>
18-
<artifactId>slf4j-api</artifactId>
19-
<version>1.7.36</version>
20-
<scope>provided</scope>
17+
<groupId>io.avaje</groupId>
18+
<artifactId>junit</artifactId>
19+
<version>1.1</version>
20+
<scope>test</scope>
2121
</dependency>
2222

2323
</dependencies>
2424

25-
<build>
26-
<plugins>
27-
<plugin>
28-
<groupId>org.moditect</groupId>
29-
<artifactId>moditect-maven-plugin</artifactId>
30-
<version>1.0.0.RC1</version>
31-
<executions>
32-
<execution>
33-
<id>add-module-infos</id>
34-
<phase>package</phase>
35-
<goals>
36-
<goal>add-module-info</goal>
37-
</goals>
38-
<configuration>
39-
<jvmVersion>9</jvmVersion>
40-
<module>
41-
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
42-
</module>
43-
</configuration>
44-
</execution>
45-
</executions>
46-
</plugin>
47-
</plugins>
48-
</build>
49-
5025
</project>

ebean-datasource-api/src/main/java/io/ebean/datasource/PostgresInitDatabase.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.ebean.datasource;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
5-
63
import java.sql.Connection;
74
import java.sql.PreparedStatement;
85
import java.sql.SQLException;
@@ -12,13 +9,13 @@
129
*/
1310
public class PostgresInitDatabase implements InitDatabase {
1411

15-
private static final Logger log = LoggerFactory.getLogger("io.ebean.datasource");
12+
private static final System.Logger log = System.getLogger("io.ebean.datasource");
1613

1714
@Override
1815
public void run(Connection connection, DataSourceConfig config) throws SQLException {
1916
String username = config.getUsername();
2017
String password = config.getPassword();
21-
log.info("Creating schema and role for {}", username);
18+
log.log(System.Logger.Level.INFO, "Creating schema and role for {0}", username);
2219
execute(connection, String.format("create schema if not exists %s", username));
2320
execute(connection, String.format("create role %s with login password '%s'", username, password));
2421
execute(connection, String.format("grant all on schema %s to %s", username, username));
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module io.ebean.datasource.api {
22

3-
requires transitive org.slf4j;
43
requires transitive java.sql;
54

65
uses io.ebean.datasource.DataSourceFactory;
76

87
exports io.ebean.datasource;
9-
}
8+
}

ebean-datasource/src/test/java/io/ebean/datasource/DataSourceConfigTest.java renamed to ebean-datasource-api/src/test/java/io/ebean/datasource/DataSourceConfigTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public void addProperty() {
2424
config.addProperty("useSSL", false);
2525
final Map<String, String> extra = config.getCustomProperties();
2626
assertThat(extra).hasSize(1);
27-
AssertionsForClassTypes.assertThat(extra.get("useSSL")).isEqualTo("false");
27+
assertThat(extra.get("useSSL")).isEqualTo("false");
2828

2929
config.addProperty("foo", 42);
30-
AssertionsForClassTypes.assertThat(extra.get("foo")).isEqualTo("42");
30+
assertThat(extra.get("foo")).isEqualTo("42");
3131

3232
config.addProperty("bar", "silly");
33-
AssertionsForClassTypes.assertThat(extra.get("bar")).isEqualTo("silly");
33+
assertThat(extra.get("bar")).isEqualTo("silly");
3434
assertThat(extra).hasSize(3);
3535
}
3636

@@ -41,9 +41,9 @@ public void parseCustom() {
4141
Map<String, String> map = config.parseCustom("a=1;b=2;c=3");
4242

4343
assertThat(map).hasSize(3);
44-
AssertionsForClassTypes.assertThat(map.get("a")).isEqualTo("1");
45-
AssertionsForClassTypes.assertThat(map.get("b")).isEqualTo("2");
46-
AssertionsForClassTypes.assertThat(map.get("c")).isEqualTo("3");
44+
assertThat(map.get("a")).isEqualTo("1");
45+
assertThat(map.get("b")).isEqualTo("2");
46+
assertThat(map.get("c")).isEqualTo("3");
4747
}
4848

4949
@Test

ebean-datasource/src/test/resources/example.properties renamed to ebean-datasource-api/src/test/resources/example.properties

File renamed without changes.

ebean-datasource/pom.xml

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.ebean</groupId>
77
<artifactId>ebean-datasource-parent</artifactId>
8-
<version>7.6-SNAPSHOT</version>
8+
<version>8.0-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>ebean-datasource</artifactId>
@@ -14,17 +14,10 @@
1414

1515
<dependencies>
1616

17-
<dependency>
18-
<groupId>org.slf4j</groupId>
19-
<artifactId>slf4j-api</artifactId>
20-
<version>1.7.36</version>
21-
<scope>provided</scope>
22-
</dependency>
23-
2417
<dependency>
2518
<groupId>io.ebean</groupId>
2619
<artifactId>ebean-datasource-api</artifactId>
27-
<version>7.6-SNAPSHOT</version>
20+
<version>8.0-SNAPSHOT</version>
2821
</dependency>
2922

3023
<dependency>
@@ -55,6 +48,13 @@
5548
<scope>test</scope>
5649
</dependency>
5750

51+
<dependency>
52+
<groupId>io.avaje</groupId>
53+
<artifactId>avaje-slf4j-jpl</artifactId>
54+
<version>1.1</version>
55+
<scope>test</scope>
56+
</dependency>
57+
5858
<!-- Override com.h2database version to get schema support -->
5959
<dependency>
6060
<groupId>com.h2database</groupId>
@@ -67,26 +67,16 @@
6767

6868
<build>
6969
<plugins>
70+
7071
<plugin>
71-
<groupId>org.moditect</groupId>
72-
<artifactId>moditect-maven-plugin</artifactId>
73-
<version>1.0.0.RC1</version>
74-
<executions>
75-
<execution>
76-
<id>add-module-infos</id>
77-
<phase>package</phase>
78-
<goals>
79-
<goal>add-module-info</goal>
80-
</goals>
81-
<configuration>
82-
<jvmVersion>9</jvmVersion>
83-
<module>
84-
<moduleInfoFile>src/main/java9/module-info.java</moduleInfoFile>
85-
</module>
86-
</configuration>
87-
</execution>
88-
</executions>
72+
<artifactId>maven-surefire-plugin</artifactId>
73+
<configuration>
74+
<argLine>
75+
--add-opens io.ebean.datasource/io.ebean.datasource.pool=ALL-UNNAMED
76+
</argLine>
77+
</configuration>
8978
</plugin>
79+
9080
</plugins>
9181
</build>
9282

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ boolean remove(PooledConnection pc) {
7373
int slotId = pc.getSlotId();
7474
if (slots[slotId] != pc) {
7575
PooledConnection heldBy = slots[slotId];
76-
Log.log.warn("Failed to remove from slot[{}] PooledConnection[{}] - HeldBy[{}]", pc.getSlotId(), pc, heldBy);
76+
Log.warn("Failed to remove from slot[{0}] PooledConnection[{1}] - HeldBy[{2}]", pc.getSlotId(), pc, heldBy);
7777
return false;
7878
}
7979
slots[slotId] = null;
@@ -86,7 +86,7 @@ boolean remove(PooledConnection pc) {
8686
*/
8787
void closeBusyConnections(long leakTimeMinutes) {
8888
long olderThanTime = System.currentTimeMillis() - (leakTimeMinutes * 60000);
89-
Log.log.debug("Closing busy connections using leakTimeMinutes {}", leakTimeMinutes);
89+
Log.debug("Closing busy connections using leakTimeMinutes {0}", leakTimeMinutes);
9090
for (int i = 0; i < slots.length; i++) {
9191
if (slots[i] != null) {
9292
//tmp.add(slots[i]);
@@ -106,11 +106,11 @@ void closeBusyConnections(long leakTimeMinutes) {
106106

107107
private void closeBusyConnection(PooledConnection pc) {
108108
try {
109-
Log.log.warn("DataSourcePool closing busy connection? " + pc.getFullDescription());
109+
Log.warn("DataSourcePool closing busy connection? {0}", pc.getFullDescription());
110110
System.out.println("CLOSING busy connection: " + pc.getFullDescription());
111111
pc.closeConnectionFully(false);
112112
} catch (Exception ex) {
113-
Log.log.error("Error when closing potentially leaked connection " + pc.getDescription(), ex);
113+
Log.error("Error when closing potentially leaked connection " + pc.getDescription(), ex);
114114
}
115115
}
116116

@@ -119,13 +119,13 @@ private void closeBusyConnection(PooledConnection pc) {
119119
*/
120120
String getBusyConnectionInformation(boolean toLogger) {
121121
if (toLogger) {
122-
Log.log.info("Dumping [{}] busy connections: (Use datasource.xxx.capturestacktrace=true ... to get stackTraces)", size());
122+
Log.info("Dumping [{0}] busy connections: (Use datasource.xxx.capturestacktrace=true ... to get stackTraces)", size());
123123
}
124124
StringBuilder sb = new StringBuilder();
125125
for (PooledConnection pc : slots) {
126126
if (pc != null) {
127127
if (toLogger) {
128-
Log.log.info("Busy Connection - {}", pc.getFullDescription());
128+
Log.info("Busy Connection - {0}", pc.getFullDescription());
129129
} else {
130130
sb.append(pc.getFullDescription()).append("\r\n");
131131
}

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.ebean.datasource.DataSourcePoolListener;
99
import io.ebean.datasource.InitDatabase;
1010
import io.ebean.datasource.PoolStatus;
11-
import org.slf4j.Logger;
1211

1312
import java.io.PrintWriter;
1413
import java.sql.Connection;
@@ -41,8 +40,6 @@
4140
*/
4241
public final class ConnectionPool implements DataSourcePool {
4342

44-
private static final Logger log = Log.log;
45-
4643
private final ReentrantLock heartbeatLock = new ReentrantLock(false);
4744
private final ReentrantLock notifyLock = new ReentrantLock(false);
4845
/**
@@ -198,7 +195,7 @@ private void tryEnsureMinimumConnections() throws SQLException {
198195
notify.dataSourceUp(this);
199196
}
200197
} catch (SQLException e) {
201-
log.error("Error trying to ensure minimum connections, maybe db server is down - message:" + e.getMessage(), e);
198+
Log.error("Error trying to ensure minimum connections, maybe db server is down - message:" + e.getMessage(), e);
202199
} finally {
203200
notifyLock.unlock();
204201
}
@@ -219,7 +216,7 @@ private void initialiseConnections() throws SQLException {
219216
"] min[" + minConnections +
220217
"] max[" + maxConnections +
221218
"] in[" + (System.currentTimeMillis() - start) + "ms]";
222-
log.info(msg);
219+
Log.info(msg);
223220
}
224221

225222
/**
@@ -232,7 +229,7 @@ private void initialiseDatabase() throws SQLException {
232229
// successfully obtained a connection so skip initDatabase
233230
connection.clearWarnings();
234231
} catch (SQLException e) {
235-
log.info("Obtaining connection using ownerUsername:{} to initialise database", config.getOwnerUsername());
232+
Log.info("Obtaining connection using ownerUsername:{0} to initialise database", config.getOwnerUsername());
236233
// expected when user does not exist, obtain a connection using owner credentials
237234
try (Connection ownerConnection = createUnpooledConnection(config.getOwnerUsername(), config.getOwnerPassword())) {
238235
// initialise the DB (typically create the user/role using the owner credentials etc)
@@ -317,7 +314,7 @@ public SQLException getDataSourceDownReason() {
317314
void notifyWarning(String msg) {
318315
if (inWarningMode.compareAndSet(false, true)) {
319316
// send an Error to the event log...
320-
log.warn(msg);
317+
Log.warn(msg);
321318
if (notify != null) {
322319
notify.dataSourceWarning(this, msg);
323320
}
@@ -338,7 +335,7 @@ private void notifyDown(SQLException reason) {
338335
// check and set false immediately so that we only alert once
339336
dataSourceUp.set(false);
340337
dataSourceDownReason = reason;
341-
log.error("FATAL: DataSourcePool [" + name + "] is down or has network error!!!", reason);
338+
Log.error("FATAL: DataSourcePool [" + name + "] is down or has network error!!!", reason);
342339
if (notify != null) {
343340
notify.dataSourceDown(this, reason);
344341
}
@@ -363,12 +360,12 @@ private void notifyUp() {
363360
dataSourceUp.set(true);
364361
startHeartBeatIfStopped();
365362
dataSourceDownReason = null;
366-
log.error("RESOLVED FATAL: DataSourcePool [" + name + "] is back up!");
363+
Log.error("RESOLVED FATAL: DataSourcePool [" + name + "] is back up!");
367364
if (notify != null) {
368365
notify.dataSourceUp(this);
369366
}
370367
} else {
371-
log.info("DataSourcePool [{}] is back up!", name);
368+
Log.info("DataSourcePool [{0}] is back up!", name);
372369
}
373370
} finally {
374371
notifyLock.unlock();
@@ -384,7 +381,7 @@ private void trimIdleConnections() {
384381
queue.trim(maxInactiveMillis, maxAgeMillis);
385382
lastTrimTime = System.currentTimeMillis();
386383
} catch (Exception e) {
387-
log.error("Error trying to trim idle connections - message:" + e.getMessage(), e);
384+
Log.error("Error trying to trim idle connections - message:" + e.getMessage(), e);
388385
}
389386
}
390387
}
@@ -414,7 +411,7 @@ private void checkDataSource() {
414411
conn.close();
415412
}
416413
} catch (SQLException ex) {
417-
log.warn("Can't close connection in checkDataSource!");
414+
Log.warn("Can't close connection in checkDataSource!");
418415
}
419416
}
420417
}
@@ -569,14 +566,14 @@ private boolean testConnection(Connection conn) throws SQLException {
569566
rset.close();
570567
}
571568
} catch (SQLException e) {
572-
log.error("Error closing resultSet", e);
569+
Log.error("Error closing resultSet", e);
573570
}
574571
try {
575572
if (stmt != null) {
576573
stmt.close();
577574
}
578575
} catch (SQLException e) {
579-
log.error("Error closing statement", e);
576+
Log.error("Error closing statement", e);
580577
}
581578
}
582579
}
@@ -588,7 +585,7 @@ boolean validateConnection(PooledConnection conn) {
588585
try {
589586
return testConnection(conn);
590587
} catch (Exception e) {
591-
log.warn("Heartbeat test failed on connection:" + conn.getName() + " message:" + e.getMessage());
588+
Log.warn("Heartbeat test failed on connection:{0} message: {1}", conn.getName(), e.getMessage());
592589
return false;
593590
}
594591
}
@@ -630,7 +627,7 @@ private void returnTheConnection(PooledConnection pooledConnection, boolean forc
630627

631628
void returnConnectionReset(PooledConnection pooledConnection) {
632629
queue.returnPooledConnection(pooledConnection, true);
633-
log.warn("Resetting DataSourcePool on read-only failure [{}]", name);
630+
Log.warn("Resetting DataSourcePool on read-only failure [{0}]", name);
634631
reset();
635632
}
636633

@@ -752,7 +749,7 @@ public void offline() {
752749
private void shutdownPool(boolean closeBusyConnections) {
753750
stopHeartBeatIfRunning();
754751
PoolStatus status = queue.shutdown(closeBusyConnections);
755-
log.info("DataSourcePool [{}] shutdown {} psc[hit:{} miss:{} put:{} rem:{}]", name, status, pscHit, pscMiss, pscPut, pscRem);
752+
Log.info("DataSourcePool [{0}] shutdown {1} psc[hit:{2} miss:{3} put:{4} rem:{5}]", name, status, pscHit, pscMiss, pscPut, pscRem);
756753
dataSourceUp.set(false);
757754
}
758755

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ PooledConnection remove() {
5555
void closeAll(boolean logErrors) {
5656
List<PooledConnection> tempList = new ArrayList<>(freeBuffer);
5757
freeBuffer.clear();
58-
Log.log.trace("... closing all {} connections from the free list with logErrors: {}", tempList.size(), logErrors);
58+
if (Log.isLoggable(System.Logger.Level.TRACE)) {
59+
Log.trace("... closing all {0} connections from the free list with logErrors: {1}", tempList.size(), logErrors);
60+
}
5961
for (PooledConnection connection : tempList) {
6062
connection.closeConnectionFully(logErrors);
6163
}

0 commit comments

Comments
 (0)