package io.github.jlprat.reactive.jee.service;

import io.github.jlprat.reactive.jee.domain.Author;
import io.github.jlprat.reactive.jee.domain.Book;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author jpra
 *         copyright (c) 2003-2016 GameDuell GmbH, All Rights Reserved
 */
@Stateless
public class BookService {

    @PersistenceContext
    private EntityManager em;

    public List<Book> getBooks() {
        return em.createNamedQuery(Book.ALL_BOOKS, Book.class).getResultList();
    }

    public Book getBook(final String isbn) {
        return em.find(Book.class, isbn);
    }

    public Book writeBook(final Author author, final String title, final int pages) {
        final Book book = new Book(UUID.randomUUID().toString(), title, author.getName(), pages);
        em.persist(book);
        return book;
    }
}

@@ -335,141 +335,182 @@
 ID;%0A
-%0A/**%0A * @author jpra%0A *         copyright (c) 2003-2016 GameDuell GmbH, All Rights Reserved%0A */%0A@Stateless%0Apublic class BookService %7B
+import java.util.logging.Logger;%0A%0A/**%0A * @author @jlprat%0A */%0A@Stateless%0Apublic class BookService %7B%0A%0A    private Logger logger = Logger.getLogger(BookService.class.getName());
 %0A%0A  
@@ -988,16 +988,138 @@
 (book);%0A
+        logger.info(%22book persisted, adding to author list%22);%0A        author.writtenBook(book);%0A        em.merge(author);%0A
         

add book to author