Clover coverage report - Coverage timestamp: Sa Jul 7 2007 09:11:40 CEST FRAMES NO FRAMES |
file stats: | LOC: | 161 |  | Methods: | 18
| NCLOC: | 78 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
OSCache.java | - | 0% | 0% | 0% |

1 |  | package com.opensymphony.oscache.hibernate;
2 |  |
3 |  | import java.util.Map;
4 |  |
5 |  | import org.hibernate.cache.Cache;
6 |  | import org.hibernate.cache.CacheException;
7 |  | import org.hibernate.cache.Timestamper;
8 |  |
9 |  | import com.opensymphony.oscache.base.NeedsRefreshException;
10 |  | import com.opensymphony.oscache.general.GeneralCacheAdministrator;
11 |  |
12 |  | /**
13 |  | * Cache plugin for Hibernate 3.2 and OpenSymphony OSCache 2.4.
14 |  | * <p/>
15 |  | * The OSCache implementation assumes that identifiers have well-behaved <tt>toString()</tt> methods.
16 |  | * This implementation <b>must</b> be threadsafe.
17 |  | *
18 |  | * @version $Revision:$
19 |  | */
20 |  | public class OSCache implements Cache {
21 |  |
22 |  | /** The OSCache 2.4 cache administrator. */
23 |  | private GeneralCacheAdministrator cache;
24 |  | private final int refreshPeriod;
25 |  | private final String cron;
26 |  | private final String regionName;
27 |  | private final String[] regionGroups;
28 |  |
29 | 0 | public OSCache(GeneralCacheAdministrator cache, int refreshPeriod, String cron, String region) {
30 | 0 | this.cache = cache;
31 | 0 | this.refreshPeriod = refreshPeriod;
32 | 0 | this.cron = cron;
33 | 0 | this.regionName = region;
34 | 0 | this.regionGroups = new String[] {region};
35 |  | }
36 |  |
37 |  | /**
38 |  | * @see org.hibernate.cache.Cache#get(java.lang.Object)
39 |  | */
40 | 0 | public Object get(Object key) throws CacheException {
41 | 0 | try {
42 | 0 | return cache.getFromCache( toString(key), refreshPeriod, cron );
43 |  | }
44 |  | catch (NeedsRefreshException e) {
45 | 0 | cache.cancelUpdate( toString(key) );
46 | 0 | return null;
47 |  | }
48 |  | }
49 |  |
50 |  | /**
51 |  | * @see org.hibernate.cache.Cache#put(java.lang.Object, java.lang.Object)
52 |  | */
53 | 0 | public void put(Object key, Object value) throws CacheException {
54 | 0 | cache.putInCache( toString(key), value, regionGroups );
55 |  | }
56 |  |
57 |  | /**
58 |  | * @see org.hibernate.cache.Cache#remove(java.lang.Object)
59 |  | */
60 | 0 | public void remove(Object key) throws CacheException {
61 | 0 | cache.flushEntry( toString(key) );
62 |  | }
63 |  |
64 |  | /**
65 |  | * @see org.hibernate.cache.Cache#clear()
66 |  | */
67 | 0 | public void clear() throws CacheException {
68 | 0 | cache.flushGroup(regionName);
69 |  | }
70 |  |
71 |  | /**
72 |  | * @see org.hibernate.cache.Cache#destroy()
73 |  | */
74 | 0 | public void destroy() throws CacheException {
75 | 0 | synchronized (cache) {
76 | 0 | cache.destroy();
77 |  | }
78 |  | }
79 |  |
80 |  | /**
81 |  | * @see org.hibernate.cache.Cache#lock(java.lang.Object)
82 |  | */
83 | 0 | public void lock(Object key) throws CacheException {
84 |  | // local cache, so we use synchronization
85 |  | }
86 |  |
87 |  | /**
88 |  | * @see org.hibernate.cache.Cache#unlock(java.lang.Object)
89 |  | */
90 | 0 | public void unlock(Object key) throws CacheException {
91 |  | // local cache, so we use synchronization
92 |  | }
93 |  |
94 |  | /**
95 |  | * @see org.hibernate.cache.Cache#nextTimestamp()
96 |  | */
97 | 0 | public long nextTimestamp() {
98 | 0 | return Timestamper.next();
99 |  | }
100 |  |
101 |  | /**
102 |  | * @see org.hibernate.cache.Cache#getTimeout()
103 |  | */
104 | 0 | public int getTimeout() {
105 | 0 | return Timestamper.ONE_MS * 60000; //ie. 60 seconds
106 |  | }
107 |  |
108 |  | /**
109 |  | * @see org.hibernate.cache.Cache#toMap()
110 |  | */
111 | 0 | public Map toMap() {
112 | 0 | throw new UnsupportedOperationException();
113 |  | }
114 |  |
115 |  | /**
116 |  | * @see org.hibernate.cache.Cache#getElementCountOnDisk()
117 |  | */
118 | 0 | public long getElementCountOnDisk() {
119 | 0 | return -1;
120 |  | }
121 |  |
122 |  | /**
123 |  | * @see org.hibernate.cache.Cache#getElementCountInMemory()
124 |  | */
125 | 0 | public long getElementCountInMemory() {
126 | 0 | return -1;
127 |  | }
128 |  |
129 |  | /**
130 |  | * @see org.hibernate.cache.Cache#getSizeInMemory()
131 |  | */
132 | 0 | public long getSizeInMemory() {
133 | 0 | return -1;
134 |  | }
135 |  |
136 |  | /**
137 |  | * @see org.hibernate.cache.Cache#getRegionName()
138 |  | */
139 | 0 | public String getRegionName() {
140 | 0 | return regionName;
141 |  | }
142 |  |
143 |  | /**
144 |  | * @see org.hibernate.cache.Cache#update(java.lang.Object, java.lang.Object)
145 |  | */
146 | 0 | public void update(Object key, Object value) throws CacheException {
147 | 0 | put(key, value);
148 |  | }
149 |  |
150 |  | /**
151 |  | * @see org.hibernate.cache.Cache#read(java.lang.Object)
152 |  | */
153 | 0 | public Object read(Object key) throws CacheException {
154 | 0 | return get(key);
155 |  | }
156 |  |
157 | 0 | private String toString(Object key) {
158 | 0 | return String.valueOf(key) + "." + regionName;
159 |  | }
160 |  |
161 |  | }