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

schemacrawler.crawl.TablePartial Maven / Gradle / Ivy

Go to download

SchemaCrawler is an open-source Java API that makes working with database metadata as easy as working with plain old Java objects. SchemaCrawler is also a database schema discovery and comprehension, and schema documentation tool. You can search for database schema objects using regular expressions, and output the schema and data in a readable text format. The output is designed to be diff-ed against other database schemas.

There is a newer version: 16.24.2
Show newest version
/*
 *
 * SchemaCrawler
 * http://www.schemacrawler.com
 * Copyright (c) 2000-2015, 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 java.util.Collection;
import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

import schemacrawler.schema.Column;
import schemacrawler.schema.ForeignKey;
import schemacrawler.schema.Index;
import schemacrawler.schema.PartialDatabaseObject;
import schemacrawler.schema.PrimaryKey;
import schemacrawler.schema.Privilege;
import schemacrawler.schema.Schema;
import schemacrawler.schema.Table;
import schemacrawler.schema.TableConstraint;
import schemacrawler.schema.TableRelationshipType;
import schemacrawler.schema.TableType;
import schemacrawler.schema.Trigger;

final class TablePartial
  extends AbstractDatabaseObject
  implements Table, PartialDatabaseObject
{

  private static final long serialVersionUID = -5968964551235088703L;

  private Column column;
  private ForeignKey foreignKey;

  TablePartial(final Schema schema, final String tableName)
  {
    super(schema, tableName);
  }

  TablePartial(final Table table)
  {
    this(requireNonNull(table, "No table provided").getSchema(),
         table.getName());
    addAttributes(table.getAttributes());
  }

  @Override
  public List getColumns()
  {
    throw new NotLoadedException();
  }

  @Override
  public String getDefinition()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getExportedForeignKeys()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getForeignKeys()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getImportedForeignKeys()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getIndexes()
  {
    throw new NotLoadedException();
  }

  @Override
  public PrimaryKey getPrimaryKey()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection> getPrivileges()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getRelatedTables(final TableRelationshipType tableRelationshipType)
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getTableConstraints()
  {
    throw new NotLoadedException();
  }

  @Override
  public TableType getTableType()
  {
    throw new NotLoadedException();
  }

  @Override
  public Collection getTriggers()
  {
    throw new NotLoadedException();
  }

  @Override
  public TableType getType()
  {
    throw new NotLoadedException();
  }

  @Override
  public boolean hasDefinition()
  {
    throw new NotLoadedException();
  }

  @Override
  public Optional lookupColumn(final String name)
  {
    if (column.getName().equals(name))
    {
      return Optional.ofNullable(column);
    }
    else
    {
      return Optional.empty();
    }
  }

  @Override
  public Optional lookupForeignKey(final String name)
  {
    if (foreignKey.getName().equals(name))
    {
      return Optional.ofNullable(foreignKey);
    }
    else
    {
      return Optional.empty();
    }
  }

  @Override
  public Optional lookupIndex(final String name)
  {
    throw new NotLoadedException();
  }

  @Override
  public Optional> lookupPrivilege(final String name)
  {
    throw new NotLoadedException();
  }

  @Override
  public Optional lookupTrigger(final String name)
  {
    throw new NotLoadedException();
  }

  void addColumn(final Column column)
  {
    this.column = column;
  }

  void addForeignKey(final ForeignKey foreignKey)
  {
    this.foreignKey = foreignKey;
  }

}