Package org.apache.openjpa.jdbc.schema
Class Table
- java.lang.Object
-
- org.apache.openjpa.jdbc.schema.NameSet
-
- org.apache.openjpa.jdbc.schema.Table
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<java.lang.Object>,SourceTracker
public class Table extends NameSet implements java.lang.Comparable<java.lang.Object>, SourceTracker
Represents a database table.- Author:
- Abe White, Stephen Kim
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.apache.openjpa.lib.meta.SourceTracker
SRC_ANNOTATIONS, SRC_OTHER, SRC_XML
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ColumnaddColumn(java.lang.String name)Deprecated.ColumnaddColumn(java.lang.String name, java.lang.String validName)Deprecated.ColumnaddColumn(DBIdentifier name)ColumnaddColumn(DBIdentifier name, DBIdentifier validName)voidaddCorrectedColumnName(java.lang.String name, boolean validate)Deprecated.voidaddCorrectedColumnName(DBIdentifier name, boolean validate)ForeignKeyaddForeignKey()Add a foreign key to the table.ForeignKeyaddForeignKey(java.lang.String name)Deprecated.ForeignKeyaddForeignKey(DBIdentifier name)IndexaddIndex(java.lang.String name)Deprecated.IndexaddIndex(DBIdentifier name)PrimaryKeyaddPrimaryKey()Set the primary key for the table.PrimaryKeyaddPrimaryKey(java.lang.String name)Deprecated.PrimaryKeyaddPrimaryKey(DBIdentifier name)UniqueaddUnique(java.lang.String name)Deprecated.UniqueaddUnique(DBIdentifier name)intcompareTo(java.lang.Object other)booleancontainsColumn(java.lang.String name)Deprecated.booleancontainsColumn(java.lang.String name, DBDictionary dict)Deprecated.booleancontainsColumn(DBIdentifier name)booleancontainsColumn(DBIdentifier name, DBDictionary dict)booleancontainsColumn(Column col)Column[]getAutoAssignedColumns()Return this table's auto-assigned columns.intgetColNumber()Return the column number in the line of the file at which this instance was parsed.ColumngetColumn(java.lang.String name)Deprecated.ColumngetColumn(DBIdentifier name)ColumngetColumn(DBIdentifier name, boolean create)java.lang.String[]getColumnNames()Return the list of column names, used only for informative (error) messages.Column[]getColumns()Return the table's columns, in alphabetical order.java.lang.StringgetComment()ForeignKeygetForeignKey(java.lang.String name)Deprecated.ForeignKeygetForeignKey(DBIdentifier name)ForeignKey[]getForeignKeys()Return all foreign keys for the table.DBIdentifiergetFullIdentifier()java.lang.StringgetFullName()Deprecated.DBIdentifiergetIdentifier()IndexgetIndex(java.lang.String name)Deprecated.IndexgetIndex(DBIdentifier name)Index[]getIndexes()Return the table's indexes.intgetLineNumber()Return the line number of the file at which this instance was parsed.java.lang.StringgetName()Deprecated.PrimaryKeygetPrimaryKey()Return the primary key for the table, if any.QualifiedDBIdentifiergetQualifiedPath()Column[]getRelationIdColumns()Return this table's relation id columns.java.lang.StringgetResourceName()Return the domain-meaningful name of the resource that was loaded from this source.SchemagetSchema()Return the schema for the table.DBIdentifiergetSchemaIdentifier()java.lang.StringgetSchemaName()Deprecated.java.io.FilegetSourceFile()Return the file from which this instance was parsed.java.lang.ObjectgetSourceScope()Return the domain-dependent scope of this instance within its file.intgetSourceType()Return the type of source.UniquegetUnique(java.lang.String name)Deprecated.UniquegetUnique(DBIdentifier name)Unique[]getUniques()Return the table's unique constraints.booleanhasComment()ColumnimportColumn(Column col)Import a column from another table.ForeignKeyimportForeignKey(ForeignKey fk)Import a foreign key; column names must match columns of this table.IndeximportIndex(Index idx)Import an index; column names must match columns of this table.PrimaryKeyimportPrimaryKey(PrimaryKey pk)Import a primary key; column names must match columns of this table.UniqueimportUnique(Unique unq)Import a constraint; column names must match columns of this table.booleanisAssociation()booleanremoveColumn(Column col)Remove the given column from the table.booleanremoveForeignKey(ForeignKey fk)Remove the given foreign key from the table.booleanremoveIndex(Index idx)Remove the given index from the table.booleanremovePrimaryKey()Remove the primary key from this table.booleanremoveUnique(Unique unq)Remove the given unique constraint from the table.voidsetAssociation()voidsetColNumber(int colNum)voidsetComment(java.lang.String comment)voidsetIdentifier(DBIdentifier name)Set the name of the table.voidsetLineNumber(int lineNum)voidsetName(java.lang.String name)Deprecated.usesetIdentifier(DBIdentifier)instead.voidsetSchemaIdentifier(DBIdentifier name)voidsetSchemaName(java.lang.String name)Deprecated.voidsetSource(java.io.File source, int srcType)java.lang.StringtoString()-
Methods inherited from class org.apache.openjpa.jdbc.schema.NameSet
addName, addName, isNameTaken, isNameTaken, removeName, removeName
-
-
-
-
Constructor Detail
-
Table
public Table()
Default constructor.
-
Table
@Deprecated public Table(java.lang.String name, Schema schema)Deprecated.Constructor.- Parameters:
name- the table nameschema- the table schema
-
Table
public Table(DBIdentifier name, Schema schema)
-
-
Method Detail
-
setAssociation
public void setAssociation()
-
isAssociation
public boolean isAssociation()
-
getSchema
public Schema getSchema()
Return the schema for the table.
-
getSchemaName
@Deprecated public java.lang.String getSchemaName()
Deprecated.The table's schema name.
-
getSchemaIdentifier
public DBIdentifier getSchemaIdentifier()
-
setSchemaName
@Deprecated public void setSchemaName(java.lang.String name)
Deprecated.The table's schema name. You can only call this method on tables whose schema object is not set.
-
setSchemaIdentifier
public void setSchemaIdentifier(DBIdentifier name)
-
getName
@Deprecated public java.lang.String getName()
Deprecated.Return the name of the table.
-
getIdentifier
public DBIdentifier getIdentifier()
-
setName
@Deprecated public void setName(java.lang.String name)
Deprecated.usesetIdentifier(DBIdentifier)instead.Set the name of the table. This method can only be called on tables that are not part of a schema.
-
setIdentifier
public void setIdentifier(DBIdentifier name)
Set the name of the table. This method can only be called on tables which are not part of a schema.- Parameters:
name- The name of the table.- Throws:
java.lang.IllegalStateException- ifgetSchema()does not return null.
-
getFullName
@Deprecated public java.lang.String getFullName()
Deprecated.Return the table name, including schema, using '.' as the catalog separator.
-
getQualifiedPath
public QualifiedDBIdentifier getQualifiedPath()
-
getFullIdentifier
public DBIdentifier getFullIdentifier()
-
getSourceFile
public java.io.File getSourceFile()
Description copied from interface:SourceTrackerReturn the file from which this instance was parsed.- Specified by:
getSourceFilein interfaceSourceTracker
-
getSourceScope
public java.lang.Object getSourceScope()
Description copied from interface:SourceTrackerReturn the domain-dependent scope of this instance within its file.- Specified by:
getSourceScopein interfaceSourceTracker
-
getSourceType
public int getSourceType()
Description copied from interface:SourceTrackerReturn the type of source.- Specified by:
getSourceTypein interfaceSourceTracker
-
setSource
public void setSource(java.io.File source, int srcType)
-
getResourceName
public java.lang.String getResourceName()
Description copied from interface:SourceTrackerReturn 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:
getResourceNamein interfaceSourceTracker
-
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.
-
getColumnNames
public java.lang.String[] getColumnNames()
Return the list of column names, used only for informative (error) messages.- Returns:
-
getColumn
@Deprecated public Column getColumn(java.lang.String name)
Deprecated.Return the column with the given name, or null if none.
-
getColumn
public Column getColumn(DBIdentifier name)
-
getColumn
public Column getColumn(DBIdentifier name, boolean create)
-
containsColumn
@Deprecated public boolean containsColumn(java.lang.String name)
Deprecated.Affirms if this table contains the column of the given name without any side-effect.
-
containsColumn
public boolean containsColumn(DBIdentifier name)
-
containsColumn
@Deprecated public boolean containsColumn(java.lang.String name, DBDictionary dict)Deprecated.Affirms if this table contains the column of the given name without any side-effect.- Parameters:
dict- the current database dictionary or null.- See Also:
can have side-effect of creating a column for dynamic table implementation.
-
containsColumn
public boolean containsColumn(DBIdentifier name, DBDictionary dict)
-
containsColumn
public boolean containsColumn(Column col)
-
addColumn
@Deprecated public Column addColumn(java.lang.String name)
Deprecated.Add a column to the table.
-
addColumn
public Column addColumn(DBIdentifier name)
-
addColumn
@Deprecated public Column addColumn(java.lang.String name, java.lang.String validName)
Deprecated.Add a column with a shortened (i.e., validated) name to the table
-
addColumn
public Column addColumn(DBIdentifier name, DBIdentifier validName)
-
addCorrectedColumnName
@Deprecated public void addCorrectedColumnName(java.lang.String name, boolean validate)Deprecated.Add a name to this NameSet
-
addCorrectedColumnName
public void addCorrectedColumnName(DBIdentifier name, boolean validate)
-
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
-
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
@Deprecated public PrimaryKey addPrimaryKey(java.lang.String name)
Deprecated.Set the primary key for the table.
-
addPrimaryKey
public PrimaryKey addPrimaryKey(DBIdentifier name)
-
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
@Deprecated public ForeignKey getForeignKey(java.lang.String name)
Deprecated.Return the foreign key with the given name. If multiple foreign keys have the name, the first match is returned.
-
getForeignKey
public ForeignKey getForeignKey(DBIdentifier name)
-
getForeignKeys
public ForeignKey[] getForeignKeys()
Return all foreign keys for the table.
-
addForeignKey
public ForeignKey addForeignKey()
Add a foreign key to the table.
-
addForeignKey
@Deprecated public ForeignKey addForeignKey(java.lang.String name)
Deprecated.Add a foreign key to the table. Duplicate key names are not allowed.
-
addForeignKey
public ForeignKey addForeignKey(DBIdentifier name)
-
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
@Deprecated public Index getIndex(java.lang.String name)
Deprecated.Return the index with the given name, or null if none.
-
getIndex
public Index getIndex(DBIdentifier name)
-
addIndex
@Deprecated public Index addIndex(java.lang.String name)
Deprecated.Add an index to the table.
-
addIndex
public Index addIndex(DBIdentifier name)
-
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
@Deprecated public Unique getUnique(java.lang.String name)
Deprecated.Return the unique constraint with the given name, or null if none.
-
getUnique
public Unique getUnique(DBIdentifier name)
-
addUnique
@Deprecated public Unique addUnique(java.lang.String name)
Deprecated.Add a unique constraint to the table.
-
addUnique
public Unique addUnique(DBIdentifier name)
-
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(java.lang.Object other)
- Specified by:
compareToin interfacejava.lang.Comparable<java.lang.Object>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hasComment
public boolean hasComment()
-
getComment
public java.lang.String getComment()
-
setComment
public void setComment(java.lang.String comment)
-
getLineNumber
public int getLineNumber()
Description copied from interface:SourceTrackerReturn the line number of the file at which this instance was parsed.- Specified by:
getLineNumberin interfaceSourceTracker
-
setLineNumber
public void setLineNumber(int lineNum)
-
getColNumber
public int getColNumber()
Description copied from interface:SourceTrackerReturn the column number in the line of the file at which this instance was parsed.- Specified by:
getColNumberin interfaceSourceTracker
-
setColNumber
public void setColNumber(int colNum)
-
-