KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > snip > storage > CacheSnipStorage


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * Wrapper with caching for loading snips
36  *
37  * DOES NOT WORK!
38  *
39  * @author Stephan J. Schmidt
40  * @version $Id: CacheSnipStorage.java 1606 2004-05-17 10:56:18Z leo $
41  */

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   // Basic manipulation methods Load,Store,Create,Remove
52
public Snip[] match(String JavaDoc pattern) {
53     return storage.match(pattern);
54   }
55
56   public Snip[] match(String JavaDoc start, String JavaDoc end) {
57     return storage.match(start, end);
58   }
59
60   // Basic manipulation methods Load,Store,Create,Remove
61
public Snip storageLoad(String JavaDoc 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 JavaDoc loadObject(String JavaDoc name) {
77     return storageLoad(name);
78   }
79
80   public void storageStore(Snip snip) {
81     storage.storageStore(snip);
82   }
83
84   public Snip storageCreate(String JavaDoc name, String JavaDoc 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   // Finder methods
96
public int storageCount() {
97     return storage.storageCount();
98   }
99
100   public List JavaDoc storageAll(String JavaDoc applicationOid) {
101     return storage.storageAll(applicationOid);
102   }
103
104   public List JavaDoc storageAll() {
105     return storage.storageAll();
106   }
107
108   public List JavaDoc storageByHotness(int size) {
109     return storage.storageByHotness(size);
110   }
111
112   public List JavaDoc storageByUser(String JavaDoc login) {
113     return storage.storageByUser(login);
114   }
115
116   public List JavaDoc storageByDateSince(Timestamp JavaDoc date) {
117     return storage.storageByDateSince(date);
118   }
119
120   public List JavaDoc storageByRecent(String JavaDoc applicationOid, int size) {
121     return storage.storageByRecent(applicationOid, size);
122   }
123
124   public List JavaDoc storageByComments(Snip parent) {
125     return storage.storageByComments(parent);
126   }
127
128   public List JavaDoc storageByParent(Snip parent) {
129     return storage.storageByParent(parent);
130   }
131
132   public List JavaDoc storageByParentNameOrder(Snip parent, int count) {
133     return storage.storageByParentNameOrder(parent, count);
134   }
135
136   public List JavaDoc storageByParentModifiedOrder(Snip parent, int count) {
137     return storage.storageByParentModifiedOrder(parent, count);
138   }
139
140   public List JavaDoc storageByDateInName(String JavaDoc nameSpace, String JavaDoc start, String JavaDoc end) {
141     return storage.storageByDateInName(nameSpace, start, end);
142   }
143 }
Popular Tags