KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > model > EntityMetadata


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: EntityMetadata.java,v 1.11 2006/12/05 01:35:37 mark Exp $
7  */

8
9 package com.sleepycat.persist.model;
10
11 import java.io.Serializable JavaDoc;
12 import java.util.Map JavaDoc;
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 JavaDoc {
24
25     private static final long serialVersionUID = 4224509631681963159L;
26
27     private String JavaDoc className;
28     private PrimaryKeyMetadata primaryKey;
29     private Map JavaDoc<String JavaDoc,SecondaryKeyMetadata> secondaryKeys;
30
31     /**
32      * Used by an {@code EntityModel} to construct entity metadata.
33      */

34     public EntityMetadata(String JavaDoc className,
35                           PrimaryKeyMetadata primaryKey,
36                           Map JavaDoc<String JavaDoc,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 JavaDoc 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 JavaDoc<String JavaDoc,SecondaryKeyMetadata> getSecondaryKeys() {
66         return secondaryKeys;
67     }
68
69     @Override JavaDoc
70     public boolean equals(Object JavaDoc other) {
71         if (other instanceof EntityMetadata) {
72             EntityMetadata o = (EntityMetadata) other;
73             return ClassMetadata.nullOrEqual(className, o.className) &&
74                    ClassMetadata.nullOrEqual(primaryKey, o.primaryKey) &&
75                    ClassMetadata.nullOrEqual(secondaryKeys, o.secondaryKeys);
76         } else {
77             return false;
78         }
79     }
80
81     @Override JavaDoc
82     public int hashCode() {
83         return ClassMetadata.hashCode(className) +
84                ClassMetadata.hashCode(primaryKey) +
85                ClassMetadata.hashCode(secondaryKeys);
86     }
87 }
88
Popular Tags