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