From 837ebef85832c3a5fdc59929370c815bf1924510 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 1 Oct 2019 12:56:55 -0400 Subject: [PATCH 01/20] Add architecture module with Hexagonal example --- architecture/README.md | 3 ++ architecture/pom.xml | 33 ++++++++++++ .../HexagonalArchitectureTaskApplication.java | 12 +++++ .../application/task/AddNewDailyTask.java | 29 ++++++++++ .../application/task/AddNewTask.java | 22 ++++++++ .../application/task/GetTasks.java | 22 ++++++++ .../commands/task/CreateTask.java | 7 +++ .../commands/task/GetAllTasks.java | 7 +++ .../architecture/domain/task/Task.java | 53 +++++++++++++++++++ .../domain/task/TaskRepository.java | 7 +++ .../architecture/domain/task/TaskService.java | 22 ++++++++ .../framework/cli/StartupRunner.java | 25 +++++++++ .../http/task/TaskApiController.java | 42 +++++++++++++++ .../framework/http/task/TaskRequest.java | 29 ++++++++++ 14 files changed, 313 insertions(+) create mode 100644 architecture/README.md create mode 100644 architecture/pom.xml create mode 100644 architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java diff --git a/architecture/README.md b/architecture/README.md new file mode 100644 index 0000000000..be093f25ed --- /dev/null +++ b/architecture/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [A Quick and Practical Example of Hexagonal Architecture in Java](https://www.baeldung.com/a-quick-and-practical-example-of-hexagonal-architecture-in-java-3/) diff --git a/architecture/pom.xml b/architecture/pom.xml new file mode 100644 index 0000000000..4ad104293e --- /dev/null +++ b/architecture/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + com.baeldung.architecture + architecture + 0.0.1-SNAPSHOT + architecture + jar + A Quick and Practical Example of Hexagonal Architecture in Java + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-web + + + diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java new file mode 100644 index 0000000000..83e4fc4c0b --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.architecture; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HexagonalArchitectureTaskApplication { + public static void main(String[] args) { + SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); + } + +} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java new file mode 100644 index 0000000000..208d1bfcc9 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java @@ -0,0 +1,29 @@ +package com.baeldung.architecture.application.task; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; + +import com.baeldung.architecture.commands.task.CreateTask; +import com.baeldung.architecture.domain.task.Task; + +import org.springframework.stereotype.Component; + +@Component +public class AddNewDailyTask implements CreateTask { + + private AddNewTask addNewTask; + + public AddNewDailyTask(AddNewTask addNewTask) { + this.addNewTask = addNewTask; + } + + @Override + public void create(Task newTask) { + Instant initialDueDate = newTask.getDueDate(); + String description = newTask.getDescription(); + for (int i = 1; i <= 5; i++) { + Task task = new Task(initialDueDate.plus(i, ChronoUnit.DAYS), description); + addNewTask.create(task); + } + } +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java new file mode 100644 index 0000000000..2e5aff4a53 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java @@ -0,0 +1,22 @@ +package com.baeldung.architecture.application.task; + +import com.baeldung.architecture.domain.task.Task; +import com.baeldung.architecture.domain.task.TaskService; +import com.baeldung.architecture.commands.task.*; + +import org.springframework.stereotype.Component; + +@Component +public class AddNewTask implements CreateTask { + + private TaskService taskService; + + public AddNewTask(TaskService taskService) { + this.taskService = taskService; + } + + @Override + public void create(Task newTask) { + taskService.createTask(newTask); + } +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java new file mode 100644 index 0000000000..54539290ba --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java @@ -0,0 +1,22 @@ +package com.baeldung.architecture.application.task; + +import com.baeldung.architecture.domain.task.Task; +import com.baeldung.architecture.domain.task.TaskService; +import com.baeldung.architecture.commands.task.*; + +import org.springframework.stereotype.Component; + +@Component +public class GetTasks implements GetAllTasks { + + private TaskService taskService; + + public GetTasks(TaskService taskService) { + this.taskService = taskService; + } + + @Override + public Iterable getAll() { + return taskService.getAllTasks(); + } +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java new file mode 100644 index 0000000000..26e6da10e2 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java @@ -0,0 +1,7 @@ +package com.baeldung.architecture.commands.task; + +import com.baeldung.architecture.domain.task.Task; + +public interface CreateTask { + public void create(Task newTask); +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java new file mode 100644 index 0000000000..d3c40db92f --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java @@ -0,0 +1,7 @@ +package com.baeldung.architecture.commands.task; + +import com.baeldung.architecture.domain.task.Task; + +public interface GetAllTasks { + public Iterable getAll(); +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java new file mode 100644 index 0000000000..240dc33571 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java @@ -0,0 +1,53 @@ +package com.baeldung.architecture.domain.task; + +import java.time.Instant; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Task { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long id; + private Instant dueDate = Instant.now(); + private String description; + + public Task() {} + + public Task(Instant dueDate, String description) { + this.dueDate = dueDate; + this.description = description; + } + + public Task(Long id, Instant dueDate, String description) { + this(dueDate, description); + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Instant getDueDate() { + return dueDate; + } + + public void setDueDate(Instant dueDate) { + this.dueDate = dueDate; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java new file mode 100644 index 0000000000..d896212714 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.architecture.domain.task; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TaskRepository extends CrudRepository {}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java new file mode 100644 index 0000000000..cace0614ad --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java @@ -0,0 +1,22 @@ +package com.baeldung.architecture.domain.task; + +import org.springframework.stereotype.Service; + +@Service +public class TaskService { + + private TaskRepository taskRepository; + + public TaskService(TaskRepository taskRepository) { + this.taskRepository = taskRepository; + } + + public void createTask(Task task) { + taskRepository.save(task); + } + + public Iterable getAllTasks() { + return taskRepository.findAll(); + } + +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java new file mode 100644 index 0000000000..260c033b71 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -0,0 +1,25 @@ +package com.baeldung.architecture.framework.cli; + +import com.baeldung.architecture.application.task.AddNewDailyTask; +import com.baeldung.architecture.domain.task.Task; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +@Component +public class StartupRunner implements ApplicationRunner { + + AddNewDailyTask addNewDailyTask; + + public StartupRunner(AddNewDailyTask addNewDailyTask) { + this.addNewDailyTask = addNewDailyTask; + } + @Override + public void run(ApplicationArguments args) throws Exception { + System.out.println("Adding daily tasks"); + Task task = new Task(); + task.setDescription("Startup Task"); + addNewDailyTask.create(task); + } +} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java new file mode 100644 index 0000000000..c6f7bff2dd --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java @@ -0,0 +1,42 @@ +package com.baeldung.architecture.framework.http.task; + +import java.time.Instant; + +import com.baeldung.architecture.application.task.AddNewTask; +import com.baeldung.architecture.application.task.GetTasks; +import com.baeldung.architecture.domain.task.Task; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("task") +public class TaskApiController { + + private AddNewTask addNewTask; + private GetTasks getTasks; + + public TaskApiController( + AddNewTask addNewTask, + GetTasks getTasks + ) { + this.addNewTask = addNewTask; + this.getTasks = getTasks; + } + + @GetMapping + Iterable listTasks() { + return getTasks.getAll(); + } + + @PostMapping(consumes = "application/json", produces = "application/json") + void createTask(@RequestBody TaskRequest taskRequest) { + Task task = new Task(); + task.setDescription(taskRequest.getDescription()); + task.setDueDate(Instant.parse(taskRequest.getDueDate())); + addNewTask.create(task); + } +} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java new file mode 100644 index 0000000000..2e353b079a --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java @@ -0,0 +1,29 @@ +package com.baeldung.architecture.framework.http.task; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +public class TaskRequest { + @JsonInclude(Include.NON_NULL) + private String description; + + @JsonInclude(Include.NON_NULL) + private String dueDate; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDueDate() { + return dueDate; + } + + public void setDueDate(String dueDate) { + this.dueDate = dueDate; + } + +} \ No newline at end of file From 616364afc443e2c4ae4c03e0b1f43f49b5a77483 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 1 Oct 2019 20:15:39 -0400 Subject: [PATCH 02/20] Fixup styling --- .../architecture/HexagonalArchitectureTaskApplication.java | 6 +++--- .../baeldung/architecture/application/task/AddNewTask.java | 2 +- .../baeldung/architecture/application/task/GetTasks.java | 2 +- .../baeldung/architecture/framework/cli/StartupRunner.java | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java index 83e4fc4c0b..69c6f4b276 100644 --- a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java +++ b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java @@ -5,8 +5,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HexagonalArchitectureTaskApplication { - public static void main(String[] args) { - SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); + } } diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java index 2e5aff4a53..70638378f9 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java @@ -19,4 +19,4 @@ public class AddNewTask implements CreateTask { public void create(Task newTask) { taskService.createTask(newTask); } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java index 54539290ba..c876f7de85 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java @@ -19,4 +19,4 @@ public class GetTasks implements GetAllTasks { public Iterable getAll() { return taskService.getAllTasks(); } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java index 260c033b71..cf38e5ee5e 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -17,7 +17,6 @@ public class StartupRunner implements ApplicationRunner { } @Override public void run(ApplicationArguments args) throws Exception { - System.out.println("Adding daily tasks"); Task task = new Task(); task.setDescription("Startup Task"); addNewDailyTask.create(task); From 646bd45c1824071ae5d17bae82799a89de69929e Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 1 Oct 2019 20:15:39 -0400 Subject: [PATCH 03/20] Fixup styling --- .../architecture/application/task/AddNewDailyTask.java | 2 +- .../com/baeldung/architecture/commands/task/CreateTask.java | 2 +- .../com/baeldung/architecture/commands/task/GetAllTasks.java | 2 +- .../com/baeldung/architecture/domain/task/TaskService.java | 2 +- .../com/baeldung/architecture/framework/cli/StartupRunner.java | 2 +- .../architecture/framework/http/task/TaskApiController.java | 2 +- .../baeldung/architecture/framework/http/task/TaskRequest.java | 3 +-- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java index 208d1bfcc9..f9ee97542c 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java @@ -26,4 +26,4 @@ public class AddNewDailyTask implements CreateTask { addNewTask.create(task); } } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java index 26e6da10e2..ec60868a22 100644 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java @@ -4,4 +4,4 @@ import com.baeldung.architecture.domain.task.Task; public interface CreateTask { public void create(Task newTask); -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java index d3c40db92f..c9aa1be5f8 100644 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java @@ -4,4 +4,4 @@ import com.baeldung.architecture.domain.task.Task; public interface GetAllTasks { public Iterable getAll(); -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java index cace0614ad..11ef0f3e19 100644 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java @@ -19,4 +19,4 @@ public class TaskService { return taskRepository.findAll(); } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java index cf38e5ee5e..449bc9386e 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -21,4 +21,4 @@ public class StartupRunner implements ApplicationRunner { task.setDescription("Startup Task"); addNewDailyTask.create(task); } -} \ No newline at end of file +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java index c6f7bff2dd..87a8f5fe4b 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java @@ -39,4 +39,4 @@ public class TaskApiController { task.setDueDate(Instant.parse(taskRequest.getDueDate())); addNewTask.create(task); } -} \ No newline at end of file +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java index 2e353b079a..70b98a32f9 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java @@ -25,5 +25,4 @@ public class TaskRequest { public void setDueDate(String dueDate) { this.dueDate = dueDate; } - -} \ No newline at end of file +} From 925a69b401f9817cce62e790435a5400c5eef7d1 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 07:01:34 -0400 Subject: [PATCH 04/20] Java example for Hibernate Types --- .../hibernate-types/.gitignore | 33 +++ persistence-modules/hibernate-types/README.md | 7 + .../hibernate-types/docker-compose.yml | 19 ++ .../docker-entrypoint-initdb.d/init-db.sql | 3 + .../docker/etc/mysql/conf.d/utf8.cnf | 7 + persistence-modules/hibernate-types/pom.xml | 214 ++++++++++++++++++ .../com/baeldung/hibernate/types/Album.java | 34 +++ .../hibernate/types/AlbumRepository.java | 8 + .../com/baeldung/hibernate/types/Artist.java | 72 ++++++ .../baeldung/hibernate/types/BaseEntity.java | 37 +++ .../baeldung/hibernate/types/CoverArt.java | 71 ++++++ .../types/HibernateTypesApplication.java | 13 ++ .../com/baeldung/hibernate/types/Song.java | 57 +++++ .../hibernate/types/SongRepository.java | 8 + .../src/main/resources/application.properties | 21 ++ .../main/resources/hibernate-types.properties | 1 + .../types/HibernateTypesIntegrationTest.java | 182 +++++++++++++++ persistence-modules/pom.xml | 1 + 18 files changed, 788 insertions(+) create mode 100644 persistence-modules/hibernate-types/.gitignore create mode 100644 persistence-modules/hibernate-types/README.md create mode 100644 persistence-modules/hibernate-types/docker-compose.yml create mode 100644 persistence-modules/hibernate-types/docker/docker-entrypoint-initdb.d/init-db.sql create mode 100644 persistence-modules/hibernate-types/docker/etc/mysql/conf.d/utf8.cnf create mode 100644 persistence-modules/hibernate-types/pom.xml create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Album.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Artist.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/BaseEntity.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/CoverArt.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Song.java create mode 100644 persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/SongRepository.java create mode 100644 persistence-modules/hibernate-types/src/main/resources/application.properties create mode 100644 persistence-modules/hibernate-types/src/main/resources/hibernate-types.properties create mode 100644 persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java diff --git a/persistence-modules/hibernate-types/.gitignore b/persistence-modules/hibernate-types/.gitignore new file mode 100644 index 0000000000..94b9c48616 --- /dev/null +++ b/persistence-modules/hibernate-types/.gitignore @@ -0,0 +1,33 @@ +.classpath +.project +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ diff --git a/persistence-modules/hibernate-types/README.md b/persistence-modules/hibernate-types/README.md new file mode 100644 index 0000000000..9d02d8c8f2 --- /dev/null +++ b/persistence-modules/hibernate-types/README.md @@ -0,0 +1,7 @@ +## Hibernate Types + +This module contains articles specific to use of Hibernate Types. + +### Relevant articles: + +- [A Guide to Hibernate Types Project](https://www.baeldung.com/a-guide-to-hibernate-types-project/) diff --git a/persistence-modules/hibernate-types/docker-compose.yml b/persistence-modules/hibernate-types/docker-compose.yml new file mode 100644 index 0000000000..3ea9fef2e7 --- /dev/null +++ b/persistence-modules/hibernate-types/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3.2' + +services: + mysql: + image: mysql:5.7 + container_name: mysql57 + restart: unless-stopped + ports: + - 53306:3306 + environment: + - MYSQL_ALLOW_EMPTY_PASSWORD=true + volumes : + - ./docker/etc/mysql/conf.d:/etc/mysql/conf.d + - ./docker/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + logging: + driver: "json-file" + options: + max-size: "50m" + max-file: "1" diff --git a/persistence-modules/hibernate-types/docker/docker-entrypoint-initdb.d/init-db.sql b/persistence-modules/hibernate-types/docker/docker-entrypoint-initdb.d/init-db.sql new file mode 100644 index 0000000000..1df234f5a1 --- /dev/null +++ b/persistence-modules/hibernate-types/docker/docker-entrypoint-initdb.d/init-db.sql @@ -0,0 +1,3 @@ +CREATE DATABASE hibernate_types; +use hibernate_types; +GRANT ALL PRIVILEGES ON hibernate_types.* TO 'mysql'@'%' IDENTIFIED BY 'admin'; diff --git a/persistence-modules/hibernate-types/docker/etc/mysql/conf.d/utf8.cnf b/persistence-modules/hibernate-types/docker/etc/mysql/conf.d/utf8.cnf new file mode 100644 index 0000000000..1885d83c8b --- /dev/null +++ b/persistence-modules/hibernate-types/docker/etc/mysql/conf.d/utf8.cnf @@ -0,0 +1,7 @@ +[mysqld] +init_connect='SET collation_connection = utf8_unicode_ci' +character-set-server = utf8 +collation-server = utf8_unicode_ci + +[client] +default-character-set = utf8 \ No newline at end of file diff --git a/persistence-modules/hibernate-types/pom.xml b/persistence-modules/hibernate-types/pom.xml new file mode 100644 index 0000000000..9fa5d66347 --- /dev/null +++ b/persistence-modules/hibernate-types/pom.xml @@ -0,0 +1,214 @@ + + + 4.0.0 + hibernate-types + 0.0.1-SNAPSHOT + hibernate-types + Introduction into hibernate types library + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + com.vladmihalcea + hibernate-types-52 + ${hibernate-types.version} + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.springframework.boot + spring-boot-devtools + ${spring-boot.version} + runtime + true + + + org.hibernate + hibernate-core + ${hibernate.version} + provided + + + org.hibernate + hibernate-ehcache + ${hibernate.version} + test + + + org.hibernate + hibernate-testing + ${hibernate.version} + test + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + mysql + mysql-connector-java + ${mysql.version} + runtime + + + org.slf4j + slf4j-api + ${slf4j.version} + provided + true + + + ch.qos.logback + logback-classic + ${logback.version} + provided + true + + + javax.xml.bind + jaxb-api + ${jaxb.version} + + + org.javassist + javassist + ${javassist.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + provided + true + + + com.google.guava + guava + ${guava.version} + provided + true + + + net.ttddyy + datasource-proxy + ${datasource-proxy.version} + test + + + com.integralblue + log4jdbc-spring-boot-starter + ${log4jdbc.version} + + + + + hibernate-types + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-war-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.version} + + ${source.version} + ${target.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + + 3 + true + + **/*IntegrationTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + none + + + **/*IntegrationTest.java + + + + + + + + + + + + 3.15.0 + 1.6 + 29.0-jre + 2.9.7 + 5.4.14.Final + 2.10.3 + 1.8 + 3.27.0-GA + 2.3.1 + 2.0.0 + 1.2.3 + 3.0.2 + 2.22.2 + 3.8.1 + 3.7.0 + 8.0.19 + 1.7.30 + 2.1.3.RELEASE + + + diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Album.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Album.java new file mode 100644 index 0000000000..f18818c3a9 --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Album.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.types; + +import org.hibernate.annotations.Type; + +import javax.persistence.*; +import java.util.List; + +@Entity(name = "Album") +@Table(name = "album") +public class Album extends BaseEntity { + @Type(type = "json") + @Column(columnDefinition = "json") + private CoverArt coverArt; + + @OneToMany(fetch = FetchType.EAGER) + private List songs; + + public CoverArt getCoverArt() { + return coverArt; + } + + public void setCoverArt(CoverArt coverArt) { + this.coverArt = coverArt; + } + + + public List getSongs() { + return songs; + } + + public void setSong(List songs) { + this.songs = songs; + } +} diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java new file mode 100644 index 0000000000..d89542de46 --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate.types; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AlbumRepository extends CrudRepository { +} diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Artist.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Artist.java new file mode 100644 index 0000000000..8f3ccb44c5 --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Artist.java @@ -0,0 +1,72 @@ +package com.baeldung.hibernate.types; + +import java.io.Serializable; + +public class Artist implements Serializable { + + private String name; + private String country; + private String genre; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getGenre() { + return genre; + } + + public void setGenre(String genre) { + this.genre = genre; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((country == null) ? 0 : country.hashCode()); + result = prime * result + ((genre == null) ? 0 : genre.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Artist other = (Artist) obj; + if (country == null) { + if (other.country != null) + return false; + } else if (!country.equals(other.country)) + return false; + if (genre == null) { + if (other.genre != null) + return false; + } else if (!genre.equals(other.genre)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + } diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/BaseEntity.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/BaseEntity.java new file mode 100644 index 0000000000..3e0fbc7595 --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/BaseEntity.java @@ -0,0 +1,37 @@ +package com.baeldung.hibernate.types; + +import com.vladmihalcea.hibernate.type.json.JsonBinaryType; +import com.vladmihalcea.hibernate.type.json.JsonStringType; +import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.TypeDefs; + +import javax.persistence.*; + +@TypeDefs({ + @TypeDef(name = "json", typeClass = JsonStringType.class), + @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) +}) +@MappedSuperclass +public class BaseEntity { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name = "id", unique = true, nullable = false) + long id; + String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/CoverArt.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/CoverArt.java new file mode 100644 index 0000000000..bd71edc53c --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/CoverArt.java @@ -0,0 +1,71 @@ +package com.baeldung.hibernate.types; + +import java.io.Serializable; + +public class CoverArt implements Serializable { + + private String frontCoverArtUrl; + private String backCoverArtUrl; + private String upcCode; + + public String getFrontCoverArtUrl() { + return frontCoverArtUrl; + } + + public void setFrontCoverArtUrl(String frontCoverArtUrl) { + this.frontCoverArtUrl = frontCoverArtUrl; + } + + public String getBackCoverArtUrl() { + return backCoverArtUrl; + } + + public void setBackCoverArtUrl(String backCoverArtUrl) { + this.backCoverArtUrl = backCoverArtUrl; + } + + public String getUpcCode() { + return upcCode; + } + + public void setUpcCode(String upcCode) { + this.upcCode = upcCode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((backCoverArtUrl == null) ? 0 : backCoverArtUrl.hashCode()); + result = prime * result + ((frontCoverArtUrl == null) ? 0 : frontCoverArtUrl.hashCode()); + result = prime * result + ((upcCode == null) ? 0 : upcCode.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CoverArt other = (CoverArt) obj; + if (backCoverArtUrl == null) { + if (other.backCoverArtUrl != null) + return false; + } else if (!backCoverArtUrl.equals(other.backCoverArtUrl)) + return false; + if (frontCoverArtUrl == null) { + if (other.frontCoverArtUrl != null) + return false; + } else if (!frontCoverArtUrl.equals(other.frontCoverArtUrl)) + return false; + if (upcCode == null) { + if (other.upcCode != null) + return false; + } else if (!upcCode.equals(other.upcCode)) + return false; + return true; + } +} diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java new file mode 100644 index 0000000000..ac379f9ee2 --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.hibernate.types; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HibernateTypesApplication { + + public static void main(String[] args) { + SpringApplication.run(HibernateTypesApplication.class, args); + } + +} diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Song.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Song.java new file mode 100644 index 0000000000..2d22296024 --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Song.java @@ -0,0 +1,57 @@ +package com.baeldung.hibernate.types; + +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; + +import java.time.YearMonth; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import com.vladmihalcea.hibernate.type.basic.YearMonthIntegerType; + +@Entity(name = "Song") +@Table(name = "song") +@TypeDef( + typeClass = YearMonthIntegerType.class, + defaultForType = YearMonth.class +) +public class Song extends BaseEntity { + + private Long length = 0L; + + @Type(type = "json") + @Column(columnDefinition = "json") + private Artist artist; + + @Column( + name = "recorded_on", + columnDefinition = "mediumint" + ) + private YearMonth recordedOn = YearMonth.now(); + + public Long getLength() { + return length; + } + + public void setLength(Long length) { + this.length = length; + } + + public Artist getArtist() { + return artist; + } + + public void setArtist(Artist artist) { + this.artist = artist; + } + + public YearMonth getRecordedOn() { + return recordedOn; + } + + public void setRecordedOn(YearMonth recordedOn) { + this.recordedOn = recordedOn; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/SongRepository.java b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/SongRepository.java new file mode 100644 index 0000000000..e79e88108b --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/SongRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate.types; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SongRepository extends CrudRepository { +} diff --git a/persistence-modules/hibernate-types/src/main/resources/application.properties b/persistence-modules/hibernate-types/src/main/resources/application.properties new file mode 100644 index 0000000000..bcd21578dd --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/resources/application.properties @@ -0,0 +1,21 @@ +log4jdbc.dump.sql.addsemicolon=true +log4jdbc.dump.sql.maxlinelength=0 +log4jdbc.trim.sql.extrablanklines=false +logging.level.jdbc.audit=fatal +logging.level.jdbc.connection=fatal +logging.level.jdbc.resultset=fatal +logging.level.jdbc.resultsettable=info +logging.level.jdbc.sqlonly=fatal +logging.level.jdbc.sqltiming=info +# logging.level.org.hibernate.SQL=DEBUG +# logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +# logging.level.org.hibernate.type.descriptor.sql=trace +# logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG +# logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE +spring.datasource.url=jdbc:mysql://localhost:53306/hibernate_types?serverTimezone=UTC&useSSL=false +spring.datasource.username=root +spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect +spring.jpa.hibernate.ddl-auto=create +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +# spring.jpa.properties.hibernate.format_sql=false +# spring.jpa.show-sql=false \ No newline at end of file diff --git a/persistence-modules/hibernate-types/src/main/resources/hibernate-types.properties b/persistence-modules/hibernate-types/src/main/resources/hibernate-types.properties new file mode 100644 index 0000000000..226b50fafd --- /dev/null +++ b/persistence-modules/hibernate-types/src/main/resources/hibernate-types.properties @@ -0,0 +1 @@ +hibernate.types.print.banner=false diff --git a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java new file mode 100644 index 0000000000..cf3c34777e --- /dev/null +++ b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java @@ -0,0 +1,182 @@ +package com.baeldung.hibernate.types; + +import com.google.common.collect.Lists; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.Duration; +import java.time.YearMonth; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +public class HibernateTypesIntegrationTest { + + @Autowired + AlbumRepository albumRepository; + + @Autowired + SongRepository songRepository; + + private void deleteAll() { + albumRepository.deleteAll(); + songRepository.deleteAll(); + } + + @BeforeEach + public void setUp() { + deleteAll(); + } + + @BeforeEach + public void tearDown() { + setUp(); + } + + + @Test + void hibernateTypeJsonTest() { + Album nullAlbum = new Album(); + nullAlbum = albumRepository.save(nullAlbum); + + Song nullSong = new Song(); + nullSong = songRepository.save(nullSong); + + Artist artist0 = new Artist(); + artist0.setCountry("England"); + artist0.setGenre("Pop"); + artist0.setName("Superstar"); + + Song song0 = new Song(); + song0.setArtist(artist0); + song0.setName("A Happy Song"); + song0.setLength(Duration.ofMinutes(4).getSeconds()); + song0 = songRepository.save(song0); + + Song song1 = new Song(); + song1.setArtist(artist0); + song1.setName("A Sad Song"); + song1.setLength(Duration.ofMinutes(2).getSeconds()); + song1 = songRepository.save(song1); + + Song song2 = new Song(); + song2.setArtist(artist0); + song2.setName("Another Happy Song"); + song2.setLength(Duration.ofMinutes(3).getSeconds()); + song2 = songRepository.save(song2); + + Artist artist1 = new Artist(); + artist1.setCountry("Jamaica"); + artist1.setGenre("Reggae"); + artist1.setName("Newcomer"); + + Song song3 = new Song(); + song3.setArtist(artist1); + song3.setName("A New Song"); + song3.setLength(Duration.ofMinutes(5).getSeconds()); + song3 = songRepository.save(song3); + + CoverArt album0CoverArt = new CoverArt(); + album0CoverArt.setUpcCode(UUID.randomUUID().toString()); + album0CoverArt.setFrontCoverArtUrl("http://fakeurl-0"); + album0CoverArt.setBackCoverArtUrl("http://fakeurl-1"); + + Album album0 = new Album(); + album0.setCoverArt(album0CoverArt); + album0.setName("Album 0"); + album0.setSong(Lists.newArrayList(song0, song1, song2)); + album0 = albumRepository.save(album0); + + CoverArt album1CoverArt = new CoverArt(); + album1CoverArt.setUpcCode(UUID.randomUUID().toString()); + album1CoverArt.setFrontCoverArtUrl("http://fakeurl-2"); + album1CoverArt.setBackCoverArtUrl("http://fakeurl-3"); + + Album album1 = new Album(); + album1.setCoverArt(album1CoverArt); + album1.setName("Album 1"); + album1.setSong(Lists.newArrayList(song3)); + albumRepository.save(album1); + + Iterable queryAlbumsResult = albumRepository.findAll(); + assertThat(queryAlbumsResult).hasSize(3); + + Iterable querySongsResult = songRepository.findAll(); + assertThat(querySongsResult).hasSize(5); + + Album queryAlbumResult; + + queryAlbumResult = albumRepository.findById(nullAlbum.getId()).get(); + assertThat(queryAlbumResult.getName()).isNull(); + assertThat(queryAlbumResult.getCoverArt()).isNull(); + assertThat(queryAlbumResult.getSongs()).isNullOrEmpty(); + + queryAlbumResult = albumRepository.findById(album0.getId()).get(); + assertThat(queryAlbumResult.getName()).isEqualTo("Album 0"); + assertThat(queryAlbumResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-0"); + assertThat(queryAlbumResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-1"); + assertThat(queryAlbumResult.getSongs()).hasSize(3); + assertThat(queryAlbumResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(song0, song1, song2); + + queryAlbumResult = albumRepository.findById(album1.getId()).get(); + assertThat(queryAlbumResult.getName()).isEqualTo("Album 1"); + assertThat(queryAlbumResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-2"); + assertThat(queryAlbumResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-3"); + assertThat(queryAlbumResult.getSongs()).hasSize(1); + assertThat(queryAlbumResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(song3); + + Song querySongResult; + + querySongResult = songRepository.findById(nullSong.getId()).get(); + assertThat(querySongResult.getName()).isNull(); + assertThat(querySongResult.getLength()).isZero(); + assertThat(querySongResult.getArtist()).isNull(); + + querySongResult = songRepository.findById(song0.getId()).get(); + assertThat(querySongResult.getName()).isEqualTo("A Happy Song"); + assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(4).getSeconds()); + assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); + assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); + assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); + + querySongResult = songRepository.findById(song1.getId()).get(); + assertThat(querySongResult.getName()).isEqualTo("A Sad Song"); + assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(2).getSeconds()); + assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); + assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); + assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); + + querySongResult = songRepository.findById(song2.getId()).get(); + assertThat(querySongResult.getName()).isEqualTo("Another Happy Song"); + assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(3).getSeconds()); + assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); + assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); + assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); + + querySongResult = songRepository.findById(song3.getId()).get(); + assertThat(querySongResult.getName()).isEqualTo("A New Song"); + assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(5).getSeconds()); + assertThat(querySongResult.getArtist().getName()).isEqualTo("Newcomer"); + assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Reggae"); + assertThat(querySongResult.getArtist().getCountry()).isEqualTo("Jamaica"); + } + + @Test + void hibernateTypeYearMonthTest() { + Song mySong = new Song(); + YearMonth now = YearMonth.of(2019, 12); + mySong.setArtist(new Artist()); + mySong.setName("My Song"); + mySong.setLength(Duration.ofMinutes(1).getSeconds()); + mySong.setRecordedOn(now); + mySong = songRepository.save(mySong); + + Song queryResult; + queryResult = songRepository.findById(mySong.getId()).get(); + assertThat(queryResult.getRecordedOn().getYear()).isEqualTo(2019); + assertThat(queryResult.getRecordedOn().getMonthValue()).isEqualTo(12); + } +} diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index ec7f0bcec2..4d39b2d98b 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -24,6 +24,7 @@ hibernate-mapping hibernate-ogm hibernate-annotations + hibernate-types hibernate-jpa hibernate-queries hibernate-enterprise From 4426454a9aa71e43def26b27e0912c84ad06b0f4 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 07:42:28 -0400 Subject: [PATCH 05/20] Fixup variable names --- .../types/HibernateTypesIntegrationTest.java | 212 +++++++++--------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java index cf3c34777e..af28eadfb8 100644 --- a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java +++ b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java @@ -38,134 +38,134 @@ public class HibernateTypesIntegrationTest { @Test - void hibernateTypeJsonTest() { - Album nullAlbum = new Album(); - nullAlbum = albumRepository.save(nullAlbum); + void whenSavingHibernateTypes_thenTheCorrectJsonIsStoredInTheDatabase() { + Album emptyAlbum = new Album(); + emptyAlbum = albumRepository.save(emptyAlbum); - Song nullSong = new Song(); - nullSong = songRepository.save(nullSong); + Song emptySong = new Song(); + emptySong = songRepository.save(emptySong); - Artist artist0 = new Artist(); - artist0.setCountry("England"); - artist0.setGenre("Pop"); - artist0.setName("Superstar"); + Artist superstarArtist = new Artist(); + superstarArtist.setCountry("England"); + superstarArtist.setGenre("Pop"); + superstarArtist.setName("Superstar"); - Song song0 = new Song(); - song0.setArtist(artist0); - song0.setName("A Happy Song"); - song0.setLength(Duration.ofMinutes(4).getSeconds()); - song0 = songRepository.save(song0); + Song aHappySong = new Song(); + aHappySong.setArtist(superstarArtist); + aHappySong.setName("A Happy Song"); + aHappySong.setLength(Duration.ofMinutes(4).getSeconds()); + aHappySong = songRepository.save(aHappySong); - Song song1 = new Song(); - song1.setArtist(artist0); - song1.setName("A Sad Song"); - song1.setLength(Duration.ofMinutes(2).getSeconds()); - song1 = songRepository.save(song1); + Song aSadSong = new Song(); + aSadSong.setArtist(superstarArtist); + aSadSong.setName("A Sad Song"); + aSadSong.setLength(Duration.ofMinutes(2).getSeconds()); + aSadSong = songRepository.save(aSadSong); - Song song2 = new Song(); - song2.setArtist(artist0); - song2.setName("Another Happy Song"); - song2.setLength(Duration.ofMinutes(3).getSeconds()); - song2 = songRepository.save(song2); + Song anotherHappySong = new Song(); + anotherHappySong.setArtist(superstarArtist); + anotherHappySong.setName("Another Happy Song"); + anotherHappySong.setLength(Duration.ofMinutes(3).getSeconds()); + anotherHappySong = songRepository.save(anotherHappySong); - Artist artist1 = new Artist(); - artist1.setCountry("Jamaica"); - artist1.setGenre("Reggae"); - artist1.setName("Newcomer"); + Artist newcomer = new Artist(); + newcomer.setCountry("Jamaica"); + newcomer.setGenre("Reggae"); + newcomer.setName("Newcomer"); - Song song3 = new Song(); - song3.setArtist(artist1); - song3.setName("A New Song"); - song3.setLength(Duration.ofMinutes(5).getSeconds()); - song3 = songRepository.save(song3); + Song aNewSong = new Song(); + aNewSong.setArtist(newcomer); + aNewSong.setName("A New Song"); + aNewSong.setLength(Duration.ofMinutes(5).getSeconds()); + aNewSong = songRepository.save(aNewSong); - CoverArt album0CoverArt = new CoverArt(); - album0CoverArt.setUpcCode(UUID.randomUUID().toString()); - album0CoverArt.setFrontCoverArtUrl("http://fakeurl-0"); - album0CoverArt.setBackCoverArtUrl("http://fakeurl-1"); + CoverArt superstarAlbumCoverArt = new CoverArt(); + superstarAlbumCoverArt.setUpcCode(UUID.randomUUID().toString()); + superstarAlbumCoverArt.setFrontCoverArtUrl("http://fakeurl-0"); + superstarAlbumCoverArt.setBackCoverArtUrl("http://fakeurl-1"); - Album album0 = new Album(); - album0.setCoverArt(album0CoverArt); - album0.setName("Album 0"); - album0.setSong(Lists.newArrayList(song0, song1, song2)); - album0 = albumRepository.save(album0); + Album superstarAlbum = new Album(); + superstarAlbum.setCoverArt(superstarAlbumCoverArt); + superstarAlbum.setName("The Superstar Album"); + superstarAlbum.setSong(Lists.newArrayList(aHappySong, aSadSong, anotherHappySong)); + superstarAlbum = albumRepository.save(superstarAlbum); - CoverArt album1CoverArt = new CoverArt(); - album1CoverArt.setUpcCode(UUID.randomUUID().toString()); - album1CoverArt.setFrontCoverArtUrl("http://fakeurl-2"); - album1CoverArt.setBackCoverArtUrl("http://fakeurl-3"); + CoverArt newcomerAlbumCoverArt = new CoverArt(); + newcomerAlbumCoverArt.setUpcCode(UUID.randomUUID().toString()); + newcomerAlbumCoverArt.setFrontCoverArtUrl("http://fakeurl-2"); + newcomerAlbumCoverArt.setBackCoverArtUrl("http://fakeurl-3"); - Album album1 = new Album(); - album1.setCoverArt(album1CoverArt); - album1.setName("Album 1"); - album1.setSong(Lists.newArrayList(song3)); - albumRepository.save(album1); + Album newcomerAlbum = new Album(); + newcomerAlbum.setCoverArt(newcomerAlbumCoverArt); + newcomerAlbum.setName("The Newcomer Album"); + newcomerAlbum.setSong(Lists.newArrayList(aNewSong)); + albumRepository.save(newcomerAlbum); - Iterable queryAlbumsResult = albumRepository.findAll(); - assertThat(queryAlbumsResult).hasSize(3); + Iterable selectAlbumsQueryResult = albumRepository.findAll(); + assertThat(selectAlbumsQueryResult).hasSize(3); - Iterable querySongsResult = songRepository.findAll(); - assertThat(querySongsResult).hasSize(5); + Iterable selectSongsQueryResult = songRepository.findAll(); + assertThat(selectSongsQueryResult).hasSize(5); - Album queryAlbumResult; + Album selectAlbumQueryResult; - queryAlbumResult = albumRepository.findById(nullAlbum.getId()).get(); - assertThat(queryAlbumResult.getName()).isNull(); - assertThat(queryAlbumResult.getCoverArt()).isNull(); - assertThat(queryAlbumResult.getSongs()).isNullOrEmpty(); + selectAlbumQueryResult = albumRepository.findById(emptyAlbum.getId()).get(); + assertThat(selectAlbumQueryResult.getName()).isNull(); + assertThat(selectAlbumQueryResult.getCoverArt()).isNull(); + assertThat(selectAlbumQueryResult.getSongs()).isNullOrEmpty(); - queryAlbumResult = albumRepository.findById(album0.getId()).get(); - assertThat(queryAlbumResult.getName()).isEqualTo("Album 0"); - assertThat(queryAlbumResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-0"); - assertThat(queryAlbumResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-1"); - assertThat(queryAlbumResult.getSongs()).hasSize(3); - assertThat(queryAlbumResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(song0, song1, song2); + selectAlbumQueryResult = albumRepository.findById(superstarAlbum.getId()).get(); + assertThat(selectAlbumQueryResult.getName()).isEqualTo("Album 0"); + assertThat(selectAlbumQueryResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-0"); + assertThat(selectAlbumQueryResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-1"); + assertThat(selectAlbumQueryResult.getSongs()).hasSize(3); + assertThat(selectAlbumQueryResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(aHappySong, aSadSong, anotherHappySong); - queryAlbumResult = albumRepository.findById(album1.getId()).get(); - assertThat(queryAlbumResult.getName()).isEqualTo("Album 1"); - assertThat(queryAlbumResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-2"); - assertThat(queryAlbumResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-3"); - assertThat(queryAlbumResult.getSongs()).hasSize(1); - assertThat(queryAlbumResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(song3); + selectAlbumQueryResult = albumRepository.findById(superstarAlbum.getId()).get(); + assertThat(selectAlbumQueryResult.getName()).isEqualTo("Album 1"); + assertThat(selectAlbumQueryResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-2"); + assertThat(selectAlbumQueryResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-3"); + assertThat(selectAlbumQueryResult.getSongs()).hasSize(1); + assertThat(selectAlbumQueryResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(aNewSong); - Song querySongResult; + Song selectSongQueryResult; - querySongResult = songRepository.findById(nullSong.getId()).get(); - assertThat(querySongResult.getName()).isNull(); - assertThat(querySongResult.getLength()).isZero(); - assertThat(querySongResult.getArtist()).isNull(); + selectSongQueryResult = songRepository.findById(emptySong.getId()).get(); + assertThat(selectSongQueryResult.getName()).isNull(); + assertThat(selectSongQueryResult.getLength()).isZero(); + assertThat(selectSongQueryResult.getArtist()).isNull(); - querySongResult = songRepository.findById(song0.getId()).get(); - assertThat(querySongResult.getName()).isEqualTo("A Happy Song"); - assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(4).getSeconds()); - assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); - assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); - assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); + selectSongQueryResult = songRepository.findById(aHappySong.getId()).get(); + assertThat(selectSongQueryResult.getName()).isEqualTo("A Happy Song"); + assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(4).getSeconds()); + assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Superstar"); + assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Pop"); + assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("England"); - querySongResult = songRepository.findById(song1.getId()).get(); - assertThat(querySongResult.getName()).isEqualTo("A Sad Song"); - assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(2).getSeconds()); - assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); - assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); - assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); + selectSongQueryResult = songRepository.findById(aSadSong.getId()).get(); + assertThat(selectSongQueryResult.getName()).isEqualTo("A Sad Song"); + assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(2).getSeconds()); + assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Superstar"); + assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Pop"); + assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("England"); - querySongResult = songRepository.findById(song2.getId()).get(); - assertThat(querySongResult.getName()).isEqualTo("Another Happy Song"); - assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(3).getSeconds()); - assertThat(querySongResult.getArtist().getName()).isEqualTo("Superstar"); - assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Pop"); - assertThat(querySongResult.getArtist().getCountry()).isEqualTo("England"); + selectSongQueryResult = songRepository.findById(anotherHappySong.getId()).get(); + assertThat(selectSongQueryResult.getName()).isEqualTo("Another Happy Song"); + assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(3).getSeconds()); + assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Superstar"); + assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Pop"); + assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("England"); - querySongResult = songRepository.findById(song3.getId()).get(); - assertThat(querySongResult.getName()).isEqualTo("A New Song"); - assertThat(querySongResult.getLength()).isEqualTo(Duration.ofMinutes(5).getSeconds()); - assertThat(querySongResult.getArtist().getName()).isEqualTo("Newcomer"); - assertThat(querySongResult.getArtist().getGenre()).isEqualTo("Reggae"); - assertThat(querySongResult.getArtist().getCountry()).isEqualTo("Jamaica"); + selectSongQueryResult = songRepository.findById(aNewSong.getId()).get(); + assertThat(selectSongQueryResult.getName()).isEqualTo("A New Song"); + assertThat(selectSongQueryResult.getLength()).isEqualTo(Duration.ofMinutes(5).getSeconds()); + assertThat(selectSongQueryResult.getArtist().getName()).isEqualTo("Newcomer"); + assertThat(selectSongQueryResult.getArtist().getGenre()).isEqualTo("Reggae"); + assertThat(selectSongQueryResult.getArtist().getCountry()).isEqualTo("Jamaica"); } @Test - void hibernateTypeYearMonthTest() { + void whenSavingAHibernateTypeYearMonth_thenTheCorrectValueIsStoredInTheDatabase() { Song mySong = new Song(); YearMonth now = YearMonth.of(2019, 12); mySong.setArtist(new Artist()); @@ -174,9 +174,9 @@ public class HibernateTypesIntegrationTest { mySong.setRecordedOn(now); mySong = songRepository.save(mySong); - Song queryResult; - queryResult = songRepository.findById(mySong.getId()).get(); - assertThat(queryResult.getRecordedOn().getYear()).isEqualTo(2019); - assertThat(queryResult.getRecordedOn().getMonthValue()).isEqualTo(12); + Song selectSongQueryResult; + selectSongQueryResult = songRepository.findById(mySong.getId()).get(); + assertThat(selectSongQueryResult.getRecordedOn().getYear()).isEqualTo(2019); + assertThat(selectSongQueryResult.getRecordedOn().getMonthValue()).isEqualTo(12); } } From a667a0191a4bc099ce92e1acf09455412938f073 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 07:48:01 -0400 Subject: [PATCH 06/20] Fix integration test --- .../hibernate/types/HibernateTypesIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java index af28eadfb8..08d4cf919d 100644 --- a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java +++ b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java @@ -115,14 +115,14 @@ public class HibernateTypesIntegrationTest { assertThat(selectAlbumQueryResult.getSongs()).isNullOrEmpty(); selectAlbumQueryResult = albumRepository.findById(superstarAlbum.getId()).get(); - assertThat(selectAlbumQueryResult.getName()).isEqualTo("Album 0"); + assertThat(selectAlbumQueryResult.getName()).isEqualTo("The Superstar Album"); assertThat(selectAlbumQueryResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-0"); assertThat(selectAlbumQueryResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-1"); assertThat(selectAlbumQueryResult.getSongs()).hasSize(3); assertThat(selectAlbumQueryResult.getSongs()).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(aHappySong, aSadSong, anotherHappySong); - selectAlbumQueryResult = albumRepository.findById(superstarAlbum.getId()).get(); - assertThat(selectAlbumQueryResult.getName()).isEqualTo("Album 1"); + selectAlbumQueryResult = albumRepository.findById(newcomerAlbum.getId()).get(); + assertThat(selectAlbumQueryResult.getName()).isEqualTo("The Newcomer Album"); assertThat(selectAlbumQueryResult.getCoverArt().getFrontCoverArtUrl()).isEqualTo("http://fakeurl-2"); assertThat(selectAlbumQueryResult.getCoverArt().getBackCoverArtUrl()).isEqualTo("http://fakeurl-3"); assertThat(selectAlbumQueryResult.getSongs()).hasSize(1); From dc3f7039cb7c38e4ef07fdcb6d09de265fbc07df Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 13:41:10 -0400 Subject: [PATCH 07/20] Revert "Fixup styling" This reverts commit 72addaf8c354879197e0c252e4d8153cc54e0e2c. --- .../architecture/application/task/AddNewDailyTask.java | 2 +- .../com/baeldung/architecture/commands/task/CreateTask.java | 2 +- .../com/baeldung/architecture/commands/task/GetAllTasks.java | 2 +- .../com/baeldung/architecture/domain/task/TaskService.java | 2 +- .../com/baeldung/architecture/framework/cli/StartupRunner.java | 2 +- .../architecture/framework/http/task/TaskApiController.java | 2 +- .../baeldung/architecture/framework/http/task/TaskRequest.java | 3 ++- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java index f9ee97542c..208d1bfcc9 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java @@ -26,4 +26,4 @@ public class AddNewDailyTask implements CreateTask { addNewTask.create(task); } } -} +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java index ec60868a22..26e6da10e2 100644 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java @@ -4,4 +4,4 @@ import com.baeldung.architecture.domain.task.Task; public interface CreateTask { public void create(Task newTask); -} +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java index c9aa1be5f8..d3c40db92f 100644 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java @@ -4,4 +4,4 @@ import com.baeldung.architecture.domain.task.Task; public interface GetAllTasks { public Iterable getAll(); -} +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java index 11ef0f3e19..cace0614ad 100644 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java @@ -19,4 +19,4 @@ public class TaskService { return taskRepository.findAll(); } -} +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java index 449bc9386e..cf38e5ee5e 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -21,4 +21,4 @@ public class StartupRunner implements ApplicationRunner { task.setDescription("Startup Task"); addNewDailyTask.create(task); } -} +} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java index 87a8f5fe4b..c6f7bff2dd 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java @@ -39,4 +39,4 @@ public class TaskApiController { task.setDueDate(Instant.parse(taskRequest.getDueDate())); addNewTask.create(task); } -} +} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java index 70b98a32f9..2e353b079a 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java @@ -25,4 +25,5 @@ public class TaskRequest { public void setDueDate(String dueDate) { this.dueDate = dueDate; } -} + +} \ No newline at end of file From a2efde1d8707cb85898c6fb0eb5321ab0dce392d Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 13:41:33 -0400 Subject: [PATCH 08/20] Revert "Fixup styling" This reverts commit 6cb35dd535bfddad1243feaae2f3d2af0dc932d7. --- .../architecture/HexagonalArchitectureTaskApplication.java | 6 +++--- .../baeldung/architecture/application/task/AddNewTask.java | 2 +- .../baeldung/architecture/application/task/GetTasks.java | 2 +- .../baeldung/architecture/framework/cli/StartupRunner.java | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java index 69c6f4b276..83e4fc4c0b 100644 --- a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java +++ b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java @@ -5,8 +5,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HexagonalArchitectureTaskApplication { - public static void main(String[] args) { - SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); + } } diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java index 70638378f9..2e5aff4a53 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java @@ -19,4 +19,4 @@ public class AddNewTask implements CreateTask { public void create(Task newTask) { taskService.createTask(newTask); } -} +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java index c876f7de85..54539290ba 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java @@ -19,4 +19,4 @@ public class GetTasks implements GetAllTasks { public Iterable getAll() { return taskService.getAllTasks(); } -} +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java index cf38e5ee5e..260c033b71 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -17,6 +17,7 @@ public class StartupRunner implements ApplicationRunner { } @Override public void run(ApplicationArguments args) throws Exception { + System.out.println("Adding daily tasks"); Task task = new Task(); task.setDescription("Startup Task"); addNewDailyTask.create(task); From 6008e4446787ab8e4a638fabfb5f734e39ecc384 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 13:41:47 -0400 Subject: [PATCH 09/20] Revert "Add architecture module with Hexagonal example" This reverts commit 50efbf3dfb3a951d276c13ab3b8f1a0cadb114d4. --- architecture/README.md | 3 -- architecture/pom.xml | 33 ------------ .../HexagonalArchitectureTaskApplication.java | 12 ----- .../application/task/AddNewDailyTask.java | 29 ---------- .../application/task/AddNewTask.java | 22 -------- .../application/task/GetTasks.java | 22 -------- .../commands/task/CreateTask.java | 7 --- .../commands/task/GetAllTasks.java | 7 --- .../architecture/domain/task/Task.java | 53 ------------------- .../domain/task/TaskRepository.java | 7 --- .../architecture/domain/task/TaskService.java | 22 -------- .../framework/cli/StartupRunner.java | 25 --------- .../http/task/TaskApiController.java | 42 --------------- .../framework/http/task/TaskRequest.java | 29 ---------- 14 files changed, 313 deletions(-) delete mode 100644 architecture/README.md delete mode 100644 architecture/pom.xml delete mode 100644 architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java diff --git a/architecture/README.md b/architecture/README.md deleted file mode 100644 index be093f25ed..0000000000 --- a/architecture/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant articles - -- [A Quick and Practical Example of Hexagonal Architecture in Java](https://www.baeldung.com/a-quick-and-practical-example-of-hexagonal-architecture-in-java-3/) diff --git a/architecture/pom.xml b/architecture/pom.xml deleted file mode 100644 index 4ad104293e..0000000000 --- a/architecture/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - 4.0.0 - com.baeldung.architecture - architecture - 0.0.1-SNAPSHOT - architecture - jar - A Quick and Practical Example of Hexagonal Architecture in Java - - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-web - - - diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java deleted file mode 100644 index 83e4fc4c0b..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.architecture; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HexagonalArchitectureTaskApplication { - public static void main(String[] args) { - SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); - } - -} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java deleted file mode 100644 index 208d1bfcc9..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.architecture.application.task; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; - -import com.baeldung.architecture.commands.task.CreateTask; -import com.baeldung.architecture.domain.task.Task; - -import org.springframework.stereotype.Component; - -@Component -public class AddNewDailyTask implements CreateTask { - - private AddNewTask addNewTask; - - public AddNewDailyTask(AddNewTask addNewTask) { - this.addNewTask = addNewTask; - } - - @Override - public void create(Task newTask) { - Instant initialDueDate = newTask.getDueDate(); - String description = newTask.getDescription(); - for (int i = 1; i <= 5; i++) { - Task task = new Task(initialDueDate.plus(i, ChronoUnit.DAYS), description); - addNewTask.create(task); - } - } -}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java deleted file mode 100644 index 2e5aff4a53..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.architecture.application.task; - -import com.baeldung.architecture.domain.task.Task; -import com.baeldung.architecture.domain.task.TaskService; -import com.baeldung.architecture.commands.task.*; - -import org.springframework.stereotype.Component; - -@Component -public class AddNewTask implements CreateTask { - - private TaskService taskService; - - public AddNewTask(TaskService taskService) { - this.taskService = taskService; - } - - @Override - public void create(Task newTask) { - taskService.createTask(newTask); - } -}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java deleted file mode 100644 index 54539290ba..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.architecture.application.task; - -import com.baeldung.architecture.domain.task.Task; -import com.baeldung.architecture.domain.task.TaskService; -import com.baeldung.architecture.commands.task.*; - -import org.springframework.stereotype.Component; - -@Component -public class GetTasks implements GetAllTasks { - - private TaskService taskService; - - public GetTasks(TaskService taskService) { - this.taskService = taskService; - } - - @Override - public Iterable getAll() { - return taskService.getAllTasks(); - } -}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java deleted file mode 100644 index 26e6da10e2..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.architecture.commands.task; - -import com.baeldung.architecture.domain.task.Task; - -public interface CreateTask { - public void create(Task newTask); -}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java deleted file mode 100644 index d3c40db92f..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.architecture.commands.task; - -import com.baeldung.architecture.domain.task.Task; - -public interface GetAllTasks { - public Iterable getAll(); -}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java deleted file mode 100644 index 240dc33571..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.architecture.domain.task; - -import java.time.Instant; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Task { - @Id - @GeneratedValue(strategy=GenerationType.AUTO) - private Long id; - private Instant dueDate = Instant.now(); - private String description; - - public Task() {} - - public Task(Instant dueDate, String description) { - this.dueDate = dueDate; - this.description = description; - } - - public Task(Long id, Instant dueDate, String description) { - this(dueDate, description); - this.id = id; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Instant getDueDate() { - return dueDate; - } - - public void setDueDate(Instant dueDate) { - this.dueDate = dueDate; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java deleted file mode 100644 index d896212714..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.architecture.domain.task; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface TaskRepository extends CrudRepository {}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java deleted file mode 100644 index cace0614ad..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.architecture.domain.task; - -import org.springframework.stereotype.Service; - -@Service -public class TaskService { - - private TaskRepository taskRepository; - - public TaskService(TaskRepository taskRepository) { - this.taskRepository = taskRepository; - } - - public void createTask(Task task) { - taskRepository.save(task); - } - - public Iterable getAllTasks() { - return taskRepository.findAll(); - } - -}; diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java deleted file mode 100644 index 260c033b71..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.architecture.framework.cli; - -import com.baeldung.architecture.application.task.AddNewDailyTask; -import com.baeldung.architecture.domain.task.Task; - -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -@Component -public class StartupRunner implements ApplicationRunner { - - AddNewDailyTask addNewDailyTask; - - public StartupRunner(AddNewDailyTask addNewDailyTask) { - this.addNewDailyTask = addNewDailyTask; - } - @Override - public void run(ApplicationArguments args) throws Exception { - System.out.println("Adding daily tasks"); - Task task = new Task(); - task.setDescription("Startup Task"); - addNewDailyTask.create(task); - } -} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java deleted file mode 100644 index c6f7bff2dd..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.architecture.framework.http.task; - -import java.time.Instant; - -import com.baeldung.architecture.application.task.AddNewTask; -import com.baeldung.architecture.application.task.GetTasks; -import com.baeldung.architecture.domain.task.Task; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("task") -public class TaskApiController { - - private AddNewTask addNewTask; - private GetTasks getTasks; - - public TaskApiController( - AddNewTask addNewTask, - GetTasks getTasks - ) { - this.addNewTask = addNewTask; - this.getTasks = getTasks; - } - - @GetMapping - Iterable listTasks() { - return getTasks.getAll(); - } - - @PostMapping(consumes = "application/json", produces = "application/json") - void createTask(@RequestBody TaskRequest taskRequest) { - Task task = new Task(); - task.setDescription(taskRequest.getDescription()); - task.setDueDate(Instant.parse(taskRequest.getDueDate())); - addNewTask.create(task); - } -} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java deleted file mode 100644 index 2e353b079a..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.architecture.framework.http.task; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -public class TaskRequest { - @JsonInclude(Include.NON_NULL) - private String description; - - @JsonInclude(Include.NON_NULL) - private String dueDate; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDueDate() { - return dueDate; - } - - public void setDueDate(String dueDate) { - this.dueDate = dueDate; - } - -} \ No newline at end of file From cabe3381634a24af850c504ae76ac9844e2d70fe Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 13:59:02 -0400 Subject: [PATCH 10/20] Update application.properties --- .../src/main/resources/application.properties | 7 ------- 1 file changed, 7 deletions(-) diff --git a/persistence-modules/hibernate-types/src/main/resources/application.properties b/persistence-modules/hibernate-types/src/main/resources/application.properties index bcd21578dd..9588139eb0 100644 --- a/persistence-modules/hibernate-types/src/main/resources/application.properties +++ b/persistence-modules/hibernate-types/src/main/resources/application.properties @@ -7,15 +7,8 @@ logging.level.jdbc.resultset=fatal logging.level.jdbc.resultsettable=info logging.level.jdbc.sqlonly=fatal logging.level.jdbc.sqltiming=info -# logging.level.org.hibernate.SQL=DEBUG -# logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE -# logging.level.org.hibernate.type.descriptor.sql=trace -# logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG -# logging.level.org.springframework.jdbc.core.StatementCreatorUtils=TRACE spring.datasource.url=jdbc:mysql://localhost:53306/hibernate_types?serverTimezone=UTC&useSSL=false spring.datasource.username=root spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect spring.jpa.hibernate.ddl-auto=create spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -# spring.jpa.properties.hibernate.format_sql=false -# spring.jpa.show-sql=false \ No newline at end of file From e91d8d6a6cc9fe1fbb0ad3ea66f6277bb6c37193 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 25 Apr 2020 14:33:28 -0400 Subject: [PATCH 11/20] Update pom --- persistence-modules/hibernate-types/pom.xml | 2 +- .../baeldung/hibernate/types/HibernateTypesIntegrationTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/persistence-modules/hibernate-types/pom.xml b/persistence-modules/hibernate-types/pom.xml index 9fa5d66347..4d686c72a5 100644 --- a/persistence-modules/hibernate-types/pom.xml +++ b/persistence-modules/hibernate-types/pom.xml @@ -205,7 +205,7 @@ 3.0.2 2.22.2 3.8.1 - 3.7.0 + 3.8.1 8.0.19 1.7.30 2.1.3.RELEASE diff --git a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java index 08d4cf919d..9d7479e77d 100644 --- a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java +++ b/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java @@ -36,7 +36,6 @@ public class HibernateTypesIntegrationTest { setUp(); } - @Test void whenSavingHibernateTypes_thenTheCorrectJsonIsStoredInTheDatabase() { Album emptyAlbum = new Album(); From d44a7f3d1c02f30cf4b375d28a6840584d3c99a1 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 08:46:23 -0400 Subject: [PATCH 12/20] Rename to hibernate-libraries --- .../.mvn/wrapper/MavenWrapperDownloader.java | 117 +++++++ .../.mvn/wrapper/maven-wrapper.properties | 2 + .../docker-compose.yml | 0 .../docker-entrypoint-initdb.d/init-db.sql | 0 .../docker/etc/mysql/conf.d/utf8.cnf | 0 persistence-modules/hibernate-libraries/mvnw | 310 ++++++++++++++++++ .../hibernate-libraries/mvnw.cmd | 182 ++++++++++ .../pom.xml | 0 .../com/baeldung/hibernate/types/Album.java | 0 .../hibernate/types/AlbumRepository.java | 0 .../com/baeldung/hibernate/types/Artist.java | 0 .../baeldung/hibernate/types/BaseEntity.java | 0 .../baeldung/hibernate/types/CoverArt.java | 0 .../types/HibernateTypesApplication.java | 0 .../com/baeldung/hibernate/types/Song.java | 0 .../hibernate/types/SongRepository.java | 0 .../src/main/resources/application.properties | 0 .../main/resources/hibernate-types.properties | 0 .../types/HibernateTypesIntegrationTest.java | 0 .../hibernate-types/.gitignore | 33 -- persistence-modules/hibernate-types/README.md | 7 - 21 files changed, 611 insertions(+), 40 deletions(-) create mode 100644 persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java create mode 100644 persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties rename persistence-modules/{hibernate-types => hibernate-libraries}/docker-compose.yml (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/docker/docker-entrypoint-initdb.d/init-db.sql (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/docker/etc/mysql/conf.d/utf8.cnf (100%) create mode 100755 persistence-modules/hibernate-libraries/mvnw create mode 100644 persistence-modules/hibernate-libraries/mvnw.cmd rename persistence-modules/{hibernate-types => hibernate-libraries}/pom.xml (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/Album.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/Artist.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/BaseEntity.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/CoverArt.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/Song.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/java/com/baeldung/hibernate/types/SongRepository.java (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/resources/application.properties (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/main/resources/hibernate-types.properties (100%) rename persistence-modules/{hibernate-types => hibernate-libraries}/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java (100%) delete mode 100644 persistence-modules/hibernate-types/.gitignore delete mode 100644 persistence-modules/hibernate-types/README.md diff --git a/persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java b/persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000..b901097f2d --- /dev/null +++ b/persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties b/persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..642d572ce9 --- /dev/null +++ b/persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/persistence-modules/hibernate-types/docker-compose.yml b/persistence-modules/hibernate-libraries/docker-compose.yml similarity index 100% rename from persistence-modules/hibernate-types/docker-compose.yml rename to persistence-modules/hibernate-libraries/docker-compose.yml diff --git a/persistence-modules/hibernate-types/docker/docker-entrypoint-initdb.d/init-db.sql b/persistence-modules/hibernate-libraries/docker/docker-entrypoint-initdb.d/init-db.sql similarity index 100% rename from persistence-modules/hibernate-types/docker/docker-entrypoint-initdb.d/init-db.sql rename to persistence-modules/hibernate-libraries/docker/docker-entrypoint-initdb.d/init-db.sql diff --git a/persistence-modules/hibernate-types/docker/etc/mysql/conf.d/utf8.cnf b/persistence-modules/hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf similarity index 100% rename from persistence-modules/hibernate-types/docker/etc/mysql/conf.d/utf8.cnf rename to persistence-modules/hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf diff --git a/persistence-modules/hibernate-libraries/mvnw b/persistence-modules/hibernate-libraries/mvnw new file mode 100755 index 0000000000..41c0f0c23d --- /dev/null +++ b/persistence-modules/hibernate-libraries/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/persistence-modules/hibernate-libraries/mvnw.cmd b/persistence-modules/hibernate-libraries/mvnw.cmd new file mode 100644 index 0000000000..86115719e5 --- /dev/null +++ b/persistence-modules/hibernate-libraries/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/persistence-modules/hibernate-types/pom.xml b/persistence-modules/hibernate-libraries/pom.xml similarity index 100% rename from persistence-modules/hibernate-types/pom.xml rename to persistence-modules/hibernate-libraries/pom.xml diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Album.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/Album.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Album.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/Album.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/AlbumRepository.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Artist.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/Artist.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Artist.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/Artist.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/BaseEntity.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/BaseEntity.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/BaseEntity.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/BaseEntity.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/CoverArt.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/CoverArt.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/CoverArt.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/CoverArt.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/HibernateTypesApplication.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Song.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/Song.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/Song.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/Song.java diff --git a/persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/SongRepository.java b/persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/SongRepository.java similarity index 100% rename from persistence-modules/hibernate-types/src/main/java/com/baeldung/hibernate/types/SongRepository.java rename to persistence-modules/hibernate-libraries/src/main/java/com/baeldung/hibernate/types/SongRepository.java diff --git a/persistence-modules/hibernate-types/src/main/resources/application.properties b/persistence-modules/hibernate-libraries/src/main/resources/application.properties similarity index 100% rename from persistence-modules/hibernate-types/src/main/resources/application.properties rename to persistence-modules/hibernate-libraries/src/main/resources/application.properties diff --git a/persistence-modules/hibernate-types/src/main/resources/hibernate-types.properties b/persistence-modules/hibernate-libraries/src/main/resources/hibernate-types.properties similarity index 100% rename from persistence-modules/hibernate-types/src/main/resources/hibernate-types.properties rename to persistence-modules/hibernate-libraries/src/main/resources/hibernate-types.properties diff --git a/persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java b/persistence-modules/hibernate-libraries/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate-types/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java rename to persistence-modules/hibernate-libraries/src/test/java/com/baeldung/hibernate/types/HibernateTypesIntegrationTest.java diff --git a/persistence-modules/hibernate-types/.gitignore b/persistence-modules/hibernate-types/.gitignore deleted file mode 100644 index 94b9c48616..0000000000 --- a/persistence-modules/hibernate-types/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -.classpath -.project -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ diff --git a/persistence-modules/hibernate-types/README.md b/persistence-modules/hibernate-types/README.md deleted file mode 100644 index 9d02d8c8f2..0000000000 --- a/persistence-modules/hibernate-types/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Hibernate Types - -This module contains articles specific to use of Hibernate Types. - -### Relevant articles: - -- [A Guide to Hibernate Types Project](https://www.baeldung.com/a-guide-to-hibernate-types-project/) From cc2dfb4206355318e25b110920e3c2af19a62f2c Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 08:52:18 -0400 Subject: [PATCH 13/20] Remove maven wrapper files --- .../.mvn/wrapper/MavenWrapperDownloader.java | 117 ------- .../.mvn/wrapper/maven-wrapper.properties | 2 - persistence-modules/hibernate-libraries/mvnw | 310 ------------------ .../hibernate-libraries/mvnw.cmd | 182 ---------- 4 files changed, 611 deletions(-) delete mode 100644 persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java delete mode 100644 persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties delete mode 100755 persistence-modules/hibernate-libraries/mvnw delete mode 100644 persistence-modules/hibernate-libraries/mvnw.cmd diff --git a/persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java b/persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index b901097f2d..0000000000 --- a/persistence-modules/hibernate-libraries/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties b/persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 642d572ce9..0000000000 --- a/persistence-modules/hibernate-libraries/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/persistence-modules/hibernate-libraries/mvnw b/persistence-modules/hibernate-libraries/mvnw deleted file mode 100755 index 41c0f0c23d..0000000000 --- a/persistence-modules/hibernate-libraries/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/persistence-modules/hibernate-libraries/mvnw.cmd b/persistence-modules/hibernate-libraries/mvnw.cmd deleted file mode 100644 index 86115719e5..0000000000 --- a/persistence-modules/hibernate-libraries/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% From 8fd2a5ee8dd72f5e6f026f44f0b6b2e0d64e0006 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 09:10:36 -0400 Subject: [PATCH 14/20] Create create-database.sh --- .../hibernate-libraries/create-database.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 persistence-modules/hibernate-libraries/create-database.sh diff --git a/persistence-modules/hibernate-libraries/create-database.sh b/persistence-modules/hibernate-libraries/create-database.sh new file mode 100644 index 0000000000..aa363b582e --- /dev/null +++ b/persistence-modules/hibernate-libraries/create-database.sh @@ -0,0 +1,8 @@ +#!/bin/bash +docker run \ + -p 53306:3306 \ + --name=mysql57-hibernate-types \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=true \ + -v ${PWD}/docker/etc/mysql/conf.d:/etc/mysql/conf.d \ + -v ${PWD}/docker/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d \ + -d mysql:5.7 From 2819b53e15e4591b3bcd399e95c45b5bd84bf2da Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 09:12:52 -0400 Subject: [PATCH 15/20] Make shell script executable --- persistence-modules/hibernate-libraries/create-database.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 persistence-modules/hibernate-libraries/create-database.sh diff --git a/persistence-modules/hibernate-libraries/create-database.sh b/persistence-modules/hibernate-libraries/create-database.sh old mode 100644 new mode 100755 From aa9ee72e9e0b1eef0689b1a58cc848e415af1f43 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 09:49:42 -0400 Subject: [PATCH 16/20] Update create-database.sh --- persistence-modules/hibernate-libraries/create-database.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/hibernate-libraries/create-database.sh b/persistence-modules/hibernate-libraries/create-database.sh index aa363b582e..fec49cd5db 100755 --- a/persistence-modules/hibernate-libraries/create-database.sh +++ b/persistence-modules/hibernate-libraries/create-database.sh @@ -3,6 +3,6 @@ docker run \ -p 53306:3306 \ --name=mysql57-hibernate-types \ -e MYSQL_ALLOW_EMPTY_PASSWORD=true \ - -v ${PWD}/docker/etc/mysql/conf.d:/etc/mysql/conf.d \ - -v ${PWD}/docker/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d \ + -v "${PWD}/docker/etc/mysql/conf.d":/etc/mysql/conf.d \ + -v "${PWD}/docker/docker-entrypoint-initdb.d":/docker-entrypoint-initdb.d \ -d mysql:5.7 From 8a30bb544c9436ec859a0697e232c1a4d8974031 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 09:50:24 -0400 Subject: [PATCH 17/20] Update pom.xml --- persistence-modules/hibernate-libraries/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml index 4d686c72a5..418437eb8b 100644 --- a/persistence-modules/hibernate-libraries/pom.xml +++ b/persistence-modules/hibernate-libraries/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - hibernate-types + hibernate-libraries 0.0.1-SNAPSHOT hibernate-types Introduction into hibernate types library From 488989e3de23df21f0050e0f46e4b5d64e8f49e0 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 09:59:02 -0400 Subject: [PATCH 18/20] Update pom.xml --- persistence-modules/hibernate-libraries/pom.xml | 6 +++--- persistence-modules/pom.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml index 4d686c72a5..0b6b5546aa 100644 --- a/persistence-modules/hibernate-libraries/pom.xml +++ b/persistence-modules/hibernate-libraries/pom.xml @@ -4,7 +4,7 @@ 4.0.0 hibernate-types 0.0.1-SNAPSHOT - hibernate-types + hibernate-libraries Introduction into hibernate types library @@ -142,8 +142,8 @@ maven-compiler-plugin ${maven.version} - ${source.version} - ${target.version} + 1.8 + 1.8 diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 4d39b2d98b..3e2c2e6a0f 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -24,7 +24,7 @@ hibernate-mapping hibernate-ogm hibernate-annotations - hibernate-types + hibernate-libraries hibernate-jpa hibernate-queries hibernate-enterprise From ade74299c8d1d4eaca1807a3e08830df6abce132 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 10:11:56 -0400 Subject: [PATCH 19/20] Remove build plugins --- .../hibernate-libraries/pom.xml | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml index 0e99b0d904..ea2dda7e88 100644 --- a/persistence-modules/hibernate-libraries/pom.xml +++ b/persistence-modules/hibernate-libraries/pom.xml @@ -132,32 +132,6 @@ true - - - org.apache.maven.plugins - maven-war-plugin - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven.version} - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - - **/*IntegrationTest.java - - - - From aca989958fb2143df787a11b0770b5a04dccba10 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sun, 17 May 2020 10:17:12 -0400 Subject: [PATCH 20/20] Remove utf8.cnf --- persistence-modules/hibernate-libraries/create-database.sh | 1 - .../hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf | 7 ------- 2 files changed, 8 deletions(-) delete mode 100644 persistence-modules/hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf diff --git a/persistence-modules/hibernate-libraries/create-database.sh b/persistence-modules/hibernate-libraries/create-database.sh index fec49cd5db..da55dc917d 100755 --- a/persistence-modules/hibernate-libraries/create-database.sh +++ b/persistence-modules/hibernate-libraries/create-database.sh @@ -3,6 +3,5 @@ docker run \ -p 53306:3306 \ --name=mysql57-hibernate-types \ -e MYSQL_ALLOW_EMPTY_PASSWORD=true \ - -v "${PWD}/docker/etc/mysql/conf.d":/etc/mysql/conf.d \ -v "${PWD}/docker/docker-entrypoint-initdb.d":/docker-entrypoint-initdb.d \ -d mysql:5.7 diff --git a/persistence-modules/hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf b/persistence-modules/hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf deleted file mode 100644 index 1885d83c8b..0000000000 --- a/persistence-modules/hibernate-libraries/docker/etc/mysql/conf.d/utf8.cnf +++ /dev/null @@ -1,7 +0,0 @@ -[mysqld] -init_connect='SET collation_connection = utf8_unicode_ci' -character-set-server = utf8 -collation-server = utf8_unicode_ci - -[client] -default-character-set = utf8 \ No newline at end of file