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:cz.fi.muni.pa165.dto.PrintedBookDAOTest.java

@Test
public void testFindAllBorrowedPrintedBooks() {
    EntityManager em = emf.createEntityManager();
    PrintedBookDAOImpl pbDAO = new PrintedBookDAOImpl();
    pbDAO.setManager(em);//from   w  w  w. j a  v a  2 s. c  o  m
    PrintedBook book = new PrintedBook();
    book.setIdPrintedBook(1);
    PrintedBook pb = pbDAO.find(book);
    em.close();
    assertEquals(1, pb.getIdPrintedBook());
}

From source file:com.impetus.client.couchdb.crud.CouchDBClientTest.java

@Test
@PerfTest(invocations = 10)//  w w  w  . jav a2  s  .  c  o  m
public void testCRUD() {
    logger.info("On testInsert");
    EntityManager em = emf.createEntityManager();
    Map<String, Client> clients = (Map<String, Client>) em.getDelegate();
    CouchDBClient client = (CouchDBClient) clients.get(_PU);
    onInsert(client);
    onUpdate(client);
    onDelete(client);
    em.close();
}

From source file:edu.csueb.cs6320.utils.UserService.java

public boolean delete(long userid) {
    EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager();

    User u = em.find(User.class, userid);
    if (u == null) {
        return false;
    }/*from w  ww . ja  v  a  2 s .c om*/
    em.getTransaction().begin();
    em.remove(u);
    em.getTransaction().commit();
    em.close();

    return true;
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.UserSkillRepositoryImplementation.java

@Override
public boolean update(UserSkill userSkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {/*w  w  w.  ja  v  a2  s.c  om*/
        em.getTransaction().begin();
        em.merge(userSkill);
        em.getTransaction().commit();
        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:pl.datamatica.traccar.api.fcm.Daemon.java

protected Daemon() {
    runnable = new Runnable() {
        @Override// ww w .  j  a va 2s  .  c o m
        public void run() {
            EntityManager em = Context.getInstance().createEntityManager();
            try {
                em.getTransaction().begin();
                doWork(em);
                em.getTransaction().commit();
            } catch (Exception e) {
                Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, null, e);
            } finally {
                em.close();
            }
        }
    };
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.UserSkillRepositoryImplementation.java

@Override
public boolean create(UserSkill userSkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {/*from  www .  j  av  a2s.  c  om*/
        em.getTransaction().begin();
        em.persist(userSkill);
        em.getTransaction().commit();
        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancySkillRepositoryImplementation.java

@Override
public boolean update(VacancySkill vacancySkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {//  w  ww .  j a v a2 s .co m
        em.getTransaction().begin();
        em.merge(vacancySkill);
        em.getTransaction().commit();
        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:cz.fi.muni.pa165.dto.PrintedBookDAOTest.java

@Test
public void testFindPrintedBooksByState() {
    EntityManager em = emf.createEntityManager();
    PrintedBookDAOImpl pbDAO = new PrintedBookDAOImpl();
    pbDAO.setManager(em);/*  ww w.  j  a  v  a  2  s.  co  m*/
    Book b = new Book();
    b.setIdBook(1);

    List<PrintedBook> l = pbDAO.findPrintedBooksByState(b, Boolean.FALSE);
    em.close();
    assertEquals(1, l.size());
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancySkillRepositoryImplementation.java

@Override
public boolean create(VacancySkill vacancySkill) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {/*w  ww .  ja  va2  s  .com*/
        em.getTransaction().begin();
        em.persist(vacancySkill);
        em.getTransaction().commit();
        success = true;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:com.espirit.moddev.examples.uxbridge.newswidget.test.CommandITCase.java

/**
 * Before test.//from   w ww  .j a va2s  .  c om
 *
 * @throws Exception the exception
 */
@Before
public void beforeTest() throws Exception {
    EntityManager em = emf.createEntityManager();

    EntityTransaction tx = em.getTransaction();
    tx.begin();
    em.createQuery("DELETE FROM article").executeUpdate();
    tx.commit();
    em.close();
}