1 package org.hibernate.engine; 3 4 import org.hibernate.EntityMode; 5 import org.hibernate.persister.collection.CollectionPersister; 6 import org.hibernate.pretty.MessageHelper; 7 import org.hibernate.type.Type; 8 9 10 11 import java.io.Serializable ; 12 13 18 public final class CollectionKey implements Serializable { 19 20 private final String role; 21 private final Serializable key; 22 private final Type keyType; 23 private final SessionFactoryImplementor factory; 24 private final int hashCode; 25 private EntityMode entityMode; 26 27 public CollectionKey(CollectionPersister persister, Serializable key, EntityMode em) { 28 this.entityMode = em; 29 this.role = persister.getRole(); 30 this.key = key; 31 this.keyType = persister.getKeyType(); 32 this.factory = persister.getFactory(); 33 this.hashCode = getHashCode(); } 35 36 public boolean equals(Object other) { 37 CollectionKey that = (CollectionKey) other; 38 return that.role.equals(role) && 39 keyType.isEqual(that.key, key, entityMode, factory); 40 } 41 42 public int getHashCode() { 43 int result = 17; 44 result = 37 * result + role.hashCode(); 45 result = 37 * result + keyType.getHashCode(key, entityMode, factory); 46 return result; 47 } 48 49 public int hashCode() { 50 return hashCode; 51 } 52 53 public String getRole() { 54 return role; 55 } 56 57 public Serializable getKey() { 58 return key; 59 } 60 61 public String toString() { 62 return "CollectionKey" + 63 MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory ); 64 } 65 } | Popular Tags |