// Path: src/main/java/com/pearson/statspoller/utilities/core_utils/StackTrace.java
// public class StackTrace {
//     
//     private static final Logger logger = LoggerFactory.getLogger(StackTrace.class.getName());
//     
//     public static String getStringFromStackTrace(Exception exception) {
//         try {
//             StringWriter stringWriter = new StringWriter();
//             PrintWriter printWriter = new PrintWriter(stringWriter);
//             
//             exception.printStackTrace(printWriter);
//             
//             return stringWriter.toString();
//         }
//         catch (Exception e) {
//             logger.error(e.toString() + " - Failed to convert stack-trace to string");
//             return null;
//         }
//     }
//     
//     public static String getStringFromStackTrace(StackTraceElement[] stackTraceElements) {
//         try {
//             
//             StringBuilder stackTrace = new StringBuilder();
//             
//             for (StackTraceElement stackTraceElement : stackTraceElements) {
//                 stackTrace.append(stackTraceElement).append(System.lineSeparator());
//             }
//             
//             return stackTrace.toString();
//         }
//         catch (Exception e) {
//             logger.error(e.toString() + " - Failed to convert stack-trace to string");
//             return null;
//         }
//     }
//     
// }


import com.pearson.statspoller.utilities.core_utils.StackTrace;
import com.google.common.collect.Lists;
import java.io.BufferedReader;
import java.math.BigDecimal;
import java.sql.BatchUpdateException;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.RowId;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
        cleanup(null, preparedStatement, null, null, CLOSE);
    }
    
    public static void cleanup(PreparedStatement preparedStatement, ResultSet results) {
        cleanup(null, preparedStatement, null, results, CLOSE);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement) {
        cleanup(connection, preparedStatement, null, null, CLOSE);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement, byte closeMode) {
        cleanup(connection, preparedStatement, null, null, closeMode);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement, ResultSet results) {
        cleanup(connection, preparedStatement, null, results, CLOSE);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement, ResultSet results, byte closeMode) {
        cleanup(connection, preparedStatement, null, results, closeMode);
    }

    public static void cleanup(Connection connection, PreparedStatement preparedStatement, Statement statement, ResultSet results, byte closeMode) {
        
        if (results != null) {
            try {
                results.close();
            }
            catch (Exception e) {
// Path: src/main/java/com/pearson/statspoller/utilities/core_utils/StackTrace.java
// public class StackTrace {
//     
//     private static final Logger logger = LoggerFactory.getLogger(StackTrace.class.getName());
//     
//     public static String getStringFromStackTrace(Exception exception) {
//         try {
//             StringWriter stringWriter = new StringWriter();
//             PrintWriter printWriter = new PrintWriter(stringWriter);
//             
//             exception.printStackTrace(printWriter);
//             
//             return stringWriter.toString();
//         }
//         catch (Exception e) {
//             logger.error(e.toString() + " - Failed to convert stack-trace to string");
//             return null;
//         }
//     }
//     
//     public static String getStringFromStackTrace(StackTraceElement[] stackTraceElements) {
//         try {
//             
//             StringBuilder stackTrace = new StringBuilder();
//             
//             for (StackTraceElement stackTraceElement : stackTraceElements) {
//                 stackTrace.append(stackTraceElement).append(System.lineSeparator());
//             }
//             
//             return stackTrace.toString();
//         }
//         catch (Exception e) {
//             logger.error(e.toString() + " - Failed to convert stack-trace to string");
//             return null;
//         }
//     }
//     
// }


// Path: src/main/java/com/pearson/statspoller/utilities/db_utils/DatabaseUtils.java
import com.pearson.statspoller.utilities.core_utils.StackTrace;
import com.google.common.collect.Lists;
import java.io.BufferedReader;
import java.math.BigDecimal;
import java.sql.BatchUpdateException;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.RowId;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

        cleanup(null, preparedStatement, null, null, CLOSE);
    }
    
    public static void cleanup(PreparedStatement preparedStatement, ResultSet results) {
        cleanup(null, preparedStatement, null, results, CLOSE);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement) {
        cleanup(connection, preparedStatement, null, null, CLOSE);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement, byte closeMode) {
        cleanup(connection, preparedStatement, null, null, closeMode);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement, ResultSet results) {
        cleanup(connection, preparedStatement, null, results, CLOSE);
    }
    
    public static void cleanup(Connection connection, PreparedStatement preparedStatement, ResultSet results, byte closeMode) {
        cleanup(connection, preparedStatement, null, results, closeMode);
    }

    public static void cleanup(Connection connection, PreparedStatement preparedStatement, Statement statement, ResultSet results, byte closeMode) {
        
        if (results != null) {
            try {
                results.close();
            }
            catch (Exception e) {
                logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));