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