Implements database, adds profiles
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package ch.gtache.fro.h2;
|
||||
|
||||
public class H2ConfigurationManager {
|
||||
}
|
||||
38
h2/src/main/java/ch/gtache/fro/modules/h2/H2Module.java
Normal file
38
h2/src/main/java/ch/gtache/fro/modules/h2/H2Module.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package ch.gtache.fro.modules.h2;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Dagger module for H2
|
||||
*/
|
||||
@Module
|
||||
public final class H2Module {
|
||||
|
||||
private H2Module() {
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Connection providesJdbcConnection() {
|
||||
try {
|
||||
final var connection = DriverManager.getConnection("jdbc:h2:mem:");
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (final SQLException e) {
|
||||
throw new RuntimeException("Error closing H2 connection", e);
|
||||
}
|
||||
}));
|
||||
return connection;
|
||||
} catch (final SQLException e) {
|
||||
throw new RuntimeException("Error connecting to H2", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
h2/src/main/java/module-info.java
Normal file
8
h2/src/main/java/module-info.java
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* H2 module for the FRO application
|
||||
*/
|
||||
module ch.gtache.fro.h2 {
|
||||
requires transitive ch.gtache.fro.database;
|
||||
exports ch.gtache.fro.h2;
|
||||
exports ch.gtache.fro.modules.h2;
|
||||
}
|
||||
Reference in New Issue
Block a user