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 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 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; }
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; }
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; }
public boolean runPriceQuery() 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\n" + "\t<print>The open price of the security \"{$sec/s:Name/text()}\" is {$sec/s:Price/s:PriceToday/s:Open/text()} dollars</print>\n"; XQPreparedExpression xqpe = xqc.prepareExpression(query); xqpe.bindString(new QName("sym"), "IBM", null); //IBM; VFINX; PTTAX XQResultSequence xqs = xqpe.executeQuery(); boolean found = false; while (xqs.next()) { System.out.println(xqs.getItemAsString(null)); found = true; } return found; }
public boolean runPriceQuery(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\n" + "\t<print>The open price of the security \"{$sec/s:Name/text()}\" is {$sec/s:Price/s:PriceToday/s:Open/text()} dollars</print>\n"; XQPreparedExpression xqpe = xqc.prepareExpression(query); xqpe.bindString(new QName("sym"), symbol, null); //IBM; VFINX; PTTAX XQResultSequence xqs = xqpe.executeQuery(); boolean found = false; while (xqs.next()) { System.out.println(xqs.getItemAsString(null)); found = true; } return found; }
@Override public String readDocument(String uri) throws XQException { String query = "declare namespace bgdb=\"http://bagridb.com/bdb\";\n" + "declare variable $uri external;\n" + "let $doc := bgdb:get-document-content($uri)\n" + "return $doc\n"; XQPreparedExpression xqpe = xqConn.prepareExpression(query); xqpe.bindString(new QName("uri"), uri, xqConn.createAtomicType(XQItemType.XQBASETYPE_ANYURI)); XQResultSequence xqs = xqpe.executeQuery(); String result = null; if (xqs.next()) { result = xqs.getItemAsString(null); } return result; }