From 969935e83c902426f5ff8d6ac535a0349c84f4d3 Mon Sep 17 00:00:00 2001 From: cizek Date: Sat, 16 Apr 2022 17:27:36 +0200 Subject: [PATCH 1/2] added generic service impl --- .../market/manager/domain/DomainService.java | 52 +++++++++++++++++++ .../manager/domain/DomainServiceImpl.java | 46 ++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java create mode 100644 src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java diff --git a/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java new file mode 100644 index 0000000..96f9215 --- /dev/null +++ b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java @@ -0,0 +1,52 @@ +package cz.fi.muni.pa165.flea.market.manager.domain; + +import lombok.NonNull; + +import java.util.List; + +/** + * Service interface for ENTITY with basic CRUD operations + * + * @param entity for the service + * + * @author Michal Cizek + */ +public interface DomainService { + /** + * Creates new entity. + * + * @param object entity to store in database + * @return created entity + */ + ENTITY create(@NonNull ENTITY object); + + /** + * Finds entity by id and returns it. + * + * @param id id of the entity to look for + * @return entity with given id + */ + ENTITY findById(@NonNull String id); + + /** + * Finds all entities. + * + * @return all stored entities + */ + List findAll(); + + /** + * Updates entity. + * + * @param object entity with new values to update + * @return updated entity + */ + ENTITY update(@NonNull ENTITY object); + + /** + * Deletes given entity. + * + * @param object entity to delete + */ + void delete(@NonNull ENTITY object); +} diff --git a/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java new file mode 100644 index 0000000..30de343 --- /dev/null +++ b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainServiceImpl.java @@ -0,0 +1,46 @@ +package cz.fi.muni.pa165.flea.market.manager.domain; + +import lombok.NonNull; + +import java.util.List; + +/** + * Implementation of {@link DomainService} + * + * @param entity for the service + * + * @author Michal Cizek + */ +public abstract class DomainServiceImpl implements DomainService { + + protected final DomainDao dao; + + public DomainServiceImpl(DomainDao dao) { + this.dao = dao; + } + + @Override + public ENTITY create(@NonNull ENTITY object) { + return dao.create(object); + } + + @Override + public ENTITY findById(@NonNull String id) { + return dao.findById(id); + } + + @Override + public List findAll() { + return dao.findAll(); + } + + @Override + public ENTITY update(@NonNull ENTITY object) { + return dao.update(object); + } + + @Override + public void delete(@NonNull ENTITY object) { + dao.delete(object); + } +} -- GitLab From 7bf8421b8e4f71bd5bef9066310feda94d3e6dd6 Mon Sep 17 00:00:00 2001 From: cizek Date: Sat, 16 Apr 2022 17:43:43 +0200 Subject: [PATCH 2/2] added java doc --- .../muni/pa165/flea/market/manager/domain/DomainService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java index 96f9215..9376c42 100644 --- a/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java +++ b/src/main/java/cz/fi/muni/pa165/flea/market/manager/domain/DomainService.java @@ -17,6 +17,7 @@ public interface DomainService { * * @param object entity to store in database * @return created entity + * @throws NullPointerException if given object is null */ ENTITY create(@NonNull ENTITY object); @@ -25,6 +26,7 @@ public interface DomainService { * * @param id id of the entity to look for * @return entity with given id + * @throws NullPointerException if given id is null */ ENTITY findById(@NonNull String id); @@ -40,6 +42,7 @@ public interface DomainService { * * @param object entity with new values to update * @return updated entity + * @throws NullPointerException if given object is null */ ENTITY update(@NonNull ENTITY object); @@ -47,6 +50,7 @@ public interface DomainService { * Deletes given entity. * * @param object entity to delete + * @throws NullPointerException if given object is null */ void delete(@NonNull ENTITY object); } -- GitLab