use of org.exist.source.StringSource in project exist by eXist-db.
the class RpcConnection method queryPT.
private Map<String, Object> queryPT(final String xquery, final XmldbURI docUri, final String s_id, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
final Source source = new StringSource(xquery);
final Optional<String> sortBy = Optional.ofNullable(parameters.get(RpcAPI.SORT_EXPR)).map(Object::toString);
return withDb((broker, transaction) -> {
final long startTime = System.currentTimeMillis();
final NodeSet nodes;
if (docUri != null && s_id != null) {
nodes = this.<NodeSet>readDocument(broker, transaction, docUri).apply((document, broker1, transaction1) -> {
final Object[] docs = new Object[1];
docs[0] = docUri.toString();
parameters.put(RpcAPI.STATIC_DOCUMENTS, docs);
if (s_id.length() > 0) {
final NodeId nodeId = factory.getBrokerPool().getNodeFactory().createFromString(s_id);
final NodeProxy node = new NodeProxy(document, nodeId);
final NodeSet nodeSet = new ExtArrayNodeSet(1);
nodeSet.add(node);
return nodeSet;
} else {
return null;
}
});
} else {
nodes = null;
}
try {
final Map<String, Object> rpcResponse = this.<Map<String, Object>>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> queryResultToTypedRpcResponse(startTime, doQuery(broker, compiledQuery, nodes, parameters), sortBy));
return rpcResponse;
} catch (final XPathException e) {
throw new EXistException(e);
}
});
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class RpcConnection method queryP.
/**
* @deprecated Use {@link #queryPT(String, XmldbURI, String, Map)} instead.
* @param xpath the query to execute
* @param docUri the document to query
* @param s_id an id
* @param parameters map of options
* @return the result of the query
* @throws EXistException if an internal error occurs
* @throws PermissionDeniedException If the current user is not allowed to perform this action
*/
private Map<String, Object> queryP(final String xpath, final XmldbURI docUri, final String s_id, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
final Source source = new StringSource(xpath);
final Optional<String> sortBy = Optional.ofNullable(parameters.get(RpcAPI.SORT_EXPR)).map(Object::toString);
return withDb((broker, transaction) -> {
final long startTime = System.currentTimeMillis();
final NodeSet nodes;
if (docUri != null && s_id != null) {
nodes = this.<NodeSet>readDocument(broker, transaction, docUri).apply((document, broker1, transaction1) -> {
final Object[] docs = new Object[1];
docs[0] = docUri.toString();
parameters.put(RpcAPI.STATIC_DOCUMENTS, docs);
if (s_id.length() > 0) {
final NodeId nodeId = factory.getBrokerPool().getNodeFactory().createFromString(s_id);
final NodeProxy node = new NodeProxy(document, nodeId);
final NodeSet nodeSet = new ExtArrayNodeSet(1);
nodeSet.add(node);
return nodeSet;
} else {
return null;
}
});
} else {
nodes = null;
}
try {
final Map<String, Object> rpcResponse = this.<Map<String, Object>>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> queryResultToRpcResponse(startTime, doQuery(broker, compiledQuery, nodes, parameters), sortBy));
return rpcResponse;
} catch (final XPathException e) {
throw new EXistException(e);
}
});
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class RpcConnection method executeQuery.
@Override
public int executeQuery(final String xpath, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
return withDb((broker, transaction) -> {
final Source source = new StringSource(xpath);
final long startTime = System.currentTimeMillis();
try {
final QueryResult result = this.<QueryResult>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> doQuery(broker, compiledQuery, null, parameters));
if (result.hasErrors()) {
throw new EXistException(result.getException());
}
result.queryTime = System.currentTimeMillis() - startTime;
return factory.resultSets.add(result);
} catch (final XPathException e) {
throw new EXistException(e);
}
});
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class RpcConnection method summary.
public Map<String, Object> summary(final String xpath) throws EXistException, PermissionDeniedException {
final Source source = new StringSource(xpath);
return this.<Map<String, Object>>withDb((broker, transaction) -> {
final long startTime = System.currentTimeMillis();
final Map<String, Object> parameters = new HashMap<>();
try {
final QueryResult qr = this.<QueryResult>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> doQuery(broker, compiledQuery, null, parameters));
if (qr == null) {
return new HashMap<>();
}
if (qr.hasErrors()) {
throw qr.getException();
}
if (qr.result == null) {
return summaryToMap(qr.queryTime, null, null, null);
}
final Tuple2<java.util.Collection<NodeCount>, java.util.Collection<DoctypeCount>> summary = summarise(qr.result);
return summaryToMap(System.currentTimeMillis() - startTime, qr.result, summary._1, summary._2);
} catch (final XPathException e) {
throw new EXistException(e);
}
});
}
use of org.exist.source.StringSource in project exist by eXist-db.
the class RpcConnection method printDiagnostics.
@Override
public String printDiagnostics(final String query, final Map<String, Object> parameters) throws EXistException, PermissionDeniedException {
final Source source = new StringSource(query);
return withDb((broker, transaction) -> {
try {
return this.<String>compileQuery(broker, transaction, source, parameters).apply(compiledQuery -> {
final StringWriter writer = new StringWriter();
compiledQuery.dump(writer);
return writer.toString();
});
} catch (final XPathException e) {
throw new EXistException(e);
}
});
}
Aggregations