Skip to content

Commit d967e6c

Browse files
mmerdesrtroilo
authored andcommitted
#470: make disposal of connection pool null-safe
1 parent 1b60fb1 commit d967e6c

File tree

1 file changed

+6
-2
lines changed
  • oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/db

1 file changed

+6
-2
lines changed

oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/db/OSHDBH2.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.sql.Statement;
99
import java.util.ArrayList;
1010
import java.util.List;
11+
import java.util.Optional;
1112
import java.util.Set;
1213
import java.util.function.Consumer;
1314
import java.util.stream.Collectors;
@@ -19,12 +20,14 @@
1920
import org.heigit.ohsome.oshdb.util.TableNames;
2021
import org.heigit.ohsome.oshdb.util.exceptions.OSHDBException;
2122

23+
import static java.util.Optional.ofNullable;
24+
2225
/**
2326
* OSHDB database backend connector to a H2 database.
2427
*/
2528
public class OSHDBH2 extends OSHDBJdbc {
2629

27-
private JdbcConnectionPool connectionPool;
30+
private final JdbcConnectionPool connectionPool;
2831

2932
/**
3033
* Opens a connection to oshdb data stored in a H2 database file.
@@ -50,6 +53,7 @@ public OSHDBH2(Path path, String user, String password) {
5053

5154
public OSHDBH2(DataSource ds) {
5255
super(ds);
56+
this.connectionPool = null;
5357
}
5458

5559
private OSHDBH2(JdbcConnectionPool ds) {
@@ -76,7 +80,7 @@ public OSHDBH2 multithreading(boolean useMultithreading) {
7680
@Override
7781
public void close() throws Exception {
7882
try {
79-
connectionPool.dispose();
83+
ofNullable(connectionPool).ifPresent(JdbcConnectionPool::dispose);
8084
} finally {
8185
super.close();
8286
}

0 commit comments

Comments
 (0)