KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > mapping > IdentifierCollection


1 //$Id: IdentifierCollection.java,v 1.2 2004/08/08 04:56:01 oneovthafew Exp $
2
package org.hibernate.mapping;
3
4 import org.hibernate.MappingException;
5 import org.hibernate.engine.Mapping;
6
7 /**
8  * A collection with a synthetic "identifier" column
9  */

10 public abstract class IdentifierCollection extends Collection {
11
12     public static final String JavaDoc DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
13
14     private KeyValue identifier;
15
16     public IdentifierCollection(PersistentClass owner) {
17         super(owner);
18     }
19
20     public KeyValue getIdentifier() {
21         return identifier;
22     }
23     public void setIdentifier(KeyValue identifier) {
24         this.identifier = identifier;
25     }
26     public final boolean isIdentified() {
27         return true;
28     }
29
30     void createPrimaryKey() {
31         if ( !isOneToMany() ) {
32             PrimaryKey pk = new PrimaryKey();
33             pk.addColumns( getIdentifier().getColumnIterator() );
34             getCollectionTable().setPrimaryKey(pk);
35         }
36         else {
37             // don't create a unique key, 'cos some
38
// databases don't like a UK on nullable
39
// columns
40
//getCollectionTable().createUniqueKey( getIdentifier().getConstraintColumns() );
41
}
42         // create an index on the key columns??
43
}
44
45     public void validate(Mapping mapping) throws MappingException {
46         super.validate(mapping);
47         if ( !getIdentifier().isValid(mapping) ) {
48             throw new MappingException(
49                 "collection id mapping has wrong number of columns: " +
50                 getRole() +
51                 " type: " +
52                 getIdentifier().getType().getName()
53             );
54         }
55     }
56
57 }
58
59
60
61
62
63
64
65
Popular Tags