/*
*
* 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.Catalog;
import schemacrawler.schema.ColumnDataType;
import schemacrawler.schema.Procedure;
import schemacrawler.schema.Schema;
import schemacrawler.schema.Table;
/**
* Represents the database schema.
*
* @author Sualeh Fatehi
*/
class MutableSchema
extends AbstractDatabaseObject
implements Schema
{
private static final long serialVersionUID = 3258128063743931187L;
private final Catalog catalog;
private final NamedObjectList<MutableColumnDataType> columnDataTypes = new NamedObjectList<MutableColumnDataType>(NamedObjectSort.alphabetical);
private final NamedObjectList<MutableTable> tables = new NamedObjectList<MutableTable>(NamedObjectSort.alphabetical);
private final NamedObjectList<MutableProcedure> procedures = new NamedObjectList<MutableProcedure>(NamedObjectSort.alphabetical);
MutableSchema(final Catalog catalog, final String name)
{
super(catalog.getName(), name, name);
this.catalog = catalog;
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.Schema#getCatalog()
*/
public Catalog getCatalog()
{
return catalog;
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.Schema#getColumnDataType(java.lang.String)
*/
public ColumnDataType getColumnDataType(final String name)
{
return columnDataTypes.lookup(name);
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.DatabaseInfo#getSystemColumnDataTypes()
*/
public ColumnDataType[] getColumnDataTypes()
{
return columnDataTypes.getAll().toArray(new ColumnDataType[columnDataTypes
.size()]);
}
/**
* {@inheritDoc}
*
* @see Object#toString()
*/
@Override
public String getFullName()
{
final StringBuilder buffer = new StringBuilder();
if (getCatalogName() != null && getCatalogName().length() > 0)
{
buffer.append(getCatalogName()).append(".");
}
if (getName() != null)
{
buffer.append(getName());
}
return buffer.toString();
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.Schema#getProcedure(java.lang.String)
*/
public Procedure getProcedure(final String name)
{
return procedures.lookup(name);
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.Schema#getProcedures()
*/
public Procedure[] getProcedures()
{
return procedures.getAll().toArray(new Procedure[procedures.size()]);
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.Schema#getTable(java.lang.String)
*/
public Table getTable(final String name)
{
return tables.lookup(name);
}
/**
* {@inheritDoc}
*
* @see schemacrawler.schema.Schema#getTables()
*/
public Table[] getTables()
{
return tables.getAll().toArray(new Table[tables.size()]);
}
void addColumnDataType(final MutableColumnDataType columnDataType)
{
columnDataTypes.add(columnDataType);
}
void addProcedure(final MutableProcedure procedure)
{
procedures.add(procedure);
}
void addTable(final MutableTable table)
{
tables.add(table);
}
NamedObjectList<MutableColumnDataType> getColumnDataTypesList()
{
return columnDataTypes;
}
MutableColumnDataType lookupByType(final int type)
{
MutableColumnDataType columnDataType = null;
final MutableColumnDataType[] allColumnDataTypes = columnDataTypes.getAll()
.toArray(new MutableColumnDataType[columnDataTypes.size()]);
for (final MutableColumnDataType currentColumnDataType: allColumnDataTypes)
{
if (type == currentColumnDataType.getType())
{
columnDataType = currentColumnDataType;
break;
}
}
return columnDataType;
}
}