/*
 * Copyright 2012-2013 Continuuity,Inc. All Rights Reserved.
 */

package com.continuuity.passport.dal.db;

import com.google.common.base.Throwables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Abstract class that has some basic operations applicable to db operations
 */
public abstract class DBAccess {

  /**
   * Close DB related objects
   *
   * @param connection DBConnection
   * @param ps         Prepared Statement
   * @param rs         Result set
   * @throws RuntimeException
   */
  public void close(Connection connection, PreparedStatement ps, ResultSet rs) {
    try {
      if (rs != null) {
        rs.close();
      }
      if (ps != null) {
        ps.close();
      }
      if (connection != null) {
        connection.close();
      }

    } catch (SQLException e) {
      throw Throwables.propagate(e);
    }
  }

  /**
   * Close DB related objects
   *
   * @param connection DBConnection
   * @param ps         Prepared Statement
   * @throws RuntimeException
   */
  public void close(Connection connection, PreparedStatement ps) {
    try {
      if (connection != null) {
        connection.close();
      }
      if (ps != null) {
        ps.close();
      }
    } catch (SQLException e) {
      throw Throwables.propagate(e);
    }
  }

  /**
   * Close DB related objects
   *
   * @param ps Prepared Statement
   * @throws RuntimeException
   */
  public void close(PreparedStatement ps) {
    try {
      if (ps != null) {
        ps.close();
      }
    } catch (SQLException e) {
      throw Throwables.propagate(e);
    }
  }

}

@@ -145,16 +145,73 @@
 owables;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -444,16 +444,94 @@
 cess %7B%0A%0A
+  private static final Logger LOG = LoggerFactory.getLogger(DBAccess.class);%0A%0A
   /**%0A  
@@ -788,24 +788,25 @@
 ltSet rs) %7B%0A
+%0A
     try %7B%0A  
@@ -863,55 +863,330 @@
     
-  if (ps != null) %7B%0A        ps.close();%0A      %7D
+%7D catch (SQLException e) %7B%0A      LOG.error(String.format(%22Error while closing Result set %25s%22, e.getMessage()));%0A    %7D%0A    try %7B%0A      if (ps != null) %7B%0A        ps.close();%0A      %7D%0A    %7D catch (SQLException e) %7B%0A      LOG.error(String.format(%22Error while closing PreparedStatement set %25s%22, e.getMessage()));%0A    %7D%0A    try %7B
 %0A   
@@ -1250,17 +1250,16 @@
       %7D%0A
-%0A
     %7D ca
@@ -1291,36 +1291,88 @@
     
-throw Throwables.propagate(e
+LOG.error(String.format(%22Error while closing Connection set %25s%22, e.getMessage())
 );%0A 

add try/catch while closing each result set, prep statement, connection