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-2007 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: package org.netbeans.modules.sql.framework.model.impl;
042:
043: import org.netbeans.modules.sql.framework.model.DBColumn;
044: import org.netbeans.modules.sql.framework.common.jdbc.SQLUtils;
045: import org.netbeans.modules.sql.framework.common.utils.XmlUtil;
046: import org.netbeans.modules.sql.framework.model.SQLConstants;
047: import org.netbeans.modules.sql.framework.model.SQLDBColumn;
048: import org.netbeans.modules.sql.framework.model.SQLDBModel;
049: import org.netbeans.modules.sql.framework.model.SQLDBTable;
050: import org.netbeans.modules.sql.framework.model.SQLDefinition;
051: import org.netbeans.modules.sql.framework.model.SQLObject;
052: import org.netbeans.modules.sql.framework.model.utils.GeneratorUtil;
053: import org.w3c.dom.Element;
054:
055: import com.sun.sql.framework.exception.BaseException;
056: import net.java.hulp.i18n.Logger;
057: import com.sun.sql.framework.utils.StringUtil;
058: import org.netbeans.modules.etl.logger.Localizer;
059: import org.netbeans.modules.etl.logger.LogUtil;
060: import org.netbeans.modules.sql.framework.model.DBTable;
061:
062: /**
063: * Abstract implementation for org.netbeans.modules.model.database.DBColumn and SQLObject interfaces.
064: *
065: * @author Sudhendra Seshachala, Jonathan Giron
066: * @version $Revision$
067: */
068: public abstract class AbstractDBColumn extends AbstractSQLObject
069: implements SQLDBColumn, Cloneable, Comparable {
070:
071: private static transient final Logger mLogger = LogUtil
072: .getLogger(AbstractDBColumn.class.getName());
073: private static transient final Localizer mLoc = Localizer.get();
074: /** Constant for indicating unknown ordinal position for this column. */
075: public static final int POSITION_UNKNOWN = Integer.MIN_VALUE;
076: /** Constant for column metadata name tag. */
077: static final String ELEMENT_TAG = "dbColumn"; // NOI18N
078: /** Constant for catalog name tag. */
079: protected static final String COLUMN_CATALOGNAME_ATTR = "catalogName"; // NOI18N
080: /** Constant for column default value tag. */
081: protected static final String COLUMN_DEFAULTVALUE_ATTR = "defaultValue"; // NOI18N
082: /** Constant for column isForeignKey name tag. */
083: protected static final String COLUMN_INDEXED_ATTR = "indexed"; // NOI18N
084: /** Constant for column isForeignKey name tag. */
085: protected static final String COLUMN_ISFK_ATTR = "isForeignKey"; // NOI18N
086: /** Constant for column isPrimaryKey name tag. */
087: protected static final String COLUMN_ISPK_ATTR = "isPrimaryKey"; // NOI18N
088: /** Constant for column model name tag. */
089: protected static final String COLUMN_MODEL_ATTR = "dbModelName"; // NOI18N
090: /** Constant for column name tag. */
091: protected static final String COLUMN_NAME_ATTR = "name"; // NOI18N
092: /** Constant for column nullable name tag. */
093: protected static final String COLUMN_NULLABLE_ATTR = "nullable"; // NOI18N
094: /** Constant for column ordinal position tag. */
095: protected static final String COLUMN_ORDINAL_POSITION_ATTR = "ordinalPosition"; // NOI18N
096: /** Constant for column precision name tag. */
097: protected static final String COLUMN_PRECISION_ATTR = "precision"; // NOI18N
098: /** Constant for column scale name tag. */
099: protected static final String COLUMN_SCALE_ATTR = "scale"; // NOI18N
100: /** Constant for schema name tag. */
101: protected static final String COLUMN_SCHEMANAME_ATTR = "schemaName"; // NOI18N
102: /** Constant for column table name tag. */
103: protected static final String COLUMN_TABLENAME_ATTR = "tableName"; // NOI18N
104: /** Constant for column type name tag. */
105: protected static final String COLUMN_TYPE_ATTR = "type"; // NOI18N
106: /** String constant for unknown SQL type */
107: protected static final String UNKNOWN_TYPE = "unknown"; // NOI18N
108:
109: /* Log4J category name */
110: private static final String LOG_CATEGORY = AbstractDBColumn.class
111: .getName();
112: /** default value */
113: protected String defaultValue;
114: /** whether this column is part of a foreign key */
115: protected boolean fkFlag;
116: /** whether this column is indexed */
117: protected boolean indexed;
118: /** JDBC SQL type, as enumerated in java.sql.Types */
119: protected int jdbcType;
120: /** name of column */
121: protected String name;
122: /** whether this column can accept null as a valid value */
123: protected boolean nullable;
124: /** Cardinal Position */
125: protected int ordinalPosition = POSITION_UNKNOWN;
126: /** DBTable to which this PK belongs */
127: protected DBTable parent;
128: /** whether this column is part of a primary key */
129: protected boolean pkFlag;
130: /** column precision (for numeric types) / width (for char types) */
131: protected int precision;
132: /** column scale (meaningful only for numeric types) */
133: protected int scale;
134:
135: /** Constructs default instance of AbstractDBColumn. */
136: public AbstractDBColumn() {
137: super ();
138: }
139:
140: /**
141: * Constructs a new instance of AbstractDBColumn using the given parameters and
142: * assuming that the column is not part of a foreign key or primary key, and that it
143: * accepts null values.
144: *
145: * @param colName name of this column
146: * @param sqlJdbcType JDBC type of this column
147: * @param colScale scale of this column
148: * @param colPrecision precision of this column
149: * @param isNullable true if nullable, false otherwise
150: * @see java.sql.Types
151: */
152: public AbstractDBColumn(String colName, int sqlJdbcType,
153: int colScale, int colPrecision, boolean isNullable) {
154: this ();
155:
156: name = colName;
157: jdbcType = sqlJdbcType;
158:
159: precision = colPrecision;
160: scale = colScale;
161:
162: nullable = isNullable;
163: }
164:
165: /**
166: * Constructs a new instance of AbstractDBColumn using the given parameters.
167: *
168: * @param colName name of this column
169: * @param sqlJdbcType JDBC type of this column
170: * @param colScale scale of this column
171: * @param colPrecision precision of this column
172: * @param isPrimaryKey true if part of a primary key, false otherwise
173: * @param isForeignKey true if part of a foreign key, false otherwise
174: * @param isIndexed true if indexed, false otherwise
175: * @param isNullable true if nullable, false otherwise
176: * @see java.sql.Types
177: */
178: public AbstractDBColumn(String colName, int sqlJdbcType,
179: int colScale, int colPrecision, boolean isPrimaryKey,
180: boolean isForeignKey, boolean isIndexed, boolean isNullable) {
181: this (colName, sqlJdbcType, colScale, colPrecision, isNullable);
182:
183: pkFlag = isPrimaryKey;
184: fkFlag = isForeignKey;
185: indexed = isIndexed;
186: }
187:
188: /**
189: * Clone method
190: *
191: * @return cloned object
192: * @throws CloneNotSupportedException - exception
193: */
194: public Object clone() throws CloneNotSupportedException {
195: return super .clone();
196: }
197:
198: /**
199: * Compares DBColumn with another object for lexicographical ordering. Null objects
200: * and those DBColumns with null names are placed at the end of any ordered collection
201: * using this method.
202: *
203: * @param refObj Object to be compared.
204: * @return -1 if the column name is less than obj to be compared. 0 if the column name
205: * is the same. 1 if the column name is greater than obj to be compared.
206: */
207: public int compareTo(Object refObj) {
208: if (refObj == null) {
209: return -1;
210: }
211:
212: if (refObj == this ) {
213: return 0;
214: }
215:
216: String myName = getDisplayName();
217: myName = (myName == null) ? name : myName;
218:
219: String refName = null;
220: if (!(refObj instanceof DBColumn)) {
221: return -1;
222: }
223:
224: DBColumn refColumn = (DBColumn) refObj;
225: refName = refColumn.getName();
226:
227: // compare primary keys
228: if (this .isPrimaryKey() && !refColumn.isPrimaryKey()) {
229: return -1;
230: } else if (!this .isPrimaryKey() && refColumn.isPrimaryKey()) {
231: return 1;
232: }
233:
234: // compare foreign keys
235: if (this .isForeignKey() && !refColumn.isForeignKey()) {
236: return -1;
237: } else if (!this .isForeignKey() && refColumn.isForeignKey()) {
238: return 1;
239: }
240:
241: return (myName != null) ? myName.compareTo(refName)
242: : (refName != null) ? 1 : -1;
243: }
244:
245: /**
246: * Sets the various member variables and collections using the given DBColumn instance
247: * as a source object. Concrete implementations should override this method, call
248: * super.copyFrom(DBColumn) to pick up member variables defined in this class and then
249: * implement its own logic for copying member variables defined within itself.
250: *
251: * @param source DBColumn from which to obtain values for member variables and
252: * collections
253: */
254: public void copyFrom(DBColumn source) {
255: name = source.getName();
256: jdbcType = source.getJdbcType();
257:
258: scale = source.getScale();
259: precision = source.getPrecision();
260:
261: ordinalPosition = source.getOrdinalPosition();
262:
263: pkFlag = source.isPrimaryKey();
264: fkFlag = source.isForeignKey();
265: indexed = source.isIndexed();
266: nullable = source.isNullable();
267:
268: parent = source.getParent();
269:
270: if (source instanceof SQLDBColumn) {
271: super .copyFromSource((SQLDBColumn) source);
272: SQLDBColumn sColumn = ((SQLDBColumn) source);
273: defaultValue = sColumn.getDefaultValue();
274: }
275: }
276:
277: /**
278: * Overrides default implementation to return value based on memberwise comparison.
279: * Concrete implementations should override this method and combine the result of
280: * super.equals(Object) [calling this method] with its own comparison of member
281: * variables declared in its class as its own return value.
282: *
283: * @param refObj Object against which we compare this instance
284: * @return true if refObj is functionally identical to this instance; false otherwise
285: */
286: public boolean equals(Object refObj) {
287: if (!(refObj instanceof SQLDBColumn)) {
288: return false;
289: }
290:
291: SQLDBColumn refMeta = (SQLDBColumn) refObj;
292: boolean result = super .equals(refObj);
293:
294: result &= (name != null) ? name.equals(refMeta.getName())
295: : (refMeta.getName() == null);
296:
297: result &= (jdbcType == refMeta.getJdbcType())
298: && (pkFlag == refMeta.isPrimaryKey())
299: && (fkFlag == refMeta.isForeignKey())
300: && (indexed == refMeta.isIndexed())
301: && (nullable == refMeta.isNullable())
302: && (scale == refMeta.getScale())
303: && (precision == refMeta.getPrecision())
304: && (ordinalPosition == refMeta.getOrdinalPosition());
305:
306: result &= (type == refMeta.getObjectType());
307:
308: return result;
309: }
310:
311: /**
312: * Get default value
313: *
314: * @return default value
315: */
316: public String getDefaultValue() {
317: return defaultValue;
318: }
319:
320: /**
321: * @see SQLObject
322: */
323: public String getDisplayName() {
324: return (displayName != null && displayName.trim().length() != 0) ? displayName
325: .trim()
326: : name.trim();
327: }
328:
329: /**
330: * @see org.netbeans.modules.model.database.DBColumn#getJdbcType
331: */
332: public int getJdbcType() {
333: return jdbcType;
334: }
335:
336: /**
337: * @see org.netbeans.modules.model.database.DBColumn#getJdbcTypeString
338: */
339: public String getJdbcTypeString() {
340: return SQLUtils.getStdSqlType(jdbcType);
341: }
342:
343: /**
344: * @see org.netbeans.modules.model.database.DBColumn#getName
345: */
346: public String getName() {
347: return this .name;
348: }
349:
350: /**
351: * Gets the Ordinal Position
352: *
353: * @return cardinalPosition to be used
354: */
355: public int getOrdinalPosition() {
356: return this .ordinalPosition;
357: }
358:
359: /**
360: * @see org.netbeans.modules.model.database.DBColumn#getParent
361: */
362: public DBTable getParent() {
363: return parent;
364: }
365:
366: /**
367: * @see org.netbeans.modules.model.database.DBColumn#getPrecision
368: */
369: public int getPrecision() {
370: return precision;
371: }
372:
373: /**
374: * get table qualified name
375: *
376: * @return qualified column name prefixed with alias
377: */
378: public String getQualifiedName() {
379: StringBuilder buf = new StringBuilder(50);
380: SQLDBTable table = (SQLDBTable) this .getParent();
381: if (table != null) {
382: buf.append(table.getQualifiedName());
383: buf.append(".");
384: }
385:
386: buf.append(this .getName());
387:
388: return buf.toString();
389: }
390:
391: /**
392: * @see org.netbeans.modules.model.database.DBColumn#getScale
393: */
394: public int getScale() {
395: return scale;
396: }
397:
398: /**
399: * Gets the hashCode for this object. Concrete implementations should override this
400: * method and combine the result of super.hashCode() [this method] and its own
401: * implementation of hashCode as its own return value.
402: *
403: * @return the hashCode of this object.
404: */
405: public int hashCode() {
406: int myHash = super .hashCode();
407:
408: myHash += (name != null) ? name.hashCode() : 0;
409: myHash += ordinalPosition;
410:
411: myHash += jdbcType + (10 * scale) + (100 * precision);
412: myHash += pkFlag ? 1 : 0;
413: myHash += fkFlag ? 2 : 0;
414: myHash += indexed ? 4 : 0;
415: myHash += nullable ? 8 : 0;
416:
417: myHash += type;
418:
419: return myHash;
420: }
421:
422: /**
423: * gui property editable check if this column is editable
424: *
425: * @return isEditable
426: */
427: public boolean isEditable() {
428: Boolean editable = (Boolean) this
429: .getAttributeObject(ATTR_EDITABLE);
430: if (editable != null) {
431: return editable.booleanValue();
432: }
433: return true;
434: }
435:
436: /**
437: * @see org.netbeans.modules.model.database.DBColumn#isForeignKey
438: */
439: public boolean isForeignKey() {
440: return fkFlag;
441: }
442:
443: /**
444: * @see org.netbeans.modules.model.database.DBColumn#isIndexed
445: */
446: public boolean isIndexed() {
447: return indexed;
448: }
449:
450: /**
451: * @see org.netbeans.modules.model.database.DBColumn#isNullable
452: */
453: public boolean isNullable() {
454: return nullable;
455: }
456:
457: /**
458: * @see org.netbeans.modules.model.database.DBColumn#isPrimaryKey
459: */
460: public boolean isPrimaryKey() {
461: return pkFlag;
462: }
463:
464: /**
465: * is this column visible
466: *
467: * @return boolean
468: */
469: public boolean isVisible() {
470: Boolean vis = (Boolean) this .getAttributeObject(ATTR_VISIBLE);
471: if (vis != null) {
472: return vis.booleanValue();
473: }
474:
475: return true;
476: }
477:
478: /**
479: * Parses the XML content, if any, represented by the given DOM element.
480: *
481: * @param columnElement DOM element to be parsed for column content
482: * @exception BaseException thrown while parsing XML, or if columnElement is null
483: */
484: public void parseXML(Element columnElement) throws BaseException {
485: if (columnElement == null) {
486: throw new BaseException("No <" + ELEMENT_TAG
487: + "> element found.");
488: }
489:
490: super .parseXML(columnElement);
491:
492: if (getId() == null || getId().trim().length() == 0) {
493: throw new BaseException("Invalid or missing ID attribute.");
494: }
495:
496: name = columnElement.getAttribute(COLUMN_NAME_ATTR);
497: if (name == null || name.trim().length() == 0) {
498: throw new BaseException(
499: "Invalid or missing name attribute.");
500: }
501:
502: String jdbcTypeStr = columnElement
503: .getAttribute(COLUMN_TYPE_ATTR);
504:
505: try {
506: this .jdbcType = Integer.parseInt(jdbcTypeStr);
507: } catch (NumberFormatException e) {
508: mLogger
509: .infoNoloc(mLoc
510: .t(
511: "PRSR102: Cannot determine JDBC int type for column{0}({1}); will try parsing as string.",
512: name, jdbcTypeStr));
513: try {
514: this .jdbcType = SQLUtils.getStdJdbcType(jdbcTypeStr);
515: } catch (IllegalArgumentException iae) {
516: mLogger
517: .infoNoloc(mLoc
518: .t(
519: "PRSR103: Cannot determine JDBC int type for column{0}by parsing as string; giving up..",
520: name));
521: this .jdbcType = SQLConstants.JDBCSQL_TYPE_UNDEFINED;
522: }
523: }
524:
525: scale = StringUtil.getInt(columnElement
526: .getAttribute(COLUMN_SCALE_ATTR));
527: if (scale == Integer.MIN_VALUE) {
528: scale = 0;
529: }
530:
531: precision = StringUtil.getInt(columnElement
532: .getAttribute(COLUMN_PRECISION_ATTR));
533: if (precision == Integer.MIN_VALUE) {
534: precision = 0;
535: }
536:
537: ordinalPosition = StringUtil.getInt(columnElement
538: .getAttribute(COLUMN_ORDINAL_POSITION_ATTR));
539: if (Integer.MIN_VALUE == ordinalPosition) {
540: ordinalPosition = POSITION_UNKNOWN;
541: }
542:
543: this .pkFlag = "true".equals(columnElement
544: .getAttribute(COLUMN_ISPK_ATTR));
545: this .fkFlag = "true".equals(columnElement
546: .getAttribute(COLUMN_ISFK_ATTR));
547: this .indexed = "true".equals(columnElement
548: .getAttribute(COLUMN_INDEXED_ATTR));
549: this .nullable = "true".equals(columnElement
550: .getAttribute(COLUMN_NULLABLE_ATTR));
551: this .defaultValue = columnElement
552: .getAttribute(COLUMN_DEFAULTVALUE_ATTR);
553: }
554:
555: /**
556: * Set default value
557: *
558: * @param defaultVal - value
559: */
560: public void setDefaultValue(String defaultVal) {
561: this .defaultValue = defaultVal;
562: }
563:
564: /**
565: * gui property editable set this column editable property
566: *
567: * @param editable - editable
568: */
569: public void setEditable(boolean editable) {
570: this .setAttribute(ATTR_EDITABLE, new Boolean(editable));
571: }
572:
573: /**
574: * Sets whether this column is flagged as part of a foreign key.
575: *
576: * @param newFlag true if this column is part of a foreign key; false otherwise
577: */
578: public void setForeignKey(boolean newFlag) {
579: fkFlag = newFlag;
580: }
581:
582: /**
583: * Sets whether this column is flagged as indexed.
584: *
585: * @param newFlag true if this column is indexed; false otherwise
586: */
587: public void setIndexed(boolean newFlag) {
588: indexed = newFlag;
589: }
590:
591: /*
592: * Setters and non-API helper methods.
593: */
594: /**
595: * Sets JDBC type of this column
596: *
597: * @param newType new JDBC type value
598: */
599: public void setJdbcType(int newType) {
600: jdbcType = newType;
601: }
602:
603: /**
604: * Set name
605: *
606: * @param name - name
607: */
608: public void setName(String theName) {
609: this .name = theName;
610: }
611:
612: /**
613: * Sets whether this column is flagged as nullable.
614: *
615: * @param newFlag true if this column is nullable; false otherwise
616: */
617: public void setNullable(boolean newFlag) {
618: nullable = newFlag;
619: }
620:
621: /**
622: * Gets the Ordinal Position
623: *
624: * @param cardinalPos to be used
625: */
626: public void setOrdinalPosition(int cardinalPos) {
627: this .ordinalPosition = cardinalPos;
628: }
629:
630: /**
631: * Sets reference to DBTable that owns this DBColumn.
632: *
633: * @param newParent new parent of this column.
634: */
635: public void setParent(DBTable newParent) {
636: parent = newParent;
637:
638: // set the id if it can be set
639: // this is helpful if ancestor relationship is set
640: // but sometimes we may have floating tables (tables not added in definition)
641: // in that case we can not set id
642: if (newParent instanceof SQLObject) {
643: try {
644: setParentObject(newParent);
645: if (newParent.getParent() instanceof SQLDBModel) {
646: SQLDBModel dbModel = (SQLDBModel) newParent
647: .getParent();
648: if (dbModel != null) {
649: SQLDefinition def = (SQLDefinition) dbModel
650: .getParentObject();
651: if (def != null) {
652: this .setId(def.generateId());
653: }
654: }
655: }
656: } catch (BaseException ex) {
657: mLogger
658: .errorNoloc(
659: mLoc
660: .t(
661: "PRSR104: could not set parent object or id for column{0}",
662: this .getName()), ex);
663: }
664: }
665: }
666:
667: /**
668: * Set precision
669: *
670: * @param precision - precision
671: */
672: public void setPrecision(int thePrecision) {
673: this .precision = thePrecision;
674: }
675:
676: /**
677: * Sets whether this column is flagged as part of a primary key.
678: *
679: * @param newFlag true if this column is part of a primary key; false otherwise
680: */
681: public void setPrimaryKey(boolean newFlag) {
682: pkFlag = newFlag;
683: }
684:
685: /**
686: * Set scale
687: *
688: * @param scale - scale
689: */
690: public void setScale(int theScale) {
691: this .scale = theScale;
692: }
693:
694: /**
695: * set this column to be visible
696: *
697: * @param visible boolean
698: */
699: public void setVisible(boolean visible) {
700: this .setAttribute(ATTR_VISIBLE, new Boolean(visible));
701: }
702:
703: /**
704: * toString
705: *
706: * @return String
707: */
708: public String toString() {
709: String cName = "Unknown";
710: try {
711: GeneratorUtil eval = GeneratorUtil.getInstance();
712: eval.setTableAliasUsed(true);
713: cName = eval.getEvaluatedString(this );
714: eval.setTableAliasUsed(false);
715: } catch (BaseException ignore) {
716: // ignore
717: }
718: return cName;
719: }
720:
721: /**
722: * @see SQLObject#toXMLString(java.lang.String)
723: */
724: public abstract String toXMLString(String prefix)
725: throws BaseException;
726:
727: /**
728: * Appends attributes defined in this abstract class to the given StringBuilder.
729: *
730: * @param xml StringBuilder to receive XML attribute output
731: */
732: protected void appendXMLAttributes(StringBuilder xml) {
733: if (xml == null) {
734: throw new IllegalArgumentException(
735: "Must supply non-null StringBuilder ref for parameter xml.");
736: }
737:
738: if (getId() != null) {
739: xml.append(" ").append(ID).append("=\"").append(id.trim())
740: .append("\"");
741: }
742:
743: xml.append(" ").append(DISPLAY_NAME).append("=\"");
744:
745: if (displayName != null) {
746: xml.append(displayName.trim());
747: }
748:
749: xml.append("\"");
750:
751: if (name != null && name.trim().length() != 0) {
752: xml.append(" ").append(COLUMN_NAME_ATTR).append("=\"")
753: .append(name.trim()).append("\"");
754: }
755:
756: // right out default column value if any
757: if (defaultValue != null && defaultValue.trim().length() != 0) {
758: xml.append(" ").append(COLUMN_DEFAULTVALUE_ATTR).append(
759: "=\"").append(
760: XmlUtil.escapeXML(defaultValue.trim()))
761: .append("\"");
762: }
763:
764: xml.append(" ").append(COLUMN_TYPE_ATTR).append("=\"").append(
765: jdbcType).append("\"");
766:
767: xml.append(" ").append(COLUMN_SCALE_ATTR).append("=\"").append(
768: scale).append("\"");
769:
770: xml.append(" ").append(COLUMN_PRECISION_ATTR).append("=\"")
771: .append(precision).append("\"");
772:
773: xml.append(" ").append(COLUMN_ORDINAL_POSITION_ATTR).append(
774: "=\"").append(ordinalPosition).append("\"");
775:
776: xml.append(" ").append(COLUMN_ISPK_ATTR).append("=\"").append(
777: String.valueOf(pkFlag)).append("\"");
778:
779: xml.append(" ").append(COLUMN_ISFK_ATTR).append("=\"").append(
780: String.valueOf(fkFlag)).append("\"");
781:
782: xml.append(" ").append(COLUMN_INDEXED_ATTR).append("=\"")
783: .append(String.valueOf(indexed)).append("\"");
784:
785: xml.append(" ").append(COLUMN_NULLABLE_ATTR).append("=\"")
786: .append(String.valueOf(nullable)).append("\"");
787: }
788:
789: /**
790: * Gets String representing tag name for this table class.
791: *
792: * @return String representing element tag for this instance
793: */
794: protected abstract String getElementTagName();
795: }
|