Search in sources :

Example 1 with Author

use of com.iluwatar.cqrs.dto.Author in project java-design-patterns by iluwatar.

the class App method main.

/**
 * 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("eEvans", "Eric Evans", "eEvans@email.com");
    commands.authorCreated("jBloch", "Joshua Bloch", "jBloch@email.com");
    commands.authorCreated("mFowler", "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");
    IQueryService queries = new QueryServiceImpl();
    // Query the database using QueryService
    Author nullAuthor = queries.getAuthorByUsername("username");
    Author eEvans = queries.getAuthorByUsername("eEvans");
    BigInteger jBlochBooksCount = queries.getAuthorBooksCount("jBloch");
    BigInteger authorsCount = queries.getAuthorsCount();
    Book dddBook = queries.getBook("Domain-Driven Design");
    List<Book> jBlochBooks = queries.getAuthorBooks("jBloch");
    LOGGER.info("Author username : {}", nullAuthor);
    LOGGER.info("Author eEvans : {}", eEvans);
    LOGGER.info("jBloch number of books : {}", jBlochBooksCount);
    LOGGER.info("Number of authors : {}", authorsCount);
    LOGGER.info("DDD book : {}", dddBook);
    LOGGER.info("jBloch books : {}", jBlochBooks);
    HibernateUtil.getSessionFactory().close();
}
Also used : CommandServiceImpl(com.iluwatar.cqrs.commandes.CommandServiceImpl) IQueryService(com.iluwatar.cqrs.queries.IQueryService) Book(com.iluwatar.cqrs.dto.Book) Author(com.iluwatar.cqrs.dto.Author) BigInteger(java.math.BigInteger) ICommandService(com.iluwatar.cqrs.commandes.ICommandService) QueryServiceImpl(com.iluwatar.cqrs.queries.QueryServiceImpl)

Example 2 with Author

use of com.iluwatar.cqrs.dto.Author in project java-design-patterns by iluwatar.

the class IntegrationTest method testGetUpdatedAuthorByUsername.

@Test
public void testGetUpdatedAuthorByUsername() {
    Author author = queryService.getAuthorByUsername("new_username2");
    Author expectedAuthor = new Author("new_name2", "new_email2", "new_username2");
    assertEquals(expectedAuthor, author);
}
Also used : Author(com.iluwatar.cqrs.dto.Author) Test(org.junit.jupiter.api.Test)

Example 3 with Author

use of com.iluwatar.cqrs.dto.Author in project java-design-patterns by iluwatar.

the class IntegrationTest method testGetAuthorByUsername.

@Test
public void testGetAuthorByUsername() {
    Author author = queryService.getAuthorByUsername("username1");
    assertEquals("username1", author.getUsername());
    assertEquals("name1", author.getName());
    assertEquals("email1", author.getEmail());
}
Also used : Author(com.iluwatar.cqrs.dto.Author) Test(org.junit.jupiter.api.Test)

Example 4 with Author

use of com.iluwatar.cqrs.dto.Author in project java-design-patterns by iluwatar.

the class QueryServiceImpl method getAuthorByUsername.

@Override
public Author getAuthorByUsername(String username) {
    Author authorDTo = null;
    try (Session session = sessionFactory.openSession()) {
        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);
        authorDTo = (Author) sqlQuery.setResultTransformer(Transformers.aliasToBean(Author.class)).uniqueResult();
    }
    return authorDTo;
}
Also used : Author(com.iluwatar.cqrs.dto.Author) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session)

Aggregations

Author (com.iluwatar.cqrs.dto.Author)4 Test (org.junit.jupiter.api.Test)2 CommandServiceImpl (com.iluwatar.cqrs.commandes.CommandServiceImpl)1 ICommandService (com.iluwatar.cqrs.commandes.ICommandService)1 Book (com.iluwatar.cqrs.dto.Book)1 IQueryService (com.iluwatar.cqrs.queries.IQueryService)1 QueryServiceImpl (com.iluwatar.cqrs.queries.QueryServiceImpl)1 BigInteger (java.math.BigInteger)1 SQLQuery (org.hibernate.SQLQuery)1 Session (org.hibernate.Session)1