org.apache.openjpa.jdbc.schema
Class Table

java.lang.Object
  extended by org.apache.openjpa.jdbc.schema.NameSet
      extended by org.apache.openjpa.jdbc.schema.Table
All Implemented Interfaces:
Comparable, SourceTracker

public class Table
extends NameSet
implements Comparable, SourceTracker

Represents a database table.

Author:
Abe White, Stephen Kim

Field Summary
 
Fields inherited from interface org.apache.openjpa.lib.meta.SourceTracker
SRC_ANNOTATIONS, SRC_OTHER, SRC_XML
 
Constructor Summary
Table()
          Default constructor.
Table(String name, Schema schema)
          Constructor.
 
Method Summary
 Column addColumn(String name)
          Add a column to the table.
 ForeignKey addForeignKey()
          Add a foreign key to the table.
 ForeignKey addForeignKey(String name)
          Add a foreign key to the table.
 Index addIndex(String name)
          Add an index to the table.
 PrimaryKey addPrimaryKey()
          Set the primary key for the table.
 PrimaryKey addPrimaryKey(String name)
          Set the primary key for the table.
 Unique addUnique(String name)
          Add a unique constraint to the table.
 int compareTo(Object other)
           
 Column[] getAutoAssignedColumns()
          Return this table's auto-assigned columns.
 Column getColumn(String name)
          Return the column with the given name, or null if none.
 Column[] getColumns()
          Return the table's columns, in alphabetical order.
 ForeignKey getForeignKey(String name)
          Return the foreign key with the given name.
 ForeignKey[] getForeignKeys()
          Return all foreign keys for the table.
 String getFullName()
          Return the table name, including schema, using '.' as the catalog separator.
 Index getIndex(String name)
          Return the index with the given name, or null if none.
 Index[] getIndexes()
          Return the table's indexes.
 String getName()
          Return the name of the table.
 PrimaryKey getPrimaryKey()
          Return the primary key for the table, if any.
 Column[] getRelationIdColumns()
          Return this table's relation id columns.
 String getResourceName()
          Return the domain-meaningful name of the resource that was loaded from this source.
 Schema getSchema()
          Return the schema for the table.
 String getSchemaName()
          The table's schema name.
 File getSourceFile()
          Return the file from which this instance was parsed.
 Object getSourceScope()
          Return the domain-dependent scope of this instance within its file.
 int getSourceType()
          Return the type of source.
 Unique getUnique(String name)
          Return the unique constraint with the given name, or null if none.
 Unique[] getUniques()
          Return the table's unique constraints.
 Column importColumn(Column col)
          Import a column from another table.
 ForeignKey importForeignKey(ForeignKey fk)
          Import a foreign key; column names must match columns of this table.
 Index importIndex(Index idx)
          Import an index; column names must match columns of this table.
 PrimaryKey importPrimaryKey(PrimaryKey pk)
          Import a primary key; column names must match columns of this table.
 Unique importUnique(Unique unq)
          Import a constraint; column names must match columns of this table.
 boolean removeColumn(Column col)
          Remove the given column from the table.
 boolean removeForeignKey(ForeignKey fk)
          Remove the given foreign key from the table.
 boolean removeIndex(Index idx)
          Remove the given index from the table.
 boolean removePrimaryKey()
          Remove the primary key from this table.
 boolean removeUnique(Unique unq)
          Remove the given unique constraint from the table.
 void setName(String name)
          Set the name of the table.
 void setSchemaName(String name)
          The table's schema name.
 void setSource(File source, int srcType)
           
 String toString()
           
 
Methods inherited from class org.apache.openjpa.jdbc.schema.NameSet
addName, isNameTaken, removeName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Table

public Table()
Default constructor.


Table

public Table(String name,
             Schema schema)
Constructor.

Parameters:
name - the table name
schema - the table schema
Method Detail

getSchema

public Schema getSchema()
Return the schema for the table.


getSchemaName

public String getSchemaName()
The table's schema name.


setSchemaName

public void setSchemaName(String name)
The table's schema name. You can only call this method on tables whose schema object is not set.


getName

public String getName()
Return the name of the table.


setName

public void setName(String name)
Set the name of the table. This method can only be called on tables that are not part of a schema.


getFullName

public String getFullName()
Return the table name, including schema, using '.' as the catalog separator.


getSourceFile

public File getSourceFile()
Description copied from interface: SourceTracker
Return the file from which this instance was parsed.

Specified by:
getSourceFile in interface SourceTracker

getSourceScope

public Object getSourceScope()
Description copied from interface: SourceTracker
Return the domain-dependent scope of this instance within its file.

Specified by:
getSourceScope in interface SourceTracker

getSourceType

public int getSourceType()
Description copied from interface: SourceTracker
Return the type of source.

Specified by:
getSourceType in interface SourceTracker

setSource

public void setSource(File source,
                      int srcType)

getResourceName

public String getResourceName()
Description copied from interface: SourceTracker
Return the domain-meaningful name of the resource that was loaded from this source. I.e., if we had loaded the source for a Java class, this would return the name of the class.

Specified by:
getResourceName in interface SourceTracker

getColumns

public Column[] getColumns()
Return the table's columns, in alphabetical order.


getAutoAssignedColumns

public Column[] getAutoAssignedColumns()
Return this table's auto-assigned columns.


getRelationIdColumns

public Column[] getRelationIdColumns()
Return this table's relation id columns.


getColumn

public Column getColumn(String name)
Return the column with the given name, or null if none.


addColumn

public Column addColumn(String name)
Add a column to the table.


removeColumn

public boolean removeColumn(Column col)
Remove the given column from the table.

Returns:
true if the column was removed, false if not in the table

importColumn

public Column importColumn(Column col)
Import a column from another table.


getPrimaryKey

public PrimaryKey getPrimaryKey()
Return the primary key for the table, if any.


addPrimaryKey

public PrimaryKey addPrimaryKey()
Set the primary key for the table.


addPrimaryKey

public PrimaryKey addPrimaryKey(String name)
Set the primary key for the table.


removePrimaryKey

public boolean removePrimaryKey()
Remove the primary key from this table.

Returns:
true if there was a pk to remove, false otherwise

importPrimaryKey

public PrimaryKey importPrimaryKey(PrimaryKey pk)
Import a primary key; column names must match columns of this table.


getForeignKey

public ForeignKey getForeignKey(String name)
Return the foreign key with the given name. If multiple foreign keys have the name, the first match is returned.


getForeignKeys

public ForeignKey[] getForeignKeys()
Return all foreign keys for the table.


addForeignKey

public ForeignKey addForeignKey()
Add a foreign key to the table.


addForeignKey

public ForeignKey addForeignKey(String name)
Add a foreign key to the table. Duplicate key names are not allowed.


removeForeignKey

public boolean removeForeignKey(ForeignKey fk)
Remove the given foreign key from the table.

Returns:
true if the key was removed, false if not in the table

importForeignKey

public ForeignKey importForeignKey(ForeignKey fk)
Import a foreign key; column names must match columns of this table.


getIndexes

public Index[] getIndexes()
Return the table's indexes.


getIndex

public Index getIndex(String name)
Return the index with the given name, or null if none.


addIndex

public Index addIndex(String name)
Add an index to the table.


removeIndex

public boolean removeIndex(Index idx)
Remove the given index from the table.

Returns:
true if the index was removed, false if not in the table

importIndex

public Index importIndex(Index idx)
Import an index; column names must match columns of this table.


getUniques

public Unique[] getUniques()
Return the table's unique constraints.


getUnique

public Unique getUnique(String name)
Return the unique constraint with the given name, or null if none.


addUnique

public Unique addUnique(String name)
Add a unique constraint to the table.


removeUnique

public boolean removeUnique(Unique unq)
Remove the given unique constraint from the table.

Returns:
true if the constraint was removed, false if not in the table

importUnique

public Unique importUnique(Unique unq)
Import a constraint; column names must match columns of this table.


compareTo

public int compareTo(Object other)
Specified by:
compareTo in interface Comparable

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006 Apache Software Foundation. All Rights Reserved.