Example usage for javax.persistence Persistence createEntityManagerFactory

List of usage examples for javax.persistence Persistence createEntityManagerFactory

Introduction

In this page you can find the example usage for javax.persistence Persistence createEntityManagerFactory.

Prototype

public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName) 

Source Link

Document

Create and return an EntityManagerFactory for the named persistence unit.

Usage

From source file:streaming.test.StreamingTest.java

public void requete11() {
    System.out.println("Requete 11");
    EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager();
    System.out.println(em.createQuery(
            "SELECT f FROM Film f WHERE f.anneeProd=(SELECT MIN(f1.anneeProd) FROM Film f1 JOIN f1.real r1 WHERE r1.prenom ='Peter')")
            .getResultList());/*from   w  ww. j a  v a  2s.com*/
}

From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImplTest.java

@SuppressWarnings("unchecked")
private static void cleanDb() {
    emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
    em = emf.createEntityManager();/*ww  w  .j  a va  2s .  c o  m*/
    em.getTransaction().begin();
    Query q = em.createQuery("from UserEntity");
    List<UserEntity> results = q.getResultList();

    for (UserEntity temp : results) {
        em.remove(temp);
    }

    q = em.createQuery("from AuthorityEntity");
    List<AuthorityEntity> res = q.getResultList();

    for (AuthorityEntity temp : res) {
        em.remove(temp);
    }
    em.getTransaction().commit();

    em.close();
    emf.close();
}

From source file:streaming.test.StreamingTest.java

public void requete12() {
    System.out.println("Requete 12");
    EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager();
    System.out.println(em.createQuery("SELECT AVG(f.anneeProd) FROM Film f").getSingleResult());
}

From source file:Logica.Usuario.java

/**
 *
 * @param cinterno/*w  w w . j  av  a2 s  . c om*/
 * @param NIT
 * @param precio
 * @return
 * @throws RemoteException
 *
 * Asocia un tem a un proveedor
 */
@Override
public boolean asociarItem(String cinterno, String NIT, String precio) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    boolean hecho = false;
    try {
        Query q = em.createNamedQuery("Ixp.findByCinterno_NIT");
        q.setParameter("cinterno", cinterno);
        q.setParameter("nit", NIT);
        IxpJpaController ixpCo = new IxpJpaController(emf);
        List<Ixp> resultList = q.getResultList();
        Ixp itm = new Ixp();
        if (!resultList.isEmpty()) {
            itm = resultList.get(0);
        }
        itm.setCinterno(cinterno);
        itm.setNit(NIT);
        itm.setPrecio(new Double(precio));
        if (resultList.isEmpty()) {
            ixpCo.create(itm);
        } else {
            ixpCo.edit(itm);
        }
        hecho = true;

    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    emf.close();
    return hecho;
}

From source file:streaming.test.StreamingTest.java

public void requete13() {
    System.out.println("Requete 13");
    EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager();
    Collection<Object[]> col = em
            .createQuery("SELECT COUNT(f.id), r FROM Film f JOIN f.real r GROUP BY r ORDER BY COUNT(f.id)")
            .getResultList();/*  w ww  .  j  av  a  2s .  c  om*/

    for (Object o[] : col) {
        System.out.println(o[0] + " " + ((Realisateur) o[1]).getNom() + " " + ((Realisateur) o[1]).getPrenom());
    }
}

From source file:streaming.test.StreamingTest.java

public void creationDBTest() {
    EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager();
}

From source file:streaming.StreamingTest.java

public void craetionSerieOK() {
    Persistence.createEntityManagerFactory("StreamingPU");
}

From source file:org.batoo.jpa.community.test.BaseCoreTest.java

/**
 * Sets up the entity manager factory./*from   ww w. j  a  v a 2  s.  co  m*/
 * 
 * @param puName
 *            the persistence unit name
 * @return the entity manager factory
 * 
 * @since 2.0.0
 */
protected EntityManagerFactoryImpl setupEmf(String puName) {
    final Thread currentThread = Thread.currentThread();

    if (this.oldContextClassLoader != null) {
        currentThread.setContextClassLoader(this.oldContextClassLoader);
    }

    this.oldContextClassLoader = currentThread.getContextClassLoader();

    final TestClassLoader cl = new TestClassLoader(this.oldContextClassLoader);
    currentThread.setContextClassLoader(cl);
    cl.setRoot(this.getRootPackage());

    return (EntityManagerFactoryImpl) Persistence.createEntityManagerFactory(puName);
}

From source file:Logica.Usuario.java

/**
 *
 * @param cinterno/*from   w w  w  .  j  a  v a  2s . com*/
 * @param NIT
 * @param precio
 * @return
 * @throws RemoteException
 *
 * Asocia un tem a un proveedor
 */
@Override
public boolean desasociarItem(String cinterno, String NIT, String precio) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    EntityManager em = emf.createEntityManager();
    boolean hecho = false;
    try {
        Query q = em.createNamedQuery("Ixp.findByCinterno_NIT");
        q.setParameter("cinterno", cinterno);
        q.setParameter("nit", NIT);
        IxpJpaController ixpCo = new IxpJpaController(emf);
        List<Ixp> resultList = q.getResultList();
        Ixp itm = new Ixp();
        if (!resultList.isEmpty()) {
            itm = resultList.get(0);
            itm.setCinterno(cinterno);
            itm.setNit(NIT);
            itm.setPrecio(new Double(precio));
            ixpCo.destroy(itm.getId());
        }
        hecho = true;
    } catch (Exception ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    }
    emf.close();
    return hecho;
}

From source file:streaming.StreamingTest.java

public void listerFilmParGenreOK() {
    EntityManager em = Persistence.createEntityManagerFactory("StreamingPU").createEntityManager();
    for (Film f : em.find(Genre.class, 1L).getListeFilmsParGenre()) {
        System.out.println(f.getTitre());
    }/*from www .  j ava  2s  .c  o m*/
}