Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 17:5a6b6a3debc7
Integrated logging into artifact database.
artifacts/trunk@33 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 08 Sep 2009 06:29:52 +0000 |
parents | 9ad6ec2d09c3 |
children | 72abee95fd64 |
comparison
equal
deleted
inserted
replaced
16:635310c6a20e | 17:5a6b6a3debc7 |
---|---|
23 import java.util.zip.GZIPInputStream; | 23 import java.util.zip.GZIPInputStream; |
24 | 24 |
25 import de.intevation.artifacts.ArtifactFactory; | 25 import de.intevation.artifacts.ArtifactFactory; |
26 import de.intevation.artifacts.Artifact; | 26 import de.intevation.artifacts.Artifact; |
27 | 27 |
28 import org.apache.log4j.Logger; | |
29 | |
28 /** | 30 /** |
29 * @author Sascha L. Teichmann | 31 * @author Sascha L. Teichmann |
30 */ | 32 */ |
31 public class Backend | 33 public class Backend |
32 { | 34 { |
35 private static Logger logger = Logger.getLogger(Backend.class); | |
36 | |
33 public static final String SQL_NEXT_ID = | 37 public static final String SQL_NEXT_ID = |
34 SQL.get("artifacts.id.nextval"); | 38 SQL.get("artifacts.id.nextval"); |
35 | 39 |
36 public static final String SQL_INSERT = | 40 public static final String SQL_INSERT = |
37 SQL.get("artifacts.insert"); | 41 SQL.get("artifacts.insert"); |
138 oos.flush(); | 142 oos.flush(); |
139 | 143 |
140 return bos.toByteArray(); | 144 return bos.toByteArray(); |
141 } | 145 } |
142 catch (IOException ioe) { | 146 catch (IOException ioe) { |
147 logger.error(ioe.getLocalizedMessage(), ioe); | |
143 throw new RuntimeException(ioe); | 148 throw new RuntimeException(ioe); |
144 } | 149 } |
145 } | 150 } |
146 } // class ArtifactProxy | 151 } // class ArtifactProxy |
147 | 152 |
153 | 158 |
154 try { | 159 try { |
155 uuid = UUID.fromString(idenitfier); | 160 uuid = UUID.fromString(idenitfier); |
156 } | 161 } |
157 catch (IllegalArgumentException iae) { | 162 catch (IllegalArgumentException iae) { |
163 logger.warn(iae.getLocalizedMessage()); | |
158 return null; | 164 return null; |
159 } | 165 } |
160 | 166 |
161 return getArtifactByUUID(uuid); | 167 return getArtifactByUUID(uuid); |
162 } | 168 } |
217 } | 223 } |
218 | 224 |
219 return new ArtifactProxy(original, id, false); | 225 return new ArtifactProxy(original, id, false); |
220 } | 226 } |
221 catch (SQLException sqle) { | 227 catch (SQLException sqle) { |
222 sqle.printStackTrace(System.err); | 228 logger.error(sqle.getLocalizedMessage(), sqle); |
223 } | 229 } |
224 finally { | 230 finally { |
225 if (load_result != null) { | 231 if (load_result != null) { |
226 try { load_result.close(); } | 232 try { load_result.close(); } |
227 catch (SQLException sqle) {} | 233 catch (SQLException sqle) {} |
248 ois = new ObjectInputStream(gis); | 254 ois = new ObjectInputStream(gis); |
249 | 255 |
250 return (Artifact)ois.readObject(); | 256 return (Artifact)ois.readObject(); |
251 } | 257 } |
252 catch (IOException ioe) { | 258 catch (IOException ioe) { |
253 ioe.printStackTrace(System.err); | 259 logger.error(ioe.getLocalizedMessage(), ioe); |
254 } | 260 } |
255 catch (ClassNotFoundException cnfe) { | 261 catch (ClassNotFoundException cnfe) { |
256 cnfe.printStackTrace(System.err); | 262 logger.error(cnfe.getLocalizedMessage(), cnfe); |
257 } | 263 } |
258 catch (ClassCastException cce) { | 264 catch (ClassCastException cce) { |
259 cce.printStackTrace(System.err); | 265 logger.error(cce.getLocalizedMessage(), cce); |
260 } | 266 } |
261 finally { | 267 finally { |
262 if (ois != null) { | 268 if (ois != null) { |
263 try { ois.close(); } | 269 try { ois.close(); } |
264 catch (IOException ioe) { } | 270 catch (IOException ioe) { } |
267 | 273 |
268 return null; | 274 return null; |
269 } | 275 } |
270 | 276 |
271 protected void artifactOutdated(int id) { | 277 protected void artifactOutdated(int id) { |
272 System.err.println("artifactOutdated: id = " + id); | 278 logger.info("artifactOutdated: id = " + id); |
273 } | 279 } |
274 | 280 |
275 protected int insertDatabase(UUID uuid, Long ttl) { | 281 protected int insertDatabase(UUID uuid, Long ttl) { |
276 Connection connection = null; | 282 Connection connection = null; |
277 PreparedStatement stmnt_next_id = null; | 283 PreparedStatement stmnt_next_id = null; |
314 connection.rollback(); | 320 connection.rollback(); |
315 throw sqle; | 321 throw sqle; |
316 } | 322 } |
317 } | 323 } |
318 catch (SQLException sqle) { | 324 catch (SQLException sqle) { |
319 sqle.printStackTrace(System.err); | 325 logger.error(sqle.getLocalizedMessage(), sqle); |
320 } | 326 } |
321 finally { | 327 finally { |
322 if (res_id != null) { | 328 if (res_id != null) { |
323 try { res_id.close(); } | 329 try { res_id.close(); } |
324 catch (SQLException sqle) {} | 330 catch (SQLException sqle) {} |
338 } | 344 } |
339 throw new RuntimeException("failed insert artifact into database"); | 345 throw new RuntimeException("failed insert artifact into database"); |
340 } | 346 } |
341 | 347 |
342 public void touch(ArtifactProxy proxy) { | 348 public void touch(ArtifactProxy proxy) { |
343 System.err.println("touch: " + proxy); | 349 logger.info("touch: " + proxy); |
344 if (proxy.isUnwritten()) { | 350 if (proxy.isUnwritten()) { |
345 store(proxy); | 351 store(proxy); |
346 return; | 352 return; |
347 } | 353 } |
348 Connection connection = null; | 354 Connection connection = null; |
360 catch (SQLException sqle) { | 366 catch (SQLException sqle) { |
361 connection.rollback(); | 367 connection.rollback(); |
362 } | 368 } |
363 } | 369 } |
364 catch (SQLException sqle) { | 370 catch (SQLException sqle) { |
365 sqle.printStackTrace(System.err); | 371 logger.error(sqle.getLocalizedMessage(), sqle); |
366 } | 372 } |
367 finally { | 373 finally { |
368 if (stmnt_touch != null) { | 374 if (stmnt_touch != null) { |
369 try { stmnt_touch.close(); } | 375 try { stmnt_touch.close(); } |
370 catch (SQLException sqle) {} | 376 catch (SQLException sqle) {} |
375 } | 381 } |
376 } | 382 } |
377 } | 383 } |
378 | 384 |
379 public void store(ArtifactProxy proxy) { | 385 public void store(ArtifactProxy proxy) { |
380 System.err.println("store: " + proxy); | 386 logger.info("store: " + proxy); |
381 Connection connection = null; | 387 Connection connection = null; |
382 PreparedStatement stmnt_update = null; | 388 PreparedStatement stmnt_update = null; |
383 DataSource dataSource = DBConnection.getDataSource(); | 389 DataSource dataSource = DBConnection.getDataSource(); |
384 try { | 390 try { |
385 connection = dataSource.getConnection(); | 391 connection = dataSource.getConnection(); |
394 catch (SQLException sqle) { | 400 catch (SQLException sqle) { |
395 connection.rollback(); | 401 connection.rollback(); |
396 } | 402 } |
397 } | 403 } |
398 catch (SQLException sqle) { | 404 catch (SQLException sqle) { |
399 sqle.printStackTrace(System.err); | 405 logger.error(sqle.getLocalizedMessage(), sqle); |
400 } | 406 } |
401 finally { | 407 finally { |
402 if (stmnt_update != null) { | 408 if (stmnt_update != null) { |
403 try { stmnt_update.close(); } | 409 try { stmnt_update.close(); } |
404 catch (SQLException sqle) {} | 410 catch (SQLException sqle) {} |