args.addValue("paging_offset", request.getPagingRequest().getFirstItem());
args.addValue("paging_fetch", request.getPagingRequest().getPagingSize());
String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args) };
final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
ConfigDocumentExtractor configDocumentExtractor = new ConfigDocumentExtractor();
if (request.equals(PagingRequest.ALL)) {
List<ConfigDocument> queryResult = namedJdbc.query(sql[0], args, configDocumentExtractor);
for (ConfigDocument configDocument : queryResult) {
if (request.getType().isInstance(configDocument.getConfig().getValue())) {
result.getDocuments().add(configDocument);
}
}
result.setPaging(Paging.of(request.getPagingRequest(), result.getDocuments()));
} else {
final int count = namedJdbc.queryForObject(sql[1], args, Integer.class);
result.setPaging(Paging.of(request.getPagingRequest(), count));
if (count > 0 && request.getPagingRequest().equals(PagingRequest.NONE) == false) {
List<ConfigDocument> queryResult = namedJdbc.query(sql[0], args, configDocumentExtractor);
for (ConfigDocument configDocument : queryResult) {
if (request.getType().isInstance(configDocument.getConfig().getValue())) {
result.getDocuments().add(configDocument);
}
}