Skip to content

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

Description

@llvieira

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions