com.googlecode.jdbw.metadata
Class Table

java.lang.Object
  extended by com.googlecode.jdbw.metadata.Table
All Implemented Interfaces:
Comparable<Table>

public class Table
extends Object
implements Comparable<Table>

Table is the primary object you deal with in a database server, they contain at least one column (often more) making the definition of the table and 0 or more rows, which each row has a value for each column.

A table normally has a primary key, a kind of unique index where each row has a value that is unique for within this table. This primary key consists of at least (and normally) one column but could be a combination of several. If you look for a particular row in the table and you know the value of the primary key column(s), this row can be fetched very quickly.

Other than a primary key, a table may also have one or more indexes. An index will make certain lookups much more efficient, you can find more information about how this works in the description of the Index class.

Author:
Martin Berglund
See Also:
Schema, Column, Index

Constructor Summary
Table(MetaDataResolver metaDataResolver, Schema schema, String tableName)
           
 
Method Summary
 int compareTo(Table o)
           
 List<Index> getAllIndexes()
           
 Catalog getCatalog()
           
 Column getColumn(int columnIndex)
          Retrieves a column by index the database
 Column getColumn(String columnName)
          Looks up one column
 Map<String,Column> getColumnMap()
           
 List<Column> getColumns()
           
 Map<String,Index> getIndexMap()
           
 String getName()
           
 int getNrOfColumns()
           
 Index getPrimaryKey()
           
 Schema getSchema()
           
 Index getUniqueKey()
          This method will return you the primary key if there is one, otherwise scan through the list of indexes and return the first available unique index.
 void invalidateCache()
          This table class will cache the columns and indexes after reading them from the database server once, this method will clear the cache, forcing them to be re-read.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Table

public Table(MetaDataResolver metaDataResolver,
             Schema schema,
             String tableName)
Method Detail

getCatalog

public Catalog getCatalog()
Returns:
The catalog which this table sorts under, i.e. the owner of this table's schema

getName

public String getName()
Returns:
Name of the table

getSchema

public Schema getSchema()
Returns:
The schema which owns the table

getUniqueKey

public Index getUniqueKey()
                   throws SQLException
This method will return you the primary key if there is one, otherwise scan through the list of indexes and return the first available unique index. If none is found, it returns null.

Returns:
First available unique index or null
Throws:
SQLException - In an error occurred while reading information from the database

getPrimaryKey

public Index getPrimaryKey()
                    throws SQLException
Returns:
The primary key of this table, represented as an Index or null if there is no primary key
Throws:
SQLException - In an error occurred while reading information from the database

invalidateCache

public void invalidateCache()
This table class will cache the columns and indexes after reading them from the database server once, this method will clear the cache, forcing them to be re-read.


getColumns

public List<Column> getColumns()
                        throws SQLException
Returns:
List of columns in the table, expected to be in order
Throws:
SQLException - In an error occurred while reading information from the database

getAllIndexes

public List<Index> getAllIndexes()
                          throws SQLException
Returns:
All indexes, including the primary key, on this table
Throws:
SQLException - In an error occurred while reading information from the database

getColumn

public Column getColumn(String columnName)
                 throws SQLException
Looks up one column

Parameters:
columnName - Name of the column to retrieve
Returns:
Column representing the column or null if there was no column by this name in the table
Throws:
SQLException - In an error occurred while reading information from the database

getColumn

public Column getColumn(int columnIndex)
                 throws SQLException
Retrieves a column by index the database

Parameters:
columnIndex - Index of the column (starting from 0)
Returns:
Column representing the column at this index in the table
Throws:
SQLException - In an error occurred while reading information from the database

getNrOfColumns

public int getNrOfColumns()
                   throws SQLException
Returns:
Number of columns this table has
Throws:
SQLException - In an error occurred while reading information from the database

compareTo

public int compareTo(Table o)
Specified by:
compareTo in interface Comparable<Table>

getColumnMap

public Map<String,Column> getColumnMap()
                                throws SQLException
Returns:
Map (column name to Column object) of all columns in this table
Throws:
SQLException - In an error occurred while reading information from the database

getIndexMap

public Map<String,Index> getIndexMap()
                              throws SQLException
Returns:
Map (index name to Index object) of all indexes in this table, including the primary key
Throws:
SQLException - In an error occurred while reading information from the database

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.