|
|||||||||||||||||||
| 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 594581 2007-11-13 16:59:33Z 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 resources. | |
| 32 | * | |
| 33 | * @version $Revision: 594581 $, $Date: 2007-11-13 16:59:33 +0000 (Tue, 13 Nov 2007) $ | |
| 34 | */ | |
| 35 | public interface DocumentCache { | |
| 36 | ||
| 37 | /** Compressed document resource type */ | |
| 38 | int COMPRESSED = 1; | |
| 39 | ||
| 40 | /** Uncompressed document resource type */ | |
| 41 | int UNCOMPRESSED = 2; | |
| 42 | ||
| 43 | /** Binary resource type */ | |
| 44 | int BINARY = 3; | |
| 45 | ||
| 46 | /** | |
| 47 | * Cache key consists of collection and resource key | |
| 48 | */ | |
| 49 | class CacheKey { | |
| 50 | private final Collection col; | |
| 51 | private final Key key; | |
| 52 | private transient int hashCode; | |
| 53 | ||
| 54 | 65643 | public CacheKey(Collection col, Key key) { |
| 55 | 65643 | this.col = col; |
| 56 | 65643 | this.key = key; |
| 57 | } | |
| 58 | ||
| 59 | 0 | public Collection getCollection() { |
| 60 | 0 | return col; |
| 61 | } | |
| 62 | ||
| 63 | 0 | public Key getKey() { |
| 64 | 0 | return key; |
| 65 | } | |
| 66 | ||
| 67 | 65643 | public int hashCode() { |
| 68 | 65643 | if (hashCode == 0) { |
| 69 | 65643 | hashCode = col.getCanonicalDocumentName(key).hashCode(); |
| 70 | } | |
| 71 | ||
| 72 | 65643 | return hashCode; |
| 73 | } | |
| 74 | ||
| 75 | 29682 | public boolean equals(Object o) { |
| 76 | 29682 | if (o instanceof DocumentCache.CacheKey) { |
| 77 | 29643 | CacheKey k = (CacheKey) o; |
| 78 | ||
| 79 | 29643 | return col == k.col && key.equals(k.key); |
| 80 | } | |
| 81 | ||
| 82 | 39 | return false; |
| 83 | } | |
| 84 | ||
| 85 | 0 | public String toString() { |
| 86 | 0 | return col.getCanonicalDocumentName(key); |
| 87 | } | |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Obtains resource entry from the cache | |
| 92 | * | |
| 93 | * @param col resource collection | |
| 94 | * @param key resource key | |
| 95 | * @return entry cached resource entry or null if not present | |
| 96 | */ | |
| 97 | Entry getEntry(Collection col, Key key); | |
| 98 | ||
| 99 | /** | |
| 100 | * Obtains resource entry metadata from cache. | |
| 101 | * | |
| 102 | * @param col resource collection | |
| 103 | * @param key resource key | |
| 104 | * @return entry cached resource metadata or null if not present | |
| 105 | */ | |
| 106 | Entry getEntryMeta(Collection col, Key key); | |
| 107 | ||
| 108 | /** | |
| 109 | * Stores resource entry value in the cache | |
| 110 | * | |
| 111 | * @param col resource collection | |
| 112 | * @param key resource key | |
| 113 | * @param type resource type: COMPRESSED, UNCOMPRESSED, BINARY | |
| 114 | * @param value entry value | |
| 115 | * @param meta resource meta attributes map | |
| 116 | */ | |
| 117 | void putEntry(Collection col, Key key, int type, Value value, Map meta); | |
| 118 | ||
| 119 | /** | |
| 120 | * Stores resource meta entry in the cache | |
| 121 | * | |
| 122 | * @param col resource collection | |
| 123 | * @param key resource key | |
| 124 | * @param type resource type: COMPRESSED, UNCOMPRESSED, BINARY | |
| 125 | * @param meta resource metadata attributes map | |
| 126 | */ | |
| 127 | void putEntryMeta(Collection col, Key key, int type, Map meta); | |
| 128 | ||
| 129 | /** | |
| 130 | * Remove resource entry from the cache | |
| 131 | * | |
| 132 | * @param col resource collection | |
| 133 | * @param key resource key | |
| 134 | */ | |
| 135 | void removeEntry(Collection col, Key key); | |
| 136 | } |
|
||||||||||