Configure H2 database and add repositories
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -39,7 +39,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>runtime</scope>
|
<!-- <scope>runtime</scope>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
package net.kapcake.bankingservice.domain;
|
package net.kapcake.bankingservice.domain;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import jakarta.persistence.ManyToOne;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
|
@Table(name = "BANKING_USER")
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
9
src/main/resources/application.yml
Normal file
9
src/main/resources/application.yml
Normal 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
|
||||||
5
src/main/resources/data.sql
Normal file
5
src/main/resources/data.sql
Normal 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);
|
||||||
Reference in New Issue
Block a user