📄 table.java
字号:
package org.apache.ddlutils.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Collection;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Represents a table in the database model.
*
* @version $Revision: 494338 $
*/
public class Table implements Serializable, Cloneable
{
/** Unique ID for serialization purposes. */
private static final long serialVersionUID = -5541154961302342608L;
/** The catalog of this table as read from the database. */
private String _catalog = null;
/** The table's schema. */
private String _schema = null;
/** The name. */
private String _name = null;
/** A desription of the table. */
private String _description = null;
/** The table's type as read from the database. */
private String _type = null;
/** The columns in this table. */
private ArrayList _columns = new ArrayList();
/** The foreign keys associated to this table. */
private ArrayList _foreignKeys = new ArrayList();
/** The indices applied to this table. */
private ArrayList _indices = new ArrayList();
/**
* Returns the catalog of this table as read from the database.
*
* @return The catalog
*/
public String getCatalog()
{
return _catalog;
}
/**
* Sets the catalog of this table.
*
* @param catalog The catalog
*/
public void setCatalog(String catalog)
{
_catalog = catalog;
}
/**
* Returns the schema of this table as read from the database.
*
* @return The schema
*/
public String getSchema()
{
return _schema;
}
/**
* Sets the schema of this table.
*
* @param schema The schema
*/
public void setSchema(String schema)
{
_schema = schema;
}
/**
* Returns the type of this table as read from the database.
*
* @return The type
*/
public String getType()
{
return _type;
}
/**
* Sets the type of this table.
*
* @param type The type
*/
public void setType(String type)
{
_type = type;
}
/**
* Returns the name of the table.
*
* @return The name
*/
public String getName()
{
return _name;
}
/**
* Sets the name of the table.
*
* @param name The name
*/
public void setName(String name)
{
_name = name;
}
/**
* Returns the description of the table.
*
* @return The description
*/
public String getDescription()
{
return _description;
}
/**
* Sets the description of the table.
*
* @param description The description
*/
public void setDescription(String description)
{
_description = description;
}
/**
* Returns the number of columns in this table.
*
* @return The number of columns
*/
public int getColumnCount()
{
return _columns.size();
}
/**
* Returns the column at the specified position.
*
* @param idx The column index
* @return The column at this position
*/
public Column getColumn(int idx)
{
return (Column)_columns.get(idx);
}
/**
* Returns the columns in this table.
*
* @return The columns
*/
public Column[] getColumns()
{
return (Column[])_columns.toArray(new Column[_columns.size()]);
}
/**
* Adds the given column.
*
* @param column The column
*/
public void addColumn(Column column)
{
if (column != null)
{
_columns.add(column);
}
}
/**
* Adds the given column at the specified position.
*
* @param idx The index where to add the column
* @param column The column
*/
public void addColumn(int idx, Column column)
{
if (column != null)
{
_columns.add(idx, column);
}
}
/**
* Adds the column after the given previous column.
*
* @param previousColumn The column to add the new column after; use
* <code>null</code> for adding at the begin
* @param column The column
*/
public void addColumn(Column previousColumn, Column column)
{
if (column != null)
{
if (previousColumn == null)
{
_columns.add(0, column);
}
else
{
_columns.add(_columns.indexOf(previousColumn), column);
}
}
}
/**
* Adds the given columns.
*
* @param columns The columns
*/
public void addColumns(Collection columns)
{
for (Iterator it = columns.iterator(); it.hasNext();)
{
addColumn((Column)it.next());
}
}
/**
* Removes the given column.
*
* @param column The column to remove
*/
public void removeColumn(Column column)
{
if (column != null)
{
_columns.remove(column);
}
}
/**
* Removes the indicated column.
*
* @param idx The index of the column to remove
*/
public void removeColumn(int idx)
{
_columns.remove(idx);
}
/**
* Returns the number of foreign keys.
*
* @return The number of foreign keys
*/
public int getForeignKeyCount()
{
return _foreignKeys.size();
}
/**
* Returns the foreign key at the given position.
*
* @param idx The foreign key index
* @return The foreign key
*/
public ForeignKey getForeignKey(int idx)
{
return (ForeignKey)_foreignKeys.get(idx);
}
/**
* Returns the foreign keys of this table.
*
* @return The foreign keys
*/
public ForeignKey[] getForeignKeys()
{
return (ForeignKey[])_foreignKeys.toArray(new ForeignKey[_foreignKeys.size()]);
}
/**
* Adds the given foreign key.
*
* @param foreignKey The foreign key
*/
public void addForeignKey(ForeignKey foreignKey)
{
if (foreignKey != null)
{
_foreignKeys.add(foreignKey);
}
}
/**
* Adds the given foreign key at the specified position.
*
* @param idx The index to add the foreign key at
* @param foreignKey The foreign key
*/
public void addForeignKey(int idx, ForeignKey foreignKey)
{
if (foreignKey != null)
{
_foreignKeys.add(idx, foreignKey);
}
}
/**
* Adds the given foreign keys.
*
* @param foreignKeys The foreign keys
*/
public void addForeignKeys(Collection foreignKeys)
{
for (Iterator it = foreignKeys.iterator(); it.hasNext();)
{
addForeignKey((ForeignKey)it.next());
}
}
/**
* Removes the given foreign key.
*
* @param foreignKey The foreign key to remove
*/
public void removeForeignKey(ForeignKey foreignKey)
{
if (foreignKey != null)
{
_foreignKeys.remove(foreignKey);
}
}
/**
* Removes the indicated foreign key.
*
* @param idx The index of the foreign key to remove
*/
public void removeForeignKey(int idx)
{
_foreignKeys.remove(idx);
}
/**
* Returns the number of indices.
*
* @return The number of indices
*/
public int getIndexCount()
{
return _indices.size();
}
/**
* Returns the index at the specified position.
*
* @param idx The position
* @return The index
*/
public Index getIndex(int idx)
{
return (Index)_indices.get(idx);
}
/**
* Adds the given index.
*
* @param index The index
*/
public void addIndex(Index index)
{
if (index != null)
{
_indices.add(index);
}
}
/**
* Adds the given index at the specified position.
*
* @param idx The position to add the index at
* @param index The index
*/
public void addIndex(int idx, Index index)
{
if (index != null)
{
_indices.add(idx, index);
}
}
/**
* Adds the given indices.
*
* @param indices The indices
*/
public void addIndices(Collection indices)
{
for (Iterator it = indices.iterator(); it.hasNext();)
{
addIndex((Index)it.next());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -