001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: *
022: * Copyright 2005 Sun Microsystems, Inc.
023: *
024: * Licensed under the Apache License, Version 2.0 (the "License");
025: * you may not use this file except in compliance with the License.
026: * You may obtain a copy of the License at
027: *
028: * http://www.apache.org/licenses/LICENSE-2.0
029: *
030: * Unless required by applicable law or agreed to in writing, software
031: * distributed under the License is distributed on an "AS IS" BASIS,
032: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
033: * See the License for the specific language governing permissions and
034: * limitations under the License.
035: *
036: */
037: package org.netbeans.modules.jdbcwizard.builder;
038:
039: /**
040: * Captures metadata information for a database table column.
041: *
042: * @author
043: */
044: public class TableColumn {
045: private String name = ""; // name of table column
046:
047: private String javaType; // Java type - ex. java.lang.String
048:
049: private String sqlType; // SQL type - ex. BIGINT, NUMERIC
050:
051: private int sqlTypeCode; // SQL type as java.sql.Types enumeration
052:
053: private boolean isNullable; // specifies if the column is nullable
054:
055: private boolean isSelected; // specifies if the column is selected
056:
057: private boolean isPrimaryKey; // specifies if the column is a primary key
058:
059: private boolean isForeignKey; // specifies if the column is a foreign key
060:
061: private int ordinalPosition = 1; // position of column among others in table
062:
063: private int numericPrecision; // numeric precision
064:
065: private int numericScale; // numeric scale
066:
067: private int numericRadix; // radix (number-base) for numeric values
068:
069: private String defaultValue;
070:
071: private String value; // added by Neena to hold the value of the column
072:
073: // constructors
074: /**
075: * Constructs an instance of TableColumn.
076: */
077: public TableColumn() {
078: this .name = "";
079: this .javaType = "";
080: this .sqlType = "";
081: this .sqlTypeCode = java.sql.Types.OTHER;
082:
083: this .isNullable = false;
084: this .isSelected = true;
085: this .isPrimaryKey = false;
086: this .isForeignKey = false;
087: }
088:
089: /**
090: * Constructs an instance of TableColumn using the given name.
091: *
092: * @param newName name of this new instance
093: */
094: public TableColumn(final String newName) {
095: this ();
096: this .name = newName;
097: }
098:
099: /**
100: * Constructs an instance of TableColumn using the given name and Java type.
101: *
102: * @param newName name of new instance
103: * @param newJavaType Java type of this new instance
104: */
105: public TableColumn(final String newName, final String newJavaType) {
106: this ();
107: this .name = newName;
108: this .javaType = newJavaType;
109: }
110:
111: /**
112: * Constructs a new instance of TableColumn using the given attributes.
113: *
114: * @param newName name of new instance
115: * @param newJavaType Java type of new instance
116: * @param newIsNullable true if column is nullable, false otherwise
117: * @param newIsSelected true if column is selected, false otherwise
118: * @param newIsPrimaryKey true if column is PK, false otherwise
119: * @param newIsForeignKey true if column if FK, false otherwise
120: * @param newSqlTypeCode SQL type code as enumerated in java.sql.Types
121: */
122: public TableColumn(final String newName, final String newJavaType,
123: final boolean newIsNullable, final boolean newIsSelected,
124: final boolean newIsPrimaryKey,
125: final boolean newIsForeignKey, final int newSqlTypeCode) {
126: this .name = newName;
127: this .javaType = newJavaType;
128: this .isNullable = newIsNullable;
129: this .isSelected = newIsSelected;
130: this .isPrimaryKey = newIsPrimaryKey;
131: this .isForeignKey = newIsForeignKey;
132: this .sqlTypeCode = newSqlTypeCode;
133: }
134:
135: public TableColumn(final TableColumn tCol) {
136: this .name = tCol.getName();
137: this .javaType = tCol.getJavaType();
138: this .sqlType = tCol.getSqlType();
139: this .sqlTypeCode = tCol.getSqlTypeCode();
140: this .isNullable = tCol.getIsNullable();
141: this .isSelected = tCol.getIsSelected();
142: this .isPrimaryKey = tCol.getIsPrimaryKey();
143: this .isForeignKey = tCol.getIsForeignKey();
144: this .ordinalPosition = tCol.getOrdinalPosition();
145: this .numericPrecision = tCol.getNumericPrecision();
146: this .numericScale = tCol.getNumericScale();
147: this .numericRadix = tCol.getNumericRadix();
148: this .defaultValue = tCol.getDefaultValue();
149: this .value = tCol.getValue();
150: }
151:
152: // getters
153: /**
154: * Gets name of column.
155: *
156: * @return name
157: */
158: public String getName() {
159: return this .name;
160: }
161:
162: /**
163: * Gets Java type.
164: *
165: * @return Java type
166: */
167: public String getJavaType() {
168: return this .javaType;
169: }
170:
171: /**
172: * Gets JDBC SQL type.
173: *
174: * @return JDBC SQL type (as String)
175: */
176: public String getSqlType() {
177: return this .sqlType;
178: }
179:
180: /**
181: * Indicates whether column is nullable
182: *
183: * @return true if nullable, false otherwise
184: */
185: public boolean getIsNullable() {
186: return this .isNullable;
187: }
188:
189: /**
190: * Indicates whether column is selected
191: *
192: * @return true if selected, false otherwise
193: */
194: public boolean getIsSelected() {
195: return this .isSelected;
196: }
197:
198: /**
199: * Indicates whether column is primary key
200: *
201: * @return true if PK, false otherwise
202: */
203: public boolean getIsPrimaryKey() {
204: return this .isPrimaryKey;
205: }
206:
207: /**
208: * Indicates whether column is foreign key
209: *
210: * @return true if FK, false otherwise
211: */
212: public boolean getIsForeignKey() {
213: return this .isForeignKey;
214: }
215:
216: /**
217: * Gets ordinal position of column among siblings in its table.
218: *
219: * @return ordinal position
220: */
221: public int getOrdinalPosition() {
222: return this .ordinalPosition;
223: }
224:
225: /**
226: * Gets precision (for numeric types) or maximum number of characters (for char or date types).
227: *
228: * @return numeric precision or maximum number of characters, as determined by column type
229: */
230: public int getNumericPrecision() {
231: return this .numericPrecision;
232: }
233:
234: /**
235: * Gets numeric scale of this column. Meaningful only for numeric columns.
236: *
237: * @return numeric scale of column; meaningless for non-numeric columns
238: */
239: public int getNumericScale() {
240: return this .numericScale;
241: }
242:
243: /**
244: * Gets radix (number base) of this column, e.g., 10 (decimal), 2 (binary). Meaningful only for
245: * numeric columns.
246: *
247: * @return numeric radix of column; meaningless for non-numeric columns
248: */
249: public int getNumericRadix() {
250: return this .numericRadix;
251: }
252:
253: /**
254: * Gets SQL type code.
255: *
256: * @param newCode SQL code
257: */
258: public int getSqlTypeCode() {
259: return this .sqlTypeCode;
260: }
261:
262: /**
263: * Gets String representation of default value for this column (may be null).
264: *
265: * @return default value, or null if none was defined
266: */
267: public String getDefaultValue() {
268: return this .defaultValue;
269: }
270:
271: /**
272: * Gets String representation of value for this column (may be null).
273: *
274: * @return value, or null if none was defined
275: */
276: public String getValue() {
277: return this .value;
278: }
279:
280: // setters
281:
282: /**
283: * Sets column name.
284: *
285: * @param newName new name of column
286: */
287: public void setName(final String newName) {
288: this .name = newName;
289: }
290:
291: /**
292: * Sets Java type of column.
293: *
294: * @param newJavaType new Java type of column
295: */
296: public void setJavaType(final String newJavaType) {
297: this .javaType = newJavaType;
298: }
299:
300: /**
301: * Sets JDBC SQL type of column
302: *
303: * @param newSqlType new JDBC SQL type (expressed as String representation)
304: */
305: public void setSqlType(final String newSqlType) {
306: this .sqlType = newSqlType;
307: }
308:
309: /**
310: * Sets nullability of column
311: *
312: * @param newIsNullable true if nullable; false otherwise
313: */
314: public void setIsNullable(final boolean newIsNullable) {
315: this .isNullable = newIsNullable;
316: }
317:
318: /**
319: * Sets selection state of column.
320: *
321: * @param newIsSelected true if selected; false otherwise
322: */
323: public void setIsSelected(final boolean newIsSelected) {
324: this .isSelected = newIsSelected;
325: }
326:
327: /**
328: * Sets whether column is a primary key. Note that multiple columns may participate in a
329: * composite PK.
330: *
331: * @param newIsPrimaryKey true if PK; false otherwise
332: */
333: public void setIsPrimaryKey(final boolean newIsPrimaryKey) {
334: this .isPrimaryKey = newIsPrimaryKey;
335: }
336:
337: /**
338: * Sets whether column is a foreign key. Note that multiple columns may participate in a
339: * composite FK.
340: *
341: * @param newIsForeignKey true if FK; false otherwise
342: */
343: public void setIsForeignKey(final boolean newIsForeignKey) {
344: this .isForeignKey = newIsForeignKey;
345: }
346:
347: /**
348: * Sets ordinal position of column.
349: *
350: * @param newPosition new ordinal position of column
351: */
352: public void setOrdinalPosition(final int newPosition) {
353: if (newPosition <= 0) {
354: throw new IllegalArgumentException(
355: "Must supply positive integer value for newPosition.");
356: }
357: this .ordinalPosition = newPosition;
358: }
359:
360: /**
361: * Sets numeric precision or maximum character width of column.
362: *
363: * @param newNumericPrecision new precision of column
364: */
365: public void setNumericPrecision(final int newNumericPrecision) {
366: this .numericPrecision = newNumericPrecision;
367: }
368:
369: /**
370: * Sets numeric scale of column.
371: *
372: * @param newNumericScale new scale of column
373: */
374: public void setNumericScale(final int newNumericScale) {
375: this .numericScale = newNumericScale;
376: }
377:
378: /**
379: * Sets numeric radix of column.
380: *
381: * @param newNumericRadix new radix of column
382: */
383: public void setNumericRadix(final int newNumericRadix) {
384: this .numericRadix = newNumericRadix;
385: }
386:
387: /**
388: * Sets default value, if any, of column.
389: *
390: * @param newDefault default value; set to null to indicate that no default exists.
391: */
392: public void setDefaultValue(final String newDefault) {
393: this .defaultValue = newDefault;
394: }
395:
396: /**
397: * Sets value, if any, of column.
398: *
399: * @param newDefault default value; set to null to indicate that no default exists.
400: */
401: public void setValue(final String newValue) {
402: this .value = newValue;
403: }
404:
405: /**
406: * Sets SQL type code.
407: *
408: * @param newCode SQL code
409: */
410: public void setSqlTypeCode(final int newCode) {
411: this.sqlTypeCode = newCode;
412: }
413: }
|