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.22.2
Show newest version
/*
========================================================================
SchemaCrawler
http://www.schemacrawler.com
Copyright (c) 2000-2016, Sualeh Fatehi .
All rights reserved.
------------------------------------------------------------------------

SchemaCrawler 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.

SchemaCrawler and the accompanying materials are made available under
the terms of the Eclipse Public License v1.0, GNU General Public License
v3 or GNU Lesser General Public License v3.

You may elect to redistribute this code under any of these licenses.

The Eclipse Public License is available at:
http://www.eclipse.org/legal/epl-v10.html

The GNU General Public License v3 and the GNU Lesser General Public
License v3 are available at:
http://www.gnu.org/licenses/

========================================================================
*/

package schemacrawler.crawl;


import static java.util.Objects.requireNonNull;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

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(this);
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  @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(this);
  }

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

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

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

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

}