/*
 * Copyright (c) 2009-2013 Topi Nieminen
 */
package fi.tnie.db;

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

public class QueryHelper {
	
	private static QueryHelper instance = new QueryHelper();
	
	public static Statement doClose(Statement st) {
		instance.close(st);
		return null;
	}
	
	public static PreparedStatement doClose(PreparedStatement ps) {
		instance.close(ps);
		return null;
	}

	public static ResultSet doClose(ResultSet rs) {
		instance.close(rs);
		return null;
	}
	public Statement close(Statement st) {
		if (st != null) {
			try {
				st.close();
			} 
			catch (SQLException e) {			
				closeError(st, e);
			}
		}
		
		return null;
	}

	public void closeError(Statement st, SQLException e) {		
	}

	public void rollbackError(Connection c, SQLException e) {      
	}
	

	public ResultSet close(ResultSet st) {
		if (st != null) {
			try {
				st.close();
			} 
			catch (SQLException e) {			
				closeError(st, e);
			}
		}
		
		return null;
	}

	public void closeError(ResultSet st, SQLException e) {		
	}

    public static Connection doClose(Connection c) {
        if (c != null) {
            try {
                c.close();
            } 
            catch (SQLException e) {            
            }
        }
        
        return null;        
    }
    
    public static void doRollback(Connection c) {
        instance.rollback(c);        
    }

    
    public void rollback(Connection c) {
        if (c != null) {
            try {
                c.rollback();
            } 
            catch (SQLException e) {            
                rollbackError(c, e);
            }
        }
    }
}

@@ -928,18 +928,18 @@
 sultSet 
+r
 s
-t
 ) %7B%0A%09%09if
@@ -932,34 +932,34 @@
 Set rs) %7B%0A%09%09if (
+r
 s
-t
  != null) %7B%0A%09%09%09t
@@ -959,34 +959,34 @@
  %7B%0A%09%09%09try %7B%0A%09%09%09%09
+r
 s
-t
 .close();%0A%09%09%09%7D %0A
@@ -1023,34 +1023,34 @@
 %0A%09%09%09%09closeError(
+r
 s
-t
 , e);%0A%09%09%09%7D%0A%09%09%7D%0A%09
@@ -1104,18 +1104,18 @@
 sultSet 
+r
 s
-t
 , SQLExc

Improve naming of the result set parameter