001: /**********************************************************************
002: Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.cache;
019:
020: import java.util.Collection;
021:
022: /**
023: * Interface for any Level 2 Cache used by JPOX.
024: * Provides the typical controls required by JPOX itself and including the JDO2 DataStoreCache methods.
025: *
026: * @version $Revision: 1.7 $
027: */
028: public interface Level2Cache {
029: /**
030: * Evict the parameter instance from the second-level cache.
031: * @param oid the object id of the instance to evict.
032: */
033: void evict(Object oid);
034:
035: /**
036: * Evict the parameter instances from the second-level cache.
037: * All instances in the PersistenceManager's cache are evicted
038: * from the second-level cache.
039: */
040: void evictAll();
041:
042: /**
043: * Evict the parameter instances from the second-level cache.
044: * @param oids the object ids of the instance to evict.
045: */
046: void evictAll(Object[] oids);
047:
048: /**
049: * Evict the parameter instances from the second-level cache.
050: * @param oids the object ids of the instance to evict.
051: */
052: void evictAll(Collection oids);
053:
054: /**
055: * Evict the parameter instances from the second-level cache.
056: * @param pcClass the class of instances to evict
057: * @param subclasses if true, evict instances of subclasses also
058: */
059: void evictAll(Class pcClass, boolean subclasses);
060:
061: /**
062: * Pin the parameter instance in the second-level cache.
063: * @param oid the object id of the instance to pin.
064: */
065: void pin(Object oid);
066:
067: /**
068: * Pin the parameter instances in the second-level cache.
069: * @param oids the object ids of the instances to pin.
070: */
071: void pinAll(Collection oids);
072:
073: /**
074: * Pin the parameter instances in the second-level cache.
075: * @param oids the object ids of the instances to pin.
076: */
077: void pinAll(Object[] oids);
078:
079: /**
080: * Pin instances in the second-level cache.
081: * @param pcClass the class of instances to pin
082: * @param subclasses if true, pin instances of subclasses also
083: */
084: void pinAll(Class pcClass, boolean subclasses);
085:
086: /**
087: * Unpin the parameter instance from the second-level cache.
088: * @param oid the object id of the instance to unpin.
089: */
090: void unpin(Object oid);
091:
092: /**
093: * Unpin the parameter instances from the second-level cache.
094: * @param oids the object ids of the instance to evict.
095: */
096: void unpinAll(Collection oids);
097:
098: /**
099: * Unpin the parameter instance from the second-level cache.
100: * @param oids the object id of the instance to evict.
101: */
102: void unpinAll(Object[] oids);
103:
104: /**
105: * Unpin instances from the second-level cache.
106: * @param pcClass the class of instances to unpin
107: * @param subclasses if true, unpin instances of subclasses also
108: */
109: void unpinAll(Class pcClass, boolean subclasses);
110:
111: /**
112: * Accessor for the number of pinned objects in the cache.
113: * @return Number of pinned objects
114: */
115: int getNumberOfPinnedObjects();
116:
117: /**
118: * Accessor for the number of unpinned objects in the cache.
119: * @return Number of unpinned objects
120: */
121: int getNumberOfUnpinnedObjects();
122:
123: /**
124: * Accessor for the total number of objects in the L2 cache.
125: * @return Number of objects
126: */
127: int getSize();
128:
129: /**
130: * Accessor for an object from the cache.
131: * @param oid The Object ID
132: * @return The L2 cacheable object
133: */
134: CachedPC get(Object oid);
135:
136: /**
137: * Method to put an object in the cache.
138: * @param oid The Object id for this object
139: * @param pc The L2 cacheable PersistenceCapable object
140: * @return The value previously associated with this oid
141: */
142: CachedPC put(Object oid, CachedPC pc);
143:
144: /**
145: * Accessor for whether the cache is empty.
146: * @return Whether it is empty.
147: */
148: boolean isEmpty();
149:
150: /**
151: * Method to clear the cache.
152: */
153: void clear();
154:
155: /**
156: * Accessor for whether an object with the specified id is in the cache
157: * @param oid The object id
158: * @return Whether it is in the cache
159: */
160: boolean containsOid(Object oid);
161:
162: /**
163: * Representation of a class whose objects will be pinned when put into the L2 cache.
164: * @version $Revision: 1.7 $
165: */
166: class PinnedClass {
167: Class cls;
168: boolean subclasses;
169:
170: /**
171: * Constructor
172: * @param cls the class
173: * @param subclasses sub classes
174: */
175: public PinnedClass(Class cls, boolean subclasses) {
176: this .cls = cls;
177: this .subclasses = subclasses;
178: }
179:
180: public boolean equals(Object obj) {
181: if (obj == null) {
182: return false;
183: }
184: if (!(obj instanceof PinnedClass)) {
185: return false;
186: }
187: PinnedClass other = (PinnedClass) obj;
188: return other.cls.getName().equals(cls.getName())
189: && other.subclasses == subclasses;
190: }
191: }
192: }
|