001: /*
002: * Copyright 2006 Le Duc Bao, Ralf Joachim
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package org.castor.ddlgen.engine.db2;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.castor.ddlgen.AbstractTypeMapper;
021: import org.castor.ddlgen.DDLGenConfiguration;
022: import org.castor.ddlgen.typeinfo.LobType;
023: import org.castor.ddlgen.typeinfo.NoParamType;
024: import org.castor.ddlgen.typeinfo.NotSupportedType;
025: import org.castor.ddlgen.typeinfo.OptionalLengthType;
026: import org.castor.ddlgen.typeinfo.OptionalPrecisionDecimalsType;
027: import org.castor.ddlgen.typeinfo.RequiredLengthType;
028: import org.castor.ddlgen.typeinfo.RequiredPrecisionType;
029:
030: /**
031: * Final TypeMapper for DB2 database.
032: *
033: * @author <a href="mailto:leducbao AT gmail DOT com">Le Duc Bao</a>
034: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
035: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
036: * @since 1.1
037: */
038: public final class Db2TypeMapper extends AbstractTypeMapper {
039: //--------------------------------------------------------------------------
040:
041: /** The <a href="http://jakarta.apache.org/commons/logging/">Jakarta Commons
042: * Logging </a> instance used for all logging. */
043: private static final Log LOG = LogFactory
044: .getLog(Db2TypeMapper.class);
045:
046: //--------------------------------------------------------------------------
047:
048: /**
049: * Construct a TypeMapper for DB2 database using given configuration to get default
050: * parameters for parameterized types.
051: *
052: * @param conf The configuration to get default parameter values from.
053: */
054: public Db2TypeMapper(final DDLGenConfiguration conf) {
055: super (conf);
056: }
057:
058: //--------------------------------------------------------------------------
059:
060: /**
061: * {@inheritDoc}
062: */
063: protected void initialize(final DDLGenConfiguration conf) {
064: // numeric types
065: LOG.warn("Db2 does not support 'BIT' type.");
066: this .add(new NotSupportedType("bit"));
067: LOG
068: .warn("Db2 does not support 'TINY' type, use SMALLINT instead.");
069: this .add(new NoParamType("tinyint", "SMALLINT"));
070: this .add(new NoParamType("smallint", "SMALLINT"));
071: this .add(new NoParamType("integer", "INTEGER"));
072: this .add(new NoParamType("int", "INTEGER"));
073: this .add(new NoParamType("bigint", "BIGINT"));
074:
075: this .add(new RequiredPrecisionType("float", "FLOAT", conf));
076: this .add(new NoParamType("double", "DOUBLE"));
077: this .add(new NoParamType("real", "REAL"));
078: this .add(new OptionalPrecisionDecimalsType("numeric",
079: "NUMERIC", conf));
080: this .add(new OptionalPrecisionDecimalsType("decimal",
081: "DECIMAL", conf));
082:
083: // character types
084: this .add(new OptionalLengthType("char", "CHAR", conf));
085: this .add(new RequiredLengthType("varchar", "VARCHAR", conf));
086: this .add(new NoParamType("longvarchar", "LONG VARCHAR"));
087:
088: // date and time types
089: this .add(new NoParamType("date", "DATE"));
090: this .add(new NoParamType("time", "TIME"));
091: this .add(new NoParamType("timestamp", "TIMESTAMP"));
092:
093: // other types
094: this .add(new OptionalLengthType("binary", "CHAR",
095: " FOR BIT DATA", conf));
096: this .add(new RequiredLengthType("varbinary", "VARCHAR",
097: " FOR BIT DATA", conf));
098: this .add(new NoParamType("longvarbinary",
099: "LONG VARCHAR FOR BIT DATA"));
100:
101: this .add(new LobType("other", "BLOB", conf));
102: this .add(new LobType("javaobject", "BLOB", conf));
103: this .add(new LobType("blob", "BLOB", conf));
104: this .add(new LobType("clob", "CLOB", conf));
105: }
106:
107: //--------------------------------------------------------------------------
108: }
|