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