From 486b1ba04380be356ff5dcbedb5c53b9b741d4f9 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 5 Jan 2025 18:48:16 +0000 Subject: [PATCH] implement code review comments --- jpa/boot-jpa-jooq-sample/Dockerfile | 11 ++++++++--- jpa/boot-jpa-jooq-sample/docker/.env | 3 +++ .../docker/docker-compose-app.yml | 6 +++--- jpa/boot-jpa-jooq-sample/pom.xml | 5 +++++ .../main/java/com/example/learning/entities/Post.java | 3 --- .../migration/02-create_post_comments_table.xml | 4 +++- .../changelog/migration/05-create_post_tag_table.xml | 4 +++- 7 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 jpa/boot-jpa-jooq-sample/docker/.env diff --git a/jpa/boot-jpa-jooq-sample/Dockerfile b/jpa/boot-jpa-jooq-sample/Dockerfile index d6036bf1d..51282e934 100644 --- a/jpa/boot-jpa-jooq-sample/Dockerfile +++ b/jpa/boot-jpa-jooq-sample/Dockerfile @@ -1,5 +1,5 @@ FROM eclipse-temurin:21.0.5_11-jre-alpine as builder -WORKDIR application +WORKDIR /app ARG JAR_FILE=target/boot-jpa-jooq-0.0.1-SNAPSHOT.jar COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract @@ -9,10 +9,15 @@ FROM eclipse-temurin:21.0.5_11-jre-alpine LABEL maintainer="rajadilipkolli" \ description="Spring Boot application with JPA and jOOQ integration" \ version="0.0.1-SNAPSHOT" -WORKDIR application +WORKDIR /app COPY --from=builder application/dependencies/ ./ COPY --from=builder application/spring-boot-loader/ ./ COPY --from=builder application/snapshot-dependencies/ ./ COPY --from=builder application/application/ ./ -ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -XX:InitialRAMPercentage=50.0" +ARG MAX_RAM_PERCENTAGE=75.0 +ARG INITIAL_RAM_PERCENTAGE=50.0 +ENV JAVA_OPTS="-XX:MaxRAMPercentage=${MAX_RAM_PERCENTAGE} -XX:InitialRAMPercentage=${INITIAL_RAM_PERCENTAGE}" ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} org.springframework.boot.loader.launch.JarLauncher"] + +HEALTHCHECK --interval=30s --timeout=3s \ + CMD wget --quiet --tries=1 --spider http://localhost:8080/actuator/health || exit 1 diff --git a/jpa/boot-jpa-jooq-sample/docker/.env b/jpa/boot-jpa-jooq-sample/docker/.env new file mode 100644 index 000000000..0c1dfdc38 --- /dev/null +++ b/jpa/boot-jpa-jooq-sample/docker/.env @@ -0,0 +1,3 @@ +POSTGRES_DB=appdb +POSTGRES_USER=appuser +POSTGRES_PASSWORD=secret diff --git a/jpa/boot-jpa-jooq-sample/docker/docker-compose-app.yml b/jpa/boot-jpa-jooq-sample/docker/docker-compose-app.yml index 2a00e4d98..7e47d8a34 100644 --- a/jpa/boot-jpa-jooq-sample/docker/docker-compose-app.yml +++ b/jpa/boot-jpa-jooq-sample/docker/docker-compose-app.yml @@ -12,6 +12,6 @@ services: environment: - SPRING_PROFILES_ACTIVE=docker - SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver - - SPRING_DATASOURCE_URL=jdbc:postgresql://postgresqldb:5432/appdb - - SPRING_DATASOURCE_USERNAME=appuser - - SPRING_DATASOURCE_PASSWORD=secret + - SPRING_DATASOURCE_URL=jdbc:postgresql://postgresqldb:5432/${POSTGRES_DB} + - SPRING_DATASOURCE_USERNAME=${POSTGRES_USER} + - SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD} diff --git a/jpa/boot-jpa-jooq-sample/pom.xml b/jpa/boot-jpa-jooq-sample/pom.xml index 22d1e9942..f40e9a8e4 100644 --- a/jpa/boot-jpa-jooq-sample/pom.xml +++ b/jpa/boot-jpa-jooq-sample/pom.xml @@ -53,6 +53,11 @@ postgresql runtime + + net.ttddyy.observation + datasource-micrometer-spring-boot + 1.0.6 + org.springdoc diff --git a/jpa/boot-jpa-jooq-sample/src/main/java/com/example/learning/entities/Post.java b/jpa/boot-jpa-jooq-sample/src/main/java/com/example/learning/entities/Post.java index 0d74ed82f..03a38a86c 100644 --- a/jpa/boot-jpa-jooq-sample/src/main/java/com/example/learning/entities/Post.java +++ b/jpa/boot-jpa-jooq-sample/src/main/java/com/example/learning/entities/Post.java @@ -161,9 +161,6 @@ public void setDetails(PostDetails details) { public void addTag(Tag tag) { PostTag postTag = new PostTag(this, tag); - if (null == tags) { - tags = new ArrayList<>(); - } this.tags.add(postTag); } diff --git a/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/02-create_post_comments_table.xml b/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/02-create_post_comments_table.xml index cb847fd5f..33de2fbe9 100644 --- a/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/02-create_post_comments_table.xml +++ b/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/02-create_post_comments_table.xml @@ -33,6 +33,8 @@ + referencedTableName="posts" + onDelete="CASCADE" + onUpdate="CASCADE"/> diff --git a/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/05-create_post_tag_table.xml b/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/05-create_post_tag_table.xml index a481f2609..967064de9 100644 --- a/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/05-create_post_tag_table.xml +++ b/jpa/boot-jpa-jooq-sample/src/main/resources/db/changelog/migration/05-create_post_tag_table.xml @@ -7,7 +7,9 @@ - + + +