Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1fa8a60
Sharding Pattern (#1056)
Azureyjt Nov 8, 2019
6d1c0b1
Resolves checkstyle errors for ambassador, async-method-invocation, b…
anuragagarwal561994 Nov 9, 2019
efc17fc
Resolves checkstyle errors for business-delegate, bytecode, caching (…
anuragagarwal561994 Nov 9, 2019
31f27a7
Resolves checkstyle errors for callback, chain, circuit-breaker (#1060)
anuragagarwal561994 Nov 9, 2019
2f49648
Resolves checkstyle errors for collection-pipeline, command, commande…
anuragagarwal561994 Nov 9, 2019
4f9ee01
Resolves checkstyle errors for converter, cqrs (#1063)
anuragagarwal561994 Nov 10, 2019
dda0953
Resolves checkstyle errors for guarded-suspension, half-sync-half-asy…
anuragagarwal561994 Nov 10, 2019
7f06f3b
Resolves checkstyle errors for intercepting-filter, interpreter, iter…
anuragagarwal561994 Nov 10, 2019
eae09fc
Resolves checkstyle errors for api-gateway, lazy-loading, leader-elec…
anuragagarwal561994 Nov 10, 2019
01e489c
Resolves checkstyle errors for dao data-bus data-locality data-mapper…
anuragagarwal561994 Nov 10, 2019
f2c91eb
Resolves checkstyle errors for delegation dependency-injection dirty-…
anuragagarwal561994 Nov 10, 2019
7c888e8
Resolves checkstyle errors for eip-* (#1069)
anuragagarwal561994 Nov 10, 2019
5ae2ce6
Resolves checkstyle errors for event-* (#1070)
anuragagarwal561994 Nov 10, 2019
4dae1fa
Resolves checkstyle errors for execute-around extension-objects (#1071)
anuragagarwal561994 Nov 10, 2019
9c8ad44
Resolves checkstyle errors for patterns starting with letter r (#1072)
anuragagarwal561994 Nov 10, 2019
b92eb52
Resolves checkstyle errors for template-method thread-pool throttling…
anuragagarwal561994 Nov 10, 2019
f0f0143
Resolves checkstyle errors for trampoline twin typeobjectpattern unit…
anuragagarwal561994 Nov 10, 2019
c441831
Java 11 migration: ambassador async-method-invocation balking bridge …
anuragagarwal561994 Nov 11, 2019
329479d
#984 update Ambassador readme
iluwatar Nov 11, 2019
0272d71
#984 update Bridge readme
iluwatar Nov 11, 2019
2628cc0
#984 update Builder readme
iluwatar Nov 11, 2019
c954a43
Resolves checkstyle errors for facade factory-kit spatial-partition s…
anuragagarwal561994 Nov 11, 2019
37599eb
Resolves checkstyle errors for feature-toggle fluentinterface flux fl…
anuragagarwal561994 Nov 11, 2019
3907951
Resolves checkstyle issues for semaphore servant serverless service-l…
anuragagarwal561994 Nov 11, 2019
1e76d91
Resolves checkstyle errors for abstract-document abstract-factory acy…
anuragagarwal561994 Nov 11, 2019
6ef840f
Resolves checkstyle errors for naked-objects null-object object-mothe…
anuragagarwal561994 Nov 12, 2019
33ea733
Java 11 migration: patterns (remaining b-c) (#1081)
anuragagarwal561994 Nov 12, 2019
3c57bf7
#984 #987 update readmes
iluwatar Nov 12, 2019
f04fc3c
Java 11 migration: patterns starting with a (#1084)
anuragagarwal561994 Nov 13, 2019
160b737
Add another real world example for Builder
iluwatar Nov 13, 2019
50467c9
Java 11 migration: patterns (t-v) (#1085)
anuragagarwal561994 Nov 14, 2019
cc571f4
Saga pattern (#1062)
besok Nov 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Resolves checkstyle errors for converter, cqrs (iluwatar#1063)
* Reduces checkstyle errors in converter

* Reduces checkstyle errors in cqrs
  • Loading branch information
anuragagarwal561994 authored and iluwatar committed Nov 10, 2019
commit 4f9ee0189c614085841668540b5350b66a85a927
7 changes: 3 additions & 4 deletions converter/src/main/java/com/iluwatar/converter/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@

package com.iluwatar.converter;


import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
* The Converter pattern is a behavioral design pattern which allows a common way of bidirectional
* conversion between corresponding types (e.g. DTO and domain representations of the logically
Expand All @@ -38,8 +36,9 @@
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Program entry point
* Program entry point.
*
* @param args command line args
*/
Expand Down
31 changes: 22 additions & 9 deletions converter/src/main/java/com/iluwatar/converter/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@

/**
* Generic converter, thanks to Java8 features not only provides a way of generic bidirectional
* conversion between corresponding types, but also a common way of converting a collection of objects
* of the same type, reducing boilerplate code to the absolute minimum.
* conversion between corresponding types, but also a common way of converting a collection of
* objects of the same type, reducing boilerplate code to the absolute minimum.
*
* @param <T> DTO representation's type
* @param <U> Domain representation's type
*/
Expand All @@ -41,7 +42,9 @@ public class Converter<T, U> {
private final Function<U, T> fromEntity;

/**
* @param fromDto Function that converts given dto entity into the domain entity.
* Constructor.
*
* @param fromDto Function that converts given dto entity into the domain entity.
* @param fromEntity Function that converts given domain entity into the dto entity.
*/
public Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity) {
Expand All @@ -50,34 +53,44 @@ public Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity)
}

/**
* Converts DTO to Entity.
*
* @param dto DTO entity
* @return The domain representation - the result of the converting function application on dto entity.
* @return The domain representation - the result of the converting function application on dto
* entity.
*/
public final U convertFromDto(final T dto) {
return fromDto.apply(dto);
}

/**
* Converts Entity to DTO.
*
* @param entity domain entity
* @return The DTO representation - the result of the converting function application on domain entity.
* @return The DTO representation - the result of the converting function application on domain
* entity.
*/
public final T convertFromEntity(final U entity) {
return fromEntity.apply(entity);
}

/**
* Converts list of DTOs to list of Entities.
*
* @param dtos collection of DTO entities
* @return List of domain representation of provided entities retrieved by
* mapping each of them with the conversion function
* @return List of domain representation of provided entities retrieved by mapping each of them
* with the conversion function
*/
public final List<U> createFromDtos(final Collection<T> dtos) {
return dtos.stream().map(this::convertFromDto).collect(Collectors.toList());
}

/**
* Converts list of Entities to list of DTOs.
*
* @param entities collection of domain entities
* @return List of domain representation of provided entities retrieved by
* mapping each of them with the conversion function
* @return List of domain representation of provided entities retrieved by mapping each of them
* with the conversion function
*/
public final List<T> createFromEntities(final Collection<U> entities) {
return entities.stream().map(this::convertFromEntity).collect(Collectors.toList());
Expand Down
19 changes: 12 additions & 7 deletions converter/src/main/java/com/iluwatar/converter/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Objects;

/**
* User class
* User class.
*/
public class User {
private String firstName;
Expand All @@ -35,10 +35,12 @@ public class User {
private String userId;

/**
* Constructor.
*
* @param firstName user's first name
* @param lastName user's last name
* @param isActive flag indicating whether the user is active
* @param userId user's identificator
* @param userId user's identificator
*/
public User(String firstName, String lastName, boolean isActive, String userId) {
this.firstName = firstName;
Expand All @@ -63,7 +65,8 @@ public String getUserId() {
return userId;
}

@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
Expand All @@ -72,15 +75,17 @@ public String getUserId() {
}
User user = (User) o;
return isActive == user.isActive && Objects.equals(firstName, user.firstName) && Objects
.equals(lastName, user.lastName) && Objects.equals(userId, user.userId);
.equals(lastName, user.lastName) && Objects.equals(userId, user.userId);
}

@Override public int hashCode() {
@Override
public int hashCode() {
return Objects.hash(firstName, lastName, isActive, userId);
}

@Override public String toString() {
@Override
public String toString() {
return "User{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
+ ", isActive=" + isActive + ", userId='" + userId + '\'' + '}';
+ ", isActive=" + isActive + ", userId='" + userId + '\'' + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class UserConverter extends Converter<UserDto, User> {
*/
public UserConverter() {
super(userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(),
userDto.getEmail()),
userDto.getEmail()),
user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(),
user.getUserId()));
user.getUserId()));
}
}
18 changes: 11 additions & 7 deletions converter/src/main/java/com/iluwatar/converter/UserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

package com.iluwatar.converter;


import java.util.Objects;

/**
* User DTO class
* User DTO class.
*/
public class UserDto {

Expand All @@ -37,6 +36,8 @@ public class UserDto {
private String email;

/**
* Constructor.
*
* @param firstName user's first name
* @param lastName user's last name
* @param isActive flag indicating whether the user is active
Expand Down Expand Up @@ -65,7 +66,8 @@ public String getEmail() {
return email;
}

@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
Expand All @@ -74,15 +76,17 @@ public String getEmail() {
}
UserDto userDto = (UserDto) o;
return isActive == userDto.isActive && Objects.equals(firstName, userDto.firstName) && Objects
.equals(lastName, userDto.lastName) && Objects.equals(email, userDto.email);
.equals(lastName, userDto.lastName) && Objects.equals(email, userDto.email);
}

@Override public int hashCode() {
@Override
public int hashCode() {
return Objects.hash(firstName, lastName, isActive, email);
}

@Override public String toString() {
@Override
public String toString() {
return "UserDto{" + "firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
+ ", isActive=" + isActive + ", email='" + email + '\'' + '}';
+ ", isActive=" + isActive + ", email='" + email + '\'' + '}';
}
}
50 changes: 24 additions & 26 deletions cqrs/src/main/java/com/iluwatar/cqrs/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@

package com.iluwatar.cqrs.app;

import java.math.BigInteger;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iluwatar.cqrs.commandes.CommandServiceImpl;
import com.iluwatar.cqrs.commandes.ICommandService;
import com.iluwatar.cqrs.constants.AppConstants;
Expand All @@ -37,59 +31,63 @@
import com.iluwatar.cqrs.queries.IQueryService;
import com.iluwatar.cqrs.queries.QueryServiceImpl;
import com.iluwatar.cqrs.util.HibernateUtil;
import java.math.BigInteger;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* CQRS : Command Query Responsibility Segregation. A pattern used to separate query services from commands or writes
* services. The pattern is very simple but it has many consequences. For example, it can be used to tackle down a
* complex domain, or to use other architectures that were hard to implement with the classical way.
*
* This implementation is an example of managing books and authors in a library. The persistence of books and authors is
* done according to the CQRS architecture. A command side that deals with a data model to persist(insert,update,delete)
* objects to a database. And a query side that uses native queries to get data from the database and return objects as
* DTOs (Data transfer Objects).
* CQRS : Command Query Responsibility Segregation. A pattern used to separate query services from
* commands or writes services. The pattern is very simple but it has many consequences. For
* example, it can be used to tackle down a complex domain, or to use other architectures that were
* hard to implement with the classical way.
*
* <p>This implementation is an example of managing books and authors in a library. The persistence
* of books and authors is done according to the CQRS architecture. A command side that deals with a
* data model to persist(insert,update,delete) objects to a database. And a query side that uses
* native queries to get data from the database and return objects as DTOs (Data transfer Objects).
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

/**
* Program entry point
*
* @param args
* command line args
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
ICommandService commands = new CommandServiceImpl();

// Create Authors and Books using CommandService
commands.authorCreated(AppConstants.E_EVANS, "Eric Evans", "eEvans@email.com");
commands.authorCreated(AppConstants.E_EVANS, "Eric Evans", "evans@email.com");
commands.authorCreated(AppConstants.J_BLOCH, "Joshua Bloch", "[email protected]");
commands.authorCreated(AppConstants.M_FOWLER, "Martin Fowler", "[email protected]");

commands.bookAddedToAuthor("Domain-Driven Design", 60.08, AppConstants.E_EVANS);
commands.bookAddedToAuthor("Effective Java", 40.54, AppConstants.J_BLOCH);
commands.bookAddedToAuthor("Java Puzzlers", 39.99, AppConstants.J_BLOCH);
commands.bookAddedToAuthor("Java Concurrency in Practice", 29.40, AppConstants.J_BLOCH);
commands.bookAddedToAuthor("Patterns of Enterprise Application Architecture", 54.01, AppConstants.M_FOWLER);
commands.bookAddedToAuthor("Patterns of Enterprise"
+ " Application Architecture", 54.01, AppConstants.M_FOWLER);
commands.bookAddedToAuthor("Domain Specific Languages", 48.89, AppConstants.M_FOWLER);
commands.authorNameUpdated(AppConstants.E_EVANS, "Eric J. Evans");

IQueryService queries = new QueryServiceImpl();

// Query the database using QueryService
Author nullAuthor = queries.getAuthorByUsername("username");
Author eEvans = queries.getAuthorByUsername(AppConstants.E_EVANS);
BigInteger jBlochBooksCount = queries.getAuthorBooksCount(AppConstants.J_BLOCH);
Author evans = queries.getAuthorByUsername(AppConstants.E_EVANS);
BigInteger blochBooksCount = queries.getAuthorBooksCount(AppConstants.J_BLOCH);
BigInteger authorsCount = queries.getAuthorsCount();
Book dddBook = queries.getBook("Domain-Driven Design");
List<Book> jBlochBooks = queries.getAuthorBooks(AppConstants.J_BLOCH);
List<Book> blochBooks = queries.getAuthorBooks(AppConstants.J_BLOCH);

LOGGER.info("Author username : {}", nullAuthor);
LOGGER.info("Author eEvans : {}", eEvans);
LOGGER.info("jBloch number of books : {}", jBlochBooksCount);
LOGGER.info("Author evans : {}", evans);
LOGGER.info("jBloch number of books : {}", blochBooksCount);
LOGGER.info("Number of authors : {}", authorsCount);
LOGGER.info("DDD book : {}", dddBook);
LOGGER.info("jBloch books : {}", jBlochBooks);
LOGGER.info("jBloch books : {}", blochBooks);

HibernateUtil.getSessionFactory().close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@

package com.iluwatar.cqrs.commandes;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.iluwatar.cqrs.domain.model.Author;
import com.iluwatar.cqrs.domain.model.Book;
import com.iluwatar.cqrs.util.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

/**
* This class is an implementation of {@link ICommandService} interface. It uses Hibernate as an api for persistence.
*
* This class is an implementation of {@link ICommandService} interface. It uses Hibernate as an api
* for persistence.
*/
public class CommandServiceImpl implements ICommandService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
package com.iluwatar.cqrs.commandes;

/**
* This interface represents the commands of the CQRS pattern
*
* This interface represents the commands of the CQRS pattern.
*/
public interface ICommandService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.cqrs.constants;

/**
*
* Class to define the constants
*
* Class to define the constants.
*/
public class AppConstants {

Expand Down
13 changes: 5 additions & 8 deletions cqrs/src/main/java/com/iluwatar/cqrs/domain/model/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

/**
* This is an Author entity. It is used by Hibernate for persistence.
*
*/
@Entity
public class Author {
Expand All @@ -42,13 +41,11 @@ public class Author {
private String email;

/**
*
* @param username
* username of the author
* @param name
* name of the author
* @param email
* email of the author
* Constructor.
*
* @param username username of the author
* @param name name of the author
* @param email email of the author
*/
public Author(String username, String name, String email) {
this.username = username;
Expand Down
Loading