2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2002, 2012 Oracle and/or its affiliates. All rights reserved.
8 package com.sleepycat.persist.model;
11 * The metadata for a secondary key field. A secondary key may be specified
12 * with the {@link SecondaryKey} annotation.
14 * <p>{@code SecondaryKeyMetadata} objects are thread-safe. Multiple threads
15 * may safely call the methods of a shared {@code SecondaryKeyMetadata}
20 public class SecondaryKeyMetadata extends FieldMetadata {
22 private static final long serialVersionUID = 8118924993396722502L;
24 private String keyName;
25 private Relationship relationship;
26 private String elementClassName;
27 private String relatedEntity;
28 private DeleteAction deleteAction;
31 * Used by an {@code EntityModel} to construct secondary key metadata.
33 public SecondaryKeyMetadata(String name,
35 String declaringClassName,
36 String elementClassName,
38 Relationship relationship,
40 DeleteAction deleteAction) {
41 super(name, className, declaringClassName);
42 this.elementClassName = elementClassName;
43 this.keyName = keyName;
44 this.relationship = relationship;
45 this.relatedEntity = relatedEntity;
46 this.deleteAction = deleteAction;
50 * Returns the class name of the array or collection element for a {@link
51 * Relationship#ONE_TO_MANY ONE_TO_MANY} or {@link
52 * Relationship#MANY_TO_MANY MANY_TO_MANY} relationship, or null for a
53 * Relationship#ONE_TO_ONE ONE_TO_ONE} or {@link Relationship#MANY_TO_ONE
54 * MANY_TO_ONE} relationship.
56 public String getElementClassName() {
57 return elementClassName;
61 * Returns the key name, which may be different from the field name.
63 public String getKeyName() {
68 * Returns the relationship between instances of the entity class and the
69 * secondary keys. This may be specified using the {@link
70 * SecondaryKey#relate} annotation.
72 public Relationship getRelationship() {
77 * Returns the class name of the related (foreign) entity, for which
78 * foreign key constraints are specified using the {@link
79 * SecondaryKey#relatedEntity} annotation.
81 public String getRelatedEntity() {
86 * Returns the action to take when a related entity is deleted having a
87 * primary key value that exists as a secondary key value for this entity.
88 * This may be specified using the {@link
89 * SecondaryKey#onRelatedEntityDelete} annotation.
91 public DeleteAction getDeleteAction() {
96 public boolean equals(Object other) {
97 if (other instanceof SecondaryKeyMetadata) {
98 SecondaryKeyMetadata o = (SecondaryKeyMetadata) other;
99 return super.equals(o) &&
100 relationship == o.relationship &&
101 ClassMetadata.nullOrEqual(deleteAction, o.deleteAction) &&
102 ClassMetadata.nullOrEqual(keyName, o.keyName) &&
103 ClassMetadata.nullOrEqual(elementClassName,
104 o.elementClassName) &&
105 ClassMetadata.nullOrEqual(relatedEntity, o.relatedEntity);
112 public int hashCode() {
113 return super.hashCode() +
114 relationship.hashCode() +
115 ClassMetadata.hashCode(deleteAction) +
116 ClassMetadata.hashCode(keyName) +
117 ClassMetadata.hashCode(elementClassName) +
118 ClassMetadata.hashCode(relatedEntity);