package xyz.danielcortes.framework;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class PersistenceManager {

  private static EntityManagerFactory factory;
  private static EntityManager em;

  static {
    factory = Persistence.createEntityManagerFactory("jpa");
    em = factory.createEntityManager();
  }


  public static EntityManager getEntityManager() {
    return em;
  }

  public static void close() {
    if (factory != null) {
      factory.close();
    }

    if (em != null) {
      em.close();
    }
  }
}
