Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 26:83a059c204f8
Connected /create with artifact db.
artifacts/trunk@61 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Sep 2009 12:29:57 +0000 |
parents | d5dc2900392f |
children | 75bdaf900473 |
comparison
equal
deleted
inserted
replaced
25:ccc6aae25585 | 26:83a059c204f8 |
---|---|
174 uuid.toString(), context); | 174 uuid.toString(), context); |
175 | 175 |
176 Long ttl = factory.timeToLiveUntouched( | 176 Long ttl = factory.timeToLiveUntouched( |
177 artifact, context); | 177 artifact, context); |
178 | 178 |
179 int id = insertDatabase(uuid, ttl); | 179 try { |
180 | 180 int id = insertDatabase(uuid, ttl); |
181 return new ArtifactProxy(artifact, id, true); | 181 return new ArtifactProxy(artifact, id, true); |
182 } | |
183 catch (Exception e) { | |
184 logger.error(e.getLocalizedMessage(), e); | |
185 } | |
186 return null; | |
182 } | 187 } |
183 | 188 |
184 protected Artifact getArtifactByUUID(UUID uuid) { | 189 protected Artifact getArtifactByUUID(UUID uuid) { |
185 | 190 |
186 Connection connection = null; | 191 Connection connection = null; |
343 } | 348 } |
344 throw new RuntimeException("failed insert artifact into database"); | 349 throw new RuntimeException("failed insert artifact into database"); |
345 } | 350 } |
346 | 351 |
347 public void touch(ArtifactProxy proxy) { | 352 public void touch(ArtifactProxy proxy) { |
348 logger.info("touch: " + proxy); | 353 |
349 if (proxy.isUnwritten()) { | 354 if (proxy.isUnwritten()) { |
350 store(proxy); | 355 store(proxy); |
351 return; | 356 return; |
352 } | 357 } |
353 Connection connection = null; | 358 |
354 PreparedStatement stmnt_touch = null; | 359 try { |
355 DataSource dataSource = DBConnection.getDataSource(); | 360 Connection connection = null; |
356 try { | 361 PreparedStatement stmnt_touch = null; |
357 connection = dataSource.getConnection(); | 362 DataSource dataSource = DBConnection.getDataSource(); |
358 try { | 363 try { |
359 connection.setAutoCommit(false); | 364 connection = dataSource.getConnection(); |
360 stmnt_touch = connection.prepareStatement(SQL_UPDATE); | 365 try { |
361 stmnt_touch.setInt(1, proxy.getId()); | 366 connection.setAutoCommit(false); |
362 stmnt_touch.execute(); | 367 stmnt_touch = connection.prepareStatement(SQL_UPDATE); |
363 connection.commit(); | 368 stmnt_touch.setInt(1, proxy.getId()); |
369 stmnt_touch.execute(); | |
370 connection.commit(); | |
371 } | |
372 catch (SQLException sqle) { | |
373 connection.rollback(); | |
374 } | |
364 } | 375 } |
365 catch (SQLException sqle) { | 376 catch (SQLException sqle) { |
366 connection.rollback(); | 377 logger.error(sqle.getLocalizedMessage(), sqle); |
367 } | 378 } |
368 } | 379 finally { |
369 catch (SQLException sqle) { | 380 if (stmnt_touch != null) { |
370 logger.error(sqle.getLocalizedMessage(), sqle); | 381 try { stmnt_touch.close(); } |
371 } | 382 catch (SQLException sqle) {} |
372 finally { | 383 } |
373 if (stmnt_touch != null) { | 384 if (connection != null) { |
374 try { stmnt_touch.close(); } | 385 try { connection.close(); } |
375 catch (SQLException sqle) {} | 386 catch (SQLException sqle) {} |
376 } | 387 } |
377 if (connection != null) { | 388 } |
378 try { connection.close(); } | 389 } |
379 catch (SQLException sqle) {} | 390 catch (Exception e) { |
380 } | 391 logger.error(e.getLocalizedMessage(), e); |
381 } | 392 } |
382 } | 393 } |
383 | 394 |
384 public void store(ArtifactProxy proxy) { | 395 public void store(ArtifactProxy proxy) { |
385 logger.info("store: " + proxy); | 396 |
386 Connection connection = null; | 397 try { |
387 PreparedStatement stmnt_update = null; | 398 Connection connection = null; |
388 DataSource dataSource = DBConnection.getDataSource(); | 399 PreparedStatement stmnt_update = null; |
389 try { | 400 DataSource dataSource = DBConnection.getDataSource(); |
390 connection = dataSource.getConnection(); | 401 try { |
391 try { | 402 connection = dataSource.getConnection(); |
392 connection.setAutoCommit(false); | 403 try { |
393 stmnt_update = connection.prepareStatement(SQL_UPDATE); | 404 connection.setAutoCommit(false); |
394 stmnt_update.setInt(1, proxy.getId()); | 405 stmnt_update = connection.prepareStatement(SQL_UPDATE); |
395 stmnt_update.setBytes(2, proxy.toBytes()); | 406 stmnt_update.setInt(2, proxy.getId()); |
396 stmnt_update.execute(); | 407 |
397 connection.commit(); | 408 byte [] bytes = proxy.toBytes(); |
409 | |
410 stmnt_update.setBytes(1, bytes); | |
411 stmnt_update.execute(); | |
412 connection.commit(); | |
413 } | |
414 catch (SQLException sqle) { | |
415 connection.rollback(); | |
416 } | |
398 } | 417 } |
399 catch (SQLException sqle) { | 418 catch (SQLException sqle) { |
400 connection.rollback(); | 419 logger.error(sqle.getLocalizedMessage(), sqle); |
401 } | 420 } |
402 } | 421 finally { |
403 catch (SQLException sqle) { | 422 if (stmnt_update != null) { |
404 logger.error(sqle.getLocalizedMessage(), sqle); | 423 try { stmnt_update.close(); } |
405 } | 424 catch (SQLException sqle) {} |
406 finally { | 425 } |
407 if (stmnt_update != null) { | 426 if (connection != null) { |
408 try { stmnt_update.close(); } | 427 try { connection.close(); } |
409 catch (SQLException sqle) {} | 428 catch (SQLException sqle) {} |
410 } | 429 } |
411 if (connection != null) { | 430 } |
412 try { connection.close(); } | 431 } |
413 catch (SQLException sqle) {} | 432 catch (Exception e) { |
414 } | 433 logger.error(e.getLocalizedMessage(), e); |
415 } | 434 } |
416 } | 435 } |
417 | 436 |
418 } | 437 } |
419 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 438 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |