Filter:   InfoImg
download Key.java
Language: Java
LOC: 31
Project Info
Hibernate
Server: SourceForge
Type: cvs
...te\cirrus\hibernate\engine\
   Batcher.java
   Cascades.java
   Key.java
   Mapping.java
   ...FactoryImplementor.java
   SessionImplementor.java
   Versioning.java

//$Id: Key.java,v 1.5 2003/03/20 13:58:45 oneovthafew Exp $
package cirrus.hibernate.engine;

import java.io.Serializable;

import cirrus.hibernate.AssertionFailure;
import cirrus.hibernate.impl.CollectionPersister;
import cirrus.hibernate.persister.ClassPersister;

/**
 * A globally unique identifier of an instance, consisting of the 
 * user-visible identifier and the identifier space (eg. tablename).
 */
public final class Key implements Serializable {
	private final Serializable id;
	private final Serializable identifierSpace;

	private Key(Serializable id, Serializable identifierSpace) {
		if (id==null) throw new AssertionFailure("null identifier");
		this.id=id;
		this.identifierSpace = identifierSpace;
	}
	
	/**
	 * Construct a unique identifier for an entity class instance
	 */
	public Key(Serializable id, ClassPersister p) {
		this( id, p.getIdentifierSpace() );
	}
	
	/**
	 * Construct a unique identifier for a collection instance
	 */
	public Key(Serializable id, CollectionPersister p) {
		this( id, p.getQualifiedTableName() );
	}
	
	/**
	 * Get the user-visible identifier
	 */
	public Serializable getIdentifier() {
		return id;
	}
	
	public boolean equals(Object other) {
		Key otherKey = (Key) other;
		return otherKey.identifierSpace.equals(this.identifierSpace) && otherKey.id.equals(this.id);
	}

	public int hashCode() { return id.hashCode(); }
	
	public String toString() {
		return id.toString();
	}
}