KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > model > PrimaryKeyMetadata


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: PrimaryKeyMetadata.java,v 1.11 2006/12/05 01:35:37 mark Exp $
7  */

8
9 package com.sleepycat.persist.model;
10
11
12 /**
13  * The metadata for a primary key field. A primary key may be specified with
14  * the {@link PrimaryKey} annotation.
15  *
16  * <p>{@code PrimaryKeyMetadata} objects are thread-safe. Multiple threads may
17  * safely call the methods of a shared {@code PrimaryKeyMetadata} object.</p>
18  *
19  * @author Mark Hayes
20  */

21 public class PrimaryKeyMetadata extends FieldMetadata {
22
23     private static final long serialVersionUID = 2946863622972437018L;
24     
25     private String JavaDoc sequenceName;
26
27     /**
28      * Used by an {@code EntityModel} to construct primary key metadata.
29      */

30     public PrimaryKeyMetadata(String JavaDoc name,
31                               String JavaDoc className,
32                               String JavaDoc declaringClassName,
33                               String JavaDoc sequenceName) {
34         super(name, className, declaringClassName);
35         this.sequenceName = sequenceName;
36     }
37
38     /**
39      * Returns the name of the sequence for assigning key values. This may be
40      * specified using the {@link PrimaryKey#sequence} annotation.
41      */

42     public String JavaDoc getSequenceName() {
43         return sequenceName;
44     }
45
46     @Override JavaDoc
47     public boolean equals(Object JavaDoc other) {
48         if (other instanceof PrimaryKeyMetadata) {
49             PrimaryKeyMetadata o = (PrimaryKeyMetadata) other;
50             return super.equals(o) &&
51                    ClassMetadata.nullOrEqual(sequenceName, o.sequenceName);
52         } else {
53             return false;
54         }
55     }
56
57     @Override JavaDoc
58     public int hashCode() {
59         return super.hashCode() + ClassMetadata.hashCode(sequenceName);
60     }
61 }
62
Popular Tags