Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java @ 230:fbd57d2eeaef
Changed semantics of locked artifact ids.
artifacts/trunk@1634 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 31 Mar 2011 14:48:28 +0000 |
parents | dd977fb7552e |
children | 16cd059945e5 |
comparison
equal
deleted
inserted
replaced
229:328ef982d768 | 230:fbd57d2eeaef |
---|---|
32 import java.io.OutputStream; | 32 import java.io.OutputStream; |
33 | 33 |
34 import java.security.MessageDigest; | 34 import java.security.MessageDigest; |
35 import java.security.NoSuchAlgorithmException; | 35 import java.security.NoSuchAlgorithmException; |
36 | 36 |
37 import java.util.ArrayList; | |
38 import java.util.Arrays; | 37 import java.util.Arrays; |
39 import java.util.Date; | 38 import java.util.Date; |
40 import java.util.HashMap; | 39 import java.util.HashMap; |
41 import java.util.HashSet; | 40 import java.util.HashSet; |
42 import java.util.List; | 41 import java.util.Set; |
43 | 42 |
44 import javax.xml.xpath.XPathConstants; | 43 import javax.xml.xpath.XPathConstants; |
45 | 44 |
46 import org.apache.commons.codec.binary.Base64; | 45 import org.apache.commons.codec.binary.Base64; |
47 import org.apache.commons.codec.binary.Hex; | 46 import org.apache.commons.codec.binary.Hex; |
58 * expose them via REST. The concrete persistent representation of the | 57 * expose them via REST. The concrete persistent representation of the |
59 * artifacts is handled by the {@link Backend backend}. | 58 * artifacts is handled by the {@link Backend backend}. |
60 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 59 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
61 */ | 60 */ |
62 public class ArtifactDatabaseImpl | 61 public class ArtifactDatabaseImpl |
63 implements ArtifactDatabase, Id.Filter, Backend.FactoryLookup | 62 implements ArtifactDatabase, |
63 DatabaseCleaner.LockedIdsProvider, | |
64 Backend.FactoryLookup | |
64 { | 65 { |
65 private static Logger logger = | 66 private static Logger logger = |
66 Logger.getLogger(ArtifactDatabaseImpl.class); | 67 Logger.getLogger(ArtifactDatabaseImpl.class); |
67 | 68 |
68 /** Message that is returned if an operation was successful.*/ | 69 /** Message that is returned if an operation was successful.*/ |
394 /** | 395 /** |
395 * A set of ids of artifact which currently running in background. | 396 * A set of ids of artifact which currently running in background. |
396 * This artifacts should not be removed from the database by the | 397 * This artifacts should not be removed from the database by the |
397 * database cleaner. | 398 * database cleaner. |
398 */ | 399 */ |
399 protected HashSet backgroundIds; | 400 protected HashSet<Integer> backgroundIds; |
400 | 401 |
401 /** | 402 /** |
402 * Default constructor. | 403 * Default constructor. |
403 */ | 404 */ |
404 public ArtifactDatabaseImpl() { | 405 public ArtifactDatabaseImpl() { |
421 * @param bootstrap The parameters to start this artifact database. | 422 * @param bootstrap The parameters to start this artifact database. |
422 * @param backend The storage backend. | 423 * @param backend The storage backend. |
423 */ | 424 */ |
424 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) { | 425 public ArtifactDatabaseImpl(FactoryBootstrap bootstrap, Backend backend) { |
425 | 426 |
426 backgroundIds = new HashSet(); | 427 backgroundIds = new HashSet<Integer>(); |
427 | 428 |
428 setupArtifactCollectionFactory(bootstrap); | 429 setupArtifactCollectionFactory(bootstrap); |
429 setupArtifactFactories(bootstrap); | 430 setupArtifactFactories(bootstrap); |
430 setupServices(bootstrap); | 431 setupServices(bootstrap); |
431 setupUserFactory(bootstrap); | 432 setupUserFactory(bootstrap); |
553 * from the database again. | 554 * from the database again. |
554 * @param id The database id of the artifact. | 555 * @param id The database id of the artifact. |
555 */ | 556 */ |
556 protected void removeIdFromBackground(int id) { | 557 protected void removeIdFromBackground(int id) { |
557 synchronized (backgroundIds) { | 558 synchronized (backgroundIds) { |
558 backgroundIds.remove(Integer.valueOf(id)); | 559 backgroundIds.remove(id); |
559 } | 560 } |
560 } | 561 } |
561 | 562 |
562 /** | 563 /** |
563 * Adds an artifact's database id to the set of artifacts | 564 * Adds an artifact's database id to the set of artifacts |
570 synchronized (backgroundIds) { | 571 synchronized (backgroundIds) { |
571 backgroundIds.add(Integer.valueOf(id)); | 572 backgroundIds.add(Integer.valueOf(id)); |
572 } | 573 } |
573 } | 574 } |
574 | 575 |
575 public List filterIds(List ids) { | 576 public Set<Integer> getLockedIds() { |
576 int N = ids.size(); | |
577 ArrayList out = new ArrayList(N); | |
578 synchronized (backgroundIds) { | 577 synchronized (backgroundIds) { |
579 for (int i = 0; i < N; ++i) { | 578 return new HashSet<Integer>(backgroundIds); |
580 Id id = (Id)ids.get(i); | 579 } |
581 // only delete artifact if its not in background. | |
582 if (!backgroundIds.contains(Integer.valueOf(id.getId()))) { | |
583 out.add(id); | |
584 } | |
585 } | |
586 } | |
587 return out; | |
588 } | 580 } |
589 | 581 |
590 public String [][] artifactFactoryNamesAndDescriptions() { | 582 public String [][] artifactFactoryNamesAndDescriptions() { |
591 return factoryNamesAndDescription; | 583 return factoryNamesAndDescription; |
592 } | 584 } |