You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I was doing the task #343, I realized that the method to close connection is being repeated in at least 6 classes.
Is there any specific reason to keep that method in all this classes? What are the trade-offs in changing it?
Maybe we can do an Util class to reuse that and just call this method in the other classes, like: Util.closeConnection(Statement statement, Connection conn).
The classic problem is: If we need to change that method we have to make this changes in every place which the method is written.
Method:
privatevoidclose(Statementstatement, Connectionconn) {
if (statement != null) {
try {
if (!statement.isClosed()) {
statement.close();
}
} catch (SQLExceptione) {
LOGGER.error("Couldn't close statement");
}
}
if (conn != null) {
try {
if (!conn.isClosed()) {
conn.close();
}
} catch (SQLExceptione) {
LOGGER.error("Couldn't close connection");
}
}
}
The text was updated successfully, but these errors were encountered:
llvieira
changed the title
[Enhancement] Method to close connection is rewritten in many classes
[Enhancement/Question] Method to close connection is rewritten in many classes
Mar 24, 2018
Hi guys,
When I was doing the task #343, I realized that the method to close connection is being repeated in at least 6 classes.
Is there any specific reason to keep that method in all this classes? What are the trade-offs in changing it?
Maybe we can do an
Util
class to reuse that and just call this method in the other classes, like:Util.closeConnection(Statement statement, Connection conn)
.The classic problem is: If we need to change that method we have to make this changes in every place which the method is written.
Method:
Classes with the same method:
The text was updated successfully, but these errors were encountered: