Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
[#141] add repo, add embedded db, add data file
Browse files Browse the repository at this point in the history
  • Loading branch information
jenarp committed Jan 12, 2022
1 parent a0ea5b6 commit 6dfa150
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src/main/java/de/bonndan/nivio/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package de.bonndan.nivio;

import de.bonndan.nivio.database.User;
import de.bonndan.nivio.database.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
Expand All @@ -11,4 +15,12 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
CommandLineRunner commandLineRunner(UserRepository userRepository) {
return args -> {
User mary = new User("Mary", "[email protected]");
userRepository.save(mary);
};
}
}
67 changes: 45 additions & 22 deletions src/main/java/de/bonndan/nivio/database/User.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
package de.bonndan.nivio.database;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.*;

@Entity
@Entity(name = "User")
@Table(
name = "user",
uniqueConstraints = {
@UniqueConstraint(name = "user_email_unique",
columnNames = "email")
}
)
public class User {

@Id
@SequenceGenerator(
name = "user_sequence",
sequenceName = "user_sequence",
allocationSize = 1
)
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "user_sequence"
)
@Column(
name = "id",
updatable = false
)
private Long id;
private String firstName;
private String lastName;

@Column(
name = "user_name",
nullable = false,
columnDefinition = "TEXT"
)
private String userName;

@Column(
name = "email",
nullable = false,
columnDefinition = "TEXT"
)
private String email;

public User(Long id, String firstName, String lastName, String email) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
public User(String userName, String email) {
this.userName = userName;
this.email = email;
}

public User() {

}

public void setId(Long id) {
this.id = id;
}

@Id
public Long getId() {
return id;
}

public String getFirstName() {
return firstName;
return userName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
this.userName = firstName;
}

public String getEmail() {
Expand All @@ -55,8 +79,7 @@ public void setEmail(String email) {
public String toString() {
return "User{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", user name='" + userName + '\'' +
", email='" + email + '\'' +
'}';
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/de/bonndan/nivio/database/UserRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.bonndan.nivio.database;

import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long> {

}
14 changes: 10 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ server:
---
spring:
datasource:
url: jdbc:h2:mem:jpadb
driver-class-name: org.h2.Driver
username: user
password: pwd
username:
password:
url: jdbc:h2:./src/main/resources/data/user;AUTO_SERVER=TRUE
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: create-drop
show-sql: true
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.H2Dialect
6 changes: 6 additions & 0 deletions src/main/resources/data/user.lock.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#FileLock
#Wed Jan 12 13:55:06 CET 2022
server=localhost\:60731
hostName=localhost
method=file
id=17e4e5b329af9f5f04f04ca0df6000cc4546139b105
Binary file added src/main/resources/data/user.mv.db
Binary file not shown.
Loading

0 comments on commit 6dfa150

Please sign in to comment.