Debian Codegraph @

lang/java/src/com/sleepycat/persist/model/EntityMetadata.java

raw
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 import java.io.Serializable;
11 import java.util.Map;
12
13 /**
14 * The metadata for a persistent entity class. An entity class may be
15 * specified with the {@link Entity} annotation.
16 *
17 * <p>{@code EntityMetadata} objects are thread-safe. Multiple threads may
18 * safely call the methods of a shared {@code EntityMetadata} object.</p>
19 *
20 * @author Mark Hayes
21 */
22 public class EntityMetadata implements Serializable {
23
24 private static final long serialVersionUID = 4224509631681963159L;
25
26 private String className;
27 private PrimaryKeyMetadata primaryKey;
28 private Map<String, SecondaryKeyMetadata> secondaryKeys;
29
30 /**
31 * Used by an {@code EntityModel} to construct entity metadata.
32 */
33 public EntityMetadata(String className,
34 PrimaryKeyMetadata primaryKey,
35 Map<String, SecondaryKeyMetadata> secondaryKeys) {
36 this.className = className;
37 this.primaryKey = primaryKey;
38 this.secondaryKeys = secondaryKeys;
39 }
40
41 /**
42 * Returns the name of the entity class.
43 */
44 public String getClassName() {
45 return className;
46 }
47
48 /**
49 * Returns the primary key metadata for this entity. Note that the primary
50 * key field may be declared in this class or in a subclass. This metadata
51 * may be specified using the {@link PrimaryKey} annotation.
52 */
53 public PrimaryKeyMetadata getPrimaryKey() {
54 return primaryKey;
55 }
56
57 /**
58 * Returns an unmodifiable map of key name to secondary key metadata, or
59 * an empty map if no secondary keys are defined for this entity. The
60 * returned map contains a mapping for each secondary key of this entity,
61 * including secondary keys declared in subclasses and superclasses. This
62 * metadata may be specified using {@link SecondaryKey} annotations.
63 */
64 public Map<String, SecondaryKeyMetadata> getSecondaryKeys() {
65 return secondaryKeys;
66 }
67
68 @Override
69 public boolean equals(Object other) {
70 if (other instanceof EntityMetadata) {
71 EntityMetadata o = (EntityMetadata) other;
72 return ClassMetadata.nullOrEqual(className, o.className) &&
73 ClassMetadata.nullOrEqual(primaryKey, o.primaryKey) &&
74 ClassMetadata.nullOrEqual(secondaryKeys, o.secondaryKeys);
75 } else {
76 return false;
77 }
78 }
79
80 @Override
81 public int hashCode() {
82 return ClassMetadata.hashCode(className) +
83 ClassMetadata.hashCode(primaryKey) +
84 ClassMetadata.hashCode(secondaryKeys);
85 }
86 }