@Override public Query createQuery(String statement, String language) throws QueryException { if (hasLanguage(language)) { return new DefaultQuery(statement, language, getQueryExecutorManager()); } else { throw new QueryException("Language [" + language + "] is not supported", null, null); } }
@Override public <T> List<T> execute(Query query) throws QueryException { if (query instanceof SecureQuery) { SecureQuery secureQuery = (SecureQuery) query; // Force checking current author rights secureQuery.checkCurrentAuthor(true); } else if (!this.authorization.hasAccess(Right.PROGRAM)) { throw new QueryException("Unsecure query require programming right", query, null); } return this.defaultQueryExecutorManager.execute(query); }
@Override public <T> List<T> execute(Query query) throws QueryException { if (query.isNamed()) { return this.namedQueryExecutorProvider.get().execute(query); } else { try { return this.componentManagerProvider.get() .<QueryExecutor>getInstance(QueryExecutor.class, query.getLanguage()).execute(query); } catch (ComponentLookupException e) { throw new QueryException("Fail to lookup query executor", query, e); } } }
/** * For a given label and its corresponding id value (fields on {@code LabeledIdentifierClass} objects), query * patient documents. * * @param label the name of the label * @param id the id value for the label * @return an empty list if no patients have the label identifier and its corresponding id value, else a list of * patient internal identifiers * @throws QueryException if there is any error during querying */ private List<String> queryPatientsByLabelAndEid(String label, String id) throws QueryException { Query q = null; try { q = this.qm.createQuery( "select doc.name from Document doc, doc.object(PhenoTips.LabeledIdentifierClass) obj " + "where obj.label = :label and obj.value = :value", Query.XWQL); q.bindValue(KEY_LABEL, label); q.bindValue(KEY_VALUE, id); return q.execute(); } catch (QueryException ex) { this.logger.warn("Failed to query patient documents with label [{}] and corresponding external ID [{}]: {}", label, id, ex.getMessage(), ex); throw new QueryException(ex.getMessage(), q, ex); } }
/** * {@inheritDoc} */ public <T> List<T> execute(final Query query) throws QueryException { String olddatabase = getContext().getDatabase(); try { if (query.getWiki() != null) { getContext().setDatabase(query.getWiki()); } return getStore().executeRead(getContext(), true, new HibernateCallback<List<T>>() { @SuppressWarnings("unchecked") public List<T> doInHibernate(Session session) { org.hibernate.Query hquery = createHibernateQuery(session, query); populateParameters(hquery, query); return hquery.list(); } }); } catch (XWikiException e) { throw new QueryException("Exception while execute query", query, e); } finally { getContext().setDatabase(olddatabase); } }