1 package org.hibernate.cache; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.EntityMode; 7 import org.hibernate.engine.SessionFactoryImplementor; 8 import org.hibernate.type.Type; 9 10 17 public class CacheKey implements Serializable { 18 private final Serializable key; 19 private final Type type; 20 private final String entityOrRoleName; 21 private final EntityMode entityMode; 22 private final int hashCode; 23 24 29 public CacheKey( 30 final Serializable id, 31 final Type type, 32 final String entityOrRoleName, 33 final EntityMode entityMode, 34 final SessionFactoryImplementor factory 35 ) { 36 this.key = id; 37 this.type = type; 38 this.entityOrRoleName = entityOrRoleName; 39 this.entityMode = entityMode; 40 hashCode = type.getHashCode(key, entityMode, factory); 41 } 42 43 public String toString() { 45 return entityOrRoleName + '#' + key.toString(); } 47 48 public boolean equals(Object other) { 49 if ( !(other instanceof CacheKey) ) return false; 50 CacheKey that = (CacheKey) other; 51 return type.isEqual(key, that.key, entityMode) && 52 entityOrRoleName.equals(that.entityOrRoleName); 53 } 54 55 public int hashCode() { 56 return hashCode; 57 } 58 59 public Serializable getKey() { 60 return key; 61 } 62 63 public String getEntityOrRoleName() { 64 return entityOrRoleName; 65 } 66 67 } 68 | Popular Tags |