@Test public void testGetVitalsLoincFromVuidSQLExceptionOnPreparedStatementClose() { try { when(mockResultSet.next()).thenReturn(false); Mockito.doThrow(new SQLException()).when(mockPreparedStatement).close(); @SuppressWarnings("unused") JLVMappedCode oMappedCode = testSubject.getVitalsLoincFromVuid("123"); fail("There should have been a TermLoadException thrown."); } catch (TermLoadException e) { try { verifyCloseMethodsCalled(); } catch (Exception e2) { System.out.println("An unexpected exception occurred. Error: " + e2.getMessage()); e2.printStackTrace(); fail("An unexpected exception occurred. Error: " + e2.getMessage()); } } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
public JLVMappedCode getVitalsLoincFromVuid(String sVuid) throws TermLoadException { JLVMappedCode oMappedCode = null; if (NullChecker.isNotNullish(sVuid)) { PreparedStatement psSelectStatement = null; ResultSet oResults = null; try { psSelectStatement = this.oDBConnection.prepareStatement(SQL_SELECT_BY_VUID); psSelectStatement.setString(SQL_PARAM_VUID, sVuid); oResults = psSelectStatement.executeQuery(); boolean bHasResult = false; if (oResults.next()) { JLVMappedCode oTempMappedCode = new JLVMappedCode(); String sLoincCode = oResults.getString(SQL_FIELD_VITALS_LOINC); if (NullChecker.isNotNullish(sLoincCode)) { oTempMappedCode.setCode(sLoincCode); bHasResult = true; } String sLoincText = oResults.getString(SQL_FIELD_VITALS_LOINC_NAME); if (NullChecker.isNotNullish(sLoincText)) { oTempMappedCode.setDisplayText(sLoincText); bHasResult = true; } if (bHasResult) { oTempMappedCode.setCodeSystem(CODE_SYSTEM_LOINC); oMappedCode = oTempMappedCode; } } } catch (SQLException e) { throw new TermLoadException("Failed to read Vitals information from the 'vitals' table. Error: " + e.getMessage(), e); } finally { TermLoadException exceptionToThrow = null; if (oResults != null) { try { oResults.close(); oResults = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the result set. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (psSelectStatement != null) { try { psSelectStatement.close(); psSelectStatement = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the prepared statement. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (exceptionToThrow != null) { throw exceptionToThrow; } } } return oMappedCode; }
JLVVitalsMap { public JLVMappedCode getVitalsLoincFromVuid(String sVuid) throws TermLoadException { JLVMappedCode oMappedCode = null; if (NullChecker.isNotNullish(sVuid)) { PreparedStatement psSelectStatement = null; ResultSet oResults = null; try { psSelectStatement = this.oDBConnection.prepareStatement(SQL_SELECT_BY_VUID); psSelectStatement.setString(SQL_PARAM_VUID, sVuid); oResults = psSelectStatement.executeQuery(); boolean bHasResult = false; if (oResults.next()) { JLVMappedCode oTempMappedCode = new JLVMappedCode(); String sLoincCode = oResults.getString(SQL_FIELD_VITALS_LOINC); if (NullChecker.isNotNullish(sLoincCode)) { oTempMappedCode.setCode(sLoincCode); bHasResult = true; } String sLoincText = oResults.getString(SQL_FIELD_VITALS_LOINC_NAME); if (NullChecker.isNotNullish(sLoincText)) { oTempMappedCode.setDisplayText(sLoincText); bHasResult = true; } if (bHasResult) { oTempMappedCode.setCodeSystem(CODE_SYSTEM_LOINC); oMappedCode = oTempMappedCode; } } } catch (SQLException e) { throw new TermLoadException("Failed to read Vitals information from the 'vitals' table. Error: " + e.getMessage(), e); } finally { TermLoadException exceptionToThrow = null; if (oResults != null) { try { oResults.close(); oResults = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the result set. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (psSelectStatement != null) { try { psSelectStatement.close(); psSelectStatement = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the prepared statement. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (exceptionToThrow != null) { throw exceptionToThrow; } } } return oMappedCode; } }
JLVVitalsMap { public JLVMappedCode getVitalsLoincFromVuid(String sVuid) throws TermLoadException { JLVMappedCode oMappedCode = null; if (NullChecker.isNotNullish(sVuid)) { PreparedStatement psSelectStatement = null; ResultSet oResults = null; try { psSelectStatement = this.oDBConnection.prepareStatement(SQL_SELECT_BY_VUID); psSelectStatement.setString(SQL_PARAM_VUID, sVuid); oResults = psSelectStatement.executeQuery(); boolean bHasResult = false; if (oResults.next()) { JLVMappedCode oTempMappedCode = new JLVMappedCode(); String sLoincCode = oResults.getString(SQL_FIELD_VITALS_LOINC); if (NullChecker.isNotNullish(sLoincCode)) { oTempMappedCode.setCode(sLoincCode); bHasResult = true; } String sLoincText = oResults.getString(SQL_FIELD_VITALS_LOINC_NAME); if (NullChecker.isNotNullish(sLoincText)) { oTempMappedCode.setDisplayText(sLoincText); bHasResult = true; } if (bHasResult) { oTempMappedCode.setCodeSystem(CODE_SYSTEM_LOINC); oMappedCode = oTempMappedCode; } } } catch (SQLException e) { throw new TermLoadException("Failed to read Vitals information from the 'vitals' table. Error: " + e.getMessage(), e); } finally { TermLoadException exceptionToThrow = null; if (oResults != null) { try { oResults.close(); oResults = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the result set. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (psSelectStatement != null) { try { psSelectStatement.close(); psSelectStatement = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the prepared statement. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (exceptionToThrow != null) { throw exceptionToThrow; } } } return oMappedCode; } @SuppressWarnings("unused") private  JLVVitalsMap();  JLVVitalsMap(Connection oDBConnection); }
JLVVitalsMap { public JLVMappedCode getVitalsLoincFromVuid(String sVuid) throws TermLoadException { JLVMappedCode oMappedCode = null; if (NullChecker.isNotNullish(sVuid)) { PreparedStatement psSelectStatement = null; ResultSet oResults = null; try { psSelectStatement = this.oDBConnection.prepareStatement(SQL_SELECT_BY_VUID); psSelectStatement.setString(SQL_PARAM_VUID, sVuid); oResults = psSelectStatement.executeQuery(); boolean bHasResult = false; if (oResults.next()) { JLVMappedCode oTempMappedCode = new JLVMappedCode(); String sLoincCode = oResults.getString(SQL_FIELD_VITALS_LOINC); if (NullChecker.isNotNullish(sLoincCode)) { oTempMappedCode.setCode(sLoincCode); bHasResult = true; } String sLoincText = oResults.getString(SQL_FIELD_VITALS_LOINC_NAME); if (NullChecker.isNotNullish(sLoincText)) { oTempMappedCode.setDisplayText(sLoincText); bHasResult = true; } if (bHasResult) { oTempMappedCode.setCodeSystem(CODE_SYSTEM_LOINC); oMappedCode = oTempMappedCode; } } } catch (SQLException e) { throw new TermLoadException("Failed to read Vitals information from the 'vitals' table. Error: " + e.getMessage(), e); } finally { TermLoadException exceptionToThrow = null; if (oResults != null) { try { oResults.close(); oResults = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the result set. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (psSelectStatement != null) { try { psSelectStatement.close(); psSelectStatement = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the prepared statement. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (exceptionToThrow != null) { throw exceptionToThrow; } } } return oMappedCode; } @SuppressWarnings("unused") private  JLVVitalsMap();  JLVVitalsMap(Connection oDBConnection); JLVMappedCode getVitalsLoincFromVuid(String sVuid); JLVMappedCode getVitalsLoincFromDodNcid(String sDodNcid); }
JLVVitalsMap { public JLVMappedCode getVitalsLoincFromVuid(String sVuid) throws TermLoadException { JLVMappedCode oMappedCode = null; if (NullChecker.isNotNullish(sVuid)) { PreparedStatement psSelectStatement = null; ResultSet oResults = null; try { psSelectStatement = this.oDBConnection.prepareStatement(SQL_SELECT_BY_VUID); psSelectStatement.setString(SQL_PARAM_VUID, sVuid); oResults = psSelectStatement.executeQuery(); boolean bHasResult = false; if (oResults.next()) { JLVMappedCode oTempMappedCode = new JLVMappedCode(); String sLoincCode = oResults.getString(SQL_FIELD_VITALS_LOINC); if (NullChecker.isNotNullish(sLoincCode)) { oTempMappedCode.setCode(sLoincCode); bHasResult = true; } String sLoincText = oResults.getString(SQL_FIELD_VITALS_LOINC_NAME); if (NullChecker.isNotNullish(sLoincText)) { oTempMappedCode.setDisplayText(sLoincText); bHasResult = true; } if (bHasResult) { oTempMappedCode.setCodeSystem(CODE_SYSTEM_LOINC); oMappedCode = oTempMappedCode; } } } catch (SQLException e) { throw new TermLoadException("Failed to read Vitals information from the 'vitals' table. Error: " + e.getMessage(), e); } finally { TermLoadException exceptionToThrow = null; if (oResults != null) { try { oResults.close(); oResults = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the result set. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (psSelectStatement != null) { try { psSelectStatement.close(); psSelectStatement = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the prepared statement. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (exceptionToThrow != null) { throw exceptionToThrow; } } } return oMappedCode; } @SuppressWarnings("unused") private  JLVVitalsMap();  JLVVitalsMap(Connection oDBConnection); JLVMappedCode getVitalsLoincFromVuid(String sVuid); JLVMappedCode getVitalsLoincFromDodNcid(String sDodNcid); static final int SQL_PARAM_VUID; static final int SQL_PARAM_DOD_NCID; static final int SQL_FIELD_VITALS_ID; static final int SQL_FIELD_VITALS_DOD_NCID; static final int SQL_FIELD_VITALS_VUID; static final int SQL_FIELD_VITALS_LOINC; static final int SQL_FIELD_VITALS_LOINC_NAME; static final String CODE_SYSTEM_LOINC; }