Example usage for javax.persistence EntityTransaction begin

List of usage examples for javax.persistence EntityTransaction begin

Introduction

In this page you can find the example usage for javax.persistence EntityTransaction begin.

Prototype

public void begin();

Source Link

Document

Start a resource transaction.

Usage

From source file:org.opencastproject.capture.admin.impl.CaptureAgentStateServiceImpl.java

/**
 * Updates or adds an agent to the database.
 * /*from ww  w  .  j  ava 2 s.c o m*/
 * @param agent
 *          The Agent you wish to modify or add in the database.
 */
protected void updateAgentInDatabase(AgentImpl agent) {
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        AgentImpl existing = getAgentEntity(agent.getName(), agent.getOrganization(), em);
        if (existing == null) {
            em.persist(agent);
        } else {
            existing.setConfiguration(agent.getConfiguration());
            existing.setLastHeardFrom(agent.getLastHeardFrom());
            existing.setState(agent.getState());
            existing.setSchedulerRoles(agent.getSchedulerRoles());
            existing.setUrl(agent.getUrl());
            em.merge(existing);
        }
        tx.commit();
        agentCache.put(agent.getName().concat(DELIMITER).concat(agent.getOrganization()),
                Tuple.tuple(agent.getState(), agent.getConfiguration()));
    } catch (RollbackException e) {
        logger.warn("Unable to commit to DB in updateAgent.");
        throw e;
    } finally {
        if (em != null)
            em.close();
    }
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public void deleteDeployment(int id) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    DeploymentDescriptor c = entityManager.find(DeploymentDescriptor.class, id);

    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();
    entityManager.remove(c);/*from w  w  w.  ja v a  2  s  . c om*/
    entityTransaction.commit();

}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public void deleteProperty(int propid) {

    EntityManager entityManager = entityManagerFactory.createEntityManager();
    BakerProperty c = entityManager.find(BakerProperty.class, propid);

    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();
    entityManager.remove(c);/*from   www .  j av  a  2  s .  co m*/
    entityTransaction.commit();

}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public InstalledBun updateInstalledBun(InstalledBun is) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
    InstalledBun resis = entityManager.merge(is);
    entityTransaction.commit();/*www  .ja  v  a 2  s  .c  om*/

    return resis;
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public void deleteInstalledBun(final InstalledBun message) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    entityManager.remove(message);//from   w ww  . ja va 2  s  .co  m

    entityTransaction.commit();
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public BakerUser updateBakerUser(BakerUser bu) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
    BakerUser resis = entityManager.merge(bu);
    entityTransaction.commit();//from   w  w  w. jav  a 2s  .co m

    return resis;
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public SubscribedResource updateSubscribedResource(SubscribedResource sm) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
    SubscribedResource resis = entityManager.merge(sm);
    entityTransaction.commit();//from w  w w  .  j  av  a 2  s  .  c o m

    return resis;
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public BakerProperty updateProperty(BakerProperty p) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
    BakerProperty bp = entityManager.merge(p);
    entityTransaction.commit();//w w w.  jav  a  2s.c o m

    return bp;
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public DeploymentDescriptor updateDeploymentDescriptor(DeploymentDescriptor d) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
    DeploymentDescriptor resis = entityManager.merge(d);
    entityTransaction.commit();/*from   w  w w .j a va  2  s.c  o  m*/

    return resis;
}

From source file:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public void deleteUser(int userid) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    BakerUser u = entityManager.find(BakerUser.class, userid);

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    entityManager.remove(u);//from www. j  a  v a 2s  .c  o  m

    entityTransaction.commit();
}