protected ResultCursor<XQItemAccessor> query(String query, Map<String, Object> params, Properties props) throws Exception { if (props == null) { props = getDocumentProperties(); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_CONTENT)); } ResultCursor<XQItemAccessor> result = getQueryManagement().executeQuery(query, params, props); assertNotNull(result); return result; }
@Override public ResultCursor<String> call() throws Exception { //((SchemaRepositoryImpl) repo).getXQProcessor(clientId); checkPermission(Permission.Value.read); return queryMgr.getDocumentUris(query, params, context); }
@Override public void cancelExecution() throws XQException { try { getQueryManagement().cancelExecution(); } catch (BagriException ex) { throw getXQException(ex); } }
@Override public Collection<String> prepareXQuery(String query, XQStaticContext ctx) throws XQException { QueryManagement qMgr = getQueryManagement(); Collection<String> names = qMgr.prepareQuery(query); if (names != null) { return names; } return super.prepareXQuery(query, ctx); }
@Override public boolean isQueryReadOnly(final String query, Properties props) throws XQException { boolean result = super.isQueryReadOnly(query); if (result) { int qKey = getQueryManagement().getQueryKey(query); XQueryExpression xqExp; try { xqExp = getXQuery(qKey, query, props); } catch (XPathException xpe) { logger.error("isQueryReadOnly.error: ", xpe); throw convertXPathException(xpe); } result = !isUpdatingExpression(xqExp.getExpression()); } return result; }
@Override public String queryDocumentByUri(String uri) throws Exception { String query = "for $doc in fn:doc(\"" + uri + "\")\n" + "return $doc\n"; try (ResultCursor<String> cursor = xRepo.getQueryManagement().executeQuery(query, null, new Properties())) { String result = null; if (!cursor.isEmpty()) { result = cursor.iterator().next(); // proc.convertToString(itr.next(), null); } return result; } }
@POST @Path("/uris") @ApiOperation(value = "getURIs: return URIs of Documents conforming to the specified XQuery") public Response getURIs(final QueryParams params) { logger.debug("getURIs; got query: {}", params); QueryManagement queryMgr = getQueryManager(); try { ResultCursor<String> cursor = queryMgr.getDocumentUris(params.query, params.params, params.props); Collection<String> uris = new ArrayList<>(); for (String uri: cursor) { uris.add(uri); } logger.trace("getURIs; returning URIs: {}", uris); return Response.ok(uris).build(); } catch (Exception ex) { logger.error("getURIs.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); //return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } }
public List<String> runQuery(String query) throws Exception { Properties props = new Properties(); List<String> result = new ArrayList<String>(); Properties outProps = getOutputProperties(props); try (ResultCursor<XQItemAccessor> cursor = xRepo.getQueryManagement().executeQuery(query, null, props)) { for (XQItemAccessor item: cursor) { result.add(proc.convertToString(item, outProps)); } } return result; }
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { String query = arguments[0].head().getStringValue(); MapItem item = (MapItem) arguments[1].head(); Map<String, Object> params = itemToMap(item); Properties props = null; if (arguments.length > 2) { props = sequence2Properties(arguments[2]); } try { ResultCursor<String> uris = qm.getDocumentUris(query, params, props); ArrayList<AtomicValue> list = new ArrayList<>(); //uris.size()); for (String uri: uris) { list.add(new StringValue(uri)); } return new AtomicArray(list); } catch (BagriException ex) { throw new XPathException(ex); } }
@Override public String queryDocumentFromCollection() throws Exception { String query = "for $doc in fn:collection()\n" + "return $doc\n"; try (ResultCursor<String> cursor = xRepo.getQueryManagement().executeQuery(query, null, new Properties())) { String result = null; if (!cursor.isEmpty()) { result = cursor.iterator().next(); // proc.convertToString(itr.next(), null); } return result; } }
public void run() { QueryManagement queryMgr = getQueryManager(); try (ResultCursor<XQItemAccessor> cursor = queryMgr.executeQuery(params.query, params.params, params.props)) { int idx = 0; for (XQItemAccessor item: cursor) { if (idx > 0) { output.write(splitter); } String chunk = item.getItemAsString(null); logger.trace("postQuery; idx: {}; chunk: {}", idx, chunk); output.write(chunk); idx++; } } catch (Exception ex) { // XDMException, IOException. handle it somehow ? logger.error("postQuery.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); } finally { try { output.close(); } catch (IOException ex) { // } } } }.start();
logger.trace("apply; going to execute query: {}\n with params: {} and props: {}", query, params, props); try { cursor = repo.getQueryManagement().executeQuery(query, params, props); empty = cursor.isEmpty(); } catch (BagriException ex) {
@Override public ResultCursor executeXQuery(String query, XQStaticContext ctx) throws XQException { Properties props = collectProperties(ctx); props = ensureProperty(props, pn_query_command, "false"); try { Map<String, Object> params = getXQItemParams(); return getQueryManagement().executeQuery(query, params, props); } catch (XPathException | BagriException ex) { throw getXQException(ex); } }
try { if (useXDM) { ResultCursor<XQItemAccessor> cursor = queryMgr.executeQuery(query, params, props); result = extractResult(cursor, props); cursor.close();
props = ensureProperty(props, pn_query_command, "true"); QueryManagement qMgr = getQueryManagement(); ResultCursorBase cursor = (ResultCursorBase) qMgr.executeQuery(command, params, props); result = new Integer(1);
try { if (useXDM) { ResultCursor<XQItemAccessor> cursor = queryMgr.executeQuery(query, null, props); result = extractResult(cursor, props); cursor.close();