User: fleury
Date: 00/09/26 10:38:31
Modified: src/main/org/jboss/ejb CacheKey.java
Log:
The new cache key is a class and does the jonathan weedon based serialization
(based on the MarshalledObject)
Revision Changes Path
1.2 +101 -81 jboss/src/main/org/jboss/ejb/CacheKey.java
Index: CacheKey.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/CacheKey.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CacheKey.java 2000/08/25 01:48:27 1.1
+++ CacheKey.java 2000/09/26 17:38:31 1.2
@@ -1,81 +1,101 @@
-
-
-/*
-* jBoss, the OpenSource EJB server
-*
-* Distributable under GPL license.
-* See terms of license at gnu.org.
-*/
-package org.jboss.ejb;
-
-/**
-* CacheKey
-*
-* CacheKey is an encapsulation of both the PrimaryKey and any cache specific key
-*
-* There are several strategies to implement the cache.
-* One is to use the hash and equals of this class to implement tables
-* Another one is to work from the value of the CacheKey
-*
-* @see org.jboss.ejb.plugins.NoPassivationInstanceCache.java
-* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.1 $
-*/
-public class CacheKey
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // The database primaryKey
- public Object id;
-
- // In case the cache doesn't use advanced cache keys, this key is virtual
- public boolean isVirtual = false;
-
- // Static --------------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public CacheKey() {
- // For externalization only
- }
- public CacheKey(Object id) {
-
- if (id == null) throw new Error("id may not be null");
-
- this.id = id;
- }
- // Z implementation ----------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // HashCode and Equals over write --------------------------------
-
- /**
- * these should be overwritten by extending Cache key
- * since they define what the cache does in the first place
- */
- public int hashCode() {
-
- // we default to the pK id
- return id.hashCode();
- }
-
-
- public boolean equals(Object object) {
-
- if (object instanceof CacheKey) {
-
- return id.equals(((CacheKey) object).id);
- }
- return false;
- }
-
- // Inner classes -------------------------------------------------
-}
-
+
+
+/*
+* jBoss, the OpenSource EJB server
+*
+* Distributable under GPL license.
+* See terms of license at gnu.org.
+*/
+package org.jboss.ejb;
+
+/**
+* CacheKey
+*
+* CacheKey is an encapsulation of both the PrimaryKey and a cache specific key
+*
+* This implementation is a safe implementation in the sense that it doesn't rely
+* on the user supplied hashcode and equals. It is also fast since the hashCode
operation
+* is pre-calculated.
+*
+* @see org.jboss.ejb.plugins.NoPassivationInstanceCache.java
+* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
+* @version $Revision: 1.2 $
+*/
+public class CacheKey
+ implements java.io.Externalizable
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // The database primaryKey
+ public Object id;
+
+ private int hashCode;
+
+ // Static --------------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public CacheKey() {
+ // For externalization only
+ }
+ public CacheKey(Object id) {
+
+ if (id == null) throw new Error("id may not be null");
+
+ this.id = id;
+
+ try {
+ hashCode = new java.rmi.MarshalledObject(id).hashCode();
+ }
+ catch (Exception e) {e.printStackTrace();}
+ }
+
+ // Z implementation ----------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ public void writeExternal(java.io.ObjectOutput out)
+ throws java.io.IOException
+ {
+ out.writeObject(id);
+ out.write(hashCode);
+ }
+
+ public void readExternal(java.io.ObjectInput in)
+ throws java.io.IOException, ClassNotFoundException
+ {
+ id = in.readObject();
+ hashCode = in.read();
+ }
+
+ // HashCode and Equals over write --------------------------------
+
+ /**
+ * these should be overwritten by extending Cache key
+ * since they define what the cache does in the first place
+ */
+ public int hashCode() {
+
+ // we default to the pK id
+ return hashCode;
+ }
+
+
+ public boolean equals(Object object) {
+
+ if (object instanceof CacheKey) {
+
+ return (hashCode ==(((CacheKey) object).hashCode));
+ }
+ return false;
+ }
+
+ // Inner classes -------------------------------------------------
+}
+