/* * * SchemaCrawler * http://sourceforge.net/projects/schemacrawler * Copyright (c) 2000-2010, Sualeh Fatehi. * * 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. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. * */ package schemacrawler.build; import schemacrawler.schema.Column; import schemacrawler.schema.ColumnMap; import schemacrawler.schema.ForeignKeyColumnMap; /** * Represents a single column mapping from a primary key column to a * foreign key column. * * @author Sualeh Fatehi */ final class ForeignKeyColumnMapMetadata extends BaseColumnMap implements ForeignKeyColumnMap { public final static class ForeignKeyColumnMapBuilder extends BaseColumnMapBuilder { private int keySequence; ForeignKeyColumnMap build() { return new ForeignKeyColumnMapMetadata(this); } public int getKeySequence() { return keySequence; } public void setKeySequence(final int keySequence) { this.keySequence = keySequence; } } private static final long serialVersionUID = 3689073962672273464L; private final Column foreignKeyColumn; private final Column primaryKeyColumn; private final int keySequence; private ForeignKeyColumnMapMetadata(final ForeignKeyColumnMapBuilder builder) { super(builder); primaryKeyColumn = builder.getPrimaryKeyColumn(); foreignKeyColumn = builder.getForeignKeyColumn(); keySequence = builder.keySequence; } /** * {@inheritDoc} */ @Override public int compareTo(final ColumnMap obj) { if (obj == null) { return -1; } final ForeignKeyColumnMap other = (ForeignKeyColumnMap) obj; int comparison = 0; if (comparison == 0) { comparison = getKeySequence() - other.getKeySequence(); } // Note: For the primary key and foreign key columns, compare by // name. if (comparison == 0) { comparison = getPrimaryKeyColumn().getFullName().compareTo(other .getPrimaryKeyColumn().getFullName()); } if (comparison == 0) { comparison = getForeignKeyColumn().getFullName().compareTo(other .getForeignKeyColumn().getFullName()); } return comparison; } /** * {@inheritDoc} * * @see schemacrawler.schema.ForeignKeyColumnMap#getForeignKeyColumn() */ public Column getForeignKeyColumn() { return foreignKeyColumn; } /** * {@inheritDoc} * * @see schemacrawler.schema.ForeignKeyColumnMap#getKeySequence() */ public int getKeySequence() { return keySequence; } /** * {@inheritDoc} * * @see schemacrawler.schema.ForeignKeyColumnMap#getPrimaryKeyColumn() */ public Column getPrimaryKeyColumn() { return primaryKeyColumn; } }