KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > entitygenerator > DbSchemaEntityMember


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.persistence.entitygenerator;
20
21 /**
22  * This class represents an instance of an member in an entity bean class which
23  * is backed by a ColumnElement representing a relational database.
24  * @author Christopher Webster
25  */

26
27 import org.netbeans.modules.dbschema.ColumnElement;
28 import org.netbeans.modules.dbschema.util.SQLTypeUtil;
29
30 class DbSchemaEntityMember extends EntityMember {
31
32    /**
33     * is this member part of primary key
34     */

35     private boolean isPrimaryKey;
36
37     /**
38      * Original mapping to sql type
39      */

40     private SQLType sqlType;
41
42     /**
43      * Column Element providing metadata
44      */

45     private ColumnElement columnElement;
46
47     public DbSchemaEntityMember(ColumnElement element) {
48         columnElement = element;
49         sqlType = SQLType.getSQLType(element.getType());
50         setMemberName(makeFieldName(element.getName().getName()));
51     isPrimaryKey = false;
52         setMemberType(sqlType.getMemberType(element));
53     }
54
55     public boolean isNullable() {
56         return columnElement.isNullable();
57     }
58
59     public boolean isPrimaryKey() {
60         return isPrimaryKey;
61     }
62
63     public void setPrimaryKey(boolean isPk, boolean isPkField) {
64         isPrimaryKey = isPk;
65
66         // this is relevant for CMP 2.1 and earlier where a pk field is not
67
// allowed to be of a primitive type, so the first corresponding class
68
// if extracted from the sqlType
69
if (isPkField) {
70             setMemberType(((Class JavaDoc)sqlType.getValidObjects().get(0)).getName());
71         }
72     }
73
74     private ColumnElement getColumnElement() {
75         return columnElement;
76     }
77     
78     public boolean supportsFinder() {
79         return sqlType.supportsFinder();
80     }
81     
82     public String JavaDoc getColumnName() {
83         return getColumnElement().getName().getName();
84     }
85     
86     public String JavaDoc getTableName() {
87         return getColumnElement().getDeclaringTable().getName().getName();
88     }
89
90     public boolean isLobType() {
91         return SQLTypeUtil.isLob(getColumnElement().getType());
92     }
93     
94 }
95
Popular Tags