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