Updating the database service

Before we dive into the web client API and perform HTTP requests to another service, we need to update the database service API to fetch all the wiki pages data in one pass. This corresponds to the following SQL query to add to db-queries.properties:

  1. all-pages-data=select * from Pages

A new method is added to the WikiDatabaseService interface:

  1. @Fluent
  2. WikiDatabaseService fetchAllPagesData(Handler<AsyncResult<List<JsonObject>>> resultHandler);

The implementation in WikiDatabaseServiceImpl is the following:

  1. @Override
  2. public WikiDatabaseService fetchAllPagesData(Handler<AsyncResult<List<JsonObject>>> resultHandler) {
  3. dbClient.query(sqlQueries.get(SqlQuery.ALL_PAGES_DATA), queryResult -> {
  4. if (queryResult.succeeded()) {
  5. resultHandler.handle(Future.succeededFuture(queryResult.result().getRows()));
  6. } else {
  7. LOGGER.error("Database query error", queryResult.cause());
  8. resultHandler.handle(Future.failedFuture(queryResult.cause()));
  9. }
  10. });
  11. return this;
  12. }