/*
 * blancoDb
 * Copyright (C) 2004-2005 Yasuo Nakanishi
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 */
package blanco.db.definition;

import java.sql.ResultSetMetaData;
import java.sql.Types;

import blanco.ig.expander.Type;

/**
 * @author Yasuo Nakanishi
 */
public class AbstractField {
    private int _isNullable = ResultSetMetaData.columnNullableUnknown;

    /**
     * 非NULLであればプリミティブ型なのだがNULLサポートのためにオブジェクトマップしているフィールド。
     */
    private boolean _isObjectMappingForPrimitiveNullSupport = false;

    private int _size = -1;

    private int _precision = -1;

    private int _scale = -1;

    private String _alias = "";

    private Type _javaType = null;

    private String _jdbcName = null;

    /**
     * JDBCから得られたタイプそのもの
     */
    private int _jdbcType = Types.OTHER;

    public AbstractField(Class type, String name) {
        this(new Type(type), name);
    }

    public AbstractField(Type type, String name) {
        _javaType = type;
        _jdbcName = name;
    }

    public String getJdbcName() {
        return _jdbcName;
    }

    public String getName() {
        String result = _jdbcName;
        if (!_alias.equals("")) {
            result = _alias;
        }
        return result;
    }

    public void setAlias(String alias) {
        _alias = alias;
    }

    public Type getJavaType() {
        return _javaType;
    }

    public int getJdbcType() {
        return _jdbcType;
    }

    public void setJdbcType(int arg) {
        _jdbcType = arg;
    }

    public final String getTypeFullName() {
        return _javaType.getFullName();
    }

    public final String getTypeName() {
        return _javaType.getName();
    }

    /**
     * @return _isNullable を戻します。
     */
    public int getNullable() {
        return _isNullable;
    }

    /**
     * @param nullable
     *            _isNullable を設定。
     */
    public void setNullable(int nullable) {
        _isNullable = nullable;
    }

    public boolean getObjectMappingForPrimitiveNullSupport() {
        return _isObjectMappingForPrimitiveNullSupport;
    }

    public void setObjectMappingForPrimitiveNullSupport(boolean arg) {
        _isObjectMappingForPrimitiveNullSupport = arg;
    }

    /**
     * @return _precision を戻します。
     */
    public int getPrecision() {
        return _precision;
    }

    /**
     * @param _precision
     *            _precision を設定。
     */
    public void setPrecision(int _precision) {
        this._precision = _precision;
    }

    /**
     * @return _scale を戻します。
     */
    public int getScale() {
        return _scale;
    }

    /**
     * @param _scale
     *            _scale を設定。
     */
    public void setScale(int _scale) {
        this._scale = _scale;
    }

    /**
     * @return _size を戻します。
     */
    public int getSize() {
        return _size;
    }

    /**
     * @param _size
     *            _size を設定。
     */
    public void setSize(int _size) {
        this._size = _size;
    }
}