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.isatools.isatab.ISATABUnloader.java

public void unload() {
    List<Study> studies = new LinkedList<Study>();

    EntityManager emgr = daoFactory.getEntityManager();
    Session session = (Session) emgr.getDelegate();
    EntityTransaction ts = emgr.getTransaction();

    if (studyAcc != null) {
        StudyDAO dao = daoFactory.getStudyDAO();
        Study study = dao.getByAcc(studyAcc);
        if (study == null) {
            log.warn("Study with accession '" + studyAcc + "' not found, no undeletion performed.");
            return;
        }//from w  w w .  j a  v  a  2  s  .c o  m
        studies.add(study);

        unloadMgr = new UnloadManager(daoFactory, study.getSubmissionTs());
        StudyUnloader unloader = (StudyUnloader) unloadMgr.getUnloader(Study.class);
        unloader.queueByAcc(studyAcc);
    } else {
        studies.addAll(daoFactory.getStudyDAO().getBySubmissionTs(unloadMgr.getSubmissionTs()));
        unloadMgr.queueAll(studies);
    }

    try {
        if (!ts.isActive()) {
            ts.begin();
        }
        unloadMgr.delete();
        ts.commit();
    } catch (HibernateException e) {
        if (ts.isActive()) {
            ts.rollback();
        }
        throw new TabInternalErrorException("Error while performing the unloading:" + e.getMessage());
    } finally {
        session.flush();
    }

    DataFilesDispatcher fileDispatcher = new DataFilesDispatcher(daoFactory.getEntityManager());
    fileDispatcher.undispatch(studies);
}

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

public TModelDetail saveTModel(SaveTModel body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {/*from w  w  w  . j a  va  2 s.co m*/
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        new ValidatePublish(publisher).validateSaveTModel(em, body, null);

        TModelDetail result = new TModelDetail();

        List<org.uddi.api_v3.TModel> apiTModelList = body.getTModel();
        for (org.uddi.api_v3.TModel apiTModel : apiTModelList) {

            org.apache.juddi.model.Tmodel modelTModel = new org.apache.juddi.model.Tmodel();

            MappingApiToModel.mapTModel(apiTModel, modelTModel);

            setOperationalInfo(em, modelTModel, publisher);

            em.persist(modelTModel);

            result.getTModel().add(apiTModel);

        }

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

        return result;
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.SAVE_TMODEL, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

public ServiceDetail saveService(SaveService body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {/*from   ww  w  .j  a v  a2s  . com*/
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        ValidatePublish validator = new ValidatePublish(publisher);
        validator.validateSaveService(em, body, null);

        ServiceDetail result = new ServiceDetail();

        List<org.uddi.api_v3.BusinessService> apiBusinessServiceList = body.getBusinessService();
        for (org.uddi.api_v3.BusinessService apiBusinessService : apiBusinessServiceList) {

            org.apache.juddi.model.BusinessService modelBusinessService = new org.apache.juddi.model.BusinessService();
            org.apache.juddi.model.BusinessEntity modelBusinessEntity = new org.apache.juddi.model.BusinessEntity();
            modelBusinessEntity.setEntityKey(apiBusinessService.getBusinessKey());

            MappingApiToModel.mapBusinessService(apiBusinessService, modelBusinessService, modelBusinessEntity);

            setOperationalInfo(em, modelBusinessService, publisher, false);

            em.persist(modelBusinessService);

            result.getBusinessService().add(apiBusinessService);

            validator.validateSaveServiceMax(em, modelBusinessService.getBusinessEntity().getEntityKey());
        }

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

        return result;
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.SAVE_SERVICE, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

public BusinessDetail saveBusiness(SaveBusiness body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();
    if (!body.getBusinessEntity().isEmpty()) {
        log.debug("Inbound save business request for key " + body.getBusinessEntity().get(0).getBusinessKey());
    }//w w w.  j a  va2 s  .c  o  m
    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        ValidatePublish validator = new ValidatePublish(publisher);
        validator.validateSaveBusiness(em, body, null);

        BusinessDetail result = new BusinessDetail();

        List<org.uddi.api_v3.BusinessEntity> apiBusinessEntityList = body.getBusinessEntity();
        for (org.uddi.api_v3.BusinessEntity apiBusinessEntity : apiBusinessEntityList) {

            org.apache.juddi.model.BusinessEntity modelBusinessEntity = new org.apache.juddi.model.BusinessEntity();

            MappingApiToModel.mapBusinessEntity(apiBusinessEntity, modelBusinessEntity);

            setOperationalInfo(em, modelBusinessEntity, publisher);

            em.persist(modelBusinessEntity);

            result.getBusinessEntity().add(apiBusinessEntity);
        }

        //check how many business this publisher owns.
        validator.validateSaveBusinessMax(em);

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

        return result;
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.SAVE_BUSINESS, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

public BindingDetail saveBinding(SaveBinding body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {//from w  w  w  .  j  a v a2 s.  c  om
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        ValidatePublish validator = new ValidatePublish(publisher);
        validator.validateSaveBinding(em, body, null);

        BindingDetail result = new BindingDetail();
        result.setListDescription(new ListDescription());
        List<org.uddi.api_v3.BindingTemplate> apiBindingTemplateList = body.getBindingTemplate();
        for (org.uddi.api_v3.BindingTemplate apiBindingTemplate : apiBindingTemplateList) {

            org.apache.juddi.model.BindingTemplate modelBindingTemplate = new org.apache.juddi.model.BindingTemplate();

            org.apache.juddi.model.BusinessService modelBusinessService = new org.apache.juddi.model.BusinessService();
            modelBusinessService.setEntityKey(apiBindingTemplate.getServiceKey());

            MappingApiToModel.mapBindingTemplate(apiBindingTemplate, modelBindingTemplate,
                    modelBusinessService);

            setOperationalInfo(em, modelBindingTemplate, publisher, false);

            em.persist(modelBindingTemplate);

            result.getBindingTemplate().add(apiBindingTemplate);
            result.getListDescription().setActualCount(result.getListDescription().getActualCount() + 1);
            result.getListDescription().setIncludeCount(result.getListDescription().getIncludeCount() + 1);
            validator.validateSaveBindingMax(em, modelBindingTemplate.getBusinessService().getEntityKey());
        }

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

        return result;
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.SAVE_BINDING, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

public void setPublisherAssertions(String authInfo, Holder<List<PublisherAssertion>> publisherAssertion)
        throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {/*from   w  w w  . jav  a2 s . c  om*/
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, authInfo);

        new ValidatePublish(publisher).validateSetPublisherAssertions(em, publisherAssertion);

        List<?> businessKeysFound = null;
        businessKeysFound = FindBusinessByPublisherQuery.select(em, null, publisher, businessKeysFound);

        // First, wipe out all previous assertions associated with this publisher
        DeletePublisherAssertionByBusinessQuery.delete(em, businessKeysFound);

        // Slate is clean for all assertions involving this publisher, now we simply need to add the new ones (and they will all be "new").
        List<org.uddi.api_v3.PublisherAssertion> apiPubAssertionList = publisherAssertion.value;
        for (org.uddi.api_v3.PublisherAssertion apiPubAssertion : apiPubAssertionList) {

            org.apache.juddi.model.PublisherAssertion modelPubAssertion = new org.apache.juddi.model.PublisherAssertion();

            MappingApiToModel.mapPublisherAssertion(apiPubAssertion, modelPubAssertion);

            org.apache.juddi.model.BusinessEntity beFrom = em.find(org.apache.juddi.model.BusinessEntity.class,
                    modelPubAssertion.getId().getFromKey());
            org.apache.juddi.model.BusinessEntity beTo = em.find(org.apache.juddi.model.BusinessEntity.class,
                    modelPubAssertion.getId().getToKey());
            modelPubAssertion.setBusinessEntityByFromKey(beFrom);
            modelPubAssertion.setBusinessEntityByToKey(beTo);

            modelPubAssertion.setFromCheck("false");
            modelPubAssertion.setToCheck("false");

            em.persist(modelPubAssertion);

            if (publisher.isOwner(modelPubAssertion.getBusinessEntityByFromKey()))
                modelPubAssertion.setFromCheck("true");
            if (publisher.isOwner(modelPubAssertion.getBusinessEntityByToKey()))
                modelPubAssertion.setToCheck("true");

        }

        tx.commit();
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.SET_PUBLISHERASSERTIONS, QueryStatus.SUCCESS, procTime);
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.SET_PUBLISHERASSERTIONS, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:org.apache.juddi.subscription.SubscriptionNotifier.java

/**
 * Sends out the notifications./* w ww . j  a  va2 s  .  com*/
 * @param getSubscriptionResults
 * @param resultList 
 * @param notificationDate 
 */
protected void notify(GetSubscriptionResults getSubscriptionResults, SubscriptionResultsList resultList,
        Date notificationDate) {
    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {
        String subscriptionKey = resultList.getSubscription().getSubscriptionKey();
        org.apache.juddi.model.Subscription modelSubscription = em
                .find(org.apache.juddi.model.Subscription.class, subscriptionKey);
        Date lastNotifiedDate = modelSubscription.getLastNotified();
        //now log to the db that we are sending the notification.
        tx.begin();
        modelSubscription.setLastNotified(notificationDate);
        em.persist(modelSubscription);
        tx.commit();

        org.apache.juddi.model.BindingTemplate bindingTemplate = em
                .find(org.apache.juddi.model.BindingTemplate.class, modelSubscription.getBindingKey());
        NotifySubscriptionListener body = new NotifySubscriptionListener();
        //         if (resultList.getServiceList()!=null && resultList.getServiceList().getServiceInfos()!=null &&
        //               resultList.getServiceList().getServiceInfos().getServiceInfo().size() == 0) {
        //            resultList.getServiceList().setServiceInfos(null);
        //         }
        body.setSubscriptionResultsList(resultList);

        //TODO if the endpoint requires an auth token, look up the security endpoint of the remote registry
        //via ClientSubscriptionInfo

        if (sendToken) {
            String authorizedName = modelSubscription.getAuthorizedName();
            UDDISecurityImpl security = new UDDISecurityImpl();

            if (authorizedName != null) { // add a security token if needed
                try {
                    //obtain a token for this publisher
                    org.uddi.api_v3.AuthToken token = security.getAuthToken(authorizedName);
                    body.setAuthInfo(token.getAuthInfo());
                } catch (DispositionReportFaultMessage e) {
                    body.setAuthInfo("Failed to generate token, please contact UDDI admin");
                    log.error(e.getMessage(), e);
                }
            }
        }

        if (bindingTemplate != null) {
            if (AccessPointType.END_POINT.toString().equalsIgnoreCase(bindingTemplate.getAccessPointType())
                    || AccessPointType.WSDL_DEPLOYMENT.toString()
                            .equalsIgnoreCase(bindingTemplate.getAccessPointType())) {
                try {
                    Notifier notifier = new NotifierFactory().getNotifier(bindingTemplate);
                    if (notifier != null) {
                        log.info("Sending out notification to " + bindingTemplate.getAccessPointUrl());
                        notifier.notifySubscriptionListener(body);
                        //there maybe more chunks we have to send
                        String chunkToken = body.getSubscriptionResultsList().getChunkToken();
                        while (chunkToken != null) {
                            UddiEntityPublisher publisher = new UddiEntityPublisher();
                            publisher.setAuthorizedName(modelSubscription.getAuthorizedName());
                            log.debug("Sending out next chunk: " + chunkToken + " to "
                                    + bindingTemplate.getAccessPointUrl());
                            getSubscriptionResults.setChunkToken(chunkToken);
                            resultList = subscriptionImpl.getSubscriptionResults(getSubscriptionResults,
                                    publisher);
                            body.setSubscriptionResultsList(resultList);
                            notifier.notifySubscriptionListener(body);
                            chunkToken = body.getSubscriptionResultsList().getChunkToken();
                        }
                        //successful notification so remove from the badNotificationList
                        if (badNotifications.containsKey(resultList.getSubscription().getSubscriptionKey()))
                            badNotifications.remove(resultList.getSubscription().getSubscriptionKey());
                    }
                } catch (Exception e) {
                    if (e.getCause() instanceof IOException) {
                        addBadNotificationToList(subscriptionKey, bindingTemplate.getAccessPointUrl());
                        //we could not notify so compensate the transaction above
                        modelSubscription.setLastNotified(lastNotifiedDate);
                        tx.begin();
                        em.persist(modelSubscription);
                        tx.commit();
                        //} else {
                        //log.warn("Unexpected WebServiceException " + e.getMessage() + e.getCause());
                    }
                    log.error("Unexpected notification exception:" + e.getClass().getCanonicalName() + " "
                            + e.getMessage() + " " + e.getCause());
                    log.debug("Unexpected notification exception:" + e.getClass().getCanonicalName() + " "
                            + e.getMessage() + " " + e.getCause(), e);
                }
            } else {
                log.info("Binding " + bindingTemplate.getEntityKey() + " has an unsupported binding type of "
                        + bindingTemplate.getAccessPointType() + ". Only "
                        + AccessPointType.END_POINT.toString() + " and "
                        + AccessPointType.WSDL_DEPLOYMENT.toString() + " are supported.");
                addBadNotificationToList(subscriptionKey,
                        bindingTemplate.getAccessPointType() + " not supported");
            }
        } else {
            log.info("There is no valid binding template defined for this subscription: "
                    + modelSubscription.getBindingKey());
            addBadNotificationToList(subscriptionKey, modelSubscription.getBindingKey() + " not found");
        }

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

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

public void addPublisherAssertions(AddPublisherAssertions body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {/*  ww w .j a v  a  2 s  .c om*/
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        new ValidatePublish(publisher).validateAddPublisherAssertions(em, body);

        List<org.uddi.api_v3.PublisherAssertion> apiPubAssertionList = body.getPublisherAssertion();
        for (org.uddi.api_v3.PublisherAssertion apiPubAssertion : apiPubAssertionList) {

            org.apache.juddi.model.PublisherAssertion modelPubAssertion = new org.apache.juddi.model.PublisherAssertion();

            MappingApiToModel.mapPublisherAssertion(apiPubAssertion, modelPubAssertion);

            org.apache.juddi.model.PublisherAssertion existingPubAssertion = em
                    .find(modelPubAssertion.getClass(), modelPubAssertion.getId());
            boolean persistNewAssertion = true;
            if (existingPubAssertion != null) {
                if (modelPubAssertion.getTmodelKey().equalsIgnoreCase(existingPubAssertion.getTmodelKey())
                        && modelPubAssertion.getKeyName().equalsIgnoreCase(existingPubAssertion.getKeyName())
                        && modelPubAssertion.getKeyValue()
                                .equalsIgnoreCase(existingPubAssertion.getKeyValue())) {
                    // This pub assertion is already been "asserted".  Simply need to set the "check" value on the existing (and persistent) assertion
                    if (publisher.isOwner(existingPubAssertion.getBusinessEntityByFromKey()))
                        existingPubAssertion.setFromCheck("true");
                    if (publisher.isOwner(existingPubAssertion.getBusinessEntityByToKey()))
                        existingPubAssertion.setToCheck("true");

                    persistNewAssertion = false;
                } else {
                    // Otherwise, it is a new relationship between these entities.  Remove the old one so the new one can be added.
                    // TODO: the model only seems to allow one assertion per two business (primary key is fromKey and toKey). Spec seems to imply as 
                    // many relationships as desired (the differentiator would be the keyedRef values).
                    em.remove(existingPubAssertion);
                }
            }

            if (persistNewAssertion) {
                org.apache.juddi.model.BusinessEntity beFrom = em.find(
                        org.apache.juddi.model.BusinessEntity.class, modelPubAssertion.getId().getFromKey());
                org.apache.juddi.model.BusinessEntity beTo = em.find(
                        org.apache.juddi.model.BusinessEntity.class, modelPubAssertion.getId().getToKey());
                modelPubAssertion.setBusinessEntityByFromKey(beFrom);
                modelPubAssertion.setBusinessEntityByToKey(beTo);

                modelPubAssertion.setFromCheck("false");
                modelPubAssertion.setToCheck("false");

                em.persist(modelPubAssertion);

                if (publisher.isOwner(modelPubAssertion.getBusinessEntityByFromKey()))
                    modelPubAssertion.setFromCheck("true");
                if (publisher.isOwner(modelPubAssertion.getBusinessEntityByToKey()))
                    modelPubAssertion.setToCheck("true");
            }

        }

        tx.commit();
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.ADD_PUBLISHERASSERTIONS, QueryStatus.SUCCESS, procTime);
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.ADD_PUBLISHERASSERTIONS, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

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

public RegisteredInfo getRegisteredInfo(GetRegisteredInfo body) throws DispositionReportFaultMessage {
    long startTime = System.currentTimeMillis();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {//from w w w. j  a va  2  s.c  om
        tx.begin();

        UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());

        new ValidatePublish(publisher).validateRegisteredInfo(body);

        List<?> businessKeysFound = null;
        businessKeysFound = FindBusinessByPublisherQuery.select(em, null, publisher, businessKeysFound);

        List<?> tmodelKeysFound = null;

        if (body.getInfoSelection().equals(InfoSelection.HIDDEN))
            tmodelKeysFound = FindTModelByPublisherQuery.select(em, null, publisher, tmodelKeysFound,
                    new DynamicQuery.Parameter(TModelQuery.ENTITY_ALIAS + ".deleted", Boolean.TRUE,
                            DynamicQuery.PREDICATE_EQUALS));
        else if (body.getInfoSelection().equals(InfoSelection.VISIBLE))
            tmodelKeysFound = FindTModelByPublisherQuery.select(em, null, publisher, tmodelKeysFound,
                    new DynamicQuery.Parameter(TModelQuery.ENTITY_ALIAS + ".deleted", Boolean.FALSE,
                            DynamicQuery.PREDICATE_EQUALS));
        else
            tmodelKeysFound = FindTModelByPublisherQuery.select(em, null, publisher, tmodelKeysFound);

        RegisteredInfo result = new RegisteredInfo();

        // Sort and retrieve the final results
        List<?> queryResults = FetchBusinessEntitiesQuery.select(em, new FindQualifiers(), businessKeysFound,
                null, null, null);
        if (queryResults.size() > 0) {
            result.setBusinessInfos(new org.uddi.api_v3.BusinessInfos());

            for (Object item : queryResults) {
                org.apache.juddi.model.BusinessEntity modelBusinessEntity = (org.apache.juddi.model.BusinessEntity) item;
                org.uddi.api_v3.BusinessInfo apiBusinessInfo = new org.uddi.api_v3.BusinessInfo();

                MappingModelToApi.mapBusinessInfo(modelBusinessEntity, apiBusinessInfo);

                result.getBusinessInfos().getBusinessInfo().add(apiBusinessInfo);
            }
        }

        // Sort and retrieve the final results
        queryResults = FetchTModelsQuery.select(em, new FindQualifiers(), tmodelKeysFound, null, null, null);
        if (queryResults.size() > 0) {
            result.setTModelInfos(new org.uddi.api_v3.TModelInfos());

            for (Object item : queryResults) {
                org.apache.juddi.model.Tmodel modelTModel = (org.apache.juddi.model.Tmodel) item;
                org.uddi.api_v3.TModelInfo apiTModelInfo = new org.uddi.api_v3.TModelInfo();

                MappingModelToApi.mapTModelInfo(modelTModel, apiTModelInfo);

                result.getTModelInfos().getTModelInfo().add(apiTModelInfo);
            }
        }

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

        return result;
    } catch (DispositionReportFaultMessage drfm) {
        long procTime = System.currentTimeMillis() - startTime;
        serviceCounter.update(PublicationQuery.GET_REGISTEREDINFO, QueryStatus.FAILED, procTime);
        throw drfm;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}

From source file:org.apache.juddi.config.AppConfig.java

private Properties getPersistentConfiguration(Configuration config) throws ConfigurationException {
    Properties result = new Properties();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {//from  w  ww.  j  av a 2s  .  co  m
        boolean seedAlways = config.getBoolean("juddi.seed.always", false);
        if (seedAlways || !Install.alreadyInstalled(config)) {
            if (seedAlways) {
                log.info("Installing UDDI seed data, loading...");
            } else {
                log.info("The 'root' publisher was not found, loading...");
            }
            try {
                Install.install(config);
            } catch (Exception e) {
                throw new ConfigurationException(e);
            } catch (Throwable t) {
                throw new ConfigurationException(t);
            }
        }

        tx.begin();

        String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
        UddiEntityPublisher rootPublisher = new UddiEntityPublisher(rootPublisherStr);
        rootPublisher.populateKeyGeneratorKeys(em);
        List<String> rootKeyGenList = rootPublisher.getKeyGeneratorKeys();
        if (rootKeyGenList == null || rootKeyGenList.size() == 0)
            throw new ConfigurationException(
                    "The 'root' publisher key generator was not found.  Please make sure that the application is properly installed.");

        String rootKeyGen = rootKeyGenList.iterator().next();
        //rootKeyGen = rootKeyGen.substring((KeyGenerator.UDDI_SCHEME + KeyGenerator.PARTITION_SEPARATOR).length());
        rootKeyGen = rootKeyGen.substring(0, rootKeyGen.length()
                - (KeyGenerator.PARTITION_SEPARATOR + KeyGenerator.KEYGENERATOR_SUFFIX).length());
        log.debug("root partition:  " + rootKeyGen);

        result.setProperty(Property.JUDDI_ROOT_PARTITION, rootKeyGen);

        // The node Id is defined as the business key of the business entity categorized as a node.  This entity is saved as part of the install.
        // Only one business entity should be categorized as a node.
        String nodeId = "";
        CategoryBag categoryBag = new CategoryBag();
        KeyedReference keyedRef = new KeyedReference();
        keyedRef.setTModelKey(Constants.NODE_CATEGORY_TMODEL);
        keyedRef.setKeyValue(Constants.NODE_KEYVALUE);
        categoryBag.getKeyedReference().add(keyedRef);
        List<?> keyList = FindBusinessByCategoryQuery.select(em, new FindQualifiers(), categoryBag, null);
        if (keyList != null && keyList.size() > 1)
            throw new ConfigurationException("Only one business entity can be categorized as the node.");

        if (keyList != null && keyList.size() > 0) {
            nodeId = (String) keyList.get(0);
        } else
            throw new ConfigurationException(
                    "A node business entity was not found.  Please make sure that the application is properly installed.");
        result.setProperty(Property.JUDDI_NODE_ID, nodeId);

        //result.setProperty(Property.JUDDI_NODE_ROOT_BUSINESS, nodeId);

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