Revision 44609

View differences:

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
7 7
import java.sql.Statement;
8 8
import java.util.Iterator;
9 9
import java.util.List;
10
import java.util.Objects;
10 11
import org.slf4j.Logger;
11 12
import org.slf4j.LoggerFactory;
12 13

  
......
19 20

  
20 21
    }
21 22

  
23
    private static String getSQLInfo(PreparedStatement st, String sql) {
24
        try {
25
            return sql+" [[ "+Objects.toString(st)+" ]]";
26
        } catch(Throwable th) {
27
            return sql;
28
        }
29
    }
30
    
22 31
    public static ResultSet executeQuery(Statement st, String sql) throws SQLException {
23 32
        LOGGER.debug("execute query SQL: " + sql);
24 33
        try {
......
71 80
    }
72 81

  
73 82
    public static ResultSet executeQuery(PreparedStatement st, String sql) throws SQLException {
74
        LOGGER.debug("execute query SQL: " + sql);
83
        if( LOGGER.isDebugEnabled() ) {
84
            LOGGER.debug("execute query SQL= "+ getSQLInfo(st,sql));
85
        }
75 86
        try {
76 87
            ResultSet rs = st.executeQuery();
77 88
            return rs;
78 89
        } catch(Exception ex) {
79
            LOGGER.warn("execute SQL: " + sql, ex);
90
            LOGGER.warn("execute query SQL: " + getSQLInfo(st,sql), ex);
80 91
            throw ex;
81 92
        }
82 93
    }
83 94

  
84 95
    public static void execute(PreparedStatement st, String sql) throws SQLException {
85
        LOGGER.debug("execute SQL: " + sql);
96
        if( LOGGER.isDebugEnabled() ) {
97
            LOGGER.debug("execute SQL= "+ getSQLInfo(st,sql));
98
        }
86 99
        try {
87 100
            st.execute();
88 101
        } catch(Exception ex) {
89
            LOGGER.warn("execute SQL: " + sql, ex);
102
            LOGGER.warn("execute SQL: " + getSQLInfo(st,sql), ex);
90 103
            throw ex;
91 104
        }
92 105
    }
93 106

  
94 107
    public static int executeUpdate(PreparedStatement st, String sql) throws SQLException {
95
        LOGGER.debug("execute update SQL: "+ sql);
108
        if( LOGGER.isDebugEnabled() ) {
109
            LOGGER.debug("execute update SQL= "+ getSQLInfo(st,sql));
110
        }
96 111
        try {
97 112
            return st.executeUpdate();
98 113
        } catch(Exception ex) {
99
            LOGGER.warn("execute SQL: " + sql, ex);
114
            LOGGER.warn("execute update SQL: " + getSQLInfo(st,sql), ex);
100 115
            throw ex;
101 116
        }
102 117
    }

Also available in: Unified diff