private List<String> runQuery(String queryString, String formattedInput, int resultsLimit) { Query query = null; List<String> queryResults = null; try { query = this.qm.createQuery(queryString, Query.XWQL); if (resultsLimit > 0) { query.setLimit(resultsLimit); query.setOffset(0); } if (StringUtils.isNotBlank(formattedInput)) { query.bindValue(UsersAndGroups.INPUT_PARAMETER, formattedInput); } queryResults = query.execute(); } catch (QueryException e) { this.logger.error("Error while performing query: [{}] ", queryString, e.getMessage()); return Collections.emptyList(); } return queryResults; }
@Override public List<String> getDocuments(String wiki, String space) throws WikiStreamException { try { Query query = this.queryManager .createQuery( "select distinct doc.name from Document doc where doc.space = :space order by doc.name asc", Query.XWQL); query.bindValue("space", space); query.setWiki(wiki); return query.execute(); } catch (QueryException e) { throw new WikiStreamException(String.format( "Failed to get the list of documents in wiki [%s] and space [%s]", wiki, space), e); } } }
@Override public Map<String, Object> provideData() { Map<String, Object> jsonMap = new HashMap<>(); try { Query q = this.qm.createQuery("from doc.object(XWiki.XWikiUsers) as user", Query.XWQL); q.addFilter(this.countFilter); long count = 0; for (String instanceId : this.wikiManager.getAllIds()) { q.setWiki(instanceId); List<Object> results = q.execute(); long instanceCount = (long) results.get(0); count += instanceCount; } jsonMap.put(PROPERTY_USER_COUNT, count); } catch (QueryException | WikiManagerException e) { logWarning("Error getting users count", e); } return jsonMap; }
private List<String> getDocumentsWithTag(String tag) throws QueryException { String query = "select doc.fullName from XWikiDocument as doc, BaseObject as obj, DBStringListProperty as prop " + "where obj.name=doc.fullName and obj.className='XWiki.TagClass' and obj.id=prop.id.id " + "and prop.id.name='tags' and :tag in elements(prop.list) order by doc.name asc"; List<String> documentsWithTag = queryManager.createQuery(query, Query.HQL).bindValue("tag", tag).execute(); return documentsWithTag; } }
/** * Fetches the next 'page' of results from the database. */ private void fetchNextResults() { try { // We use basic pagination (absolute offset) because we don't expect the database to change too much while // the synchronization takes place. Also, the database is used as the reference store, meaning that we // update the Solr index to match the database, not the other way around. results = getQuery().setWiki(wiki).setOffset(offset).execute(); offset += LIMIT; } catch (QueryException e) { results = Collections.emptyList(); logger.error("Failed to query the database.", e); } }
/** * {@inheritDoc} * * @see EventStream#searchEvents(Query) */ public List<Event> searchEvents(Query query) throws QueryException { Query q = this.qm.createQuery("select event from ActivityEventImpl event " + query.getStatement(), query.getLanguage()); for (Map.Entry<String, Object> entry : query.getNamedParameters().entrySet()) { q.bindValue(entry.getKey(), entry.getValue()); } for (Map.Entry<Integer, Object> entry : query.getPositionalParameters().entrySet()) { q.bindValue(entry.getKey(), entry.getValue()); } List<ActivityEvent> events = q.execute(); return convertActivitiesToEvents(events); }
private List<String> runQuery(String queryString, String input, int resultsLimit) { String formattedInput = String.format(PhenotipsFamilyExport.INPUT_FORMAT, input); // Query patients Query query = null; List<String> queryResults = null; try { query = this.qm.createQuery(queryString, Query.XWQL); query.setLimit(resultsLimit); query.bindValue(PhenotipsFamilyExport.INPUT_PARAMETER, formattedInput); queryResults = query.execute(); } catch (QueryException e) { this.logger.error("Error while performing patiets query: [{}] ", e.getMessage()); return Collections.emptyList(); } return queryResults; }
@Override public List<String> getSpaces(String wiki) throws WikiStreamException { try { return this.queryManager.getNamedQuery("getSpaces").setWiki(wiki).execute(); } catch (QueryException e) { throw new WikiStreamException(String.format("Failed to get the list of spaces in wiki [%s]", wiki), e); } }
@Override public <T> List<T> execute() throws QueryException { return this.query.execute(); }
countQuery.setWiki(getWiki()); for (Map.Entry<Integer, Object> entry : getPositionalParameters().entrySet()) { countQuery.bindValue(entry.getKey(), entry.getValue()); countQuery.bindValue(entry.getKey(), entry.getValue()); countQuery.addFilter(filter); countQuery.addFilter(this.componentManager.<QueryFilter>getInstance(QueryFilter.class, "count")); List<Long> results = countQuery.execute(); result = results.get(0); } catch (Exception e) {
private long getLastUsedId() throws QueryException { this.logger.debug("getLastUsedId()"); long crtMaxID = 0; Query q = this.qm.createQuery("select family.identifier " + "from Document doc, " + " doc.object(PhenoTips.FamilyClass) as family " + "where family.identifier is not null " + "order by family.identifier desc", Query.XWQL).setLimit(1); List<Long> crtMaxIDList = q.execute(); if (crtMaxIDList.size() > 0 && crtMaxIDList.get(0) != null) { crtMaxID = crtMaxIDList.get(0); } crtMaxID = Math.max(crtMaxID, 0); return crtMaxID; }
query.setOffset(start); query.setLimit(nb); query.bindValues(values); String wikiPrefix = wiki + DefaultWatchListStore.WIKI_SPACE_SEP; try { query.setWiki(wiki); List<String> upDocsInWiki = query.execute();
@Override public List<Event> getRecentPersonalMessages(DocumentReference author, int limit, int offset) { List<Event> result = new ArrayList<Event>(); try { Query q = this.qm.createQuery( "where event.application = 'MessageStream' and event.type = 'personalMessage'" + " and event.user = :user order by event.date desc", Query.XWQL); q.bindValue("user", this.serializer.serialize(author)); q.setLimit(limit > 0 ? limit : 30).setOffset(offset >= 0 ? offset : 0); result = this.stream.searchEvents(q); } catch (QueryException ex) { LOG.warn("Failed to search personal messages: {}", ex.getMessage()); } return result; }
@Override public Query bindValue(int index, Object val) { this.query.bindValue(index, val); return this; }
query.bindValues(parameters); query.addFilter(Utils.getComponent(QueryFilter.class, UniqueDocumentFilter.HINT)); if (!includeHiddenDocuments) { query.addFilter(Utils.getComponent(QueryFilter.class, HiddenDocumentFilter.HINT)); results = query.execute(); } catch (QueryException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN,
query = queryManager.createQuery(select + whereClause + orderBy, Query.HQL).setLimit(LIMIT); countQuery = queryManager.createQuery(whereClause, Query.HQL).addFilter(countFilter); query.bindValue("space", this.localEntityReferenceSerializer.serialize(spaceReference)); if (documentReference != null) { query.bindValue("name", documentReference.getName()); for (Map.Entry<String, Object> parameter : query.getNamedParameters().entrySet()) { countQuery.bindValue(parameter.getKey(), parameter.getValue());
/** * Get all tags within the wiki. * * @param context XWiki context. * @return list of tags (alphabetical order). * @throws com.xpn.xwiki.XWikiException if search query fails (possible failures: DB access problems, etc). */ public static List<String> getAllTags(XWikiContext context) throws XWikiException { List<String> results; String hql = "select distinct elements(prop.list) from XWikiDocument as doc, BaseObject as obj, " + "DBStringListProperty as prop where obj.name=doc.fullName and obj.className='XWiki.TagClass' and " + "obj.id=prop.id.id and prop.id.name='tags'"; try { Query query = context.getWiki().getStore().getQueryManager().createQuery(hql, Query.HQL); query.addFilter(Utils.<QueryFilter> getComponent(QueryFilter.class, HiddenDocumentFilter.HINT)); results = query.execute(); } catch (QueryException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, String.format("Failed to get all tags", hql), e); } Collections.sort(results, String.CASE_INSENSITIVE_ORDER); return results; }
@Override public Query setWiki(String wiki) { this.query.setWiki(wiki); return this; }