KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > columns > MetadataColumn


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns;
23
24 import java.lang.reflect.AnnotatedElement JavaDoc;
25
26 import javax.persistence.Column;
27 import javax.persistence.AttributeOverride;
28
29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.MetadataAccessor;
30 import oracle.toplink.essentials.internal.helper.DatabaseField;
31
32 /**
33  * Object to hold onto column metadata in a TopLink database field.
34  *
35  * @author Guy Pelletier
36  * @since TopLink EJB 3.0 Reference Implementation
37  */

38 public class MetadataColumn {
39     protected String JavaDoc m_attributeName;
40     protected DatabaseField m_databaseField;
41     protected AnnotatedElement JavaDoc m_annotatedElement;
42     
43     public static final int DEFAULT_SCALE = 0;
44     public static final int DEFAULT_LENGTH = 255;
45     public static final int DEFAULT_PRECISION = 0;
46     
47     public static final String JavaDoc DEFAULT_NAME = "";
48     public static final String JavaDoc DEFAULT_TABLE = "";
49     public static final String JavaDoc DEFAULT_COLUMN_DEFINITION = "";
50     
51     public static final boolean DEFAULT_UNIQUE = false;
52     public static final boolean DEFAULT_NULLABLE = true;
53     public static final boolean DEFAULT_UPDATABLE = true;
54     public static final boolean DEFAULT_INSERTABLE = true;
55     
56     /**
57      * INTERNAL:
58      * Called for attribute overrides.
59      */

60     public MetadataColumn(AttributeOverride attributeOverride, AnnotatedElement JavaDoc annotatedElement) {
61         this(attributeOverride.column(), attributeOverride.name(), annotatedElement);
62     }
63     
64     /**
65      * INTERNAL:
66      * Called for basic mappings.
67      */

68     public MetadataColumn(Column column, MetadataAccessor accessor) {
69         this(column, accessor.getAttributeName(), accessor.getAnnotatedElement());
70     }
71     
72     /**
73      * INTERNAL:
74      */

75     public MetadataColumn(Column column, String JavaDoc attributeName, AnnotatedElement JavaDoc annotatedElement) {
76         this(attributeName, annotatedElement);
77         
78         if (column != null) {
79             // Apply the values from the column annotation.
80
m_databaseField.setUnique(column.unique());
81             m_databaseField.setNullable(column.nullable());
82             m_databaseField.setUpdatable(column.updatable());
83             m_databaseField.setInsertable(column.insertable());
84         
85             m_databaseField.setScale(column.scale());
86             m_databaseField.setLength(column.length());
87             m_databaseField.setPrecision(column.precision());
88         
89             m_databaseField.setName(column.name());
90             m_databaseField.setTableName(column.table());
91             m_databaseField.setColumnDefinition(column.columnDefinition());
92         }
93     }
94     
95     /**
96      * INTERNAL:
97      * Initialize the database field with the default values.
98      */

99     public MetadataColumn(String JavaDoc attributeName, AnnotatedElement JavaDoc annotatedElement) {
100         m_attributeName = attributeName;
101         m_annotatedElement = annotatedElement;
102         m_databaseField = new DatabaseField();
103      
104         // Apply default values.
105
m_databaseField.setUnique(DEFAULT_UNIQUE);
106         m_databaseField.setNullable(DEFAULT_NULLABLE);
107         m_databaseField.setUpdatable(DEFAULT_UPDATABLE);
108         m_databaseField.setInsertable(DEFAULT_INSERTABLE);
109         
110         m_databaseField.setScale(DEFAULT_SCALE);
111         m_databaseField.setLength(DEFAULT_LENGTH);
112         m_databaseField.setPrecision(DEFAULT_PRECISION);
113         
114         m_databaseField.setName(DEFAULT_NAME);
115         m_databaseField.setTableName(DEFAULT_TABLE);
116         m_databaseField.setColumnDefinition(DEFAULT_COLUMN_DEFINITION);
117     }
118     
119     /**
120      * INTERNAL:
121      */

122     public AnnotatedElement JavaDoc getAnnotatedElement() {
123         return m_annotatedElement;
124     }
125     
126     /**
127      * INTERNAL:
128      */

129     public String JavaDoc getAttributeName() {
130         return m_attributeName;
131     }
132     
133     /**
134      * INTERNAL:
135      */

136     public DatabaseField getDatabaseField() {
137         return m_databaseField;
138     }
139     
140     /**
141      * INTERNAL:
142      */

143     public String JavaDoc getUpperCaseAttributeName() {
144         return m_attributeName.toUpperCase();
145     }
146     
147     /**
148      * INTERNAL:
149      */

150     public boolean loadedFromXML() {
151         return false;
152     }
153 }
154
Popular Tags