1
//$Id: CollectionKey.java 9194 2006-02-01 19:59:07Z steveebersole $
2
package org.hibernate.engine;
4
import org.hibernate.EntityMode;
5
import org.hibernate.persister.collection.CollectionPersister;
6
import org.hibernate.pretty.MessageHelper;
7
import org.hibernate.type.Type;
11
import java.io.Serializable;
12
import java.io.ObjectOutputStream;
13
import java.io.IOException;
14
import java.io.ObjectInputStream;
17
* Uniquely identifies a collection instance in a particular session.
21
public final class CollectionKey implements Serializable {
23
private final String role;
24
private final Serializable key;
25
private final Type keyType;
26
private final SessionFactoryImplementor factory;
27
private final int hashCode;
28
private EntityMode entityMode;
30
public CollectionKey(CollectionPersister persister, Serializable key, EntityMode em) {
31
this( persister.getRole(), key, persister.getKeyType(), em, persister.getFactory() );
34
private CollectionKey(
38
EntityMode entityMode,
39
SessionFactoryImplementor factory) {
42
this.keyType = keyType;
43
this.entityMode = entityMode;
44
this.factory = factory;
45
this.hashCode = generateHashCode(); //cache the hashcode
48
public boolean equals(Object other) {
49
CollectionKey that = (CollectionKey) other;
50
return that.role.equals(role) &&
51
keyType.isEqual(that.key, key, entityMode, factory);
54
public int generateHashCode() {
56
result = 37 * result + role.hashCode();
57
result = 37 * result + keyType.getHashCode(key, entityMode, factory);
61
public int hashCode() {
65
public String getRole() {
69
public Serializable getKey() {
73
public String toString() {
74
return "CollectionKey" +
75
MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory );
79
* Custom serialization routine used during serialization of a
80
* Session/PersistenceContext for increased performance.
82
* @param oos The stream to which we should write the serial data.
83
* @throws java.io.IOException
85
void serialize(ObjectOutputStream oos) throws IOException {
86
oos.writeObject( role );
87
oos.writeObject( key );
88
oos.writeObject( keyType );
89
oos.writeObject( entityMode.toString() );
93
* Custom deserialization routine used during deserialization of a
94
* Session/PersistenceContext for increased performance.
96
* @param ois The stream from which to read the entry.
97
* @param session The session being deserialized.
98
* @return The deserialized CollectionKey
100
* @throws ClassNotFoundException
102
static CollectionKey deserialize(
103
ObjectInputStream ois,
104
SessionImplementor session) throws IOException, ClassNotFoundException {
105
return new CollectionKey(
106
( String ) ois.readObject(),
107
( Serializable ) ois.readObject(),
108
( Type ) ois.readObject(),
109
EntityMode.parse( ( String ) ois.readObject() ),
b'\\ No newline at end of file'