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

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/*ww  w  .  j a  va2  s  .co  m*/
    SubscribedResource resis = entityManager.merge(sm);
    entityTransaction.commit();

    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();/*from   w  ww . j  a  va 2 s .co  m*/
    BakerProperty bp = entityManager.merge(p);
    entityTransaction.commit();

    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();//  www  .j  a va  2  s.co m
    DeploymentDescriptor resis = entityManager.merge(d);
    entityTransaction.commit();

    return resis;
}

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();/*from ww w .jav a2 s .c  o  m*/

    entityManager.persist(is);
    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();//from  ww  w .  j  av a 2  s  . c o  m

    Query q = entityManager.createQuery("DELETE FROM InstalledBun ");
    q.executeUpdate();
    entityManager.flush();

    entityTransaction.commit();
}

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();//from   www .jav a2s  .  c  o m

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

}

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

private void createSocialSiteUser(String id) throws UserManagementException {
    EntityManager em = null;
    User user = null;/*from w  w w  .  j ava2 s. c  om*/

    try {
        em = strategy.getEntityManager(false);
        UserManager userManager = new UserManagerImpl(em);
        user = userManager.getUserByUserId(id);
        if (user == null) {
            Date now = new Date();
            user = new User();
            user.setUserId(id);
            user.setUserName(id);
            user.resetPassword(id, "SHA");
            user.setFullName(id);
            user.setEmailAddress(id + "@sun.com");
            user.setCreationDate(now);
            user.setUpdateDate(now);
            user.setAccessDate(now);
            user.setEnabled(true);

            em.getTransaction().begin();
            try {
                userManager.registerUser(user);
                userManager.grantRole("user", user);
                em.persist(user);
            } catch (Throwable t) {
                try {
                    if (em.getTransaction().isActive())
                        em.getTransaction().rollback();
                } catch (Throwable t2) {
                    log.error("Failed to rollback transaction: " + em.getTransaction(), t2);
                }
                throw new UserManagementException(t);
            }
            em.getTransaction().commit();
        }
    } finally {
        try {
            if (em != null) {
                em.close();
            }
        } catch (Throwable t) {
            throw new UserManagementException(t);
        }
    }
}

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

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();//from w  ww  .j av a  2s.  c  om

    Query q = entityManager.createQuery("DELETE FROM BakerUser ");
    q.executeUpdate();
    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();/*from  w w w  .  j a  va2s .co m*/

    entityManager.persist(sm);
    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();/*from w w  w. j av a  2s  .  c  om*/

    Query q = entityManager.createQuery("DELETE FROM SubscribedResource ");
    q.executeUpdate();
    entityManager.flush();

    entityTransaction.commit();

}