. . bonus points if you know the robot??™s name).
We already saw code like this when we initially discussed Spring JDBC, so it shouldn??™t be
anything new. We??™re using the values stored in the Config object this time though, so if you
wanted to connect to another RDBMS, it shouldn??™t require more than changing the properties
file appropriately.
Next up is the validateDatabase() method that we saw called earlier from the
DWikiContextListener class:
protected void validateDatabase() throws Exception {
log.trace("DatabaseWorker.validateDatabase() - Entry");
try {
log.trace("DatabaseWorker.validateDatabase() - Checking tables");
jdbcTemplate.queryForList(SQL_TABLE_ARTICLES_EXIST);
jdbcTemplate.queryForList(SQL_TABLE_ARTICLEHISTORY_EXIST);
jdbcTemplate.queryForList(SQL_TABLE_ARTICLECOMMENTS_EXIST);
} catch (Exception e) {
createTables();
}
log.trace("DatabaseWorker.validateDatabase() - Exit");
} // End validateDatabase().
So, here??™s the story: the application starts up, and DWikiContextListener fires. It calls
validateDatabase() here, which then tries to query each of the tables. If an exception is
thrown, we take that to mean the database hasn??™t been properly initialized (i.
Pages:
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436