use of annis.sqlgen.ResultSetTypedIterator in project ANNIS by korpling.
the class QueryDaoImpl method find.
@Transactional(readOnly = true)
@Override
public boolean find(final QueryData queryData, final OutputStream out) {
prepareTransaction(queryData);
Boolean finished = getJdbcTemplate().execute(new ConnectionCallback<Boolean>() {
@Override
public Boolean doInConnection(Connection con) throws SQLException, DataAccessException {
try (Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
String sql = findSqlGenerator.toSql(queryData);
PrintWriter w;
try (ResultSet rs = stmt.executeQuery(sql)) {
w = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
ResultSetTypedIterator<Match> itMatches = new ResultSetTypedIterator<>(rs, findSqlGenerator);
int i = 1;
while (itMatches.hasNext()) {
// write single match to output stream
Match m = itMatches.next();
w.print(m.toString());
w.print("\n");
// flush after every 10th item
if (i % 10 == 0) {
w.flush();
}
i++;
}
// end for each match
}
w.flush();
return true;
} catch (UnsupportedEncodingException ex) {
log.error("Your system is not able to handle UTF-8 but ANNIS really needs this charset", ex);
}
return false;
}
});
return finished;
}
Aggregations