|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DocumentCache.java | 75% | 75% | 50% | 68.2% |
|
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | * | |
17 | * $Id: DocumentCache.java 712324 2008-11-08 00:32:01Z vgritsenko $ | |
18 | */ | |
19 | ||
20 | package org.apache.xindice.core.cache; | |
21 | ||
22 | import org.apache.xindice.core.Collection; | |
23 | import org.apache.xindice.core.data.Entry; | |
24 | import org.apache.xindice.core.data.Key; | |
25 | import org.apache.xindice.core.data.Value; | |
26 | ||
27 | import java.util.Map; | |
28 | ||
29 | /** | |
30 | * DocumentCache implements a simple caching system for | |
31 | * collection resource entries. | |
32 | * | |
33 | * @version $Revision: 712324 $, $Date: 2008-11-08 00:32:01 +0000 (Sat, 08 Nov 2008) $ | |
34 | */ | |
35 | public interface DocumentCache { | |
36 | ||
37 | /** | |
38 | * Cache key consists of collection and resource key | |
39 | */ | |
40 | class CacheKey { | |
41 | private final Collection col; | |
42 | private final Key key; | |
43 | private transient int hashCode; | |
44 | ||
45 | 109797 | public CacheKey(Collection col, Key key) { |
46 | 109797 | this.col = col; |
47 | 109797 | this.key = key; |
48 | } | |
49 | ||
50 | 0 | public Collection getCollection() { |
51 | 0 | return col; |
52 | } | |
53 | ||
54 | 0 | public Key getKey() { |
55 | 0 | return key; |
56 | } | |
57 | ||
58 | 109797 | public int hashCode() { |
59 | 109797 | if (hashCode == 0) { |
60 | 109797 | hashCode = col.getCanonicalDocumentName(key).hashCode(); |
61 | } | |
62 | ||
63 | 109797 | return hashCode; |
64 | } | |
65 | ||
66 | 32107 | public boolean equals(Object o) { |
67 | 32107 | if (o instanceof DocumentCache.CacheKey) { |
68 | 32090 | CacheKey k = (CacheKey) o; |
69 | ||
70 | 32090 | return col == k.col && key.equals(k.key); |
71 | } | |
72 | ||
73 | 17 | return false; |
74 | } | |
75 | ||
76 | 0 | public String toString() { |
77 | 0 | return col.getCanonicalDocumentName(key); |
78 | } | |
79 | } | |
80 | ||
81 | /** | |
82 | * Obtains resource entry from the cache | |
83 | * | |
84 | * @param col resource collection | |
85 | * @param key resource key | |
86 | * @return entry cached resource entry or null if not present | |
87 | */ | |
88 | Entry getEntry(Collection col, Key key); | |
89 | ||
90 | /** | |
91 | * Obtains resource entry metadata from cache. | |
92 | * | |
93 | * @param col resource collection | |
94 | * @param key resource key | |
95 | * @return entry cached resource metadata or null if not present | |
96 | */ | |
97 | Entry getEntryMeta(Collection col, Key key); | |
98 | ||
99 | /** | |
100 | * Stores resource entry value in the cache | |
101 | * | |
102 | * @param col resource collection | |
103 | * @param key resource key | |
104 | * @param type resource type: COMPRESSED, UNCOMPRESSED, BINARY | |
105 | * @param value entry value | |
106 | * @param meta resource meta attributes map | |
107 | */ | |
108 | void putEntry(Collection col, Key key, byte type, Value value, Map meta); | |
109 | ||
110 | /** | |
111 | * Stores resource meta entry in the cache | |
112 | * | |
113 | * @param col resource collection | |
114 | * @param key resource key | |
115 | * @param type resource type: COMPRESSED, UNCOMPRESSED, BINARY | |
116 | * @param meta resource metadata attributes map | |
117 | */ | |
118 | void putEntryMeta(Collection col, Key key, byte type, Map meta); | |
119 | ||
120 | /** | |
121 | * Remove resource entry from the cache | |
122 | * | |
123 | * @param col resource collection | |
124 | * @param key resource key | |
125 | */ | |
126 | void removeEntry(Collection col, Key key); | |
127 | } |
|