1 package org.hibernate.engine; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.AssertionFailure; 7 import org.hibernate.EntityMode; 8 import org.hibernate.persister.entity.EntityPersister; 9 import org.hibernate.pretty.MessageHelper; 10 import org.hibernate.type.Type; 11 12 19 public final class EntityKey implements Serializable { 20 private final Serializable identifier; 21 private final Serializable rootEntityName; 22 private final String entityName; 23 private final Type identifierType; 24 private final boolean isBatchLoadable; 25 private final SessionFactoryImplementor factory; 26 private final int hashCode; 27 private final EntityMode entityMode; 28 29 32 public EntityKey(Serializable id, EntityPersister persister, EntityMode entityMode) { 33 if (id==null) throw new AssertionFailure("null identifier"); 34 this.identifier = id; 35 this.entityMode = entityMode; 36 this.rootEntityName = persister.getRootEntityName(); 37 this.entityName = persister.getEntityName(); 38 this.identifierType = persister.getIdentifierType(); 39 this.isBatchLoadable = persister.isBatchLoadable(); 40 this.factory = persister.getFactory(); 41 hashCode = getHashCode(); } 43 44 public boolean isBatchLoadable() { 45 return isBatchLoadable; 46 } 47 48 51 public Serializable getIdentifier() { 52 return identifier; 53 } 54 55 public String getEntityName() { 56 return entityName; 57 } 58 59 public boolean equals(Object other) { 60 EntityKey otherKey = (EntityKey) other; 61 return otherKey.rootEntityName.equals(this.rootEntityName) && 62 identifierType.isEqual(otherKey.identifier, this.identifier, entityMode, factory); 63 } 64 65 private int getHashCode() { 66 int result = 17; 67 result = 37 * result + rootEntityName.hashCode(); 68 result = 37 * result + identifierType.getHashCode(identifier, entityMode, factory); 69 return result; 70 } 71 72 public int hashCode() { 73 return hashCode; 74 } 75 76 public String toString() { 77 return "EntityKey" + 78 MessageHelper.infoString( factory.getEntityPersister(entityName), identifier, factory ); 79 } 80 81 } 82 | Popular Tags |