Example usage for javax.persistence EntityManager getTransaction

List of usage examples for javax.persistence EntityManager getTransaction

Introduction

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

Prototype

public EntityTransaction getTransaction();

Source Link

Document

Return the resource-level EntityTransaction object.

Usage

From source file:vn.edu.vnuk.tasks_jpa.dao.TaskDao.java

public void delete(Long id) throws SQLException {

    Task task = this.read(id);

    EntityManager manager = getEntityManager();
    manager.getTransaction().begin();
    task = manager.merge(task);/* w w w.  j  a va  2  s . com*/
    manager.remove(task);
    manager.getTransaction().commit();
    manager.close();

}

From source file:com.romb.hashfon.helper.Helper.java

public void persistObject(EntityManager em, Object o) {
    em.getTransaction().begin();
    em.persist(o);
    em.getTransaction().commit();
}

From source file:com.romb.hashfon.helper.Helper.java

public void mergeObject(EntityManager em, Object o) {
    em.getTransaction().begin();
    em.merge(o);
    em.getTransaction().commit();
}

From source file:com.romb.hashfon.helper.Helper.java

public void removeObject(EntityManager em, Object o, Long id) {
    em.getTransaction().begin();
    em.remove(o);
    em.getTransaction().commit();
}

From source file:cz.fi.muni.pa165.daoImpl.TroopDAOImpl.java

@Override
public List<Troop> getAllTroops() {
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    List<Troop> troops = em.createQuery("SELECT t FROM Troop t", Troop.class).getResultList();
    em.getTransaction().commit();/*from  w w  w.  j  ava2 s  .c  o m*/
    em.close();
    return troops;
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryReferenceCheckImpl.java

@Override
public void perform(long now) {
    logger.debug("{}", name);
    EntityManager em = datastore.getEntityManager();
    try {//  w w w . j a v a 2  s . co  m
        em.getTransaction().begin();
        TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllPublic",
                VirtualCollection.class);
        q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
        for (VirtualCollection vc : q.getResultList()) {
            checkValidityOfReferences(vc);
        }
        em.getTransaction().commit();
    } catch (RuntimeException e) {
        logger.error("unexpected error while doing " + name, e);
    } finally {
        datastore.closeEntityManager();
    }
}

From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java

public void update(final PurseSeineTrip trip) {
    final EntityManager mgr = emf.createEntityManager();
    final EntityTransaction xa = mgr.getTransaction();
    try {/*from  w  ww.j av a2  s  .  c  o m*/
        xa.begin();
        mgr.merge(trip);
        xa.commit();
    } catch (Exception ex) {
        if (xa.isActive()) {
            xa.rollback();
        }
    } finally {
        mgr.close();
    }
}

From source file:cz.fi.muni.pa165.daoImpl.TroopDAOImpl.java

@Override
public Troop getTroop(Long id) throws IllegalArgumentException {
    if (id == null) {
        throw new IllegalArgumentException("getTroop called with null");
    }/*from  w w w  . j  a  v a 2 s  .c om*/
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Troop troop = em.find(Troop.class, id);
    em.getTransaction().commit();
    em.close();
    return troop;
}

From source file:cz.fi.muni.pa165.daoImpl.TroopDAOImpl.java

@Override
public void updateTroop(Troop troop) throws IllegalArgumentException {
    if (troop == null || troop.getName() == null || troop.getMission() == null
            || troop.getAmountOfMoney() == null) {
        throw new IllegalArgumentException("Update troop called with wrong param");
    }/*from  w  w w  .j av a  2 s.  co  m*/
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    em.merge(troop);
    em.getTransaction().commit();
    em.close();
}

From source file:cz.fi.muni.pa165.daoImpl.TroopDAOImpl.java

@Override
public List<Troop> findTroopByName(String name) throws IllegalArgumentException {
    List<Troop> troop;/* ww  w.jav  a2 s  . co m*/
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    troop = em.createQuery("SELECT t FROM Troop t WHERE t.name = :name").setParameter("name", name)
            .getResultList();
    //query.setParameter("name", name);
    em.getTransaction().commit();
    em.close();
    return troop;
}