@Override public String queryDocumentByUri(String uri) throws XQException { String query = "for $doc in fn:doc(\"" + uri + "\")\n" + "return $doc\n"; XQExpression xqe = xqConn.createExpression(); XQResultSequence xqs = xqe.executeQuery(query); String result = null; if (xqs.next()) { result = xqs.getItemAsString(null); } return result; }
private String[] extractResult(XQResultSequence sequence, Properties props) throws BagriException { try { List<String> buff = new ArrayList<>(); if (sequence.first()) { do { buff.add(sequence.getItemAsString(props)); } while (sequence.next()); } return buff.toArray(new String[buff.size()]); } catch (Exception ex) { logger.error("extractResult.error", ex); throw new BagriException(ex, BagriException.ecQuery); } }
@Override public List<Node> mapResults(XQResultSequence result) { List<Node> results = new ArrayList<Node>(); try { while(result.next()) { XQItemType type = result.getItemType(); if(isNodeType(type)) { Node n = result.getNode(); results.add(n); } } } catch (Exception e) { throw new MessagingException("Caught Exception while mapping the result sequence to string",e); } return results; }
List list = new ArrayList(); while (result.next()) { Object itemValue = getItemValue(result.getItem()); if (itemValue instanceof Document) { itemValue = DOMUtils.cloneNode(document, ((Document) itemValue).getDocumentElement()); } else if (XPathConstants.NODE.equals(type)) { XQItem item = null; if (result.count() > 0) { result.first(); if (result.isOnItem()) { item = result.getItem(); resultValue = result.getSequenceAsString(new Properties()); } else if (XPathConstants.NUMBER.equals(type)) { resultValue = result.getSequenceAsString(new Properties()); resultValue = Integer.parseInt((String) resultValue); } else if (XPathConstants.BOOLEAN.equals(type)) { resultValue = result.getSequenceAsString(new Properties()); resultValue = Boolean.parseBoolean((String) resultValue);
public boolean searchSecQuery() throws XQException { String query = "declare default element namespace \"http://tpox-benchmark.com/security\";\n" + "for $sec in fn:collection(\"CLN_Security\")/s:Security\n" + "where $sec[SecurityInformation/*/Sector = 'Technology' and PE[. >= xs:decimal('25') and . < xs:decimal('28.0')] and Yield > xs:decimal('0')]\n" + "return <Security>\n" + "\t{$sec/Symbol}\n" + "\t{$sec/Name}\n" + "\t{$sec/SecurityType}\n" + "\t{$sec/SecurityInformation//Sector}\n" + "\t{$sec/PE}\n" + "\t{$sec/Yield}\n" + "</Security>"; XQExpression xqe = xqc.createExpression(); XQResultSequence xqs = xqe.executeQuery(query); int cnt = 0; while (xqs.next()) { cnt++; } System.out.println("Got " + cnt + " results"); return cnt > 0; }
private void doZap(Source source, Result result, Object... params) { XQResultSequence seq = null; try { XQPreparedExpression expression = resource(params); expression.bindDocument(XQConstants.CONTEXT_ITEM, source, null); bindExpressionContext(expression, staticParams); bindExpressionContext(expression, resourceParameters(params)); seq = expression.executeQuery(); seq.writeSequenceToResult(result); } catch (Exception e) { throw new RuntimeException("XQuery processing failed", e); } finally { if (seq != null && !seq.isClosed()) { try { seq.close(); } catch (XQException e) { LOG.trace("XQLTransmogrifier didn't return a value.", e); } } } }
@Override public boolean isClosed() { return parent.isClosed() || super.isClosed(); }
@Override public List<Boolean> mapResults(XQResultSequence result) { List<Boolean> results = new ArrayList<Boolean>(); try { //check for boolean or string type and convert it accordingly, if a node then get it's text //content and convert to boolean while(result.next()) { XQItemType type = result.getItemType(); Boolean value = convertToBoolean(type, result); if(value == null && isNodeType(type)) { Node n = result.getNode(); value = Boolean.valueOf(transformNodeToString(n)); } results.add(value); } } catch (Exception e) { throw new MessagingException("Caught Exception while mapping the result sequence to string",e); } return results; }
public boolean searchSecQuery() throws XQException { String query = "declare default element namespace \"http://tpox-benchmark.com/security\";\n" + "for $sec in fn:collection(\"/{http://tpox-benchmark.com/security}Security\")/Security\n" + "where $sec[SecurityInformation/*/Sector = 'Technology' and PE[. >= xs:decimal('25') and . < xs:decimal('28.0')] and Yield > xs:decimal('0')]\n" + "return <Security>\n" + "\t{$sec/Symbol}\n" + "\t{$sec/Name}\n" + "\t{$sec/SecurityType}\n" + "\t{$sec/SecurityInformation//Sector}\n" + "\t{$sec/PE}\n" + "\t{$sec/Yield}\n" + "</Security>"; XQExpression xqe = xqc.createExpression(); XQResultSequence xqs = xqe.executeQuery(query); int cnt = 0; while (xqs.next()) { cnt++; } System.out.println("Got " + cnt + " results"); return cnt > 0; }
@Override public String queryDocumentFromCollection() throws XQException { String query = "for $doc in fn:collection()\n" + "return $doc\n"; XQExpression xqe = xqConn.createExpression(); XQResultSequence xqs = xqe.executeQuery(query); String result = null; if (xqs.next()) { result = xqs.getItemAsString(null); } return result; }
@Override public List<Number> mapResults(XQResultSequence result) { List<Number> results = new ArrayList<Number>(); try { while(result.next()) { XQItemType type = result.getItemType(); Number value = convertToNumber(type, result); if(value == null && isNodeType(type)) { Node n = result.getNode(); String strValue = transformNodeToString(n); if(StringUtils.hasText(strValue)) { if(strValue.indexOf('.') > 0) { value = Double.valueOf(strValue); } else { value = Long.valueOf(strValue); } } } results.add(value); } } catch (Exception e) { throw new MessagingException("Caught Exception while mapping the result sequence to string",e); } return results; }
@Override protected int execQuery(String query, Map<String, Parameter> params) throws XQException { XQPreparedExpression xqpe = getConnection().prepareExpression(query); bindParams(params, xqpe); XQResultSequence xqs = xqpe.executeQuery(); int cnt = 0; if (fetchSize > 0) { while (xqs.next() && cnt < fetchSize) { cnt++; } } else { while (xqs.next()) { cnt++; } } //xqs.close(); will be closed at next line xqpe.close(); return cnt; }
public boolean runSecQuery() throws XQException { String query = "declare namespace s=\"http://tpox-benchmark.com/security\";\n" + "declare variable $sym external;\n" + "for $sec in fn:collection(\"/{http://tpox-benchmark.com/security}Security\")/s:Security\n" + "where $sec/s:Symbol=$sym\n" + //'IBM'\n" + "return $sec\n"; XQPreparedExpression xqpe = xqc.prepareExpression(query); xqpe.bindString(new QName("sym"), "IBM", null); XQResultSequence xqs = xqpe.executeQuery(); boolean found = false; while (xqs.next()) { System.out.println(xqs.getItemAsString(null)); found = true; } return found; }
List<String> results = new ArrayList<String>(); try { while(result.next()) { XQItemType type = result.getItemType(); String value = convertToString(type, result); if(value == null) { if(boolValue == null) { if(isNodeType(type)) { Node n = result.getNode(); value = transformNodeToString(n);
while (xqs.next()) {
public boolean runSecQuery(String symbol) throws XQException { String query = "declare namespace s=\"http://tpox-benchmark.com/security\";\n" + "declare variable $sym external;\n" + "for $sec in fn:collection(\"CLN_Security\")/s:Security\n" + "where $sec/s:Symbol=$sym\n" + "return $sec\n"; XQPreparedExpression xqpe = xqc.prepareExpression(query); xqpe.bindString(new QName("sym"), symbol, null); XQResultSequence xqs = xqpe.executeQuery(); boolean found = false; while (xqs.next()) { System.out.println(xqs.getItemAsString(null)); found = true; } return found; }
while (xqs.next()) { cnt++;