Yair Zaslavsky has uploaded a new change for review. Change subject: core: Cleanup on notification service resource closing ......................................................................
core: Cleanup on notification service resource closing This patch introduces DbUtils for DB-related helper methods. It uses these methods to perform quiet resource closing at the NotificationService Bug-Id: https://bugzilla.redhat.com/882847 Change-Id: I54fb540ee52255f017933b000b9b509c4e156123 Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- A backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/db/DbUtils.java M backend/manager/tools/engine-notifier/engine-notifier-service/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java 2 files changed, 62 insertions(+), 47 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/9740/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/db/DbUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/db/DbUtils.java new file mode 100644 index 0000000..663de41 --- /dev/null +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/db/DbUtils.java @@ -0,0 +1,57 @@ +package org.ovirt.engine.core.utils.db; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +/** + * Helper methods to handle DB related issues + */ +public class DbUtils { + + public static void closeQuietly(ResultSet resultSet, Connection connection) { + closeQuietly(resultSet, null, connection); + } + + public static void closeQuietly(ResultSet resultSet, Statement statement, Connection connection) { + closeQuietly(resultSet); + closeQuietly(statement); + closeQuietly(connection); + } + + public static void closeQuietly(ResultSet result) { + if (result != null) { + try { + result.close(); + } catch (SQLException e) { + } + } + } + + public static void closeQuietly(Statement statement) { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + } + } + + } + + public static void closeQuietly(Connection connection) { + if (connection != null) { + try { + connection.close(); + + } catch (SQLException e) { + } + } + } + + public static void closeQuietly(PreparedStatement ps, Connection connection) { + closeQuietly(null,ps,connection); + } + +} diff --git a/backend/manager/tools/engine-notifier/engine-notifier-service/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java b/backend/manager/tools/engine-notifier/engine-notifier-service/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java index d9bc44f..d033897 100644 --- a/backend/manager/tools/engine-notifier/engine-notifier-service/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java +++ b/backend/manager/tools/engine-notifier/engine-notifier-service/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java @@ -32,6 +32,7 @@ import org.ovirt.engine.core.notifier.utils.sender.EventSender; import org.ovirt.engine.core.notifier.utils.sender.EventSenderResult; import org.ovirt.engine.core.tools.common.db.StandaloneDataSource; +import org.ovirt.engine.core.utils.db.DbUtils; /** * Responsible for an execution of the service for the current events in the system which should be notified to the @@ -195,28 +196,7 @@ eventSubscribers.add(getEventAuditLogSubscriber(rs)); } } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - log.error("Failed to release resultset of event_audit_log_subscriber", e); - } - } - if (ps != null) { - try { - ps.close(); - } catch (SQLException e) { - log.error("Failed to release statement of event_audit_log_subscriber", e); - } - } - if (connection != null) { - try { - connection.close(); - } catch (SQLException e) { - log.error("Failed to close connection of event_audit_log_subscriber", e); - throw e; - } - } + DbUtils.closeQuietly(rs, ps, connection); } DbUser dbUser = null; for (event_audit_log_subscriber eventSubscriber:eventSubscribers) { @@ -254,12 +234,7 @@ + eventSubscriber.getaudit_log_id()); } } finally { - if (ps != null) { - ps.close(); - } - if (connection != null) { - connection.close(); - } + DbUtils.closeQuietly(ps,connection); } } @@ -280,12 +255,7 @@ cs.setString(7, eventHistory.getsubscriber_id().toString()); cs.executeUpdate(); } finally { - if (cs != null) { - cs.close(); - } - if (connection != null) { - connection.close(); - } + DbUtils.closeQuietly(cs,connection); } } @@ -322,19 +292,7 @@ dbUser.setemail(rs.getString("email")); } } finally { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - log.error("Failed to release resultset of db user query", e); - } - } - if (ps != null) { - ps.close(); - } - if (connection != null) { - connection.close(); - } + DbUtils.closeQuietly(rs,connection); } return dbUser; } -- To view, visit http://gerrit.ovirt.org/9740 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I54fb540ee52255f017933b000b9b509c4e156123 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches