Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public T inserir(T entity) throws Exception {
  2. try {
  3. manager.getTransaction().begin();
  4. manager.persist(entity);
  5. manager.getTransaction().commit();
  6. } catch (Exception e) {
  7. manager.getTransaction().rollback();
  8. }
  9. return entity;
  10. }`
  11.  
  12. public void excluir(T entity) {
  13. try {
  14. manager.getTransaction().begin();
  15. manager.remove(entity);
  16. manager.getTransaction().commit();
  17. } catch (Exception e) {
  18. manager.getTransaction().rollback();
  19. }
  20. }
  21.  
  22. public Item inserir(Item item){
  23. try {
  24. return geralDAO.inserir(item);
  25. } catch (Exception e) {
  26. System.err.println(e.getMessage());
  27. return null;
  28. }
  29. }
  30.  
  31. public void excluir(Item item){
  32. try {
  33. geralDAO.excluir(item);
  34.  
  35. } catch (Exception e) {
  36. System.err.println("Erro ao deletar", e.getMessage());
  37. }
  38. }
  39.  
  40. public void setProdutos(ProdutosVO produto) throws Exception{
  41. try {
  42. EntityManagerFactory factory = Persistence.createEntityManagerFactory("model");
  43. EntityManager manager = factory.createEntityManager();
  44.  
  45. manager.getTransaction().begin();
  46. manager.persist(produto);
  47. manager.getTransaction().commit();
  48.  
  49. } catch (Exception e) {
  50. throw new Exception(e);
  51. }finally {
  52. manager.close();
  53. factory.close();
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement