daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Nov 22nd, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.vives.persistence.DAO;
  2.  
  3. import org.springframework.stereotype.Repository;
  4. import org.vives.domain.Beer;
  5.  
  6. import javax.persistence.*;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. @Repository
  11. public class BeerDAO {
  12.  
  13.     @PersistenceContext
  14.     EntityManager entityManager;
  15.  
  16.     public Beer findOne( long id ){
  17.         return entityManager.find( Beer.class, id );
  18.     }
  19.  
  20.     @SuppressWarnings("unchecked")
  21.     public List<Beer> findAll(){
  22.         List<Beer> beers = entityManager.createQuery("from Beer" ).getResultList();
  23.         return beers;
  24.     }
  25.  
  26.     public void create( Beer entity ){
  27.         entityManager.persist( entity );
  28.     }
  29.  
  30.     public Beer update( Beer entity ){
  31.         return entityManager.merge( entity );
  32.     }
  33.  
  34.     public void delete( Beer entity ){
  35.         entityManager.remove( entity );
  36.     }
  37.  
  38.     public void deleteById( long entityId ){
  39.         Beer entity = findOne( entityId );
  40.         delete( entity );
  41.     }
  42.  
  43. }
RAW Paste Data
Top