KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: EntityUniqueKey.java,v 1.7 2005/05/11 22:12:16 oneovthafew Exp $
2
package org.hibernate.engine;
3
4 import org.hibernate.EntityMode;
5 import org.hibernate.pretty.MessageHelper;
6 import org.hibernate.type.Type;
7
8 /**
9  * @author Gavin King
10  */

11 public class EntityUniqueKey {
12     private final String JavaDoc uniqueKeyName;
13     private final String JavaDoc entityName;
14     private final Object JavaDoc key;
15     private final Type keyType;
16     private final EntityMode entityMode;
17     private final int hashCode;
18     
19     public EntityUniqueKey(
20             final String JavaDoc entityName,
21             final String JavaDoc uniqueKeyName,
22             final Object JavaDoc semiResolvedKey,
23             final Type keyType,
24             final EntityMode entityMode,
25             final SessionFactoryImplementor factory
26     ) {
27         this.uniqueKeyName = uniqueKeyName;
28         this.entityName = entityName;
29         this.key = semiResolvedKey;
30         this.keyType = keyType.getSemiResolvedType(factory);
31         this.entityMode = entityMode;
32         this.hashCode = getHashCode(factory);
33     }
34
35     public String JavaDoc getEntityName() {
36         return entityName;
37     }
38
39     public Object JavaDoc getKey() {
40         return key;
41     }
42
43     public String JavaDoc getUniqueKeyName() {
44         return uniqueKeyName;
45     }
46     
47     public int getHashCode(SessionFactoryImplementor factory) {
48         int result = 17;
49         result = 37 * result + entityName.hashCode();
50         result = 37 * result + uniqueKeyName.hashCode();
51         result = 37 * result + keyType.getHashCode(key, entityMode, factory);
52         return result;
53     }
54     
55     public int hashCode() {
56         return hashCode;
57     }
58     
59     public boolean equals(Object JavaDoc other) {
60         EntityUniqueKey that = (EntityUniqueKey) other;
61         return that.entityName.equals(entityName) &&
62             that.uniqueKeyName.equals(uniqueKeyName) &&
63             keyType.isEqual(that.key, key, entityMode);
64     }
65     
66     public String JavaDoc toString() {
67         return "EntityUniqueKey" + MessageHelper.infoString(entityName, uniqueKeyName, key);
68     }
69 }
70
Popular Tags