use of org.jumpmind.symmetric.web.rest.model.QueryResults in project symmetric-ds by JumpMind.
the class RestService method queryNodeImpl.
private QueryResults queryNodeImpl(ISymmetricEngine engine, String sql, boolean isQuery) {
QueryResults results = new QueryResults();
org.jumpmind.symmetric.web.rest.model.Row xmlRow = null;
org.jumpmind.symmetric.web.rest.model.Column xmlColumn = null;
ISqlTemplate sqlTemplate = engine.getSqlTemplate();
try {
if (!isQuery) {
int updates = sqlTemplate.update(sql);
results.setNbrResults(updates);
return results;
}
List<Row> rows = sqlTemplate.query(sql);
int nbrRows = 0;
for (Row row : rows) {
xmlRow = new org.jumpmind.symmetric.web.rest.model.Row();
Iterator<Map.Entry<String, Object>> itr = row.entrySet().iterator();
int columnOrdinal = 0;
while (itr.hasNext()) {
xmlColumn = new org.jumpmind.symmetric.web.rest.model.Column();
xmlColumn.setOrdinal(++columnOrdinal);
Map.Entry<String, Object> pair = (Map.Entry<String, Object>) itr.next();
xmlColumn.setName(pair.getKey());
if (pair.getValue() != null) {
xmlColumn.setValue(pair.getValue().toString());
}
xmlRow.getColumnData().add(xmlColumn);
}
xmlRow.setRowNum(++nbrRows);
results.getResults().add(xmlRow);
}
results.setNbrResults(nbrRows);
} catch (Exception ex) {
log.error("Exception while executing sql.", ex);
throw new NotAllowedException("Error while executing sql %s. Error is %s", sql, ex.getCause().getMessage());
}
return results;
}
Aggregations