@Override
public ResultSet query( String repository,
String workspace,
String text,
String lang ) throws RemoteException {
ResultSet rs = new ResultSet();
try {
Session session = connector().find(repository).session(workspace);
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(text, lang);
QueryResult qr = q.execute();
rs.setColumnNames(qr.getColumnNames());
ArrayList<String[]> rows = new ArrayList<>();
RowIterator it = qr.getRows();
while (it.hasNext()) {
Row row = it.nextRow();
String[] list = new String[qr.getColumnNames().length];
for (int i = 0; i < qr.getColumnNames().length; i++) {
Value v = row.getValue(qr.getColumnNames()[i]);
list[i] = v != null ? v.getString() : "null";
}
rows.add(list);
}
rs.setRows(rows);
logger.debug("Query result: " + rs.getRows().size());
return rs;
} catch (Exception e) {
throw new RemoteException(e.getMessage());
}
}