001: /* ====================================================================
002: * The QueryForm License, Version 1.1
003: *
004: * Copyright (c) 1998 - 2004 David F. Glasser. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by
022: * David F. Glasser."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "QueryForm" and "David F. Glasser" must
027: * not be used to endorse or promote products derived from this
028: * software without prior written permission. For written
029: * permission, please contact dglasser@pobox.com.
030: *
031: * 5. Products derived from this software may not be called "QueryForm",
032: * nor may "QueryForm" appear in their name, without prior written
033: * permission of David F. Glasser.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL DAVID F. GLASSER, THE APACHE SOFTWARE
039: * FOUNDATION OR ITS CONTRIBUTORS, OR ANY AUTHORS OR DISTRIBUTORS
040: * OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This product includes software developed by the
051: * Apache Software Foundation (http://www.apache.org/).
052: *
053: * ====================================================================
054: *
055: * $Source: /cvsroot/qform/qform/src/org/glasser/sql/Column.java,v $
056: * $Revision: 1.2 $
057: * $Author: dglasser $
058: * $Date: 2004/09/28 01:37:57 $
059: *
060: * --------------------------------------------------------------------
061: */
062: package org.glasser.sql;
063:
064: import java.util.*;
065: import java.sql.*;
066: import java.lang.reflect.*;
067: import org.glasser.util.*;
068:
069: public class Column implements java.io.Serializable {
070:
071: protected String tableCatalog = null;
072:
073: protected String tableSchema = null;
074:
075: protected String tableName = null;
076:
077: protected String columnName = null;
078:
079: protected int dataType = 0;
080:
081: protected String typeName = null;
082:
083: protected int columnSize = 0;
084:
085: protected int decimalDigits = 0;
086:
087: protected int radix = 0;
088:
089: protected boolean nullable = true;
090:
091: protected String remarks = null;
092:
093: protected String columnDefaultValue = null;
094:
095: protected int ordinal = -1;
096:
097: protected boolean pkComponent = false;
098:
099: protected boolean isForeignKey = false;
100:
101: // setters
102:
103: public void setTableCatalog(String tableCatalog) {
104: this .tableCatalog = tableCatalog;
105: }
106:
107: public void setTableSchema(String tableSchema) {
108: this .tableSchema = tableSchema;
109: }
110:
111: public void setTableName(String tableName) {
112: this .tableName = tableName;
113: }
114:
115: public void setColumnName(String columnName) {
116: this .columnName = columnName;
117: }
118:
119: public void setDataType(int dataType) {
120: this .dataType = dataType;
121: }
122:
123: public void setTypeName(String typeName) {
124: this .typeName = typeName;
125: }
126:
127: public void setColumnSize(int columnSize) {
128: this .columnSize = columnSize;
129: }
130:
131: public void setDecimalDigits(int decimalDigits) {
132: this .decimalDigits = decimalDigits;
133: }
134:
135: public void setRadix(int radix) {
136: this .radix = radix;
137: }
138:
139: public void setNullable(boolean nullable) {
140: this .nullable = nullable;
141: }
142:
143: public void setRemarks(String remarks) {
144: this .remarks = remarks;
145: }
146:
147: public void setColumnDefaultValue(String columnDefaultValue) {
148: this .columnDefaultValue = columnDefaultValue;
149: }
150:
151: public void setOrdinal(int ordinal) {
152: this .ordinal = ordinal;
153: }
154:
155: public void setPkComponent(boolean pkComponent) {
156: this .pkComponent = pkComponent;
157: }
158:
159: public void setIsForeignKey(boolean isForeignKey) {
160: this .isForeignKey = isForeignKey;
161: }
162:
163: // getters
164:
165: public String getTableCatalog() {
166: return tableCatalog;
167: }
168:
169: public String getTableSchema() {
170: return tableSchema;
171: }
172:
173: public String getTableName() {
174: return tableName;
175: }
176:
177: public String getColumnName() {
178: return columnName;
179: }
180:
181: public int getDataType() {
182: return dataType;
183: }
184:
185: public String getTypeName() {
186: return typeName;
187: }
188:
189: public int getColumnSize() {
190: return columnSize;
191: }
192:
193: public int getDecimalDigits() {
194: return decimalDigits;
195: }
196:
197: public int getRadix() {
198: return radix;
199: }
200:
201: public boolean getNullable() {
202: return nullable;
203: }
204:
205: public String getRemarks() {
206: return remarks;
207: }
208:
209: public String getColumnDefaultValue() {
210: return columnDefaultValue;
211: }
212:
213: public int getOrdinal() {
214: return ordinal;
215: }
216:
217: public boolean getPkComponent() {
218: return pkComponent;
219: }
220:
221: public boolean getIsForeignKey() {
222: return isForeignKey;
223: }
224:
225: /**
226: * Returns the columnName enclosed in the provided "quote" characters, if
227: * the columnName contains a space or a hyphen, otherwise returns the columnName as-is.
228: * Normally, the openQuote and closeQuote args will both be regular double quotation
229: * marks ("), however, Microsoft databases use square brackets ([ and ]).
230: */
231: public String maybeQuoteColumnName(char openQuote, char closeQuote) {
232: if (columnName == null)
233: return null;
234: if (columnName.trim().length() == 0)
235: return "";
236: if (columnName.indexOf(' ') < 0 && columnName.indexOf('-') < 0)
237: return columnName;
238: StringBuffer buffer = new StringBuffer(columnName.length() + 4);
239: return buffer.append(openQuote).append(columnName).append(
240: closeQuote).toString();
241: }
242:
243: static Object[][] sqlTypes = {
244: { "ARRAY", new Integer(java.sql.Types.ARRAY) },
245: { "BIGINT", new Integer(java.sql.Types.BIGINT) },
246: { "BINARY", new Integer(java.sql.Types.BINARY) },
247: { "BIT", new Integer(java.sql.Types.BIT) },
248: { "BLOB", new Integer(java.sql.Types.BLOB) },
249: { "CHAR", new Integer(java.sql.Types.CHAR) },
250: { "CLOB", new Integer(java.sql.Types.CLOB) },
251: { "DATE", new Integer(java.sql.Types.DATE) },
252: { "DECIMAL", new Integer(java.sql.Types.DECIMAL) },
253: { "DISTINCT", new Integer(java.sql.Types.DISTINCT) },
254: { "DOUBLE", new Integer(java.sql.Types.DOUBLE) },
255: { "FLOAT", new Integer(java.sql.Types.FLOAT) },
256: { "INTEGER", new Integer(java.sql.Types.INTEGER) },
257: { "JAVA_OBJECT", new Integer(java.sql.Types.JAVA_OBJECT) },
258: { "LONGVARBINARY",
259: new Integer(java.sql.Types.LONGVARBINARY) },
260: { "LONGVARCHAR", new Integer(java.sql.Types.LONGVARCHAR) },
261: { "NULL", new Integer(java.sql.Types.NULL) },
262: { "NUMERIC", new Integer(java.sql.Types.NUMERIC) },
263: { "OTHER", new Integer(java.sql.Types.OTHER) },
264: { "REAL", new Integer(java.sql.Types.REAL) },
265: { "REF", new Integer(java.sql.Types.REF) },
266: { "SMALLINT", new Integer(java.sql.Types.SMALLINT) },
267: { "STRUCT", new Integer(java.sql.Types.STRUCT) },
268: { "TIME", new Integer(java.sql.Types.TIME) },
269: { "TIMESTAMP", new Integer(java.sql.Types.TIMESTAMP) },
270: { "TINYINT", new Integer(java.sql.Types.TINYINT) },
271: { "VARBINARY", new Integer(java.sql.Types.VARBINARY) },
272: { "VARCHAR", new Integer(java.sql.Types.VARCHAR) } };
273:
274: final static Hashtable typeStrings = new Hashtable();
275:
276: static {
277: for (int j = 0; j < sqlTypes.length; j++) {
278: typeStrings.put(sqlTypes[1], sqlTypes[0]);
279: }
280: }
281:
282: }
|