All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datanucleus.metadata.JoinMetaData Maven / Gradle / Ivy

/**********************************************************************
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 - addition of table name
2005 Andy Jefferson - added primary-key, unique, and others
    ...
**********************************************************************/
package org.datanucleus.metadata;

import java.util.ArrayList;
import java.util.List;

import org.datanucleus.ClassLoaderResolver;
import org.datanucleus.util.StringUtils;

/**
 * Secondary tables and join tables are mapped using a join condition that
 * associates a column or columns in the secondary or join table with a column
 * or columns in the primary table, typically the primary tables primary key
 * columns. Column elements used for relationship mapping or join conditions
 * specify the column name and optionally the target column name. The target
 * column name is the name of the column in the associated table corresponding
 * to the named column. The target column name is optional when the target
 * column is the single primary key column of the associated table.
 */
public class JoinMetaData extends MetaData implements ColumnMetaDataContainer
{
    /** the foreign-key element. */
    ForeignKeyMetaData foreignKeyMetaData;

    /** the index element. */
    IndexMetaData indexMetaData;

    /** the unique element. */
    UniqueMetaData uniqueMetaData;

    /** PrimaryKey MetaData */
    protected PrimaryKeyMetaData primaryKeyMetaData;

    /** column elements */
    final List columns = new ArrayList();
       
    /** if is outer join. Outer joins return all elements from at least one of the sides joined. */
    boolean outer = false;

    /** the table name. */
    String table;

    /** the catalog name. */
    String catalog;

    /** the schema name. */
    String schema;

    /** the column name. */
    String columnName;

    /** The indexing value */
    protected IndexedValue indexed=null;

    /** Whether to add a unique constraint. */
    protected boolean unique;

    // -------------------------------------------------------------------------
    // Fields below here are not represented in the output MetaData. They are
    // for use internally in the operation of the JDO system. The majority are
    // for convenience to save iterating through the fields since the fields
    // are fixed once initialised.

    /**
     * Contains the metadata for column
     */
    protected ColumnMetaData[] columnMetaData;

    /**
     * Constructor to create a copy of the passed JoinMetaData.
     * @param joinmd Existing join metadata to copy
     */
    public JoinMetaData(JoinMetaData joinmd)
    {
        this.table = joinmd.table;
        this.catalog = joinmd.catalog;
        this.schema = joinmd.schema;
        this.columnName = joinmd.columnName;
        this.outer = joinmd.outer;
        this.indexed = joinmd.indexed;
        this.unique = joinmd.unique;
        for (int i=0;i or  so is not applicable
            //TODO fix message for property and field
            throw new InvalidMetaDataException(LOCALISER, "044130",
                ((AbstractMemberMetaData)parent).getFullFieldName());
        }

        // Cater for user specifying column name, or columns
        if (columns.size() == 0 && columnName != null)
        {
            columnMetaData = new ColumnMetaData[1];
            columnMetaData[0] = new ColumnMetaData();
            columnMetaData[0].setName(columnName);
            columnMetaData[0].parent = this;
            columnMetaData[0].initialise(clr, mmgr);
        }
        else
        {
            columnMetaData = new ColumnMetaData[columns.size()];
            for (int i=0; i\n");

        // Primary-key
        if (primaryKeyMetaData != null)
        {
            sb.append(primaryKeyMetaData.toString(prefix + indent, indent));
        }

        // Add columns
        if (columnMetaData != null)
        {
            for (int i=0;i\n");
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy