1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.boot.hl7v3;
17
18
19 import org.openehealth.ipf.commons.ihe.hl7v3.storage.Hl7v3ContinuationStorage;
20 import org.springframework.cache.Cache;
21 import org.springframework.cache.CacheManager;
22
23
24
25
26
27
28
29 public class CachingHl7v3ContinuationStorage implements Hl7v3ContinuationStorage {
30
31 private static final String INTERACTIVE_CONTINUATION_CACHE = "interactiveHl7v3ContinuationCache";
32
33 private final Cache cache;
34
35 private static final String MESSAGE_SUFFIX = ".message";
36 private static final String LAST_RESULT_NUMBER_SUFFIX = ".lastIndex";
37 private static final String CONTINUATION_QUANTITY_SUFFIX = ".quantity";
38
39 CachingHl7v3ContinuationStorage(CacheManager cacheManager) {
40 this.cache = cacheManager.getCache(INTERACTIVE_CONTINUATION_CACHE);
41 }
42
43 @Override
44 public void storeMessage(String key, String message) {
45 cache.put(key + MESSAGE_SUFFIX, message);
46 }
47
48 @Override
49 public String getMessage(String key) {
50 return cache.get(key + MESSAGE_SUFFIX, String.class);
51 }
52
53 @Override
54 public void storeLastResultNumber(String key, int lastResultNumber) {
55 cache.put(key + LAST_RESULT_NUMBER_SUFFIX, lastResultNumber);
56 }
57
58 @Override
59 public int getLastResultNumber(String key) {
60 Integer i = cache.get(key + LAST_RESULT_NUMBER_SUFFIX, Integer.class);
61 return (i != null) ? i : -1;
62 }
63
64 @Override
65 public void storeContinuationQuantity(String key, int continuationQuantity) {
66 cache.put(key + CONTINUATION_QUANTITY_SUFFIX, continuationQuantity);
67 }
68
69 @Override
70 public int getContinuationQuantity(String key) {
71 Integer i = cache.get(key + CONTINUATION_QUANTITY_SUFFIX, Integer.class);
72 return (i != null) ? i : -1;
73 }
74
75 @Override
76 public boolean remove(String key) {
77 cache.evict(key + LAST_RESULT_NUMBER_SUFFIX);
78 cache.evict(key + CONTINUATION_QUANTITY_SUFFIX);
79 if (cache.get(key + MESSAGE_SUFFIX) != null) {
80 cache.evict(key + MESSAGE_SUFFIX);
81 return true;
82 }
83 return false;
84 }
85
86 }
87