protected Collection<String> fetchQueryResults(String query, Map<String, Object> params, Properties props) throws Exception { List<String> result = new ArrayList<>(); try (ResultCursor<XQItemAccessor> cursor = query(query, params, props)) { for (XQItemAccessor item: cursor) { result.add(item.getAtomicValue()); } } return result; }
if (command.equals(cmd_store_document)) { XQItemAccessor item = getBoundItem(params, "uri"); String uri = item.getAtomicValue(); item = getBoundItem(params, "doc"); String xml = item.getItemAsString(null); } else if (command.equals(cmd_remove_document)) { XQItemAccessor item = getBoundItem(params, "uri"); String uri = item.getAtomicValue(); dMgr.removeDocument(uri, null); return Collections.emptyIterator();
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();
protected void checkCursorResult(ResultCursor<XQItemAccessor> results, String expected) throws Exception { try { Iterator<XQItemAccessor> iter = results.iterator(); assertTrue(iter.hasNext()); if (expected == null) { assertNotNull(iter.next().getObject()); } else { Properties props = new Properties(); props.setProperty("method", "text"); XQItem item = (XQItem) iter.next(); assertEquals(expected, item.getItemAsString(props)); } assertFalse(iter.hasNext()); } finally { results.close(); } }
@Override public XQSequenceType getStaticVariableType(QName name) throws XQException { checkState(ex_expression_closed); if (name == null) { throw new XQException("name is null"); } if (getVarNames().contains(name)) { // where can I get var type?? XQItemType type; XQItemAccessor acc = (XQItemAccessor) getBindings().get(name); if (acc != null) { type = acc.getItemType(); } else { type = connection.createItemType(); } return new BagriXQSequenceType(type, OCC_ZERO_OR_MORE); } throw new XQException("Static variable [" + name + "] does not exist"); }
private Collection<String> toCollection(ResultCursor<XQItemAccessor> cursor) throws BagriException { if (cursor == null) { return null; } try { List<String> result = new ArrayList<>(); for (XQItemAccessor item: cursor) { result.add(item.getAtomicValue()); } return result; } catch (XQException ex) { throw new BagriException(ex, BagriException.ecQuery); } }
DocumentKey fraKey = factory.newDocumentKey(uri, revision, version); try { String fragment = item.getAtomicValue(); String fUri = baseUri + ".r" + revision + ".v" + version + ext; Document doc = loadDocument(fraKey, fUri, fragment, srcFormat, createdAt, createdBy, txStart, collections, props);