1 25 26 package org.snipsnap.snip.storage; 27 28 import org.snipsnap.snip.Snip; 29 import org.snipsnap.util.ApplicationAwareMap; 30 31 import java.sql.Timestamp ; 32 import java.util.List ; 33 34 42 43 public class CacheSnipStorage implements SnipStorage, CacheStorage { 44 private ApplicationAwareMap cache; 45 private SnipStorage storage; 46 47 public CacheSnipStorage(SnipStorage storage) { 48 this.storage = storage; 49 } 50 51 public Snip[] match(String pattern) { 53 return storage.match(pattern); 54 } 55 56 public Snip[] match(String start, String end) { 57 return storage.match(start, end); 58 } 59 60 public Snip storageLoad(String name) { 62 Snip snip; 63 if (cache.getMap().containsKey(name)) { 64 snip = (Snip) cache.getMap().get(name); 65 } else { 66 snip = storage.storageLoad(name); 67 cache.getMap().put(snip.getName(), snip); 68 } 69 return snip; 70 } 71 72 public ApplicationAwareMap getCache() { 73 return cache; 74 } 75 76 public Object loadObject(String name) { 77 return storageLoad(name); 78 } 79 80 public void storageStore(Snip snip) { 81 storage.storageStore(snip); 82 } 83 84 public Snip storageCreate(String name, String content) { 85 Snip snip = storage.storageCreate(name, content); 86 cache.getMap().put(snip.getName(), snip); 87 return snip; 88 } 89 90 public void storageRemove(Snip snip) { 91 cache.getMap().remove(snip); 92 storage.storageRemove(snip); 93 } 94 95 public int storageCount() { 97 return storage.storageCount(); 98 } 99 100 public List storageAll(String applicationOid) { 101 return storage.storageAll(applicationOid); 102 } 103 104 public List storageAll() { 105 return storage.storageAll(); 106 } 107 108 public List storageByHotness(int size) { 109 return storage.storageByHotness(size); 110 } 111 112 public List storageByUser(String login) { 113 return storage.storageByUser(login); 114 } 115 116 public List storageByDateSince(Timestamp date) { 117 return storage.storageByDateSince(date); 118 } 119 120 public List storageByRecent(String applicationOid, int size) { 121 return storage.storageByRecent(applicationOid, size); 122 } 123 124 public List storageByComments(Snip parent) { 125 return storage.storageByComments(parent); 126 } 127 128 public List storageByParent(Snip parent) { 129 return storage.storageByParent(parent); 130 } 131 132 public List storageByParentNameOrder(Snip parent, int count) { 133 return storage.storageByParentNameOrder(parent, count); 134 } 135 136 public List storageByParentModifiedOrder(Snip parent, int count) { 137 return storage.storageByParentModifiedOrder(parent, count); 138 } 139 140 public List storageByDateInName(String nameSpace, String start, String end) { 141 return storage.storageByDateInName(nameSpace, start, end); 142 } 143 } | Popular Tags |