~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/mapping/IdentifierCollection.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: IdentifierCollection.java 4173 2004-08-08 04:56:01Z oneovthafew $
 
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 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