daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 57 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. package ch.myWinery.persistence;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.EntityManager;
  6. import javax.persistence.EntityManagerFactory;
  7. import javax.persistence.Persistence;
  8. import javax.persistence.Query;
  9. import ch.myWinery.model.Wine;
  10.  
  11. public class WineryDB {
  12.     private static WineryDB wineryDB;
  13.     private static EntityManagerFactory emf;
  14.     private static EntityManager em;
  15.  
  16.     private WineryDB() {
  17.         emf = Persistence.createEntityManagerFactory("WineryDatabase");
  18.         em = emf.createEntityManager();
  19.     }
  20.  
  21.     @SuppressWarnings("unchecked")
  22.     public List<Wine> getWines() {
  23.         return em.createQuery("select w from Wine w").getResultList();
  24.     }
  25.  
  26.     public Wine getWine(int id) {
  27.  
  28.         Query query = em.createNamedQuery(Wine.findByID);
  29.         query.setParameter("id", id);
  30.  
  31.         Wine wine = (Wine) query.getSingleResult();
  32.  
  33.         return wine;
  34.     }
  35.  
  36.     public static WineryDB getInstance() {
  37.         if (wineryDB == null) {
  38.             wineryDB = new WineryDB();
  39.         }
  40.         return wineryDB;
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top