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:gr.upatras.ece.nam.baker.impl.BakerJpaController.java

public void saveProperty(BakerProperty p) {
    logger.info("Will BakerProperty = " + p.getName());

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();

    entityManager.persist(p);//  w  ww  . j a  v  a  2s .c  om
    entityManager.flush();
    entityTransaction.commit();

}

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

public void saveInstalledBun(InstalledBun is) {
    logger.info("Will create InstalledBun = " + is.getUuid());

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    entityManager.persist(is);/*from w  ww  .  j a va2  s  .c  o m*/
    entityManager.flush();
    entityTransaction.commit();
}

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

public void deleteAllInstalledBuns() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    Query q = entityManager.createQuery("DELETE FROM InstalledBun ");
    q.executeUpdate();//  www.  j  a  va 2  s  .  com
    entityManager.flush();

    entityTransaction.commit();
}

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

public void deleteAllUsers() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    Query q = entityManager.createQuery("DELETE FROM BakerUser ");
    q.executeUpdate();//from   www  .  ja  v  a2 s  . co m
    entityManager.flush();

    entityTransaction.commit();

}

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

public void saveSubscribedResource(SubscribedResource sm) {
    logger.info("Will save SubscribedResource = " + sm.getURL());

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    entityManager.persist(sm);//from  w w w  . j  a va2  s.c  om
    entityManager.flush();
    entityTransaction.commit();

}

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

public void deleteAllSubscribedResources() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    Query q = entityManager.createQuery("DELETE FROM SubscribedResource ");
    q.executeUpdate();// w w w.  j av  a 2s .  c  om
    entityManager.flush();

    entityTransaction.commit();

}

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

public void saveUser(BakerUser bu) {
    logger.info("Will save BakerUser = " + bu.getName());

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    entityManager.persist(bu);// w ww .  ja  va  2 s .c o m

    entityManager.flush();
    entityTransaction.commit();

}

From source file:org.opencastproject.messages.MailService.java

public MessageTemplate updateMessageTemplate(MessageTemplate template) throws MailServiceException {
    EntityManager em = null;/*from  ww w  .  j  a va2 s  . co  m*/
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        String orgId = securityService.getOrganization().getId();
        MessageTemplateDto msgTmpl = mergeMessageTemplate(template, orgId, em);
        tx.commit();
        return msgTmpl.toMessageTemplate(userDirectoryService);
    } catch (Exception e) {
        logger.error("Could not update message template '{}': {}", template, e.getMessage());
        if (tx.isActive())
            tx.rollback();
        throw new MailServiceException(e);
    } finally {
        if (em != null)
            em.close();
    }
}

From source file:org.opencastproject.messages.MailService.java

public MessageSignature updateMessageSignature(MessageSignature signature) throws MailServiceException {
    EntityManager em = null;//from   www.  j av  a2 s .c  om
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        String orgId = securityService.getOrganization().getId();
        MessageSignatureDto msgSign = mergeMessageSignature(signature, orgId, em);
        tx.commit();
        return msgSign.toMessageSignature(userDirectoryService);
    } catch (Exception e) {
        logger.error("Could not update message signature '{}': {}", signature, e.getMessage());
        if (tx.isActive())
            tx.rollback();
        throw new MailServiceException(e);
    } finally {
        if (em != null)
            em.close();
    }
}

From source file:org.opencastproject.messages.MailService.java

public EmailConfiguration updateEmailConfiguration(EmailConfiguration emailConfiguration)
        throws MailServiceException {
    EntityManager em = null;//from  w  w w.  j ava 2  s.  c o m
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        String orgId = securityService.getOrganization().getId();
        EmailConfigurationDto emailConfig = mergeEmailConfiguration(emailConfiguration, orgId, em);
        tx.commit();
        EmailConfiguration updatedEmailConfiguration = emailConfig.toEmailConfiguration();
        updateSmtpConfiguration(updatedEmailConfiguration);
        return updatedEmailConfiguration;
    } catch (Exception e) {
        logger.error("Could not update email configuration '{}': {}", emailConfiguration, e.getMessage());
        if (tx.isActive())
            tx.rollback();
        throw new MailServiceException(e);
    } finally {
        if (em != null)
            em.close();
    }
}