Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plain JDBC ApplicationErrorDao implementation #316

Merged

Conversation

sleberknight
Copy link
Member

@sleberknight sleberknight commented Nov 13, 2023

  • Add JdbcApplicationErrorDao, a plain JDBC implementation of ApplicationErrorDao
  • Since the logic to map from a ResultSet is identical for the JDBC and JDBI implementations, move that logic from the Jdbi3ApplicationErrorRowMapper into ApplicationErrorJdbc in a new method 'mapFrom(ResultSet)'. Also, fix how the port is set, using rs.getInt instead of intValueOrNull, since the port field in ApplicationError is an int, not Integer
  • Add new constructor accepting only a Throwable to ApplicationErrorJdbc.ApplicationErrorJdbcException
  • Add a helper method to ApplicationErrorJdbc for the JDBC implementation, nextOrThrow
  • Add abstract base test class, AbstractJdbcApplicationErrorDaoTest, and two subclasses for testing against H2 and Postgres. The base test class uses transaction rollback so that tests execute in a transaction but are never committed.
  • Make sure to shut down the in-memory H2 database in both H2Jdbi3ApplicationErrorDaoTest and H2JdbcApplicationErrorDaoTest. Otherwise, if the H2 JDBI test runs after the JDBC one, the tests fail because they expect the database to be empty. By shutting the in-memory database down, we ensure the tests are completely isolated.
  • Add TestHelpers test utility with one method, shutdownH2Database, to shut down an H2 database

Misc:

  • Remove two redundant warning suppression annotations from ErrorContextUtilitiesTest

Closes #248

* Add JdbcApplicationErrorDao, a plain JDBC implementation of
  ApplicationErrorDao
* Since the logic to map from a ResultSet is identical for the
  JDBC and JDBI implementations, move that logic from the
  Jdbi3ApplicationErrorRowMapper into ApplicationErrorJdbc in
  a new method 'mapFrom(ResultSet)'. Also, fix how the port
  is set, using rs.getInt instead of intValueOrNull, since
  the port field in ApplicationError is an int, not Integer
* Add new constructor accepting only a Throwable to
  ApplicationErrorJdbc.ApplicationErrorJdbcException
* Add several new helper methods to ApplicationErrorJdbc
  for the JDBC implementation, nextOrThrow and shutdownH2Database
* Add abstract base test class, AbstractJdbcApplicationErrorDaoTest,
  and two subclasses for testing against H2 and Postgres
* Make sure to shut down the in-memory H2 database in both
  H2Jdbi3ApplicationErrorDaoTest and H2JdbcApplicationErrorDaoTest.
  Otherwise, if the H2 JDBI test runs after the JDBC one, the
  tests fail because they expect the database to be empty.
  By shutting the in-memory database down, we ensure the tests
  are completely isolated.

Misc:

* Remove two redundant warning suppression annotations from
  ErrorContextUtilitiesTest

Closes #248
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

84.2% 84.2% Coverage
0.0% 0.0% Duplication

@sleberknight sleberknight merged commit 7f52359 into master Nov 18, 2023
6 checks passed
@sleberknight sleberknight deleted the 248-add-plain-JDBC-implementation-of-ApplicationErroDao branch November 18, 2023 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add plain JDBC ApplicationErrorDao implementation
3 participants