Commit 94489320 authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Use Hikari connection pool in all queries

parent c862f733
...@@ -41,8 +41,8 @@ public class DatabaseHandler { ...@@ -41,8 +41,8 @@ public class DatabaseHandler {
try { try {
// String jdbcurl = H2GISDBFactory.createDataSource(DB_NAME, // String jdbcurl = H2GISDBFactory.createDataSource(DB_NAME,
// true, ";AUTO_SERVER=TRUE").getConnection().getMetaData().getURL(); // true, ";AUTO_SERVER=TRUE").getConnection().getMetaData().getURL();
String jdbcurl = H2GISDBFactory.createSpatialDataBase(DB_NAME, true, ";AUTO_SERVER=TRUE").getMetaData().getURL();
logger.info(jdbcurl); logger.info("2] {}",jdbcurl);
HikariDataSource ds = new HikariDataSource(); HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(jdbcurl); ds.setJdbcUrl(jdbcurl);
...@@ -216,7 +216,7 @@ public class DatabaseHandler { ...@@ -216,7 +216,7 @@ public class DatabaseHandler {
public List<CityObject> getAllCityObjects() { public List<CityObject> getAllCityObjects() {
List<CityObject> cos = new ArrayList<>(); List<CityObject> cos = new ArrayList<>();
try (Connection con = new ConnectionWrapper(H2GISDBFactory.openSpatialDataBase(DB_NAME))) { try (Connection con = dataSource.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT gmlid, bbox, data FROM features")) { try (PreparedStatement ps = con.prepareStatement("SELECT gmlid, bbox, data FROM features")) {
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
cos.addAll(retrieveCityObjects(rs)); cos.addAll(retrieveCityObjects(rs));
...@@ -235,7 +235,7 @@ public class DatabaseHandler { ...@@ -235,7 +235,7 @@ public class DatabaseHandler {
public List<GmlId> getBufferIntersectingObjects(GmlId gmlID, double bufferSize) { public List<GmlId> getBufferIntersectingObjects(GmlId gmlID, double bufferSize) {
List<GmlId> intersectingObjects = new ArrayList<>(); List<GmlId> intersectingObjects = new ArrayList<>();
try (Connection con = new ConnectionWrapper(H2GISDBFactory.openSpatialDataBase(DB_NAME))) { try (Connection con = dataSource.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" + try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" +
" WHERE ST_INTERSECTS(ST_BUFFER(tab1.bbox,?), (SELECT bbox FROM features WHERE gmlid = ?)) " + " WHERE ST_INTERSECTS(ST_BUFFER(tab1.bbox,?), (SELECT bbox FROM features WHERE gmlid = ?)) " +
"AND tab1.gmlid <> ?")) { "AND tab1.gmlid <> ?")) {
...@@ -261,7 +261,7 @@ public class DatabaseHandler { ...@@ -261,7 +261,7 @@ public class DatabaseHandler {
public List<GmlId> getBBoxIntersectingObjects(GmlId id) { public List<GmlId> getBBoxIntersectingObjects(GmlId id) {
List<GmlId> intersectingObjects = new ArrayList<>(); List<GmlId> intersectingObjects = new ArrayList<>();
try (Connection con = new ConnectionWrapper(H2GISDBFactory.openSpatialDataBase(DB_NAME))) { try (Connection con = dataSource.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" + try (PreparedStatement ps = con.prepareStatement("SELECT gmlid FROM features AS tab1" +
" WHERE ST_INTERSECTS(tab1.bbox, (SELECT bbox FROM features WHERE gmlid = ?)) AND tab1.gmlid <> ?")) " WHERE ST_INTERSECTS(tab1.bbox, (SELECT bbox FROM features WHERE gmlid = ?)) AND tab1.gmlid <> ?"))
{ {
...@@ -283,7 +283,7 @@ public class DatabaseHandler { ...@@ -283,7 +283,7 @@ public class DatabaseHandler {
public int getFeatureCount() { public int getFeatureCount() {
int count = -1; int count = -1;
try (Connection con = new ConnectionWrapper(H2GISDBFactory.openSpatialDataBase(DB_NAME))) { try (Connection con = dataSource.getConnection()) {
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(gmlid) AS nr FROM features")) { try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(gmlid) AS nr FROM features")) {
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
if (rs.next()) { if (rs.next()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment