KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > identitymaps > WeakCacheKey


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.identitymaps;
23
24 import java.lang.ref.*;
25 import java.util.Vector JavaDoc;
26
27 /**
28  * <p><b>Purpose</b>: Container class for storing objects in an IdentityMap.
29  * The weak cache key uses a weak reference to allow garbage collection of its object.
30  * The cache key itself however will remain and thus should cleaned up every no and then.
31  * <p><b>Responsibilities</b>:<ul>
32  * <li> Hold key and object.
33  * <li> Maintain and update the current writeLockValue.
34  * </ul>
35  * @since TOPLink/Java 1.0
36  */

37 public class WeakCacheKey extends CacheKey {
38
39     /** Reference is maintained weak to allow garbage collection */
40     protected WeakReference reference;
41
42     /**
43      * Initialize the newly allocated instance of this class.
44      * @param primaryKey contains values extracted from the object
45      * @param writeLockValue is the write lock value, null if optimistic locking not being used for this object.
46      * @param readTime the time TopLInk read the cache key
47      */

48     public WeakCacheKey(Vector JavaDoc primaryKey, Object JavaDoc object, Object JavaDoc writeLockValue, long readTime) {
49         super(primaryKey, object, writeLockValue, readTime);
50     }
51
52     public Object JavaDoc getObject() {
53         return getReference().get();
54     }
55
56     public WeakReference getReference() {
57         return reference;
58     }
59
60     public void setObject(Object JavaDoc object) {
61         setReference(new WeakReference(object));
62     }
63
64     protected void setReference(WeakReference reference) {
65         this.reference = reference;
66     }
67 }
68
Popular Tags