comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 313:ddc35c950e97

Backend: Handle forgotten store/create event source. artifacts/trunk@2440 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 01 Aug 2011 15:43:44 +0000
parents fa056f9c8a0c
children 31ee2b3b5a57
comparison
equal deleted inserted replaced
312:fa056f9c8a0c 313:ddc35c950e97
355 SQL_ALL_ARTIFACTS = sql.get("all.artifacts"); 355 SQL_ALL_ARTIFACTS = sql.get("all.artifacts");
356 } 356 }
357 357
358 public void addListener(BackendListener listener) { 358 public void addListener(BackendListener listener) {
359 listeners.add(listener); 359 listeners.add(listener);
360 logger.debug("# listeners: " + listeners.size());
360 } 361 }
361 362
362 public void addAllListeners(List<BackendListener> others) { 363 public void addAllListeners(List<BackendListener> others) {
363 listeners.addAll(others); 364 listeners.addAll(others);
365 logger.debug("# listeners: " + listeners.size());
364 } 366 }
365 367
366 /** 368 /**
367 * Sets the factory lookup mechanism to decouple ArtifactDatabase 369 * Sets the factory lookup mechanism to decouple ArtifactDatabase
368 * and Backend. 370 * and Backend.
601 603
602 if (!isValidIdentifier(uuid)) { 604 if (!isValidIdentifier(uuid)) {
603 throw new RuntimeException("No valid UUID"); 605 throw new RuntimeException("No valid UUID");
604 } 606 }
605 607
606 final int [] id = new int[1]; 608 final int [] id = new int[1];
609 final boolean [] stored = new boolean[1];
607 610
608 SQLExecutor.Instance exec = sqlExecutor.new Instance() { 611 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
609 public boolean doIt() throws SQLException { 612 public boolean doIt() throws SQLException {
610 613
611 prepareStatement(SQL_GET_ID); 614 prepareStatement(SQL_GET_ID);
616 ? Integer.valueOf(result.getInt(1)) 619 ? Integer.valueOf(result.getInt(1))
617 : null; 620 : null;
618 621
619 reset(); 622 reset();
620 623
621 if (ID != null) { // already in database 624 if (stored[0] = ID != null) { // already in database
622 prepareStatement(SQL_REPLACE); 625 prepareStatement(SQL_REPLACE);
623 626
624 if (ttl == null) { 627 if (ttl == null) {
625 stmnt.setNull(1, Types.BIGINT); 628 stmnt.setNull(1, Types.BIGINT);
626 } 629 }
670 } 673 }
671 }; 674 };
672 675
673 if (!exec.runWrite()) { 676 if (!exec.runWrite()) {
674 throw new RuntimeException("failed insert artifact into database"); 677 throw new RuntimeException("failed insert artifact into database");
678 }
679
680 if (stored[0]) {
681 fireStoredArtifact(artifact);
682 }
683 else {
684 fireCreatedArtifact(artifact);
675 } 685 }
676 686
677 return id[0]; 687 return id[0];
678 } 688 }
679 689
1736 } 1746 }
1737 1747
1738 boolean success = sqlExecutor.new Instance() { 1748 boolean success = sqlExecutor.new Instance() {
1739 @Override 1749 @Override
1740 public boolean doIt() throws SQLException { 1750 public boolean doIt() throws SQLException {
1741 logger.debug("doIt");
1742
1743 // a little cache to avoid too much deserializations. 1751 // a little cache to avoid too much deserializations.
1744 LRUCache<String, Artifact> alreadyLoaded = 1752 LRUCache<String, Artifact> alreadyLoaded =
1745 new LRUCache<String, Artifact>(200); 1753 new LRUCache<String, Artifact>(200);
1746 1754
1747 prepareStatement(SQL_ALL_ARTIFACTS); 1755 prepareStatement(SQL_ALL_ARTIFACTS);

http://dive4elements.wald.intevation.org