Example usage for javax.persistence EntityManager close

List of usage examples for javax.persistence EntityManager close

Introduction

In this page you can find the example usage for javax.persistence EntityManager close.

Prototype

public void close();

Source Link

Document

Close an application-managed entity manager.

Usage

From source file:com.medigy.persist.Ejb3TestCase.java

protected void tearDown() throws Exception {
    final EntityManager entityManager = getEntityManager();
    final EntityTransaction transaction = entityManager.getTransaction();
    SetupTestConfiguration.getInstance().getPostInsertEventListener().deleteEntityList(entityManager);
    transaction.commit();/*from w  w w.j  a  va2s.  c om*/
    entityManager.close();
    SessionManager.getInstance().popActiveSession();
}

From source file:com.github.jrh3k5.membership.renewal.mailer.service.jpa.JpaMembershipService.java

@Override
public void updateMembership(JpaMembershipRecord membership) {
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    try {/*from   w w w . j a  v  a 2s  .  c om*/
        updateMembership(entityManager, membership);
    } finally {
        entityManager.close();
    }
}

From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.NewsITCase.java

/**
 * Count news./*from ww  w . j a  va 2 s  .  c  o m*/
 *
 * @return the long
 * @throws Exception the exception
 */
private long countNews() throws Exception {
    EntityManager em = emf.createEntityManager();
    Query query = em.createQuery("SELECT COUNT(p.fs_id) FROM news p");
    Long countResult = (Long) query.getSingleResult();

    em.close();

    return countResult;
}

From source file:net.maritimecloud.identityregistry.controllers.LogoControllerTest.java

private void assertNumberOfLogos(int expectedLogoCount) {
    EntityManager em = emf.createEntityManager();
    try {/*  w  w  w .j  a v a  2 s  .c om*/
        List<Logo> logos = em.createQuery("select l from Logo l", Logo.class).getResultList();
        assertEquals("Number of logos", expectedLogoCount, logos.size());
    } catch (Exception e) {
        em.close();
    }
}

From source file:com.github.jrh3k5.membership.renewal.mailer.service.jpa.JpaMembershipService.java

@Override
public JpaMembershipRecord getByName(String givenName, String familyName) {
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    try {/*from  w w  w.  j  a v a  2  s  .c om*/
        return getByName(entityManager, givenName, familyName);
    } finally {
        entityManager.close();
    }
}

From source file:fr.desbureaux.repository.ActivitiRepository.java

public String getActiveActiviti() {
    EntityManager em = this.entityManagerFactory.createEntityManager();
    try {//  w  w w  .j  a v a  2 s  . com
        Query query = em.createNativeQuery("select act_id_ from act_ru_execution");
        return (String) query.getSingleResult();
    } catch (NoResultException nre) {
        return "none";
    } finally {
        if (em != null) {
            em.close();
        }
    }
}

From source file:com.soen.ebanking.dao.ObjectDao.java

public void deleteObject(Object object, long id, Class<T> ClassName) {
    EntityManager em = this.getEMF().createEntityManager();
    try {// ww  w .  j av  a  2  s  . c o m
        em.getTransaction().begin();
        T entity = em.find(ClassName, id);
        em.remove(entity);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}

From source file:ejb.bean.UsuarioDAOJPAImplBean.java

/**Mtodo para a busca de todos os usurios existentes no banco de dados.
 * @author Richel Sensineli//from  w w w  .  ja  v  a 2s .  c  om
 * @param nome String - Nome do usurio
 * @return Collection list
 */
@Override
public Collection buscaTodosUsuarios() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("UsuarioPU");
    EntityManager em = emf.createEntityManager();
    Query q = em.createQuery("select u from UsuarioImpl u");
    Collection result = null;
    result = q.getResultList();
    em.clear();
    em.close();
    emf.close();
    return result;
}

From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java

/**
 * Release database session, rolls back any uncommitted changes.
 *///  w  w w.  j av  a  2 s.  co  m
public void release() {
    EntityManager em = getEntityManager(false);
    if (isTransactionActive(em)) {
        em.getTransaction().rollback();
    }
    em.close();
    setThreadLocalEntityManager(null);
}

From source file:com.soen.ebanking.dao.ObjectDao.java

public T getAnObjectsByCondition(String tableName, String whereString) {
    EntityManager em = this.getEMF().createEntityManager();
    try {//w  w w.  j  av  a 2 s . c o  m

        T result = (T) em.createQuery("Select t FROM " + tableName + " t WHERE " + whereString)
                .getSingleResult();
        return result;
    } finally {
        em.close();
    }
}