List of usage examples for javax.persistence EntityTransaction begin
public void begin();
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves a specified quantity of annotations associated to a Resource specified by its URL and ordered by AnnotationStatus * @param _url/* w w w . jav a 2 s . c o m*/ * @param asc * @param first_indice * @param max_results * @return */ public List<Annotation> retrieveAnnotationsGroupByStatus(String _url, boolean asc, int first_indice, int max_results) { //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url) .getSingleResult(); if (_uri == null) { tx.commit(); // //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : there is no uri " + _url); return new ArrayList<Annotation>(); } //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotated as annotated inner join annotated.representsResource as uri where uri=?").setParameter(1, _uri).getResultList(); String order_by_clause = " annotation.id desc"; if (asc) order_by_clause = " annotation.id asc"; Query _query = em.createQuery( "select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? order by annotation.status," + order_by_clause) .setParameter(1, _uri); _query.setFirstResult(first_indice); _query.setMaxResults(max_results); List<Annotation> annotations = _query.getResultList(); //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? group by annotation.status" ).setParameter(1, _uri).getResultList(); tx.commit(); //em.close(); return annotations; } catch (Exception e) { //tx.commit(); tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : " + e.getMessage()); return new ArrayList<Annotation>(); } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves a specified quantity of annotations associated to a specified Resource through its URL, ordered by FirstAuthor * @param _url//from w ww. jav a 2 s . c o m * @param asc * @param first_indice * @param max_results * @return */ public List<Annotation> retrieveAnnotationsGroupByFirstAuthor(String _url, boolean asc, int first_indice, int max_results) { //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url) .getSingleResult(); if (_uri == null) { tx.commit(); // //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : there is no uri " + _url); return new ArrayList<Annotation>(); } //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotated as annotated inner join annotated.representsResource as uri where uri=?").setParameter(1, _uri).getResultList(); String order_by_clause = " annotation.id desc"; if (asc) order_by_clause = " annotation.id asc"; Query _query = em.createQuery( "select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? order by annotation.creator," + order_by_clause) .setParameter(1, _uri); _query.setFirstResult(first_indice); _query.setMaxResults(max_results); List<Annotation> annotations = _query.getResultList(); //List annotations = em.createQuery("select distinct annotation from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? group by annotation.status" ).setParameter(1, _uri).getResultList(); tx.commit(); //em.close(); return annotations; } catch (Exception e) { //tx.commit(); tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.retrieveAnnotations] unable to retrieve Annotations" + " cause : " + e.getMessage()); return new ArrayList<Annotation>(); } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Tests if an agent has expressed a Flame on a resource * @param _creator/*w w w . j a va 2 s. c o m*/ * @param _url_to_test * @return */ public boolean flameExpressed(Agent _creator, String _url_to_test) { long nb = 0; //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url_to_test) .getSingleResult(); if (_uri == null) { tx.commit(); System.out.println("[RetrieveAnnotation.flameExpressed] unable to retrieve Annotations" + " cause : there is no uri " + _url_to_test); return false; } AnnotationStatus status_flame = (AnnotationStatus) em .createQuery("from AnnotationStatus where label = ?").setParameter(1, "Flame") .getSingleResult(); if (status_flame != null) { Object nb_annotations_flame = em.createQuery( " select count(distinct annotation.id) from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? and annotation.creator=? and annotation.status=?") .setParameter(1, _uri).setParameter(2, _creator).setParameter(3, status_flame) .getSingleResult(); if (nb_annotations_flame instanceof Long) { nb = ((Long) nb_annotations_flame).longValue(); } } tx.commit(); if (nb > 0) return true; else return false; } catch (Exception e) { tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.flameExpressed] unable to retrieve Annotations" + " on url : " + _url_to_test + " cause : " + e.getMessage()); return false; //to prevent to express its opinion if the system fails } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Tests if an agent has expressed a Trolling on a resource * @param _creator/*w ww .j a v a 2 s . c om*/ * @param _url_to_test * @return */ public boolean trollExpressed(Agent _creator, String _url_to_test) { long nb = 0; //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url_to_test) .getSingleResult(); if (_uri == null) { tx.commit(); System.out.println("[RetrieveAnnotation.trollExpressed] unable to retrieve Annotations" + " cause : there is no uri " + _url_to_test); return false; } AnnotationStatus status_troll = (AnnotationStatus) em .createQuery("from AnnotationStatus where label = ?").setParameter(1, "Troll") .getSingleResult(); if (status_troll != null) { Object nb_annotations_troll = em.createQuery( " select count(distinct annotation.id) from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? and annotation.creator=? and annotation.status=?") .setParameter(1, _uri).setParameter(2, _creator).setParameter(3, status_troll) .getSingleResult(); if (nb_annotations_troll instanceof Long) { nb = ((Long) nb_annotations_troll).longValue(); } } tx.commit(); if (nb > 0) return true; else return false; } catch (Exception e) { tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.trollExpressed] unable to retrieve Annotations" + " on url : " + _url_to_test + " cause : " + e.getMessage()); return false; //to prevent to express its opinion if the system fails } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Creates an AnnotationStatus that specifies another AnnotationStatus * @param label//from w w w. j a v a 2 s .c o m * @param comment * @param father * @return */ public boolean createAnnotationStatusChild(String label, String comment, String color, AnnotationStatus father, JSONArray descripteur) { label = StringOp.deleteBlanks(label); if (!StringOp.isNull(label)) { comment = StringOp.deleteBlanks(comment); AnnotationStatus _as = new AnnotationStatus(); _as.setComment(comment); _as.setLabel(label); _as.setFather(father); _as.setDescripteur(descripteur); _as.setColor(color); // EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (father.getId() != null) { AnnotationStatus _synchro_father = em.find(AnnotationStatus.class, father.getId()); if (_synchro_father != null) _as.setFather(_synchro_father); } em.persist(_as); tx.commit(); // em.close(); return true; } catch (Exception e) { System.out .println("[CreateAnnotationStatus.createAnnotationStatus] fails to create AnnotationStatus" + " label : " + label + " comment : " + comment + " cause : " + e.getMessage()); tx.rollback(); // em.close(); return false; } } else { System.out.println("[CreateAnnotationStatus.createAnnotationStatus] unable to persist AnnotationStatus" + " not a valid label : " + label); return false; } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Tests if an agent has expressed an opinion (agree or disagree) on a resource * @param _creator/*from w ww .j a v a 2s . com*/ * @param _url_to_test * @return */ public boolean agreementExpressed(Agent _creator, String _url_to_test) { long nb = 0; //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); URI _uri = (URI) em.createQuery("from URI where effectiveURI = ?").setParameter(1, _url_to_test) .getSingleResult(); if (_uri == null) { tx.commit(); System.out.println("[RetrieveAnnotation.agreementExpressed] unable to retrieve Annotations" + " cause : there is no uri " + _url_to_test); return false; } AnnotationStatus status_agree = (AnnotationStatus) em .createQuery("from AnnotationStatus where label = ?").setParameter(1, "Accord") .getSingleResult(); AnnotationStatus status_disagree = (AnnotationStatus) em .createQuery("from AnnotationStatus where label = ?").setParameter(1, "Dsaccord") .getSingleResult(); AnnotationStatus status_clarify = (AnnotationStatus) em .createQuery("from AnnotationStatus where label = ?").setParameter(1, "A clarifier") .getSingleResult(); //if(status_agree != null) if (status_agree != null || status_disagree != null || status_clarify != null) { Object nb_annotations_agree = em.createQuery( " select count(distinct annotation.id) from Annotation as annotation inner join annotation.annotatedURIs as uri where uri=? and annotation.creator=? and (annotation.status=? or annotation.status=? or annotation.status=?)") .setParameter(1, _uri).setParameter(2, _creator).setParameter(3, status_agree) .setParameter(4, status_disagree).setParameter(5, status_clarify).getSingleResult(); if (nb_annotations_agree instanceof Long) { nb = ((Long) nb_annotations_agree).longValue(); } } tx.commit(); if (nb > 0) return true; else return false; } catch (Exception e) { tx.rollback(); //em.close(); System.out.println("[RetrieveAnnotation.agreementExpressed] unable to retrieve Annotations" + " on url : " + _url_to_test + " cause : " + e.getMessage()); return false; //to prevent to express its opinion if the system fails } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Creates an AnnotationStatus/* w w w.ja v a 2 s.co m*/ * @param label * @param comment * @return */ public boolean createAnnotationStatus(String label, String comment, String color, JSONArray descripteur) { label = StringOp.deleteBlanks(label); if (!StringOp.isNull(label)) { comment = StringOp.deleteBlanks(comment); AnnotationStatus _as = new AnnotationStatus(); _as.setComment(comment); _as.setLabel(label); _as.setDescripteur(descripteur); _as.setColor(color); // EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); AnnotationStatus annotationstatus = (AnnotationStatus) em .createQuery("from AnnotationStatus where label = ?").setParameter(1, label) .getSingleResult(); tx.commit(); if (annotationstatus != null) { System.out.println( "[CreateAnnotationStatus.createAnnotationStatus] this status already exists. Status : " + label); return false; } } catch (Exception e) { tx.rollback(); System.out.println( "[CreateAnnotationStatus.createAnnotationStatus] this status doesn't already exist. Status : " + label + " is gonna be created."); } try { tx.begin(); em.persist(_as); tx.commit(); // em.close(); return true; } catch (Exception e) { System.out .println("[CreateAnnotationStatus.createAnnotationStatus] fails to create AnnotationStatus" + " label : " + label + " comment : " + comment + " cause : " + e.getMessage()); tx.rollback(); // em.close(); return false; } } else { System.out.println("[CreateAnnotationStatus.createAnnotationStatus] unable to persist AnnotationStatus" + " not a valid label : " + label); return false; } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Creates an Annotation/*from w w w . java 2 s . c o m*/ * @param label * @param context_creation * @param hTMLContent * @param access * @param representsResource * @param status * @param added * @param annotated * @return */ public boolean createAnnotation(String label, String context_creation, URI access, URI representsResource, AnnotationStatus status, Collection<Resource> added, Collection<Resource> annotated, Collection<URI> annotatedURIs, Agent _creator) { label = StringOp.deleteBlanks(label); if (!StringOp.isNull(label)) { Annotation _annotation = new Annotation(); _annotation.setContextCreation(context_creation); _annotation.setCreation(new Date()); _annotation.setLabel(label); _annotation.setAccess(access); _annotation.setRepresentsResource(representsResource); _annotation.setStatus(status); _annotation.setCreator(_creator); //_annotation.setAdded(added); //_annotation.setAnnotated(annotated); //_annotation.setAnnotatedURIs(annotatedURIs); //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (representsResource.getId() != null) { URI _synchro_represents_resource = em.find(URI.class, representsResource.getId()); if (_synchro_represents_resource != null) _annotation.setRepresentsResource(_synchro_represents_resource); } if (access.getId() != null) { URI _synchro_access = em.find(URI.class, access.getId()); if (_synchro_access != null) _annotation.setAccess(_synchro_access); } if (status.getId() != null) { AnnotationStatus _synchro_status = em.find(AnnotationStatus.class, status.getId()); if (_synchro_status != null) _annotation.setStatus(_synchro_status); } if (_creator != null && _creator.getId() != null) { Agent _synchro_agent = em.find(_creator.getClass(), _creator.getId()); if (_synchro_agent != null) _annotation.setCreator(_synchro_agent); } Collection<Resource> _synchro_added = new ArrayList<Resource>(); for (Resource _to_add : added) { if (_to_add.getId() != null) { Resource _synchro_to_add = em.find(_to_add.getClass(), _to_add.getId()); if (_synchro_to_add != null) _synchro_added.add(_synchro_to_add); } else _synchro_added.add(_to_add); } _annotation.setAdded(_synchro_added); Collection<Resource> _synchro_annotated = new ArrayList<Resource>(); for (Resource _to_annotate : annotated) { if (_to_annotate.getId() != null) { Resource _synchro_to_annotate = em.find(_to_annotate.getClass(), _to_annotate.getId()); if (_synchro_to_annotate != null) _synchro_annotated.add(_synchro_to_annotate); } else _synchro_annotated.add(_to_annotate); } _annotation.setAnnotated(_synchro_annotated); Collection<URI> synchro_annotatedURIs = new ArrayList<URI>(); for (URI _to_annotate : annotatedURIs) { if (_to_annotate.getId() != null) { URI _synchro_to_annotate = em.find(_to_annotate.getClass(), _to_annotate.getId()); if (_synchro_to_annotate != null) { //empcher qu'une mme URI soit ajoute plusieurs fois une mme annotation if (!synchro_annotatedURIs.contains(_synchro_to_annotate)) synchro_annotatedURIs.add(_synchro_to_annotate); } } else synchro_annotatedURIs.add(_to_annotate); } _annotation.setAnnotatedURIs(synchro_annotatedURIs); em.persist(_annotation); tx.commit(); em.close(); return true; } catch (Exception e) { System.out.println( "[CreateAnnotation.createAnnotation] fails to create annotation" + " context creation : " + context_creation + " label : " + label + " cause : " + e.getMessage()); tx.rollback(); //em.close(); return false; } } else { System.out.println("[CreateAnnotation.createAnnotation] unable to persist annotation" + " not a valid label : " + label); return false; } }
From source file:de.iai.ilcd.model.dao.DataSetDao.java
/** * Set the {@link DataSet#setMostRecentVersion(boolean) most recent version flags} for all data sets with the * specified uuid. Please note that this method * <strong>does not open a separate transaction</strong>. * /* ww w . j a va 2 s.c o m*/ * @param uuid * uuid of the data sets */ @SuppressWarnings("unchecked") protected boolean setMostRecentVersionFlags(String uuid) { EntityManager em = PersistenceUtil.getEntityManager(); EntityTransaction t = em.getTransaction(); try { Query q = em.createQuery("SELECT a FROM " + this.getJpaName() + " a WHERE a.uuid.uuid=:uuid ORDER BY a.version.majorVersion desc, a.version.minorVersion desc, a.version.subMinorVersion desc"); q.setParameter("uuid", uuid); List<T> res = q.getResultList(); if (!res.isEmpty()) { t.begin(); // get first element and mark it as most recent version (correct order is taken care of in query!) T tmp = res.get(0); tmp.setMostRecentVersion(true); tmp = em.merge(tmp); // set "false" for all other elements if required final int size = res.size(); if (size > 1) { for (int i = 1; i < size; i++) { tmp = res.get(i); if (tmp.isMostRecentVersion()) { tmp.setMostRecentVersion(false); tmp = em.merge(tmp); } } } t.commit(); return true; } else { DataSetDao.LOGGER.warn("Most recent version flag was called for non-existent UUID: " + uuid); return false; } } catch (Exception e) { DataSetDao.LOGGER.error("Could not set most recent version flag for UUID: " + uuid); if (t.isActive()) { t.rollback(); } return false; } }
From source file:org.apache.juddi.api.impl.UDDISubscriptionImpl.java
@SuppressWarnings("unchecked") public SubscriptionResultsList getSubscriptionResults(GetSubscriptionResults body, UddiEntityPublisher publisher) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {//w w w . j a v a 2 s.com tx.begin(); if (publisher == null) { publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateSubscription(publisher).validateGetSubscriptionResults(em, body); } org.apache.juddi.model.Subscription modelSubscription = em .find(org.apache.juddi.model.Subscription.class, body.getSubscriptionKey()); SubscriptionFilter subscriptionFilter = null; try { subscriptionFilter = (SubscriptionFilter) JAXBMarshaller.unmarshallFromString( modelSubscription.getSubscriptionFilter(), JAXBMarshaller.PACKAGE_SUBSCRIPTION); } catch (JAXBException e) { logger.error("JAXB Exception while unmarshalling subscription filter", e); throw new FatalErrorException(new ErrorMessage("errors.Unspecified")); } if (logger.isDebugEnabled()) logger.debug("filter=" + modelSubscription.getSubscriptionFilter()); SubscriptionResultsList result = new SubscriptionResultsList(); result.setChunkToken("0"); //chunkToken: Optional element used to retrieve subsequent groups of data when the first invocation of this API indicates more data is available. This occurs when a chunkToken is returned whose value is not "0" in the validValuesList structure described in the next section. To retrieve the next chunk of data, the chunkToken returned should be used as an argument to the next invocation of this API. result.setCoveragePeriod(body.getCoveragePeriod()); // The subscription structure is required output for the results org.uddi.sub_v3.Subscription apiSubscription = new org.uddi.sub_v3.Subscription(); MappingModelToApi.mapSubscription(modelSubscription, apiSubscription); result.setSubscription(apiSubscription); Date startPointDate = new Date( body.getCoveragePeriod().getStartPoint().toGregorianCalendar().getTimeInMillis()); Date endPointDate = new Date( body.getCoveragePeriod().getEndPoint().toGregorianCalendar().getTimeInMillis()); Integer chunkData = null; if (body.getChunkToken() != null && body.getChunkToken().length() > 0) { SubscriptionChunkToken chunkToken = em.find(SubscriptionChunkToken.class, body.getChunkToken()); if (chunkToken == null) throw new InvalidValueException(new ErrorMessage( "errors.getsubscriptionresult.InvalidChunkToken", body.getChunkToken())); if (!chunkToken.getSubscriptionKey().equals(chunkToken.getSubscriptionKey())) throw new InvalidValueException(new ErrorMessage( "errors.getsubscriptionresult.NonMatchingChunkToken", body.getChunkToken())); if (chunkToken.getStartPoint() != null && chunkToken.getStartPoint().getTime() != startPointDate.getTime()) throw new InvalidValueException(new ErrorMessage( "errors.getsubscriptionresult.NonMatchingChunkToken", body.getChunkToken())); if (chunkToken.getEndPoint() != null && chunkToken.getEndPoint().getTime() != endPointDate.getTime()) throw new InvalidValueException(new ErrorMessage( "errors.getsubscriptionresult.NonMatchingChunkToken", body.getChunkToken())); if (chunkToken.getExpiresAfter().before(new Date())) throw new InvalidValueException(new ErrorMessage( "errors.getsubscriptionresult.ExpiredChunkToken", body.getChunkToken())); chunkData = chunkToken.getData(); // We've got the data from the chunk token, now it is no longer needed (once it's called, it's used up) em.remove(chunkToken); } if (subscriptionFilter.getFindBinding() != null) { //Get the current matching keys List<?> currentMatchingKeys = getSubscriptionMatches(subscriptionFilter, em); // See if there's any missing keys by comparing against the previous matches. If so, they missing keys are added to the KeyBag and // then added to the result List<String> missingKeys = getMissingKeys(currentMatchingKeys, modelSubscription.getSubscriptionMatches()); if (missingKeys != null && missingKeys.size() > 0) { KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); for (String key : missingKeys) missingKeyBag.getBindingKey().add(key); result.getKeyBag().add(missingKeyBag); } // Re-setting the subscription matches to the new matching key collection //modelSubscription.getSubscriptionMatches().clear(); //for (Object key : currentMatchingKeys) { // SubscriptionMatch subMatch = new SubscriptionMatch(modelSubscription, (String)key); // modelSubscription.getSubscriptionMatches().add(subMatch); //} // Now, finding the necessary entities, within the coverage period limits if (modelSubscription.isBrief()) { KeyBag resultsKeyBag = new KeyBag(); for (String key : (List<String>) currentMatchingKeys) resultsKeyBag.getBindingKey().add(key); result.getKeyBag().add(resultsKeyBag); } else { FindBinding fb = subscriptionFilter.getFindBinding(); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(fb.getFindQualifiers()); // To do subscription "chunking", the listHead and maxRows are nulled which will set them to system default. User settings for // these values don't make sense with the "chunking" feature. fb.setListHead(null); fb.setMaxRows(null); // Setting the start index to the chunkData Holder<Integer> subscriptionStartIndex = new Holder<Integer>(chunkData); BindingDetail bindingDetail = InquiryHelper.getBindingDetailFromKeys(fb, findQualifiers, em, currentMatchingKeys, startPointDate, endPointDate, subscriptionStartIndex, modelSubscription.getMaxEntities()); // Upon exiting above function, if more results are to be had, the subscriptionStartIndex will contain the latest value (or null // if no more results) chunkData = subscriptionStartIndex.value; result.setBindingDetail(bindingDetail); } } if (subscriptionFilter.getFindBusiness() != null) { //Get the current matching keys List<?> currentMatchingKeys = getSubscriptionMatches(subscriptionFilter, em); List<String> missingKeys = getMissingKeys(currentMatchingKeys, modelSubscription.getSubscriptionMatches()); if (missingKeys != null && missingKeys.size() > 0) { KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); for (String key : missingKeys) missingKeyBag.getBusinessKey().add(key); result.getKeyBag().add(missingKeyBag); } // Re-setting the subscription matches to the new matching key collection //modelSubscription.getSubscriptionMatches().clear(); //for (Object key : currentMatchingKeys) { // SubscriptionMatch subMatch = new SubscriptionMatch(modelSubscription, (String)key); // modelSubscription.getSubscriptionMatches().add(subMatch); //} // Now, finding the necessary entities, within the coverage period limits if (modelSubscription.isBrief()) { KeyBag resultsKeyBag = new KeyBag(); for (String key : (List<String>) currentMatchingKeys) resultsKeyBag.getBusinessKey().add(key); result.getKeyBag().add(resultsKeyBag); } else { FindBusiness fb = subscriptionFilter.getFindBusiness(); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(fb.getFindQualifiers()); // To do subscription "chunking", the listHead and maxRows are nulled which will set them to system default. User settings for // these values don't make sense with the "chunking" feature. fb.setListHead(null); fb.setMaxRows(null); // Setting the start index to the chunkData Holder<Integer> subscriptionStartIndex = new Holder<Integer>(chunkData); BusinessList businessList = InquiryHelper.getBusinessListFromKeys(fb, findQualifiers, em, currentMatchingKeys, startPointDate, endPointDate, subscriptionStartIndex, modelSubscription.getMaxEntities()); // Upon exiting above function, if more results are to be had, the subscriptionStartIndex will contain the latest value (or null // if no more results) chunkData = subscriptionStartIndex.value; result.setBusinessList(businessList); } } if (subscriptionFilter.getFindService() != null) { //Get the current matching keys List<?> currentMatchingKeys = getSubscriptionMatches(subscriptionFilter, em); if (logger.isDebugEnabled()) logger.debug("current matching keys=" + currentMatchingKeys); List<String> missingKeys = getMissingKeys(currentMatchingKeys, modelSubscription.getSubscriptionMatches()); if (missingKeys != null && missingKeys.size() > 0) { KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); for (String key : missingKeys) missingKeyBag.getServiceKey().add(key); result.getKeyBag().add(missingKeyBag); } // Re-setting the subscription matches to the new matching key collection //modelSubscription.getSubscriptionMatches().clear(); //for (Object key : currentMatchingKeys) { // SubscriptionMatch subMatch = new SubscriptionMatch(modelSubscription, (String)key); // modelSubscription.getSubscriptionMatches().add(subMatch); //} // Now, finding the necessary entities, within the coverage period limits if (modelSubscription.isBrief()) { KeyBag resultsKeyBag = new KeyBag(); for (String key : (List<String>) currentMatchingKeys) resultsKeyBag.getServiceKey().add(key); result.getKeyBag().add(resultsKeyBag); } else { FindService fs = subscriptionFilter.getFindService(); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(fs.getFindQualifiers()); // To do subscription "chunking", the listHead and maxRows are nulled which will set them to system default. User settings for // these values don't make sense with the "chunking" feature. fs.setListHead(null); fs.setMaxRows(null); // Setting the start index to the chunkData Holder<Integer> subscriptionStartIndex = new Holder<Integer>(chunkData); ServiceList serviceList = InquiryHelper.getServiceListFromKeys(fs, findQualifiers, em, currentMatchingKeys, startPointDate, endPointDate, subscriptionStartIndex, modelSubscription.getMaxEntities()); if (serviceList.getServiceInfos() == null || serviceList.getServiceInfos().getServiceInfo().size() == 0) { serviceList = null; } // Upon exiting above function, if more results are to be had, the subscriptionStartIndex will contain the latest value (or null // if no more results) chunkData = subscriptionStartIndex.value; result.setServiceList(serviceList); } } if (subscriptionFilter.getFindTModel() != null) { //Get the current matching keys List<?> currentMatchingKeys = getSubscriptionMatches(subscriptionFilter, em); List<String> missingKeys = getMissingKeys(currentMatchingKeys, modelSubscription.getSubscriptionMatches()); if (missingKeys != null && missingKeys.size() > 0) { KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); for (String key : missingKeys) missingKeyBag.getTModelKey().add(key); result.getKeyBag().add(missingKeyBag); } // Re-setting the subscription matches to the new matching key collection //modelSubscription.getSubscriptionMatches().clear(); //for (Object key : currentMatchingKeys) { // SubscriptionMatch subMatch = new SubscriptionMatch(modelSubscription, (String)key); // modelSubscription.getSubscriptionMatches().add(subMatch); //} // Now, finding the necessary entities, within the coverage period limits if (modelSubscription.isBrief()) { KeyBag resultsKeyBag = new KeyBag(); for (String key : (List<String>) currentMatchingKeys) resultsKeyBag.getTModelKey().add(key); result.getKeyBag().add(resultsKeyBag); } else { FindTModel ft = subscriptionFilter.getFindTModel(); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(ft.getFindQualifiers()); // To do subscription "chunking", the listHead and maxRows are nulled which will set them to system default. User settings for // these values don't make sense with the "chunking" feature. ft.setListHead(null); ft.setMaxRows(null); // Setting the start index to the chunkData Holder<Integer> subscriptionStartIndex = new Holder<Integer>(chunkData); // If more results are to be had, chunkData will come out with a value and a new token will be generated below. Otherwise, it will // be null and no token will be generated. TModelList tmodelList = InquiryHelper.getTModelListFromKeys(ft, findQualifiers, em, currentMatchingKeys, startPointDate, endPointDate, subscriptionStartIndex, modelSubscription.getMaxEntities()); // Upon exiting above function, if more results are to be had, the subscriptionStartIndex will contain the latest value (or null // if no more results) chunkData = subscriptionStartIndex.value; result.setTModelList(tmodelList); } } if (subscriptionFilter.getFindRelatedBusinesses() != null) { FindRelatedBusinesses findRelatedBusiness = subscriptionFilter.getFindRelatedBusinesses(); RelatedBusinessesList relatedBusinessList = InquiryHelper .getRelatedBusinessesList(findRelatedBusiness, em, startPointDate, endPointDate); result.setRelatedBusinessesList(relatedBusinessList); } if (subscriptionFilter.getGetBindingDetail() != null) { GetBindingDetail getDetail = subscriptionFilter.getGetBindingDetail(); // Running through the key list here to determine the deleted keys and store the existing entities. KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); List<org.apache.juddi.model.BindingTemplate> existingList = new ArrayList<org.apache.juddi.model.BindingTemplate>( 0); for (String key : getDetail.getBindingKey()) { org.apache.juddi.model.BindingTemplate modelBindingTemplate = em .find(org.apache.juddi.model.BindingTemplate.class, key); if (modelBindingTemplate != null) existingList.add(modelBindingTemplate); else missingKeyBag.getBindingKey().add(key); } // Store deleted keys in the results if (missingKeyBag.getBindingKey() != null && missingKeyBag.getBindingKey().size() > 0) result.getKeyBag().add(missingKeyBag); KeyBag resultsKeyBag = new KeyBag(); BindingDetail bindingDetail = new BindingDetail(); // Set the currentIndex to 0 or the value of the chunkData int currentIndex = 0; if (chunkData != null) currentIndex = chunkData; int returnedRowCount = 0; while (currentIndex < existingList.size()) { org.apache.juddi.model.BindingTemplate modelBindingTemplate = existingList.get(currentIndex); if (startPointDate.after(modelBindingTemplate.getModifiedIncludingChildren())) { currentIndex++; continue; } if (endPointDate.before(modelBindingTemplate.getModifiedIncludingChildren())) { currentIndex++; continue; } if (modelSubscription.isBrief()) { resultsKeyBag.getBindingKey().add(modelBindingTemplate.getEntityKey()); } else { org.uddi.api_v3.BindingTemplate apiBindingTemplate = new org.uddi.api_v3.BindingTemplate(); MappingModelToApi.mapBindingTemplate(modelBindingTemplate, apiBindingTemplate); bindingDetail.getBindingTemplate().add(apiBindingTemplate); returnedRowCount++; } // If the returned rows equals the max allowed, we can end the loop. if (modelSubscription.getMaxEntities() != null) { if (returnedRowCount == modelSubscription.getMaxEntities()) break; } currentIndex++; } // If the loop was broken prematurely (max row count hit) we set the chunk data to the next index to start with. // A non-null value of chunk data will cause a chunk token to be generated. if (currentIndex < (existingList.size() - 1)) chunkData = currentIndex + 1; else chunkData = null; if (modelSubscription.isBrief()) result.getKeyBag().add(resultsKeyBag); else result.setBindingDetail(bindingDetail); } if (subscriptionFilter.getGetBusinessDetail() != null) { GetBusinessDetail getDetail = subscriptionFilter.getGetBusinessDetail(); // Running through the key list here to determine the deleted keys and store the existing entities. KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); List<org.apache.juddi.model.BusinessEntity> existingList = new ArrayList<org.apache.juddi.model.BusinessEntity>( 0); for (String key : getDetail.getBusinessKey()) { org.apache.juddi.model.BusinessEntity modelBusinessEntity = em .find(org.apache.juddi.model.BusinessEntity.class, key); if (modelBusinessEntity != null) existingList.add(modelBusinessEntity); else missingKeyBag.getBusinessKey().add(key); } // Store deleted keys in the results if (missingKeyBag.getBusinessKey() != null && missingKeyBag.getBusinessKey().size() > 0) result.getKeyBag().add(missingKeyBag); KeyBag resultsKeyBag = new KeyBag(); BusinessDetail businessDetail = new BusinessDetail(); // Set the currentIndex to 0 or the value of the chunkData int currentIndex = 0; if (chunkData != null) currentIndex = chunkData; int returnedRowCount = 0; while (currentIndex < existingList.size()) { org.apache.juddi.model.BusinessEntity modelBusinessEntity = existingList.get(currentIndex); if (startPointDate.after(modelBusinessEntity.getModifiedIncludingChildren())) { currentIndex++; continue; } if (endPointDate.before(modelBusinessEntity.getModifiedIncludingChildren())) { currentIndex++; continue; } if (modelSubscription.isBrief()) { resultsKeyBag.getBusinessKey().add(modelBusinessEntity.getEntityKey()); } else { org.uddi.api_v3.BusinessEntity apiBusinessEntity = new org.uddi.api_v3.BusinessEntity(); MappingModelToApi.mapBusinessEntity(modelBusinessEntity, apiBusinessEntity); businessDetail.getBusinessEntity().add(apiBusinessEntity); returnedRowCount++; } // If the returned rows equals the max allowed, we can end the loop. if (modelSubscription.getMaxEntities() != null) { if (returnedRowCount == modelSubscription.getMaxEntities()) break; } currentIndex++; } // If the loop was broken prematurely (max row count hit) we set the chunk data to the next index to start with. // A non-null value of chunk data will cause a chunk token to be generated. if (currentIndex < (existingList.size() - 1)) chunkData = currentIndex + 1; else chunkData = null; if (modelSubscription.isBrief()) result.getKeyBag().add(resultsKeyBag); else result.setBusinessDetail(businessDetail); } if (subscriptionFilter.getGetServiceDetail() != null) { GetServiceDetail getDetail = subscriptionFilter.getGetServiceDetail(); // Running through the key list here to determine the deleted keys and store the existing entities. KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); List<org.apache.juddi.model.BusinessService> existingList = new ArrayList<org.apache.juddi.model.BusinessService>( 0); for (String key : getDetail.getServiceKey()) { org.apache.juddi.model.BusinessService modelBusinessService = em .find(org.apache.juddi.model.BusinessService.class, key); if (modelBusinessService != null) existingList.add(modelBusinessService); else missingKeyBag.getBusinessKey().add(key); } // Store deleted keys in the results if (missingKeyBag.getServiceKey() != null && missingKeyBag.getServiceKey().size() > 0) result.getKeyBag().add(missingKeyBag); KeyBag resultsKeyBag = new KeyBag(); ServiceDetail serviceDetail = new ServiceDetail(); // Set the currentIndex to 0 or the value of the chunkData int currentIndex = 0; if (chunkData != null) currentIndex = chunkData; int returnedRowCount = 0; while (currentIndex < existingList.size()) { org.apache.juddi.model.BusinessService modelBusinessService = existingList.get(currentIndex); if (startPointDate.after(modelBusinessService.getModifiedIncludingChildren())) { currentIndex++; continue; } if (endPointDate.before(modelBusinessService.getModifiedIncludingChildren())) { currentIndex++; continue; } if (modelSubscription.isBrief()) { resultsKeyBag.getServiceKey().add(modelBusinessService.getEntityKey()); } else { org.uddi.api_v3.BusinessService apiBusinessService = new org.uddi.api_v3.BusinessService(); MappingModelToApi.mapBusinessService(modelBusinessService, apiBusinessService); serviceDetail.getBusinessService().add(apiBusinessService); returnedRowCount++; } // If the returned rows equals the max allowed, we can end the loop. if (modelSubscription.getMaxEntities() != null) { if (returnedRowCount == modelSubscription.getMaxEntities()) break; } currentIndex++; } // If the loop was broken prematurely (max row count hit) we set the chunk data to the next index to start with. // A non-null value of chunk data will cause a chunk token to be generated. if (currentIndex < (existingList.size() - 1)) chunkData = currentIndex + 1; else chunkData = null; if (modelSubscription.isBrief()) result.getKeyBag().add(resultsKeyBag); else result.setServiceDetail(serviceDetail); } if (subscriptionFilter.getGetTModelDetail() != null) { GetTModelDetail getDetail = subscriptionFilter.getGetTModelDetail(); // Running through the key list here to determine the deleted keys and store the existing entities. KeyBag missingKeyBag = new KeyBag(); missingKeyBag.setDeleted(true); List<org.apache.juddi.model.Tmodel> existingList = new ArrayList<org.apache.juddi.model.Tmodel>(0); for (String key : getDetail.getTModelKey()) { org.apache.juddi.model.Tmodel modelTModel = em.find(org.apache.juddi.model.Tmodel.class, key); if (modelTModel != null) existingList.add(modelTModel); else missingKeyBag.getTModelKey().add(key); } // Store deleted keys in the results if (missingKeyBag.getTModelKey() != null && missingKeyBag.getTModelKey().size() > 0) result.getKeyBag().add(missingKeyBag); KeyBag resultsKeyBag = new KeyBag(); TModelDetail tmodelDetail = new TModelDetail(); // Set the currentIndex to 0 or the value of the chunkData int currentIndex = 0; if (chunkData != null) currentIndex = chunkData; int returnedRowCount = 0; while (currentIndex < existingList.size()) { org.apache.juddi.model.Tmodel modelTModel = existingList.get(currentIndex); if (startPointDate.after(modelTModel.getModifiedIncludingChildren())) { currentIndex++; continue; } if (endPointDate.before(modelTModel.getModifiedIncludingChildren())) { currentIndex++; continue; } if (modelSubscription.isBrief()) { resultsKeyBag.getTModelKey().add(modelTModel.getEntityKey()); } else { org.uddi.api_v3.TModel apiTModel = new org.uddi.api_v3.TModel(); MappingModelToApi.mapTModel(modelTModel, apiTModel); tmodelDetail.getTModel().add(apiTModel); returnedRowCount++; } // If the returned rows equals the max allowed, we can end the loop. if (modelSubscription.getMaxEntities() != null) { if (returnedRowCount == modelSubscription.getMaxEntities()) break; } currentIndex++; } // If the loop was broken prematurely (max row count hit) we set the chunk data to the next index to start with. // A non-null value of chunk data will cause a chunk token to be generated. if (currentIndex < (existingList.size() - 1)) chunkData = currentIndex + 1; else chunkData = null; if (modelSubscription.isBrief()) result.getKeyBag().add(resultsKeyBag); else result.setTModelDetail(tmodelDetail); } if (subscriptionFilter.getGetAssertionStatusReport() != null) { // The coverage period doesn't apply here (basically because publisher assertions don't keep operational info). GetAssertionStatusReport getAssertionStatusReport = subscriptionFilter .getGetAssertionStatusReport(); List<AssertionStatusItem> assertionList = PublicationHelper.getAssertionStatusItemList(publisher, getAssertionStatusReport.getCompletionStatus(), em); AssertionStatusReport assertionStatusReport = new AssertionStatusReport(); for (AssertionStatusItem asi : assertionList) assertionStatusReport.getAssertionStatusItem().add(asi); result.setAssertionStatusReport(assertionStatusReport); } // If chunkData contains non-null data, a new token must be created and the token returned in the results if (chunkData != null) { String chunkToken = CHUNK_TOKEN_PREFIX + UUID.randomUUID(); SubscriptionChunkToken newChunkToken = new SubscriptionChunkToken(chunkToken); newChunkToken.setSubscriptionKey(body.getSubscriptionKey()); newChunkToken.setStartPoint(startPointDate); newChunkToken.setEndPoint(endPointDate); newChunkToken.setData(chunkData); int chunkExpirationMinutes = DEFAULT_CHUNKEXPIRATION_MINUTES; try { chunkExpirationMinutes = AppConfig.getConfiguration() .getInt(Property.JUDDI_SUBSCRIPTION_CHUNKEXPIRATION_MINUTES); } catch (ConfigurationException ce) { throw new FatalErrorException(new ErrorMessage("errors.configuration.Retrieval")); } newChunkToken.setExpiresAfter( new Date(System.currentTimeMillis() + ((long) chunkExpirationMinutes * 60L * 1000L))); em.persist(newChunkToken); result.setChunkToken(chunkToken); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.GET_SUBSCRIPTIONRESULTS, QueryStatus.SUCCESS, procTime); return result; } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.GET_SUBSCRIPTIONRESULTS, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }