KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > engine > CollectionKey


1 //$Id: CollectionKey.java,v 1.6 2005/02/16 12:50:12 oneovthafew Exp $
2
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 JavaDoc;
12
13 /**
14  * Uniquely identifies a collection instance in a particular session.
15  *
16  * @author Gavin King
17  */

18 public final class CollectionKey implements Serializable JavaDoc {
19
20     private final String JavaDoc role;
21     private final Serializable JavaDoc 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 JavaDoc 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(); //cache the hashcode
34
}
35
36     public boolean equals(Object JavaDoc 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 JavaDoc getRole() {
54         return role;
55     }
56
57     public Serializable JavaDoc getKey() {
58         return key;
59     }
60
61     public String JavaDoc toString() {
62         return "CollectionKey" +
63             MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory );
64     }
65 }
Popular Tags