Package org.jpox.store.rdbms.mapping

Source Code of org.jpox.store.rdbms.mapping.ColumnMapping

/**********************************************************************
Copyright (c) 2004 Erik Bengtson and others. All rights reserved.
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.

Contributors:
2004 Andy Jefferson - coding standards and localisation of messages
    ...
**********************************************************************/
package org.jpox.store.rdbms.mapping;

import org.jpox.store.exceptions.UnsupportedDataTypeException;
import org.jpox.store.mapped.DatastoreField;
import org.jpox.store.mapped.MappedStoreManager;
import org.jpox.store.mapped.mapping.JavaTypeMapping;
import org.jpox.store.rdbms.Column;
import org.jpox.store.rdbms.typeinfo.TypeInfo;

/**
* Column Mapping.
*
* @version $Revision: 1.12 $
**/
public abstract class ColumnMapping extends RDBMSMapping
{
    protected Column column;

    /**
     * Create a new Mapping.
     *
     * @param storeMgr The Store Manager that this Mapping should use.
     * @param mapping The Class that this mapping maps to the database.
     */
    public ColumnMapping(MappedStoreManager storeMgr, JavaTypeMapping mapping)
    {
        super(storeMgr, mapping);
    }

    /**
     * Accessor for whether the mapping is decimal-based.
     * @return Whether the mapping is decimal based
     */
    public boolean isDecimalBased()
    {
        return false;
    }

    /**
     * Accessor for whether the mapping is integer-based.
     * @return Whether the mapping is integer based
     */
    public boolean isIntegerBased()
    {
        return false;
    }

    /**
     * Accessor for whether the mapping is string-based.
     * @return Whether the mapping is string based
     */
    public boolean isStringBased()
    {
        return false;
    }

    /**
     * Accessor for whether the mapping is bit-based.
     * @return Whether the mapping is bit based
     */
    public boolean isBitBased()
    {
        return false;
    }

    /**
     * Accessor for whether the mapping is boolean-based.
     * @return Whether the mapping is boolean based
     */
    public boolean isBooleanBased()
    {
        return false;
    }

    public boolean isNullable()
    {
        if (column != null)
        {
            return column.isNullable();
        }
        return true;
    }

    /**
     * Accessor for the datastore field
     * @return The column
     */
    public DatastoreField getDatastoreField()
    {
        return column;
    }

  /**
   * Returns the TypeInfo (JDBC SQL type) for columns.
     * This method is capable of returning only one TypeInfo (SQL Type).
     * In that way, it seems adequate for using in 1 column Mapping or many
   * columns that share the same TypeInfo.
   * However adequate in most of uses, Mappings using two or more columns
     * should overwrite the initTypeInfo method to appropriate set differents
     * TypeInfo (SQL type) for all the columns
   * @return The TypeInfo
   */
    public abstract TypeInfo getTypeInfo();

  /**
   * Sets the TypeInfo for the columns of the Mapping.
   * Mappings using two or more columns using different TypeInfo(s) should
     * overwrite this method to appropriate set the TypeInfo (SQL type) for
     * all the columns
   */
    protected void initTypeInfo()
    {
        TypeInfo typeInfo = getTypeInfo();
        if (typeInfo == null)
        {
            throw new UnsupportedDataTypeException(LOCALISER.msg("055000",column));
        }

        if (column != null)
        {
            column.setTypeInfo(typeInfo);
        }
    }

    /**
     * @return Returns the column.
     */
    public Column getColumn()
    {
        return column;
    }
   
    /* (non-Javadoc)
     * @see org.jpox.store.rdbms.mapping.RDBMSMapping#includeInFetchStatement()
     */
    public boolean includeInFetchStatement()
    {
        return true;
    }

    /* (non-Javadoc)
     * @see org.jpox.store.rdbms.mapping.RDBMSMapping#getInsertionInputParameter()
     */
    public String getInsertionInputParameter()
    {
        return column.getWrapperFunction(Column.WRAPPER_FUNCTION_INSERT);
    }

    /* (non-Javadoc)
     * @see org.jpox.store.rdbms.mapping.RDBMSMapping#getUpdateInputParameter()
     */
    public String getUpdateInputParameter()
    {
        return column.getWrapperFunction(Column.WRAPPER_FUNCTION_UPDATE);
    }

    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }

        if (!(obj instanceof ColumnMapping))
        {
            return false;
        }

        ColumnMapping cm = (ColumnMapping)obj;

        return getClass().equals(cm.getClass()) &&
            storeMgr.equals(cm.storeMgr) &&
            (column == null ? cm.column == null : column.equals(cm.column));
    }

    public int hashCode()
    {
        return storeMgr.hashCode() ^
             (column == null ? 0 : column.hashCode());
    }
}
TOP

Related Classes of org.jpox.store.rdbms.mapping.ColumnMapping

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.