1 package org.hibernate.engine; 3 4 import org.hibernate.EntityMode; 5 import org.hibernate.pretty.MessageHelper; 6 import org.hibernate.type.Type; 7 8 11 public class EntityUniqueKey { 12 private final String uniqueKeyName; 13 private final String entityName; 14 private final Object key; 15 private final Type keyType; 16 private final EntityMode entityMode; 17 private final int hashCode; 18 19 public EntityUniqueKey( 20 final String entityName, 21 final String uniqueKeyName, 22 final Object 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 getEntityName() { 36 return entityName; 37 } 38 39 public Object getKey() { 40 return key; 41 } 42 43 public String 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 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 toString() { 67 return "EntityUniqueKey" + MessageHelper.infoString(entityName, uniqueKeyName, key); 68 } 69 } 70 | Popular Tags |