Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement/Question] Method to close connection is rewritten in many classes #344

Open
llvieira opened this issue Mar 23, 2018 · 0 comments

Comments

@llvieira
Copy link
Member

llvieira commented Mar 23, 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:

private void close(Statement statement, Connection conn) {
    if (statement != null) {
        try {
            if (!statement.isClosed()) {
                statement.close();
            }
        } catch (SQLException e) {
            LOGGER.error("Couldn't close statement");
        }
    }

    if (conn != null) {
        try {
            if (!conn.isClosed()) {
                conn.close();
            }
        } catch (SQLException e) {
            LOGGER.error("Couldn't close connection");
        }
    }
}

Classes with the same method:

src/main/java/org/fogbowcloud/manager/occi/ManagerDataStore.java
src/main/java/org/fogbowcloud/manager/core/plugins/benchmarking/ssh/SHHBenchmarkingDataStore.java
src/main/java/org/fogbowcloud/manager/occi/network/NetworkDataStore.java
src/main/java/org/fogbowcloud/manager/occi/instance/InstanceDataStore.java
src/main/java/org/fogbowcloud/manager/core/plugins/accounting/AccountingDataStore.java
src/main/java/org/fogbowcloud/manager/occi/storage/StorageDataStore.java
@llvieira 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant