/*
 * 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 (connection != null) {
        connection.close();
      }
      if (ps != null) {
        ps.close();
      }
      if (rs != null) {
        rs.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);
    }
  }

}

@@ -673,34 +673,26 @@
 %7B%0A      if (
-connection
+rs
  != null) %7B%0A
@@ -695,34 +695,26 @@
 ) %7B%0A        
-connection
+rs
 .close();%0A  
@@ -773,34 +773,42 @@
     %7D%0A      if (
-rs
+connection
  != null) %7B%0A    
@@ -803,34 +803,42 @@
 null) %7B%0A        
-rs
+connection
 .close();%0A      
@@ -831,32 +831,33 @@
 lose();%0A      %7D%0A
+%0A
     %7D catch (SQL

Change the order in which connection, rs, ps is closed