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.apache.juddi.api.impl.UDDIInquiryImpl.java

public OperationalInfos getOperationalInfo(GetOperationalInfo body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();
    try {// w ww  .  j a va2 s .c o m
        new ValidateInquiry(null).validateGetOperationalInfo(body);
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(InquiryQuery.GET_OPERATIONALINFO, QueryStatus.FAILED, procTime);
        throw drfm;
    }

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();

        if (isAuthenticated())
            this.getEntityPublisher(em, body.getAuthInfo());

        OperationalInfos result = new OperationalInfos();

        List<String> entityKeyList = body.getEntityKey();
        for (String entityKey : entityKeyList) {
            org.apache.juddi.model.UddiEntity modelUddiEntity = null;
            try {
                modelUddiEntity = em.find(org.apache.juddi.model.UddiEntity.class, entityKey);
            } catch (ClassCastException e) {
            }
            if (modelUddiEntity == null)
                throw new InvalidKeyPassedException(
                        new ErrorMessage("errors.invalidkey.EntityNotFound", entityKey));

            org.uddi.api_v3.OperationalInfo apiOperationalInfo = new org.uddi.api_v3.OperationalInfo();

            MappingModelToApi.mapOperationalInfo(modelUddiEntity, apiOperationalInfo);

            result.getOperationalInfo().add(apiOperationalInfo);
        }

        tx.commit();
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(InquiryQuery.GET_OPERATIONALINFO, QueryStatus.SUCCESS, procTime);

        return result;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java

public TModelDetail getTModelDetail(GetTModelDetail body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();
    try {/*from  w ww .j  av a2  s .  c  o m*/
        new ValidateInquiry(null).validateGetTModelDetail(body);
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(InquiryQuery.GET_TMODELDETAIL, QueryStatus.FAILED, procTime);
        throw drfm;
    }

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();

        if (isAuthenticated())
            this.getEntityPublisher(em, body.getAuthInfo());

        TModelDetail result = new TModelDetail();

        List<String> tmodelKeyList = body.getTModelKey();
        for (String tmodelKey : tmodelKeyList) {
            org.apache.juddi.model.Tmodel modelTModel = null;
            try {
                modelTModel = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey);
            } catch (ClassCastException e) {
            }
            if (modelTModel == null)
                throw new InvalidKeyPassedException(
                        new ErrorMessage("errors.invalidkey.TModelNotFound", tmodelKey));

            org.uddi.api_v3.TModel apiTModel = new org.uddi.api_v3.TModel();

            MappingModelToApi.mapTModel(modelTModel, apiTModel);

            result.getTModel().add(apiTModel);
        }

        tx.commit();
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(InquiryQuery.GET_TMODELDETAIL, QueryStatus.SUCCESS, procTime);

        return result;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

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

    return resis;
}

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();
    entityManager.persist(prod);//ww w  .  j av a 2  s  .  co  m
    entityManager.flush();
    entityTransaction.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();

    entityManager.persist(c);/*  w  ww . j  av  a2 s  . c  o  m*/
    entityManager.flush();
    entityTransaction.commit();
}

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

public Category updateCategory(Category c) {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
    Category resis = entityManager.merge(c);
    entityTransaction.commit();/*  w w w . j  a v  a2 s.c  om*/

    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();
    FStoreProperty bp = entityManager.merge(p);
    entityTransaction.commit();/*from  w  w  w .j a  v a2  s.c o m*/

    return bp;
}

From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java

public ServiceDetail getServiceDetail(GetServiceDetail body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();
    try {/*from  w ww  .j  ava2s. c  o  m*/
        new ValidateInquiry(null).validateGetServiceDetail(body);
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(InquiryQuery.GET_SERVICEDETAIL, QueryStatus.FAILED, procTime);
        throw drfm;
    }

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();

        if (isAuthenticated())
            this.getEntityPublisher(em, body.getAuthInfo());

        ServiceDetail result = new ServiceDetail();

        List<String> serviceKeyList = body.getServiceKey();
        for (String serviceKey : serviceKeyList) {
            org.apache.juddi.model.BusinessService modelBusinessService = null;
            try {
                modelBusinessService = em.find(org.apache.juddi.model.BusinessService.class, serviceKey);
            } catch (ClassCastException e) {
            }
            if (modelBusinessService == null)
                throw new InvalidKeyPassedException(
                        new ErrorMessage("errors.invalidkey.ServiceNotFound", serviceKey));

            org.uddi.api_v3.BusinessService apiBusinessService = new org.uddi.api_v3.BusinessService();

            MappingModelToApi.mapBusinessService(modelBusinessService, apiBusinessService);

            result.getBusinessService().add(apiBusinessService);
        }

        tx.commit();
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(InquiryQuery.GET_SERVICEDETAIL, QueryStatus.SUCCESS, procTime);

        return result;

    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();

    entityManager.remove(u);//from  ww w. j  a v  a2  s  .  c  o m

    entityTransaction.commit();
}

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();

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

}