mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-24 17:34:57 +00:00
* #2449 bump maven-checkstyle-plugin from 3.1.0 to 3.2.0 + resolve checkstyle issues * remove FileSelectorJFrame.java to resolve checkstyle issue * remove FileSelectorJFrame.java to resolve checkstyle issue * remove FileSelectorJFrame.java to resolve checkstyle issue * add refactored file with correct filename to resolve checkstyle issue * add the test data * change filenames from JFrame to Jframe for checkstyle * fix code smell from sonar report * add new testcases to improve the test coverage * remove code smell
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ package com.iluwatar.cqrs.commandes;
|
||||
/**
|
||||
* This interface represents the commands of the CQRS pattern.
|
||||
*/
|
||||
public interface ICommandService {
|
||||
public interface CommandService {
|
||||
|
||||
void authorCreated(String username, String name, String email);
|
||||
|
||||
@@ -30,10 +30,10 @@ import com.iluwatar.cqrs.util.HibernateUtil;
|
||||
import org.hibernate.SessionFactory;
|
||||
|
||||
/**
|
||||
* This class is an implementation of {@link ICommandService} interface. It uses Hibernate as an api
|
||||
* This class is an implementation of {@link CommandService} interface. It uses Hibernate as an api
|
||||
* for persistence.
|
||||
*/
|
||||
public class CommandServiceImpl implements ICommandService {
|
||||
public class CommandServiceImpl implements CommandService {
|
||||
|
||||
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
/**
|
||||
* This interface represents the query methods of the CQRS pattern.
|
||||
*/
|
||||
public interface IQueryService {
|
||||
public interface QueryService {
|
||||
|
||||
Author getAuthorByUsername(String username);
|
||||
|
||||
@@ -34,51 +34,51 @@ import org.hibernate.SessionFactory;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
/**
|
||||
* This class is an implementation of {@link IQueryService}. It uses Hibernate native queries to
|
||||
* This class is an implementation of {@link QueryService}. It uses Hibernate native queries to
|
||||
* return DTOs from the database.
|
||||
*/
|
||||
public class QueryServiceImpl implements IQueryService {
|
||||
public class QueryServiceImpl implements QueryService {
|
||||
|
||||
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||
|
||||
@Override
|
||||
public Author getAuthorByUsername(String username) {
|
||||
Author authorDTo;
|
||||
Author authorDto;
|
||||
try (var session = sessionFactory.openSession()) {
|
||||
Query<Author> sqlQuery = session.createQuery(
|
||||
"select new com.iluwatar.cqrs.dto.Author(a.name, a.email, a.username)"
|
||||
+ " from com.iluwatar.cqrs.domain.model.Author a where a.username=:username");
|
||||
sqlQuery.setParameter(AppConstants.USER_NAME, username);
|
||||
authorDTo = sqlQuery.uniqueResult();
|
||||
authorDto = sqlQuery.uniqueResult();
|
||||
}
|
||||
return authorDTo;
|
||||
return authorDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book getBook(String title) {
|
||||
Book bookDTo;
|
||||
Book bookDto;
|
||||
try (var session = sessionFactory.openSession()) {
|
||||
Query<Book> sqlQuery = session.createQuery(
|
||||
"select new com.iluwatar.cqrs.dto.Book(b.title, b.price)"
|
||||
+ " from com.iluwatar.cqrs.domain.model.Book b where b.title=:title");
|
||||
sqlQuery.setParameter("title", title);
|
||||
bookDTo = sqlQuery.uniqueResult();
|
||||
bookDto = sqlQuery.uniqueResult();
|
||||
}
|
||||
return bookDTo;
|
||||
return bookDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Book> getAuthorBooks(String username) {
|
||||
List<Book> bookDTos;
|
||||
List<Book> bookDtos;
|
||||
try (var session = sessionFactory.openSession()) {
|
||||
Query<Book> sqlQuery = session.createQuery(
|
||||
"select new com.iluwatar.cqrs.dto.Book(b.title, b.price)"
|
||||
+ " from com.iluwatar.cqrs.domain.model.Author a, com.iluwatar.cqrs.domain.model.Book b "
|
||||
+ "where b.author.id = a.id and a.username=:username");
|
||||
sqlQuery.setParameter(AppConstants.USER_NAME, username);
|
||||
bookDTos = sqlQuery.list();
|
||||
bookDtos = sqlQuery.list();
|
||||
}
|
||||
return bookDTos;
|
||||
return bookDtos;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
|
||||
import com.iluwatar.cqrs.dto.Author;
|
||||
import com.iluwatar.cqrs.dto.Book;
|
||||
import com.iluwatar.cqrs.queries.IQueryService;
|
||||
import com.iluwatar.cqrs.queries.QueryService;
|
||||
import com.iluwatar.cqrs.queries.QueryServiceImpl;
|
||||
import java.math.BigInteger;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
@@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
class IntegrationTest {
|
||||
|
||||
private static IQueryService queryService;
|
||||
private static QueryService queryService;
|
||||
|
||||
@BeforeAll
|
||||
static void initializeAndPopulateDatabase() {
|
||||
|
||||
Reference in New Issue
Block a user