Advertisement
andersonalmada

Untitled

Jul 22nd, 2022
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package br.ufc.mandacaru5.service;
  2.  
  3. import java.util.List;
  4.  
  5. import org.springframework.stereotype.Service;
  6.  
  7. import br.ufc.mandacaru5.dao.ProductDAO;
  8. import br.ufc.mandacaru5.dao.ProductMemoryDAO;
  9. import br.ufc.mandacaru5.model.Product;
  10.  
  11. @Service
  12. public class ProductService {
  13.  
  14.     ProductDAO productDAO = new ProductMemoryDAO();
  15.  
  16.     public void save(int id, Product entity) {
  17.         if(id != 0) {
  18.             entity.setId(id);
  19.         }
  20.         productDAO.save(entity);
  21.     }
  22.  
  23.     public void delete(int id) {
  24.         productDAO.delete(id);
  25.     }
  26.  
  27.     public Product find(int id) {
  28.         if(id < 1) {
  29.             return null;
  30.         }
  31.        
  32.         return productDAO.find(id);
  33.     }
  34.  
  35.     public List<Product> findAll() {
  36.         return productDAO.findAll();
  37.     }
  38.  
  39.     public Product findByName(String str) {
  40.         if(str.length() < 3) {
  41.             return null;
  42.         }
  43.        
  44.         return productDAO.findByName(str);
  45.     }
  46.  
  47.     public List<Product> findAllByName(String str) {
  48.         return productDAO.findAllByName(str);
  49.     }
  50.  
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement