@Test void testIsDuplicateKey_isDuplicateKey_usingSetDuplicateKeyCodes() { List<Integer> errorCodes = new ArrayList<>(); errorCodes.add(-104); SQLErrorCodesResolver sqlErrorCodesResolver = new SQLErrorCodesResolver(errorCodes); SQLException sqlException = new SQLException("test", "error", errorCodes.get(0)); boolean isDuplicateKey = sqlErrorCodesResolver.isDuplicateKeyViolation(new PersistenceException("error", sqlException)); assertTrue(isDuplicateKey); }
@Override public boolean isDuplicateKeyViolation(Exception exception) { return causeIsEntityExistsException(exception) || findException(exception, SQLException.class) .map(sqlException -> isDuplicateKeyCode(sqlException, duplicateKeyCodes)).orElse(false); }
SQLErrorCodesResolver implements PersistenceExceptionResolver { @Override public boolean isDuplicateKeyViolation(Exception exception) { return causeIsEntityExistsException(exception) || findException(exception, SQLException.class) .map(sqlException -> isDuplicateKeyCode(sqlException, duplicateKeyCodes)).orElse(false); } }
SQLErrorCodesResolver implements PersistenceExceptionResolver { @Override public boolean isDuplicateKeyViolation(Exception exception) { return causeIsEntityExistsException(exception) || findException(exception, SQLException.class) .map(sqlException -> isDuplicateKeyCode(sqlException, duplicateKeyCodes)).orElse(false); } SQLErrorCodesResolver(List<Integer> duplicateKeyCodes);  SQLErrorCodesResolver(DataSource dataSource);  SQLErrorCodesResolver(String databaseProductName);  SQLErrorCodesResolver(Properties properties, String databaseProductName);  SQLErrorCodesResolver(Properties properties, DataSource dataSource); }
SQLErrorCodesResolver implements PersistenceExceptionResolver { @Override public boolean isDuplicateKeyViolation(Exception exception) { return causeIsEntityExistsException(exception) || findException(exception, SQLException.class) .map(sqlException -> isDuplicateKeyCode(sqlException, duplicateKeyCodes)).orElse(false); } SQLErrorCodesResolver(List<Integer> duplicateKeyCodes);  SQLErrorCodesResolver(DataSource dataSource);  SQLErrorCodesResolver(String databaseProductName);  SQLErrorCodesResolver(Properties properties, String databaseProductName);  SQLErrorCodesResolver(Properties properties, DataSource dataSource); @Override boolean isDuplicateKeyViolation(Exception exception); }
SQLErrorCodesResolver implements PersistenceExceptionResolver { @Override public boolean isDuplicateKeyViolation(Exception exception) { return causeIsEntityExistsException(exception) || findException(exception, SQLException.class) .map(sqlException -> isDuplicateKeyCode(sqlException, duplicateKeyCodes)).orElse(false); } SQLErrorCodesResolver(List<Integer> duplicateKeyCodes);  SQLErrorCodesResolver(DataSource dataSource);  SQLErrorCodesResolver(String databaseProductName);  SQLErrorCodesResolver(Properties properties, String databaseProductName);  SQLErrorCodesResolver(Properties properties, DataSource dataSource); @Override boolean isDuplicateKeyViolation(Exception exception);  }