Revision 47784 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
JDBCUtils.java | ||
---|---|---|
85 | 85 |
} |
86 | 86 |
|
87 | 87 |
public static ResultSet executeQuery(Statement st, String sql) throws SQLException { |
88 |
if( LOGGER.isDebugEnabled() ) { |
|
89 |
LOGGER.debug("["+getConnId(st)+"] executeQuery(st) SQL= " + sql); |
|
90 |
} |
|
88 |
ResultSet rs; |
|
91 | 89 |
try { |
92 |
@SuppressWarnings("null") |
|
93 |
ResultSet rs = st.executeQuery(sql); |
|
90 |
if( LOGGER.isDebugEnabled() ) { |
|
91 |
long t1 = System.currentTimeMillis(); |
|
92 |
rs = st.executeQuery(sql); |
|
93 |
long t2 = System.currentTimeMillis(); |
|
94 |
LOGGER.debug("["+getConnId(st)+"] executeQuery(st) "+(t2-t1)+"ms SQL= " + sql); |
|
95 |
} else { |
|
96 |
rs = st.executeQuery(sql); |
|
97 |
} |
|
94 | 98 |
return rs; |
95 | 99 |
} catch(Exception ex) { |
96 | 100 |
LOGGER.debug("execute SQL: " + sql, ex); |
... | ... | |
98 | 102 |
} |
99 | 103 |
} |
100 | 104 |
|
101 |
@SuppressWarnings("null") |
|
102 | 105 |
public static void execute(Statement st, String sql) throws SQLException { |
103 |
if( LOGGER.isDebugEnabled() ) { |
|
104 |
LOGGER.debug("["+getConnId(st)+"] execute(st) SQL: " + sql); |
|
105 |
} |
|
106 | 106 |
try { |
107 |
st.execute(sql); |
|
107 |
if( LOGGER.isDebugEnabled() ) { |
|
108 |
long t1 = System.currentTimeMillis(); |
|
109 |
st.execute(sql); |
|
110 |
long t2 = System.currentTimeMillis(); |
|
111 |
LOGGER.debug("["+getConnId(st)+"] execute(st) "+(t2-t1)+"ms SQL: " + sql); |
|
112 |
} else { |
|
113 |
st.execute(sql); |
|
114 |
} |
|
108 | 115 |
} catch(Exception ex) { |
109 | 116 |
LOGGER.debug("execute SQL: " + sql, ex); |
110 | 117 |
throw ex; |
... | ... | |
112 | 119 |
} |
113 | 120 |
|
114 | 121 |
public static void execute(Connection connection, String sql) throws SQLException { |
115 |
if( LOGGER.isDebugEnabled() ) { |
|
116 |
LOGGER.debug("["+getConnId(connection)+"] execute(conn) SQL: " + sql); |
|
117 |
} |
|
118 | 122 |
try { |
119 |
@SuppressWarnings("null") |
|
120 | 123 |
Statement st = connection.createStatement(); |
121 |
st.execute(sql); |
|
124 |
if( LOGGER.isDebugEnabled() ) { |
|
125 |
long t1 = System.currentTimeMillis(); |
|
126 |
st.execute(sql); |
|
127 |
long t2 = System.currentTimeMillis(); |
|
128 |
LOGGER.debug("["+getConnId(connection)+"] execute(conn) "+(t2-t1)+"ms SQL: " + sql); |
|
129 |
} else { |
|
130 |
st.execute(sql); |
|
131 |
} |
|
122 | 132 |
} catch(Exception ex) { |
123 | 133 |
LOGGER.debug("execute SQL: " + sql, ex); |
124 | 134 |
throw ex; |
... | ... | |
134 | 144 |
while( it.hasNext() ) { |
135 | 145 |
sql = it.next(); |
136 | 146 |
if( LOGGER.isDebugEnabled() ) { |
137 |
LOGGER.debug("["+getConnId(connection)+"] execute(conn) SQLs: " + sql); |
|
147 |
long t1 = System.currentTimeMillis(); |
|
148 |
st.execute(sql); |
|
149 |
long t2 = System.currentTimeMillis(); |
|
150 |
LOGGER.debug("["+getConnId(connection)+"] execute(conn, sqls) "+(t2-t1)+"ms SQLs: " + sql); |
|
151 |
} else { |
|
152 |
st.execute(sql); |
|
138 | 153 |
} |
139 |
st.execute(sql); |
|
140 | 154 |
} |
141 | 155 |
} catch (SQLException ex) { |
142 | 156 |
LOGGER.debug("execute SQL: " + sql, ex); |
... | ... | |
147 | 161 |
} |
148 | 162 |
|
149 | 163 |
public static ResultSet executeQuery(PreparedStatement st, String sql) throws SQLException { |
150 |
if( LOGGER.isDebugEnabled() ) { |
|
151 |
LOGGER.debug("["+getConnId(st)+"] executeQuery(pst) SQL= "+ getSQLInfo(st,sql)); |
|
152 |
} |
|
164 |
ResultSet rs; |
|
153 | 165 |
try { |
154 |
@SuppressWarnings("null") |
|
155 |
ResultSet rs = st.executeQuery(); |
|
166 |
if( LOGGER.isDebugEnabled() ) { |
|
167 |
long t1 = System.currentTimeMillis(); |
|
168 |
rs = st.executeQuery(); |
|
169 |
long t2 = System.currentTimeMillis(); |
|
170 |
LOGGER.debug("["+getConnId(st)+"] executeQuery(pst) "+(t2-t1)+"ms SQL= "+ getSQLInfo(st,sql)); |
|
171 |
} else { |
|
172 |
rs = st.executeQuery(); |
|
173 |
} |
|
156 | 174 |
return rs; |
157 | 175 |
} catch(Exception ex) { |
158 | 176 |
LOGGER.debug("execute query SQL: " + getSQLInfo(st,sql), ex); |
... | ... | |
160 | 178 |
} |
161 | 179 |
} |
162 | 180 |
|
163 |
@SuppressWarnings("null") |
|
164 | 181 |
public static void execute(PreparedStatement st, String sql) throws SQLException { |
165 |
if( LOGGER.isDebugEnabled() ) { |
|
166 |
LOGGER.debug("["+getConnId(st)+"] execute(pst) SQL= "+ getSQLInfo(st,sql)); |
|
167 |
} |
|
168 | 182 |
try { |
169 |
st.execute(); |
|
183 |
if( LOGGER.isDebugEnabled() ) { |
|
184 |
long t1 = System.currentTimeMillis(); |
|
185 |
st.execute(); |
|
186 |
long t2 = System.currentTimeMillis(); |
|
187 |
LOGGER.debug("["+getConnId(st)+"] execute(pst) "+(t2-t1)+"ms SQL= "+ getSQLInfo(st,sql)); |
|
188 |
} else { |
|
189 |
st.execute(); |
|
190 |
} |
|
170 | 191 |
} catch(Exception ex) { |
171 | 192 |
LOGGER.debug("execute SQL: " + getSQLInfo(st,sql), ex); |
172 | 193 |
throw new SQLException(ex.getMessage() +getSQLInfo(st,sql), ex); |
... | ... | |
174 | 195 |
} |
175 | 196 |
|
176 | 197 |
public static int executeUpdate(PreparedStatement st, String sql) throws SQLException { |
177 |
if( LOGGER.isDebugEnabled() ) { |
|
178 |
LOGGER.debug("["+getConnId(st)+"] executeUpdate(pst) SQL= "+ getSQLInfo(st,sql)); |
|
179 |
} |
|
198 |
int r; |
|
180 | 199 |
try { |
181 |
return st.executeUpdate(); |
|
200 |
if( LOGGER.isDebugEnabled() ) { |
|
201 |
long t1 = System.currentTimeMillis(); |
|
202 |
r = st.executeUpdate(); |
|
203 |
long t2 = System.currentTimeMillis(); |
|
204 |
LOGGER.debug("["+getConnId(st)+"] executeUpdate(pst) "+(t2-t1)+"ms SQL= "+ getSQLInfo(st,sql)); |
|
205 |
} else { |
|
206 |
r = st.executeUpdate(); |
|
207 |
} |
|
208 |
return r; |
|
182 | 209 |
} catch(Exception ex) { |
183 | 210 |
LOGGER.debug("execute update SQL: " + getSQLInfo(st,sql), ex); |
184 | 211 |
throw new SQLException(ex.getMessage() +getSQLInfo(st,sql), ex); |
... | ... | |
186 | 213 |
} |
187 | 214 |
|
188 | 215 |
public static int executeUpdate(Statement st, String sql) throws SQLException { |
189 |
if( LOGGER.isDebugEnabled() ) { |
|
190 |
LOGGER.debug("["+getConnId(st)+"] executeUpdate(st) SQL= "+ sql); |
|
191 |
} |
|
216 |
int r; |
|
192 | 217 |
try { |
193 |
return st.executeUpdate(sql); |
|
218 |
if( LOGGER.isDebugEnabled() ) { |
|
219 |
long t1 = System.currentTimeMillis(); |
|
220 |
r = st.executeUpdate(sql); |
|
221 |
long t2 = System.currentTimeMillis(); |
|
222 |
LOGGER.debug("["+getConnId(st)+"] executeUpdate(st) "+(t2-t1)+"ms SQL= "+ sql); |
|
223 |
} else { |
|
224 |
r = st.executeUpdate(sql); |
|
225 |
} |
|
226 |
return r; |
|
194 | 227 |
} catch(Exception ex) { |
195 | 228 |
LOGGER.debug("execute update SQL: " + sql, ex); |
196 | 229 |
throw ex; |
... | ... | |
198 | 231 |
} |
199 | 232 |
|
200 | 233 |
public static int[] executeBatch(PreparedStatement st, String sql) throws SQLException { |
201 |
if( LOGGER.isDebugEnabled() ) { |
|
202 |
LOGGER.debug("["+getConnId(st)+"] executeBatch(pst) SQL= "+ getSQLInfo(st,sql)); |
|
203 |
} |
|
234 |
int[] r; |
|
204 | 235 |
try { |
205 |
return st.executeBatch(); |
|
236 |
if( LOGGER.isDebugEnabled() ) { |
|
237 |
long t1 = System.currentTimeMillis(); |
|
238 |
r = st.executeBatch(); |
|
239 |
long t2 = System.currentTimeMillis(); |
|
240 |
LOGGER.debug("["+getConnId(st)+"] executeBatch(pst) "+(t2-t1)+"ms SQL= "+ getSQLInfo(st,sql)); |
|
241 |
} else { |
|
242 |
r = st.executeBatch(); |
|
243 |
} |
|
244 |
return r; |
|
206 | 245 |
} catch(Exception ex) { |
207 | 246 |
LOGGER.debug("execute batch SQL: " + getSQLInfo(st,sql), ex); |
208 | 247 |
throw ex; |
... | ... | |
210 | 249 |
} |
211 | 250 |
|
212 | 251 |
public static void addBatch(PreparedStatement st, String sql) throws SQLException { |
213 |
if( LOGGER.isDebugEnabled() ) { |
|
214 |
LOGGER.debug("["+getConnId(st)+"] addBatch(pst) SQL= "+ getSQLInfo(st,sql)); |
|
215 |
} |
|
216 | 252 |
try { |
217 |
st.addBatch(); |
|
253 |
if( LOGGER.isDebugEnabled() ) { |
|
254 |
long t1 = System.currentTimeMillis(); |
|
255 |
st.addBatch(); |
|
256 |
long t2 = System.currentTimeMillis(); |
|
257 |
LOGGER.debug("["+getConnId(st)+"] addBatch(pst) "+(t2-t1)+"ms SQL= "+ getSQLInfo(st,sql)); |
|
258 |
} else { |
|
259 |
st.addBatch(); |
|
260 |
} |
|
218 | 261 |
} catch(Exception ex) { |
219 | 262 |
LOGGER.debug("add batch SQL: " + getSQLInfo(st,sql), ex); |
220 | 263 |
throw ex; |
Also available in: Unified diff