User: fleury
Date: 00/08/24 18:48:27
Added: src/main/org/jboss/ejb CacheKey.java
EntityInstanceCache.java
Log:
New cache key and the EntityInstanceCache.
The caches for entity are responsible for creating the CacheKey they want. The rest
is transparent
Revision Changes Path
1.1 jboss/src/main/org/jboss/ejb/CacheKey.java
Index: CacheKey.java
===================================================================
/*
* 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 -------------------------------------------------
}
1.1 jboss/src/main/org/jboss/ejb/EntityInstanceCache.java
Index: EntityInstanceCache.java
===================================================================
package org.jboss.ejb;
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
import java.rmi.RemoteException;
import javax.ejb.NoSuchEntityException;
/**
* EntityCaches can work from several keys
*
* A cache can use the natural primaryKey from the EJBObject, or DB dependent
* keys or a proprietary key
*
* @see NoPassivationEntityInstanceCache.java
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
* @version $Revision: 1.1 $
*/
public interface EntityInstanceCache
extends InstanceCache
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
/**
* Returns the key used to cache the context
*
* @param id Object id / primary key
*
* @return Cache key
*/
public Object createCacheKey( Object id );
}