508 : sonar qube critical issue fixes (#852)

* 508 : sonar qube critical issue fixes

* 508 : Sunar Qube Fixes
Define a constant instead of duplicating this literal "user_accounts" 4 times.
Define a constant instead of duplicating this literal "userID" 5 times
Define a constant instead of duplicating this literal "additionalInfo" 4 times.
Define a constant instead of duplicating this literal "userName" 4 times.

* 508 : Sunar Qube Fixes
Define a constant instead of duplicating this literal "user_accounts" 4 times.

* 508 : Sonar Qube Fixes
Define a constant instead of duplicating this literal "eEvans" 4 times
Define a constant instead of duplicating this literal "jBloch" 6 times
Define a constant instead of duplicating this literal "mFowler" 3 times

* 508 : Sonar Qube FIxes
Define a constant instead of duplicating this literal "username" 3 times.

* 508: sonar qube issue fixes
Define a constant instead of duplicating this literal "customerDao.getAllCustomers(): " 4 times.

* 508 : sonar qube issue fixes
Define a constant instead of duplicating this literal "App.main(), student : " 4 times.

* 508 : sonar Qube issue fixes
Define a constant instead of duplicating this literal "{} hits {}. {} is damaged!" 3 times.
Define a constant instead of duplicating this literal "{} hits {}." 4 times.

* 508 : Define a constant instead of duplicating this literal "{} hits {}." 4 times.

* 508 : checkstyle fixes

* 508: checkstyle fixes

* 508: checkstyle fixes

* 508: checkstyle fixes

* 508: checkstyle fixes

* 508: checkstyle fixes

* 508: cqrs checkstyle fixes
This commit is contained in:
kanwarpreet25
2019-07-28 18:09:40 +05:30
committed by Ilkka Seppälä
parent 17bfc91f45
commit c6ecf58687
17 changed files with 146 additions and 87 deletions

View File

@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import com.iluwatar.cqrs.commandes.CommandServiceImpl;
import com.iluwatar.cqrs.commandes.ICommandService;
import com.iluwatar.cqrs.constants.AppConstants;
import com.iluwatar.cqrs.dto.Author;
import com.iluwatar.cqrs.dto.Book;
import com.iluwatar.cqrs.queries.IQueryService;
@ -60,27 +61,27 @@ public class App {
ICommandService commands = new CommandServiceImpl();
// Create Authors and Books using CommandService
commands.authorCreated("eEvans", "Eric Evans", "eEvans@email.com");
commands.authorCreated("jBloch", "Joshua Bloch", "jBloch@email.com");
commands.authorCreated("mFowler", "Martin Fowler", "mFowler@email.com");
commands.authorCreated(AppConstants.E_EVANS, "Eric Evans", "eEvans@email.com");
commands.authorCreated(AppConstants.J_BLOCH, "Joshua Bloch", "jBloch@email.com");
commands.authorCreated(AppConstants.M_FOWLER, "Martin Fowler", "mFowler@email.com");
commands.bookAddedToAuthor("Domain-Driven Design", 60.08, "eEvans");
commands.bookAddedToAuthor("Effective Java", 40.54, "jBloch");
commands.bookAddedToAuthor("Java Puzzlers", 39.99, "jBloch");
commands.bookAddedToAuthor("Java Concurrency in Practice", 29.40, "jBloch");
commands.bookAddedToAuthor("Patterns of Enterprise Application Architecture", 54.01, "mFowler");
commands.bookAddedToAuthor("Domain Specific Languages", 48.89, "mFowler");
commands.authorNameUpdated("eEvans", "Eric J. Evans");
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("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("eEvans");
BigInteger jBlochBooksCount = queries.getAuthorBooksCount("jBloch");
Author eEvans = queries.getAuthorByUsername(AppConstants.E_EVANS);
BigInteger jBlochBooksCount = queries.getAuthorBooksCount(AppConstants.J_BLOCH);
BigInteger authorsCount = queries.getAuthorsCount();
Book dddBook = queries.getBook("Domain-Driven Design");
List<Book> jBlochBooks = queries.getAuthorBooks("jBloch");
List<Book> jBlochBooks = queries.getAuthorBooks(AppConstants.J_BLOCH);
LOGGER.info("Author username : {}", nullAuthor);
LOGGER.info("Author eEvans : {}", eEvans);

View File

@ -0,0 +1,15 @@
package com.iluwatar.cqrs.constants;
/**
*
* Class to define the constants
*
*/
public class AppConstants {
public static final String E_EVANS = "eEvans";
public static final String J_BLOCH = "jBloch";
public static final String M_FOWLER = "mFowler";
public static final String USER_NAME = "username";
}

View File

@ -30,6 +30,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import com.iluwatar.cqrs.constants.AppConstants;
import com.iluwatar.cqrs.dto.Author;
import com.iluwatar.cqrs.dto.Book;
import com.iluwatar.cqrs.util.HibernateUtil;
@ -50,7 +51,7 @@ public class QueryServiceImpl implements IQueryService {
SQLQuery sqlQuery = session
.createSQLQuery("SELECT a.username as \"username\", a.name as \"name\", a.email as \"email\""
+ "FROM Author a where a.username=:username");
sqlQuery.setParameter("username", username);
sqlQuery.setParameter(AppConstants.USER_NAME, username);
authorDTo = (Author) sqlQuery.setResultTransformer(Transformers.aliasToBean(Author.class)).uniqueResult();
}
return authorDTo;
@ -74,7 +75,7 @@ public class QueryServiceImpl implements IQueryService {
try (Session session = sessionFactory.openSession()) {
SQLQuery sqlQuery = session.createSQLQuery("SELECT b.title as \"title\", b.price as \"price\""
+ " FROM Author a , Book b where b.author_id = a.id and a.username=:username");
sqlQuery.setParameter("username", username);
sqlQuery.setParameter(AppConstants.USER_NAME, username);
bookDTos = sqlQuery.setResultTransformer(Transformers.aliasToBean(Book.class)).list();
}
return bookDTos;
@ -86,7 +87,7 @@ public class QueryServiceImpl implements IQueryService {
try (Session session = sessionFactory.openSession()) {
SQLQuery sqlQuery = session.createSQLQuery(
"SELECT count(b.title)" + " FROM Book b, Author a where b.author_id = a.id and a.username=:username");
sqlQuery.setParameter("username", username);
sqlQuery.setParameter(AppConstants.USER_NAME, username);
bookcount = (BigInteger) sqlQuery.uniqueResult();
}
return bookcount;