JDBCCertRecordStoreConnection implements CertRecordStoreConnection { RuntimeException sqlError(SQLException ex, String caller) { String sqlState = ex.getSQLState(); int code = ResourceException.INTERNAL_SERVER_ERROR; String msg; if (ex instanceof SQLTimeoutException) { code = ResourceException.SERVICE_UNAVAILABLE; msg = "Statement cancelled due to timeout"; } else { msg = ex.getMessage() + ", state: " + sqlState + ", code: " + ex.getErrorCode(); } LOGGER.error("SQLError: {}", msg); return new ResourceException(code, msg); } JDBCCertRecordStoreConnection(Connection con); @Override void setOperationTimeout(int queryTimeout); @Override void close(); @Override X509CertRecord getX509CertRecord(String provider, String instanceId, String service); @Override boolean updateX509CertRecord(X509CertRecord certRecord); @Override boolean insertX509CertRecord(X509CertRecord certRecord); @Override boolean deleteX509CertRecord(String provider, String instanceId, String service); @Override int deleteExpiredX509CertRecords(int expiryTimeMins); @Override List<X509CertRecord> updateUnrefreshedCertificatesNotificationTimestamp(String lastNotifiedServer,
                                                                      long lastNotifiedTime,
                                                                      String provider); static final String DB_COLUMN_INSTANCE_ID; static final String DB_COLUMN_INSTANCE_PROVIDER; static final String DB_COLUMN_SERVICE; static final String DB_COLUMN_CURRENT_IP; static final String DB_COLUMN_CURRENT_SERIAL; static final String DB_COLUMN_CURRENT_TIME; static final String DB_COLUMN_PREV_IP; static final String DB_COLUMN_PREV_SERIAL; static final String DB_COLUMN_PREV_TIME; static final String DB_COLUMN_CLIENT_CERT; static final String DB_COLUMN_LAST_NOTIFIED_TIME; static final String DB_COLUMN_LAST_NOTIFIED_SERVER; static final String DB_COLUMN_EXPIRY_TIME; static final String DB_COLUMN_HOSTNAME; }
@Test public void testSqlError() throws SQLException { JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn); SQLException ex = new SQLException("sql-reason", "08S01", 9999); ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError"); assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode()); ex = new SQLException("sql-reason", "40001", 9999); rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError"); assertEquals(ResourceException.INTERNAL_SERVER_ERROR, rEx.getCode()); SQLTimeoutException tex = new SQLTimeoutException(); rEx = (ResourceException) jdbcConn.sqlError(tex, "sqlError"); assertEquals(ResourceException.SERVICE_UNAVAILABLE, rEx.getCode()); jdbcConn.close(); }