/*
 * Copyright 2006-2011 the Seasar Foundation and the Others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
/**
 * 
 */
package org.seasar.codegen.dbms;

import org.seasar.codegen.element.DataType;
import org.seasar.codegen.element.FieldSetting;
import org.seasar.codegen.exception.InternalGenerateException;

/**
 * @author azusa
 * 
 */
public class HSQL extends AbstractDbms {

    public String convDBTypeToDataType(String typeName) {
        return typeName;
    }

    public DataType selectBestDataType(FieldSetting fieldSetting)
            throws InternalGenerateException {
        String typeName = fieldSetting.getTypeName();
        fieldSetting.setRdbType(fieldSetting.getTypeName());
        DataType dataType = null;

        if (typeName.startsWith("INTEGER")) {
            dataType = getAnyDataType(fieldSetting, "int");
        } else if (typeName.startsWith("INT")) {
            dataType = getAnyDataType(fieldSetting, "int");
        } else if (typeName.startsWith("DOUBLE PRECISION")) {
            dataType = getAnyDataType(fieldSetting, "BigDecimal");
        } else if (typeName.startsWith("DOUBLE")) {
            dataType = getAnyDataType(fieldSetting, "BigDecimal");
        } else if (typeName.startsWith("FLOAT")) {
            dataType = getAnyDataType(fieldSetting, "short");
        } else if (typeName.startsWith("VARCHAR")) {
            dataType = getAnyDataType(fieldSetting, "String");
        } else if (typeName.startsWith("VARCHAR_IGNORECASE")) {
            dataType = getAnyDataType(fieldSetting, "String");
        } else if (typeName.startsWith("CHAR")) {
            dataType = getAnyDataType(fieldSetting, "String");
        } else if (typeName.startsWith("CHARACTER")) {
            dataType = getAnyDataType(fieldSetting, "String");
        } else if (typeName.startsWith("LONGVARCHAR")) {
            dataType = getAnyDataType(fieldSetting, "String");
        } else if (typeName.startsWith("DATE")) {
            dataType = getAnyDataType(fieldSetting, "Date");
        } else if (typeName.startsWith("TIMESTAMP")) {
            dataType = getAnyDataType(fieldSetting, "Timestamp");
        } else if (typeName.startsWith("TIME")) {
            dataType = getAnyDataType(fieldSetting, "Time");
        } else if (typeName.startsWith("DATETIME")) {
            dataType = getAnyDataType(fieldSetting, "Timestamp");
        } else if (typeName.startsWith("DECIMAL")) {
            dataType = getDECIMAL(fieldSetting);
        } else if (typeName.startsWith("NUMERIC")) {
            dataType = getDECIMAL(fieldSetting);
        } else if (typeName.startsWith("BOOLEAN")) {
            dataType = getAnyDataType(fieldSetting, "boolean");
        } else if (typeName.startsWith("BIT")) {
            dataType = getAnyDataType(fieldSetting, "boolean");
        } else if (typeName.startsWith("BIT")) {
            dataType = getAnyDataType(fieldSetting, "boolean");
        } else if (typeName.startsWith("TINYINT")) {
            dataType = getAnyDataType(fieldSetting, "byte");
        } else if (typeName.startsWith("SMALLINT")) {
            dataType = getAnyDataType(fieldSetting, "short");
        } else if (typeName.startsWith("SMALLINT")) {
            dataType = getAnyDataType(fieldSetting, "long");
        } else if (typeName.startsWith("BIGINT")) {
            dataType = getAnyDataType(fieldSetting, "long");
        } else if (typeName.startsWith("BIGINT")) {
            dataType = getAnyDataType(fieldSetting, "long");
        } else if (typeName.startsWith("REAL")) {
            dataType = getAnyDataType(fieldSetting, "BigDecimal");
        } else if (typeName.startsWith("BINARY")) {
            dataType = getAnyDataType(fieldSetting, "byte[]");
        } else if (typeName.startsWith("VARBINARY")) {
            dataType = getAnyDataType(fieldSetting, "byte[]");
        } else if (typeName.startsWith("LONGVARBINARY")) {
            dataType = getAnyDataType(fieldSetting, "byte[]");
        } else if (typeName.startsWith("OTHER")) {
            dataType = getAnyDataType(fieldSetting, "Object");
        } else if (typeName.startsWith("OBJECT")) {
            dataType = getAnyDataType(fieldSetting, "Object");
        } else {
            throw new InternalGenerateException(fieldSetting.getTypeName());
        }

        return dataType;
    }

    public String getSuffix() {
        return "hsql";
    }

}
