Skip to content

Instantly share code, notes, and snippets.

@asicfr
Created October 15, 2012 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asicfr/3891574 to your computer and use it in GitHub Desktop.
Save asicfr/3891574 to your computer and use it in GitHub Desktop.
struts2RestJpaBootstrap - book service
package org.demo.business.service;
import java.util.List;
import org.demo.util.EntityManagerHelper;
import org.demo.vo.bean.Book;
import org.demo.vo.dao.JpaBookDAO;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
public class BookServices implements IServices<Book, Integer> {
protected final Logger LOG = LoggerFactory.getLogger(BookServices.class);
public Book load(Integer id) {
if (LOG.isDebugEnabled()) LOG.debug("load");
EntityManagerHelper.beginTransaction();
JpaBookDAO bookDAO = new JpaBookDAO();
Book book = bookDAO.findById(id);
EntityManagerHelper.commitAndCloseEntityManager();
return book ;
}
public void save(Book entity) {
if (LOG.isDebugEnabled()) LOG.debug("save");
EntityManagerHelper.beginTransaction();
JpaBookDAO bookDAO = new JpaBookDAO();
bookDAO.update(entity);
EntityManagerHelper.commitAndCloseEntityManager();
}
public void delete(Integer id) {
if (LOG.isDebugEnabled()) LOG.debug("delete");
EntityManagerHelper.beginTransaction();
JpaBookDAO bookDAO = new JpaBookDAO();
bookDAO.delete(id);
EntityManagerHelper.commitAndCloseEntityManager();
}
public List<Book> search(Book book) {
if (LOG.isDebugEnabled()) LOG.debug("search");
EntityManagerHelper.beginTransaction();
JpaBookDAO bookDAO = new JpaBookDAO();
List<Book> liste = bookDAO.search(book);
EntityManagerHelper.commitAndCloseEntityManager();
return liste;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment