001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.dbschema.jdbcimpl;
043:
044: import org.netbeans.modules.dbschema.*;
045:
046: public class ColumnElementImpl extends DBMemberElementImpl implements
047: ColumnElement.Impl {
048:
049: protected int _type;
050: protected boolean _isNullable;
051: protected Integer _length;
052: protected Integer _precision;
053: protected Integer _scale;
054:
055: /** Creates new ColumnElementImpl */
056: public ColumnElementImpl() {
057: }
058:
059: /** Creates new ColumnElementImpl with the specified name */
060: public ColumnElementImpl(String name) {
061: super (name);
062: }
063:
064: /** Creates new ColumnElementImpl */
065: public ColumnElementImpl(String name, String type,
066: String isNullable, String size, String decimal) {
067: super (name);
068:
069: _type = new Integer(type).intValue();
070: int nullable = new Integer(isNullable).intValue();
071:
072: /*
073: if (isNullable.trim().equals("YES")) //NOI18N
074: _isNullable = true;
075: else
076: _isNullable = false;
077: */
078: if (nullable == 0)
079: //not allows null (0)
080: _isNullable = false;
081: else
082: //allows null (1) or nobody knows (2)
083: _isNullable = true;
084:
085: if (size != null)
086: _length = new Integer(size);
087: else
088: _length = null;
089:
090: if (size != null)
091: _precision = new Integer(size);
092: else
093: _precision = new Integer(0);
094:
095: if (decimal != null)
096: _scale = new Integer(decimal);
097: else
098: _scale = null;
099: }
100:
101: /** Get the value type of the column.
102: * @return the type
103: */
104: public int getType() {
105: return _type;
106: }
107:
108: /** Set the value type of the column.
109: * @param type the type
110: * @throws DBException if impossible
111: */
112: public void setType(int type) throws DBException {
113: _type = type;
114: }
115:
116: /** Returns whether the column is nullable.
117: * @return a flag representing whether the column is nullable
118: */
119: public boolean isNullable() {
120: return _isNullable;
121: }
122:
123: /** Set whether the column is nullable.
124: * @param flag flag representing whether the column is nullable
125: * @throws DBException if impossible
126: */
127: public void setNullable(boolean isNullable) throws DBException {
128: _isNullable = isNullable;
129: }
130:
131: /** Get the length of the column - for character type fields only.
132: * @return the length, <code>null</code> if it is not a character type
133: * field or there is no length.
134: */
135: public Integer getLength() {
136: return _length;
137: }
138:
139: /** Set the length of the column - for character type fields only.
140: * @param length the length for the column if it a character type
141: * @throws DBException if impossible
142: */
143: public void setLength(Integer length) throws DBException {
144: _length = length;
145: }
146:
147: /** Get the precision of the column - for numeric type fields only.
148: * @return the precision, <code>null</code> if it is not a numeric type
149: * field or there is no precision.
150: */
151: public Integer getPrecision() {
152: return _precision;
153: }
154:
155: /** Set the precision of the column - for numeric type fields only.
156: * @param precision the precision for the column if it a numeric type
157: * @throws DBException if impossible
158: */
159: public void setPrecision(Integer precision) throws DBException {
160: _precision = precision;
161: }
162:
163: /** Get the scale of the column - for numeric type fields only.
164: * @return the scale, <code>null</code> if it is not a numeric type
165: * field or there is no scale.
166: */
167: public Integer getScale() {
168: return _scale;
169: }
170:
171: /** Set the scale of the column - for numeric type fields only.
172: * @param scale the scale for the column if it a numeric type
173: * @throws DBException if impossible
174: */
175: public void setScale(Integer scale) throws DBException {
176: _scale = scale;
177: }
178: }
|