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: package org.netbeans.modules.sql.framework.codegen.db2v7;
020:
021: import java.sql.Types;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.netbeans.modules.sql.framework.codegen.AbstractTypeGenerator;
026: import org.netbeans.modules.sql.framework.codegen.DataType;
027:
028: import com.sun.sql.framework.jdbc.SQLUtils;
029:
030: /**
031: * @author Ritesh Adval
032: * @author Ahimanikya Satapathy
033: * @version $Revision$
034: */
035: public class DB2V7TypeGenerator extends AbstractTypeGenerator {
036:
037: private static Map<Integer, DataType> supportedDataTypes;
038:
039: @Override
040: public String generate(int jdbcType, int precision, int scale) {
041: String result = super .generate(jdbcType, precision, scale);
042: if (SQLUtils.isBinary(jdbcType)) {
043: result += " FOR BIT DATA ";
044: }
045: return (result);
046: }
047:
048: @Override
049: public boolean isPrecisionRequired(int jdbcType) {
050: if (jdbcType == Types.BLOB || jdbcType == Types.CLOB) {
051: return true;
052: } else {
053: return super .isPrecisionRequired(jdbcType);
054: }
055: }
056:
057: public Map createSupportedDataTypesMap() {
058: if (supportedDataTypes == null) {
059: supportedDataTypes = new HashMap<Integer, DataType>();
060:
061: // bit is mapped to numeric
062: supportedDataTypes.put(new Integer(Types.BIT),
063: DataType.NUMERIC);
064:
065: supportedDataTypes.put(new Integer(Types.INTEGER),
066: DataType.INTEGER);
067: supportedDataTypes.put(new Integer(Types.BIGINT),
068: DataType.BIGINT);
069: // tinyint is mapped to numeric
070: supportedDataTypes.put(new Integer(Types.TINYINT),
071: DataType.NUMERIC);
072: supportedDataTypes.put(new Integer(Types.SMALLINT),
073: DataType.SMALLINT);
074:
075: supportedDataTypes.put(new Integer(Types.DECIMAL),
076: DataType.DECIMAL);
077: supportedDataTypes.put(new Integer(Types.DOUBLE),
078: DataType.FLOAT);
079: supportedDataTypes.put(new Integer(Types.FLOAT),
080: DataType.FLOAT);
081: supportedDataTypes.put(new Integer(Types.NUMERIC),
082: DataType.NUMERIC);
083: supportedDataTypes.put(new Integer(Types.REAL),
084: DataType.REAL);
085:
086: supportedDataTypes.put(new Integer(Types.DATE),
087: DataType.DATE);
088: supportedDataTypes.put(new Integer(Types.TIME),
089: DataType.TIME);
090: supportedDataTypes.put(new Integer(Types.TIMESTAMP),
091: DataType.TIMESTAMP);
092:
093: supportedDataTypes.put(new Integer(Types.CHAR),
094: DataType.CHAR);
095: supportedDataTypes.put(new Integer(Types.VARCHAR),
096: DataType.VARCHAR);
097: supportedDataTypes.put(new Integer(Types.LONGVARCHAR),
098: DataType.LONG_VARCHAR);
099:
100: supportedDataTypes.put(new Integer(Types.BINARY),
101: DataType.CHAR);
102: supportedDataTypes.put(new Integer(Types.VARBINARY),
103: DataType.VARCHAR);
104: supportedDataTypes.put(new Integer(Types.LONGVARBINARY),
105: DataType.LONG_VARCHAR);
106:
107: supportedDataTypes.put(new Integer(Types.OTHER),
108: DataType.VARCHAR);
109:
110: supportedDataTypes.put(new Integer(Types.BLOB),
111: DataType.BLOB);
112: supportedDataTypes.put(new Integer(Types.CLOB),
113: DataType.CLOB);
114: }
115: return supportedDataTypes;
116: }
117:
118: }
|