Implements database, adds profiles
This commit is contained in:
29
h2/pom.xml
Normal file
29
h2/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>ch.gtache.fro</groupId>
|
||||
<artifactId>fro</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>fro-h2</artifactId>
|
||||
|
||||
<properties>
|
||||
<h2.version>2.4.240</h2.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ch.gtache.fro</groupId>
|
||||
<artifactId>fro-database</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -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