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.mysql;
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.NoParamType;
023: import org.castor.ddlgen.typeinfo.OptionalLengthType;
024: import org.castor.ddlgen.typeinfo.OptionalPrecisionDecimalsType;
025: import org.castor.ddlgen.typeinfo.OptionalPrecisionType;
026: import org.castor.ddlgen.typeinfo.RequiredLengthType;
027:
028: /**
029: * Final TypeMapper for MySQL database.
030: *
031: * @author <a href="mailto:leducbao AT gmail DOT com">Le Duc Bao</a>
032: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
033: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
034: * @since 1.1
035: */
036: public final class MysqlTypeMapper extends AbstractTypeMapper {
037: //--------------------------------------------------------------------------
038:
039: /** The <a href="http://jakarta.apache.org/commons/logging/">Jakarta Commons
040: * Logging </a> instance used for all logging. */
041: private static final Log LOG = LogFactory
042: .getLog(MysqlTypeMapper.class);
043:
044: //--------------------------------------------------------------------------
045:
046: /**
047: * Construct a TypeMapper for MySQL database using given configuration to
048: * get default parameters for parameterized types.
049: *
050: * @param conf The configuration to get default parameter values from.
051: */
052: public MysqlTypeMapper(final DDLGenConfiguration conf) {
053: super (conf);
054: }
055:
056: //--------------------------------------------------------------------------
057:
058: /**
059: * {@inheritDoc}
060: */
061: protected void initialize(final DDLGenConfiguration conf) {
062: // numeric types
063: this .add(new NoParamType("bit", "TINYINT(1)"));
064: this .add(new OptionalPrecisionType("tinyint", "TINYINT", conf));
065: this
066: .add(new OptionalPrecisionType("smallint", "SMALLINT",
067: conf));
068: this .add(new OptionalPrecisionType("integer", "INTEGER", conf));
069: this .add(new OptionalPrecisionType("int", "INTEGER", conf));
070: this .add(new OptionalPrecisionType("bigint", "BIGINT", conf));
071:
072: this .add(new OptionalPrecisionDecimalsType("float", "FLOAT",
073: conf));
074: this .add(new OptionalPrecisionDecimalsType("double", "DOUBLE",
075: conf));
076: this
077: .add(new OptionalPrecisionDecimalsType("real", "REAL",
078: conf));
079: this .add(new OptionalPrecisionDecimalsType("numeric",
080: "NUMERIC", conf));
081: this .add(new OptionalPrecisionDecimalsType("decimal",
082: "DECIMAL", conf));
083:
084: // character types
085: this .add(new OptionalLengthType("char", "CHAR", conf));
086: this .add(new OptionalLengthType("varchar", "VARCHAR", conf));
087: LOG
088: .warn("MySql does not support 'LONGVARCHAR' type, use VARCHAR instead.");
089: this
090: .add(new OptionalLengthType("longvarchar", "VARCHAR",
091: conf));
092:
093: // date and time types
094: this .add(new NoParamType("date", "DATE"));
095: this .add(new NoParamType("time", "TIME"));
096: this .add(new OptionalPrecisionType("timestamp", "TIMESTAMP",
097: conf));
098:
099: // other types
100: this .add(new RequiredLengthType("binary", "BINARY", conf));
101: this
102: .add(new RequiredLengthType("varbinary", "VARBINARY",
103: conf));
104: LOG
105: .warn("MySql does not support 'LONGBINARY' type, use VARBINARY instead.");
106: this .add(new RequiredLengthType("longvarbinary", "VARBINARY",
107: conf));
108:
109: this .add(new NoParamType("other", "BLOB"));
110: this .add(new NoParamType("javaobject", "BLOB"));
111: this .add(new NoParamType("blob", "BLOB"));
112: this .add(new NoParamType("clob", "TEXT"));
113: }
114:
115: //--------------------------------------------------------------------------
116: }
|