diff --git a/src/main/java/org/kiwiproject/dropwizard/error/dao/jdk/JdbcApplicationErrorDao.java b/src/main/java/org/kiwiproject/dropwizard/error/dao/jdk/JdbcApplicationErrorDao.java index 27c318d..3c158bd 100644 --- a/src/main/java/org/kiwiproject/dropwizard/error/dao/jdk/JdbcApplicationErrorDao.java +++ b/src/main/java/org/kiwiproject/dropwizard/error/dao/jdk/JdbcApplicationErrorDao.java @@ -11,11 +11,10 @@ import org.kiwiproject.dropwizard.error.dao.ApplicationErrorDao; import org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc; -import org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc.ApplicationErrorJdbcException; import org.kiwiproject.dropwizard.error.dao.ApplicationErrorStatus; import org.kiwiproject.dropwizard.error.model.ApplicationError; +import org.kiwiproject.jdbc.UncheckedSQLException; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -27,6 +26,8 @@ import java.util.List; import java.util.Optional; +import javax.sql.DataSource; + /** * Implementation of {@link ApplicationErrorDao} that uses plain JDBC, and therefore does not require * any additional dependencies outside the JDK. It might be useful when an application is using a @@ -58,7 +59,7 @@ public Optional getById(long id) { return Optional.empty(); } } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -82,7 +83,7 @@ private long countUsingQuery(String sql) { nextOrThrow(rs); return rs.getLong(1); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -98,7 +99,7 @@ public long countUnresolvedErrorsSince(ZonedDateTime since) { return rs.getLong(1); } } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -117,7 +118,7 @@ public long countUnresolvedErrorsOnHostSince(ZonedDateTime since, String hostNam return rs.getLong(1); } } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -130,7 +131,7 @@ public List getAllErrors(int pageNumber, int pageSize) { try (var conn = connection(); var stmt = conn.createStatement(); var rs = stmt.executeQuery(sql)) { return collectErrors(rs, pageSize); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -154,7 +155,7 @@ private List getErrors(boolean resolved, int pageNumber, int p ps.setBoolean(1, resolved); return collectErrors(ps, pageSize); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -171,7 +172,7 @@ public List getUnresolvedErrorsByDescription(String descriptio ps.setString(1, description); return collectErrors(ps, DEFAULT_PAGE_SIZE); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -185,7 +186,7 @@ public List getUnresolvedErrorsByDescriptionAndHost(String des ps.setString(2, hostName); return collectErrors(ps, DEFAULT_PAGE_SIZE); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -232,7 +233,7 @@ public long insertError(ApplicationError newError) { return generatedKeys.getLong(1); } } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -248,7 +249,7 @@ public void incrementCount(long id) { var count = ps.executeUpdate(); checkState(count == 1, "Unable to increment count. No ApplicationError found with id %s", id); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -277,7 +278,7 @@ public ApplicationError resolve(long id) { var count = ps.executeUpdate(); checkState(count == 1, "Unable to resolve. No ApplicationError found with id %s", id); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } return getById(id).orElseThrow(); @@ -290,7 +291,7 @@ public int resolveAllUnresolvedErrors() { try (var conn = connection(); var stmt = conn.createStatement()) { return stmt.executeUpdate(sql); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } @@ -311,7 +312,7 @@ private int deleteResolvedErrorsBeforeUsingQuery(String sql, ZonedDateTime expir ps.setTimestamp(1, timestampFromZonedDateTime(expirationDate)); return ps.executeUpdate(); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } } diff --git a/src/test/java/org/kiwiproject/dropwizard/error/util/TestHelpers.java b/src/test/java/org/kiwiproject/dropwizard/error/util/TestHelpers.java index b710886..e214786 100644 --- a/src/test/java/org/kiwiproject/dropwizard/error/util/TestHelpers.java +++ b/src/test/java/org/kiwiproject/dropwizard/error/util/TestHelpers.java @@ -6,16 +6,18 @@ import lombok.extern.slf4j.Slf4j; import org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc; import org.kiwiproject.dropwizard.error.dao.ApplicationErrorJdbc.ApplicationErrorJdbcException; +import org.kiwiproject.jdbc.UncheckedSQLException; import org.kiwiproject.test.jdbc.SimpleSingleConnectionDataSource; import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.MySQLContainer; import org.testcontainers.utility.DockerImageName; -import javax.sql.DataSource; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import javax.sql.DataSource; + @UtilityClass @Slf4j public class TestHelpers { @@ -58,7 +60,7 @@ public static void migrateDatabase(JdbcDatabaseContainer container, String mi try (var conn = DriverManager.getConnection(jdbcUrl, container.getUsername(), container.getPassword())) { ApplicationErrorJdbc.migrateDatabase(conn, migrationsFilename); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } LOG.info("Completed migrating {} container database using file {}", dockerImageName, migrationsFilename); @@ -84,7 +86,7 @@ public static void migrateDatabase(SimpleSingleConnectionDataSource dataSource, try { ApplicationErrorJdbc.migrateDatabase(dataSource.getConnection(), migrationsFilename); } catch (SQLException e) { - throw new ApplicationErrorJdbcException(e); + throw new UncheckedSQLException(e); } LOG.info("Completed migrating database using file {}", migrationsFilename); }