Initiate Postgres connection pool on startup

This commit is contained in:
P0nk
2023-02-25 00:11:33 +01:00
parent 8bb825ef02
commit f6f3c9c3e3
6 changed files with 77 additions and 14 deletions

View File

@@ -0,0 +1,28 @@
package database;
import database.note.NoteRowMapper;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.Jdbi;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class PgDatabaseConnection {
private final DataSource dataSource;
private final Jdbi jdbi;
public PgDatabaseConnection(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbi = Jdbi.create(dataSource)
.registerRowMapper(new NoteRowMapper()); // TODO: configure jdbi elsewhere
}
public Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
public Handle getHandle() {
return jdbi.open();
}
}