Newer
Older
labs / tiddlers / content / labs / lab07 / _Labs_07_Switch the Application to H2.md

The application is likely still using the JDBI DAOs. The database configuration for the JDBI DAOs is contained in the JdbiConnectionFactory class in the dao package.

  1. Open the JdbiConnectionFactory file.

  2. Uncomment the 3 lines of code that are currently commented out. These are the settings for H2.

  3. Comment out the 3 lines of code that are the settings for PostgreSQL.

  4. While were are here, let's examine this class a bit.

    • Both sets of settings have a JDBC URL. This is how we tell JDBC where to find the database.

    • The JDBC URL for H2 has a lot of options appended to it. These options put H2 into PostgreSQL compatibility mode. Remember earlier how we mentioned that a quirk of PostgreSQL is that it returns result sets that have lowercase column names? H2 (and most other DBMSs) uses uppercase column names in the result set. We don't want to have to rewrite all of the code to use uppercase column names, so we make H2 behave like PostgreSQL --- it will now use lowercase column names.

    • There is a bunch of code that refers to Hikari. Hikari is a JDBC connection pool. It can take a decent amount of time for an application to connect to a remote database --- enough time that the user is going to notice the system stutter each time a new connection needs to be made. Hikari solves that problem by creating a pool of reusable connections when the database is first accessed. It creates them all in parallel so that the user doesn't have to wait very long for this to happen.

      Once the pool is created the application can get connections from the pool instantaneously --- no more stutters.