/* * * SchemaCrawler * http://sourceforge.net/projects/schemacrawler * Copyright (c) 2000-2009, 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.crawl; import schemacrawler.schema.DatabaseObject; /** * Represents a database object. * * @author Sualeh Fatehi */ abstract class AbstractDatabaseObject extends AbstractNamedObject implements DatabaseObject { private static final long serialVersionUID = 3099561832386790624L; private final String schemaName; private final String catalogName; AbstractDatabaseObject(final String catalogName, final String schemaName, final String name) { super(name); this.catalogName = catalogName; this.schemaName = schemaName; } /** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } final AbstractDatabaseObject other = (AbstractDatabaseObject) obj; if (catalogName == null) { if (other.catalogName != null) { return false; } } else if (!catalogName.equals(other.catalogName)) { return false; } if (schemaName == null) { if (other.schemaName != null) { return false; } } else if (!schemaName.equals(other.schemaName)) { return false; } return super.equals(obj); } /** * {@inheritDoc} * * @see schemacrawler.schema.DatabaseObject#getCatalogName() */ public final String getCatalogName() { return catalogName; } /** * {@inheritDoc} * * @see Object#toString() */ public String getFullName() { final StringBuilder buffer = new StringBuilder(); if (schemaName != null) { if (catalogName != null && catalogName.length() > 0) { buffer.append(catalogName).append("."); } if (schemaName != null && schemaName.length() > 0) { buffer.append(schemaName).append("."); } } if (getName() != null) { buffer.append(getName()); } return buffer.toString(); } /** * {@inheritDoc} * * @see schemacrawler.schema.DatabaseObject#getSchemaName() */ public final String getSchemaName() { return schemaName; } /** * {@inheritDoc} * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (catalogName == null? 0: catalogName.hashCode()); result = prime * result + (schemaName == null? 0: schemaName.hashCode()); result = prime * result + super.hashCode(); return result; } /** * {@inheritDoc} * * @see Object#toString() */ @Override public String toString() { return getFullName(); } }