KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > ColumnElementImpl


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
20 package org.netbeans.modules.dbschema.jdbcimpl;
21
22 import org.netbeans.modules.dbschema.*;
23
24 public class ColumnElementImpl extends DBMemberElementImpl implements ColumnElement.Impl {
25
26     protected int _type;
27     protected boolean _isNullable;
28     protected Integer JavaDoc _length;
29     protected Integer JavaDoc _precision;
30     protected Integer JavaDoc _scale;
31
32     /** Creates new ColumnElementImpl */
33     public ColumnElementImpl() {
34     }
35
36     /** Creates new ColumnElementImpl with the specified name */
37     public ColumnElementImpl (String JavaDoc name) {
38         super(name);
39     }
40
41     /** Creates new ColumnElementImpl */
42     public ColumnElementImpl(String JavaDoc name, String JavaDoc type, String JavaDoc isNullable, String JavaDoc size, String JavaDoc decimal) {
43         super(name);
44         
45         _type = new Integer JavaDoc(type).intValue();
46         int nullable = new Integer JavaDoc(isNullable).intValue();
47
48 /*
49         if (isNullable.trim().equals("YES")) //NOI18N
50             _isNullable = true;
51         else
52             _isNullable = false;
53 */

54         if (nullable == 0)
55             //not allows null (0)
56
_isNullable = false;
57         else
58             //allows null (1) or nobody knows (2)
59
_isNullable = true;
60         
61         if (size != null)
62             _length = new Integer JavaDoc(size);
63         else
64             _length = null;
65
66         if (size != null)
67             _precision = new Integer JavaDoc(size);
68         else
69             _precision = new Integer JavaDoc(0);
70
71         if (decimal != null)
72             _scale = new Integer JavaDoc(decimal);
73         else
74             _scale = null;
75     }
76   
77     /** Get the value type of the column.
78      * @return the type
79      */

80     public int getType() {
81         return _type;
82     }
83   
84     /** Set the value type of the column.
85      * @param type the type
86      * @throws DBException if impossible
87      */

88     public void setType(int type) throws DBException {
89         _type = type;
90     }
91   
92     /** Returns whether the column is nullable.
93      * @return a flag representing whether the column is nullable
94      */

95     public boolean isNullable() {
96         return _isNullable;
97     }
98   
99     /** Set whether the column is nullable.
100      * @param flag flag representing whether the column is nullable
101      * @throws DBException if impossible
102      */

103     public void setNullable(boolean isNullable) throws DBException {
104         _isNullable = isNullable;
105     }
106   
107     /** Get the length of the column - for character type fields only.
108      * @return the length, <code>null</code> if it is not a character type
109      * field or there is no length.
110      */

111     public Integer JavaDoc getLength() {
112         return _length;
113     }
114   
115     /** Set the length of the column - for character type fields only.
116      * @param length the length for the column if it a character type
117      * @throws DBException if impossible
118      */

119     public void setLength(Integer JavaDoc length) throws DBException {
120         _length = length;
121     }
122   
123     /** Get the precision of the column - for numeric type fields only.
124      * @return the precision, <code>null</code> if it is not a numeric type
125      * field or there is no precision.
126      */

127     public Integer JavaDoc getPrecision() {
128         return _precision;
129     }
130   
131     /** Set the precision of the column - for numeric type fields only.
132      * @param precision the precision for the column if it a numeric type
133      * @throws DBException if impossible
134      */

135     public void setPrecision(Integer JavaDoc precision) throws DBException {
136         _precision = precision;
137     }
138   
139     /** Get the scale of the column - for numeric type fields only.
140      * @return the scale, <code>null</code> if it is not a numeric type
141      * field or there is no scale.
142      */

143     public Integer JavaDoc getScale() {
144         return _scale;
145     }
146   
147     /** Set the scale of the column - for numeric type fields only.
148      * @param scale the scale for the column if it a numeric type
149      * @throws DBException if impossible
150      */

151     public void setScale(Integer JavaDoc scale) throws DBException {
152         _scale = scale;
153     }
154 }
155
Popular Tags