Advertisement
andersonalmada

Untitled

Jul 8th, 2022
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package mandacaru3;
  2.  
  3. import java.util.List;
  4.  
  5. import mandacaru3.dao.ProductDAO;
  6. import mandacaru3.dao.ProductHibernateDAO;
  7. import mandacaru3.entities.Product;
  8.  
  9. public class Main {
  10.  
  11.     public static void main(String[] args) {
  12.  
  13.         ProductDAO productDAO = new ProductHibernateDAO();
  14.  
  15.         Product product = new Product(0, "notebook", 2000.4);
  16.  
  17.         // Add
  18.         productDAO.save(product);
  19.  
  20.         // Find
  21.         Product auxProduct = productDAO.find(1);
  22.         System.out.println(auxProduct);
  23.  
  24.         // Find by Name
  25.         Product auxProduct2 = productDAO.findByName("caderno");
  26.         System.out.println(auxProduct2);
  27.  
  28.         // Find All
  29.         List<Product> list = productDAO.findAll();
  30.         System.out.println(list);
  31.  
  32.         // Find All by Name
  33.         list = productDAO.findAllByName("notebook");
  34.         System.out.println(list);
  35.  
  36.         // Update
  37.         Product auxProduct3 = productDAO.find(1);
  38.         auxProduct3.setName("televisao");
  39.         auxProduct3.setPrice(400.5);
  40.         productDAO.save(auxProduct3);
  41.         System.out.println(auxProduct3);
  42.  
  43.         // Delete
  44.         //productDAO.delete(4);
  45.     }
  46.  
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement