HTML and CSS Reference
In-Depth Information
public interface BookManagerLocal {
public Book getBookInformation(Integer bookID) throws BookNotFound;
public Book registerBook(Book book) throws BookAlreadyExists;
public Book updateBook(Book book) throws BookNotFound;
public void removeBook(Integer bookID) throws BookNotFound;
public byte[] getBookContent(Integer bookID) throws BookNotFound;
public List<Book> getAllBooks(Book book);
Ti Using @local annotation is suitable when the eJB client is running in the same JVM of the eJB itself. @local
annotation is more efficient than @remote annotation as it does not require argument marshalling, transportation,
and un-marshalling.
Listing 13-4 shows the BookManager EJB class's registerBook and updateBook methods.
Listing 13-4. BookManager EJB's Register and Update Book Methods
package com.jsfprohtml5.megaapp.service;
import com.jsfprohtml5.megaapp.model.Book;
import com.jsfprohtml5.megaapp.service.exception.BookAlreadyExists;
import com.jsfprohtml5.megaapp.service.exception.BookNotFound;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
public class BookManager implements BookManagerLocal {
@PersistenceContext(unitName = "megaAppUnit")
EntityManager em;
//Other interface methods ...
public Book registerBook(Book book) throws BookAlreadyExists {
Query query = em.createQuery("select book from Book book where "
+ "book.isbn = :isbn");
query.setParameter("isbn", book.getIsbn());
Search WWH ::

Custom Search