Configure H2 database and add repositories

This commit is contained in:
2023-05-06 22:54:19 +02:00
parent a4be85620f
commit efc9f9c77c
10 changed files with 59 additions and 6 deletions

View File

@@ -39,7 +39,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<!-- <scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -0,0 +1,14 @@
package net.kapcake.bankingservice.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.h2.tools.Server;
import java.sql.SQLException;
@Configuration
public class BankingServiceConfig {
@Bean(initMethod = "start", destroyMethod = "stop")
public Server h2Server() throws SQLException {
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092");
}
}

View File

@@ -1,13 +1,11 @@
package net.kapcake.bankingservice.domain;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.*;
import lombok.Data;
@Entity
@Data
@Table(name = "BANKING_USER")
public class User {
@Id
@GeneratedValue

View File

@@ -0,0 +1,7 @@
package net.kapcake.bankingservice.repositories;
import net.kapcake.bankingservice.domain.Address;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AddressRepository extends JpaRepository<Address, Long> {
}

View File

@@ -0,0 +1,7 @@
package net.kapcake.bankingservice.repositories;
import net.kapcake.bankingservice.domain.BankAccount;
import org.springframework.data.jpa.repository.JpaRepository;
public interface BankAccountRepository extends JpaRepository<BankAccount, Long> {
}

View File

@@ -0,0 +1,7 @@
package net.kapcake.bankingservice.repositories;
import net.kapcake.bankingservice.domain.Payment;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PaymentRepository extends JpaRepository<Payment, Long> {
}

View File

@@ -0,0 +1,7 @@
package net.kapcake.bankingservice.repositories;
import net.kapcake.bankingservice.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Long> {
}

View File

@@ -1 +0,0 @@

View File

@@ -0,0 +1,9 @@
spring:
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
driver-class-name: org.h2.Driver
username: bank
password: bankPassword
jpa:
database-platform: org.hibernate.dialect.H2Dialect
defer-datasource-initialization: true

View File

@@ -0,0 +1,5 @@
INSERT INTO ADDRESS (id, street, number, postal_code, country)
values (1, 'street', 1, 9999, 'Luxembourg');
INSERT INTO BANKING_USER (id, username, password, address_id)
values (1, 'user1', 'test', 1);