Skip to content

Commit

Permalink
Update Databse configs
Browse files Browse the repository at this point in the history
  • Loading branch information
barcellos-pedro committed Feb 7, 2024
1 parent e81bea7 commit 3426fc7
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_URL=jdbc:postgresql://localhost:5432/todo_db
DB_USERNAME=todo_dev
DB_PASSWORD=todo-123
DB_NAME=todo_db
PGADMIN_MAIL=todo@gmail.com
PGADMIN_PASSWORD=todo123
47 changes: 28 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.pedro</groupId>
<artifactId>rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
Expand All @@ -16,6 +18,7 @@
<properties>
<java.version>21</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -39,35 +42,41 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<!-- Local Database (Development only) -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<!-- Metrics -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>com.wavefront</groupId>-->
<!-- <artifactId>wavefront-spring-boot-starter</artifactId>-->
<!-- <version>3.0.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.wavefront</groupId>-->
<!-- <artifactId>wavefront-spring-boot-starter</artifactId>-->
<!-- <version>3.0.1</version>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>io.micrometer</groupId>-->
<!-- <artifactId>micrometer-registry-wavefront</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.micrometer</groupId>-->
<!-- <artifactId>micrometer-registry-wavefront</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->

<!-- Tracing -->
<!-- <dependency>-->
<!-- <groupId>io.micrometer</groupId>-->
<!-- <artifactId>micrometer-tracing-bridge-otel</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.micrometer</groupId>-->
<!-- <artifactId>micrometer-tracing-bridge-otel</artifactId>-->
<!-- </dependency>-->
</dependencies>

<build>
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/pedro/rest/configuration/Properties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.pedro.rest.configuration;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Properties {

@Value("${DB_URL}")
private String dbUrl;

@Value("${DB_USERNAME}")
private String dbUsername;

@Value("${DB_PASSWORD}")
private String dbPassword;

@Value("${DB_NAME}")
private String dbName;

@Value("${PGADMIN_MAIL}")
private String pgAdminMail;

@Value("${PGADMIN_PASSWORD}")
private String pgAdminPassord;

@PostConstruct
public void printProperties() {
System.out.println("#### [App Properties] ####");
System.out.println("DB_URL: " + dbUrl);
System.out.println("DB_USERNAME: " + dbUsername);
System.out.println("DB_PASSWORD: " + dbPassword);
System.out.println("DB_NAME: " + dbName);
System.out.println("PGADMIN_MAIL: " + pgAdminMail);
System.out.println("PGADMIN_PASSWORD: " + pgAdminPassord);
}
}
6 changes: 4 additions & 2 deletions src/main/java/com/pedro/rest/model/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

import java.io.Serializable;
import java.util.Objects;

@Entity
public class Employee {
public class Employee implements Serializable {
@Id
@GeneratedValue
private Long id;
private String firstName;
private String lastName;
private String role;

Employee() {
// no-args constructor required by JPA spec
protected Employee() {
}

public Employee(String firstName, String lastName, String role) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Debug Spring Framework
# logging.level.org.springframework.boot=DEBUG

# Database
# Check IDE (eclipse/intellij) configuration to set .env file path
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}

spring.jpa.hibernate.ddl-auto=create-drop

# Enable SQL logging
spring.datasource.log-statement=true
logging.level.org.hibernate.SQL=DEBUG

# Hibernate specific: Show SQL with formatted parameters
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true

# Observability
# management.wavefront.application.name=rest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.test.context.ActiveProfiles;

import java.util.List;

Expand All @@ -23,6 +24,7 @@
import static org.mockito.Mockito.verify;

@SpringBootTest
@ActiveProfiles("test")
public class EmployeeServiceIntegrationTest {
@Autowired
private EmployeeServiceImpl service;
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:h2:mem:rest_db
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true

0 comments on commit 3426fc7

Please sign in to comment.