Example usage for javax.persistence EntityTransaction commit

List of usage examples for javax.persistence EntityTransaction commit

Introduction

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

Prototype

public void commit();

Source Link

Document

Commit the current resource transaction, writing any unflushed changes to the database.

Usage

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public FStoreUser updateFStoreUser(FStoreUser bu) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/*from w ww.j a  v  a  2s. c  om*/
    FStoreUser resis = entityManager.merge(bu);
    entityTransaction.commit();

    return resis;
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public Product updateProduct(Product bm) {
    logger.info("================= updateProduct ==================");
    logger.info("bmgetId=" + bm.getId());
    logger.info("bm getName= " + bm.getName());
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/*from w w w .j a  va  2s  .  co  m*/
    Product resis = entityManager.merge(bm);
    entityTransaction.commit();

    return resis;
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/*www  .java2 s.c  o m*/
    FStoreProperty bp = entityManager.merge(p);
    entityTransaction.commit();

    return bp;
}

From source file:it.infn.ct.futuregateway.apiserver.v1.ApplicationCollectionService.java

/**
 * Register a new application./*from ww  w .  j  a v  a 2 s .  c o m*/
 *
 * @param application The application to register
 * @return The registered application
 */
@POST
@Status(Response.Status.CREATED)
@Consumes({ MediaType.APPLICATION_JSON, Constants.INDIGOMIMETYPE })
@Produces(Constants.INDIGOMIMETYPE)
public final Application createApplication(final Application application) {
    if (application.getInfrastructureIds() == null || application.getInfrastructureIds().isEmpty()) {
        throw new BadRequestException();
    }
    Date now = new Date();
    application.setDateCreated(now);
    EntityManager em = getEntityManager();
    EntityTransaction et = null;
    try {
        et = em.getTransaction();
        et.begin();
        List<Infrastructure> lstInfra = new LinkedList<>();
        for (String infraId : application.getInfrastructureIds()) {
            Infrastructure infra = em.find(Infrastructure.class, infraId);
            if (infra == null) {
                throw new BadRequestException();
            }
            lstInfra.add(infra);
        }
        application.setInfrastructures(lstInfra);
        em.persist(application);
        et.commit();
        log.debug("New application registered: " + application.getId());
    } catch (BadRequestException re) {
        throw re;
    } catch (RuntimeException re) {
        log.error("Impossible to create the application");
        log.error(re);
        throw re;
    } finally {
        if (et != null && et.isActive()) {
            et.rollback();
        }
        em.close();
    }
    return application;
}

From source file:org.apache.juddi.replication.ReplicationNotifier.java

@Deprecated
private Node getNode(String messageSender) {
    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = null;
    try {// w  w  w  .  j  a  v a 2s .  co m
        tx = em.getTransaction();
        tx.begin();
        Node api = new Node();
        org.apache.juddi.model.Node find = em.find(org.apache.juddi.model.Node.class, messageSender);
        if (find != null) {
            MappingModelToApi.mapNode(find, api);
        }
        tx.commit();
        return api;
    } catch (Exception ex) {
        log.error("error", ex);
        if (tx != null && tx.isActive()) {
            tx.rollback();
        }
    } finally {
        em.close();
    }
    return null;
}

From source file:com.eucalyptus.objectstorage.entities.upgrade.ObjectStorage400Upgrade.java

private static void generateCanonicaIDs() throws Exception {
    EntityTransaction tran = Entities.get(AccountEntity.class);
    try {/*from www. j a v a2s .c om*/
        List<AccountEntity> accounts = Entities.query(new AccountEntity());
        if (accounts != null && accounts.size() > 0) {
            for (AccountEntity account : accounts) {
                if (account.getCanonicalId() == null || account.getCanonicalId().equals("")) {
                    account.populateCanonicalId();
                    LOG.debug("Assigning canonical id " + account.getCanonicalId() + " for account "
                            + account.getAccountNumber());
                }
            }
        }
        tran.commit();
    } catch (Exception e) {
        LOG.error("Failed to generate and assign canonical ids", e);
        tran.rollback();
        throw e;
    } finally {
        if (tran.isActive()) {
            tran.commit();
        }
    }
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public void saveCategory(Category c) {
    logger.info("Will category = " + c.getName());

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();/* w  w w. ja v  a  2  s.c o m*/

    entityManager.persist(c);
    entityManager.flush();
    entityTransaction.commit();
}

From source file:org.eclipse.smila.recordstorage.impl.RecordStorageImpl.java

/**
 * {@inheritDoc}/*from  w w w  .  j  ava 2  s. c  o m*/
 */
@Override
public void storeRecord(final Record record) throws RecordStorageException {
    if (record == null) {
        throw new RecordStorageException("parameter record is null");
    }
    _lock.readLock().lock();
    try {
        final EntityManager em = createEntityManager();
        final EntityTransaction transaction = em.getTransaction();
        try {
            final RecordDao dao = new RecordDao(record);
            transaction.begin();
            if (findRecordDao(em, record.getId()) == null) {
                em.persist(dao);
            } else {
                em.merge(dao);
            }
            transaction.commit();
            if (_log.isTraceEnabled()) {
                _log.trace("stored record Id:" + record.getId());
            }
        } catch (final Exception e) {
            if (transaction.isActive()) {
                transaction.rollback();
            }
            throw new RecordStorageException(e, "error storing record id: " + record.getId());
        } finally {
            closeEntityManager(em);
        }
    } finally {
        _lock.readLock().unlock();
    }
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

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

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();/* ww  w .  j  a  va2 s.  c om*/

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

}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

public void saveProduct(Product prod) {
    logger.info("Will save Product = " + prod.getName());

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();
    entityTransaction.begin();//from w ww. j a v a 2s.  c  om
    entityManager.persist(prod);
    entityManager.flush();
    entityTransaction.commit();

}