Revision 44191 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/JDBCUtils.java

View differences:

JDBCUtils.java
7 7
import java.sql.Statement;
8 8
import java.util.Iterator;
9 9
import java.util.List;
10
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
11 10
import org.slf4j.Logger;
12 11
import org.slf4j.LoggerFactory;
13 12

  
13
@SuppressWarnings("UseSpecificCatch")
14 14
public class JDBCUtils {
15 15

  
16
    private static final Logger logger = LoggerFactory.getLogger(JDBCUtils.class);
16
    private static final Logger LOGGER = LoggerFactory.getLogger(JDBCUtils.class);
17 17
    
18 18
    private JDBCUtils() {
19 19

  
20 20
    }
21 21

  
22 22
    public static ResultSet executeQuery(Statement st, String sql) throws SQLException {
23
        logger.debug("execute query SQL: " + sql);
23
        LOGGER.debug("execute query SQL: " + sql);
24 24
        try {
25 25
            ResultSet rs = st.executeQuery(sql);
26 26
            return rs;
27 27
        } catch(Exception ex) {
28
            logger.warn("execute SQL: " + sql, ex);
28
            LOGGER.warn("execute SQL: " + sql, ex);
29 29
            throw ex;
30 30
        }
31 31
    }
32 32

  
33 33
    public static void execute(Statement st, String sql) throws SQLException {
34
        logger.debug("execute SQL: " + sql);
34
        LOGGER.debug("execute SQL: " + sql);
35 35
        try {
36 36
            st.execute(sql);
37 37
        } catch(Exception ex) {
38
            logger.warn("execute SQL: " + sql, ex);
38
            LOGGER.warn("execute SQL: " + sql, ex);
39 39
            throw ex;
40 40
        }
41 41
    }
42 42

  
43 43
    public static void execute(Connection connection, String sql) throws SQLException {
44
        logger.debug("execute SQL: " + sql);
44
        LOGGER.debug("execute SQL: " + sql);
45 45
        Statement st = connection.createStatement();
46 46
        try {
47 47
            st.execute(sql);
48 48
        } catch(Exception ex) {
49
            logger.warn("execute SQL: " + sql, ex);
49
            LOGGER.warn("execute SQL: " + sql, ex);
50 50
            throw ex;
51 51
        }
52 52
    }
......
59 59
            Iterator<String> it = sqls.iterator();
60 60
            while( it.hasNext() ) {
61 61
                sql = it.next();
62
                logger.debug("execute SQL: " + sql);
62
                LOGGER.debug("execute SQL: " + sql);
63 63
                st.execute(sql);
64 64
            }
65 65
        } catch (SQLException ex) {
66
            logger.warn("execute SQL: " + sql, ex);
66
            LOGGER.warn("execute SQL: " + sql, ex);
67 67
            throw ex;
68 68
        } finally {
69 69
            JDBCUtils.closeQuietly(st);
......
71 71
    }
72 72

  
73 73
    public static ResultSet executeQuery(PreparedStatement st, String sql) throws SQLException {
74
        logger.debug("execute query SQL: " + sql);
74
        LOGGER.debug("execute query SQL: " + sql);
75 75
        try {
76 76
            ResultSet rs = st.executeQuery();
77 77
            return rs;
78 78
        } catch(Exception ex) {
79
            logger.warn("execute SQL: " + sql, ex);
79
            LOGGER.warn("execute SQL: " + sql, ex);
80 80
            throw ex;
81 81
        }
82 82
    }
83 83

  
84 84
    public static void execute(PreparedStatement st, String sql) throws SQLException {
85
        logger.debug("execute SQL: " + sql);
85
        LOGGER.debug("execute SQL: " + sql);
86 86
        try {
87 87
            st.execute();
88 88
        } catch(Exception ex) {
89
            logger.warn("execute SQL: " + sql, ex);
89
            LOGGER.warn("execute SQL: " + sql, ex);
90 90
            throw ex;
91 91
        }
92 92
    }
93 93

  
94 94
    public static int executeUpdate(PreparedStatement st, String sql) throws SQLException {
95
        logger.debug("execute update SQL: "+ sql);
95
        LOGGER.debug("execute update SQL: "+ sql);
96 96
        try {
97 97
            return st.executeUpdate();
98 98
        } catch(Exception ex) {
99
            logger.warn("execute SQL: " + sql, ex);
99
            LOGGER.warn("execute SQL: " + sql, ex);
100 100
            throw ex;
101 101
        }
102 102
    }
......
108 108
        try {
109 109
            obj.close();
110 110
        } catch (Exception e) {
111
            logger.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
111
            LOGGER.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
112 112
        }
113 113
    }
114 114

  
......
119 119
        try {
120 120
            obj.close();
121 121
        } catch (Exception e) {
122
            logger.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
122
            LOGGER.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
123 123
        }
124 124
    }
125 125

  
126
    public static void closeQuietly(Connection obj) {
127
        if (obj == null) {
126
    public static void closeQuietly(Connection conn) {
127
        if (conn == null) {
128 128
            return;
129 129
        }
130
        LOGGER.debug("Closing connection "+ conn.hashCode() + " ("+conn.toString()+")");
130 131
        try {
131
            obj.close();
132
            conn.close();
132 133
        } catch (Exception e) {
133
            logger.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
134
            LOGGER.warn("Problems closing " + conn.getClass().getSimpleName() + " '" + conn.toString() + "'.", e);
134 135
        }
135 136
    }
136 137
    
......
139 140
            return;
140 141
        }
141 142
        try {
143
            LOGGER.debug("Closing " + obj.getClass().getSimpleName() + " "+ obj.hashCode() + " ("+obj.toString()+")");
142 144
            obj.close();
143 145
        } catch (Exception e) {
144
            logger.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
146
            LOGGER.warn("Problems closing " + obj.getClass().getSimpleName() + " '" + obj.toString() + "'.", e);
145 147
        }
146 148
    }
147 149
}

Also available in: Unified diff