Merge pull request #611 from mookkiah/issue_587_dao

Issue 587 SonarQube reports bugs - Module DAO
This commit is contained in:
Ilkka Seppälä 2017-08-17 22:24:52 +03:00 committed by GitHub
commit 68d094a847

View File

@ -65,8 +65,8 @@ public class DbCustomerDao implements CustomerDao {
Connection connection; Connection connection;
try { try {
connection = getConnection(); connection = getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * FROM CUSTOMERS"); PreparedStatement statement = connection.prepareStatement("SELECT * FROM CUSTOMERS"); //NOSONAR
ResultSet resultSet = statement.executeQuery(); ResultSet resultSet = statement.executeQuery(); //NOSONAR
return StreamSupport.stream(new Spliterators.AbstractSpliterator<Customer>(Long.MAX_VALUE, return StreamSupport.stream(new Spliterators.AbstractSpliterator<Customer>(Long.MAX_VALUE,
Spliterator.ORDERED) { Spliterator.ORDERED) {
@ -82,7 +82,7 @@ public class DbCustomerDao implements CustomerDao {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
}, false).onClose(() -> mutedClose(connection)); }, false).onClose(() -> mutedClose(connection, statement, resultSet));
} catch (SQLException e) { } catch (SQLException e) {
throw new Exception(e.getMessage(), e); throw new Exception(e.getMessage(), e);
} }
@ -92,8 +92,10 @@ public class DbCustomerDao implements CustomerDao {
return dataSource.getConnection(); return dataSource.getConnection();
} }
private void mutedClose(Connection connection) { private void mutedClose(Connection connection, PreparedStatement statement, ResultSet resultSet) {
try { try {
resultSet.close();
statement.close();
connection.close(); connection.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();