• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/java/src/com/sleepycat/persist/model/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9package com.sleepycat.persist.model;
10
11/**
12 * The metadata for a primary key field.  A primary key may be specified with
13 * the {@link PrimaryKey} annotation.
14 *
15 * <p>{@code PrimaryKeyMetadata} objects are thread-safe.  Multiple threads may
16 * safely call the methods of a shared {@code PrimaryKeyMetadata} object.</p>
17 *
18 * @author Mark Hayes
19 */
20public class PrimaryKeyMetadata extends FieldMetadata {
21
22    private static final long serialVersionUID = 2946863622972437018L;
23
24    private String sequenceName;
25
26    /**
27     * Used by an {@code EntityModel} to construct primary key metadata.
28     */
29    public PrimaryKeyMetadata(String name,
30                              String className,
31                              String declaringClassName,
32                              String sequenceName) {
33        super(name, className, declaringClassName);
34        this.sequenceName = sequenceName;
35    }
36
37    /**
38     * Returns the name of the sequence for assigning key values.  This may be
39     * specified using the {@link PrimaryKey#sequence} annotation.
40     */
41    public String getSequenceName() {
42        return sequenceName;
43    }
44
45    @Override
46    public boolean equals(Object other) {
47        if (other instanceof PrimaryKeyMetadata) {
48            PrimaryKeyMetadata o = (PrimaryKeyMetadata) other;
49            return super.equals(o) &&
50                   ClassMetadata.nullOrEqual(sequenceName, o.sequenceName);
51        } else {
52            return false;
53        }
54    }
55
56    @Override
57    public int hashCode() {
58        return super.hashCode() + ClassMetadata.hashCode(sequenceName);
59    }
60}
61