planetj.database
Class Table

java.lang.Object
  |
  +--planetj.database.Table
All Implemented Interfaces:
IDBObject, ITable, IXMLObject, Serializable
Direct Known Subclasses:
AdministrationTable, ApplicationTable, CacheDetailsTable, ConnectionTable, FieldDataTable, OperationTable, PossibleValueTable, ThemeTable

public class Table
extends Object
implements IDBObject, Serializable, IXMLObject, ITable

Author:
PlanetJ Corporation
See Also:
Serialized Form

Field Summary
static String className
           
static String KEY_SEPARATOR
           
 
Method Summary
 StringBuffer appendFullyQualifiedName(StringBuffer sb)
          Appends the library qualified name of the table, such as "mylibrary.mytable"
static StringBuffer appendFullyQualifiedName(Table t, StringBuffer sb)
          Appends the library qualified name of the table, such as "mylibrary.mytable"
 int copyFieldDescriptors(String newAlias)
          Copies all of this table's FD's into another system alias.
 void createFieldDescriptors()
          This is to be overridden to allow Table subclasses to create their own unique FieldDescriptors.
static Table createTable(String systemAlias, String libName, String tblName)
          Creates and returns a new Table using the given system alias, library name, and table name.
static Table createTable(String pSystemAlias, String pLibraryName, String pTableName, Class pTableClass)
          Creates and returns a new Table using the given system Alias, library name, and table name.
 boolean createTableInDB(SQLContext context, boolean overwrite, List fds)
          Creates this table in the database specified in the SQLContext.
 List getAllOrderedColumnNames()
          Returns a List of column names in this Table.
 List getAllOrderedColumnNames(boolean pDatabaseOnly)
          Returns a List of column names in this Table.
 RowCollection getAllRows()
          Gets all the rows from the table
 RowCollection getAssociations()
          Return a RowCollection of FieldDescriptorRows for this Table that have a Associations defined for them.
 List getAutoIncrementFieldDescriptors()
          Returns a List containing all the FieldDescriptorRow objects which describe Auto-Increment fields in the table
 String getCreationSQL()
          Gets the "CREATE TABLE" SQL statement that can be used to recreate this table.
 String getCreationSQL(String newSystem, String newLibrary, String newTable)
          Gets the "CREATE TABLE" SQL statement that can be used to duplicate this table on another system.
 String getCreationSQL(Table table)
          Gets the "CREATE TABLE" SQL statement that can be used to duplicate this table on another system.
 String getCreationSQL(Table table, List fieldDescriptors)
          Gets the "CREATE TABLE" SQL statement that can be used to duplicate this table on another system.
 List getFieldDescriptor(Class pFldClass)
          Returns an IFieldDescriptor for the specified Type
 FieldDescriptorRow getFieldDescriptor(String fldName)
          Returns a FieldDescriptorRow for the specified field name.
 FieldDescriptorCollection getFieldDescriptorCollection()
          Returns a Map of FieldDescriptors for this table.
 FieldDescriptorCollection getFieldDescriptorCollection(boolean pCreate)
          Returns a Map of FieldDescriptors for this table.
 Iterator getFieldDescriptorsWithAssociations()
          Return a Collection of FieldDescriptorRow for this Table that have a Associations defined for them
 List getFieldDescriptorsWithUsageIdOverlap(Table t)
          Gets the FD's in this table whose usageids equal the usageids in one or more fields of another table
 List getFieldNames()
          Returns a List of Field names in this Table.
 String getFullyQualifiedName()
          Returns the library qualified name of the table, such as "mylibrary.mytable"
 byte[] getIPAddress()
          Gets the IP address of the system containing this ITable
 List getKeyFieldNames()
          Returns a List of names of Fields that are part of the Table's key.
 long getLastUpdated()
          Gets when this table was last updated by the DataEngine, or when this table's metatdata was last invalidated - whichever is later.
 Library getLibrary()
          Returns the Library to which this Table belongs to.
 String getLibraryName()
          Returns the name of the Library to which this Table belongs.
 List getLogicalFieldNames()
          Returns a List of Field names in this Table.
 long getMetadataInvalidationTime()
          Gets when this table's metadata was last invalidated.
 String getMetaDataSystemAlias()
          Gets the alias of the system this Table's Library's DBSystem uses for retrieving its meta data.
 String getName()
          Gets the name of this ITable
 List getPhysicalFieldNames()
          Returns a List of Field names in this Table.
 PhysicalTable getPhysicalTable()
          Gets information about the Table's location.
 Row getRow(RowKey rowKey)
          Reads a row from the this table in the database with the specified key
 Class getRowClass()
          Gets the subclass of Row that should be used for rows read from this table
 DBSystem getSystem()
          Returns the system of the Library to which this Table belongs.
 String getSystemAlias()
          Returns the system url of the Library to which this Table belongs (the Library gets the url from it's DBSystem).
 String getSystemURL()
          Returns the system url of the Library to which this Table belongs (the Library gets the url from it's DBSystem).
static Table getTable(String pSystemAlias, String pLibraryName, String pTableName)
          Get the Table for the given table name using the specified library name and system url.
static Table getTable(String pSystemAlias, String pLibraryName, String pTableName, boolean create)
          Get the Table for the given table name using the specified library name and system url.
 TableDescriptor getTableDescriptor()
          Gets the table descriptor
 StringBuffer getXMLData(StringBuffer pXMLData)
          This returns a StringBuffer containing all necessary XML data for this object.
 boolean isCheckedDataFileForFDs()
          Return flag to indicate if Field data file has already been checked for FieldDescriptors.
 boolean isExistenceConfirmed()
          Return whether or not this Table's existence in the database has been confirmed.
 boolean isFDsReadFromDBMetadata()
          Return flag to indicate if FD's have been read from the database metadata
 boolean isShared()
          Tests if this table is a logical "shared" table
 void setCheckedDataFileForFDs(boolean pCheckedDataFileForFDs)
          Set flag to indicate Field data file has already been checked for FieldDescriptors.
 void setFDsReadFromDBMetadata(boolean pAllFDsRead)
          Set flag to indicate FDs have been read from DB metadata
 void setLastUpdated(long newLastUpdated)
          Sets when this table was last updated by DataEngine
 void setMetadataInvalidationTime(long time)
          Sets when this table's metadata was last invalidated.
 String toString()
          Returns the String representation of this Table.
 TableCollection toTableCollection()
          Returns a new TableCollection object containing this table
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_SEPARATOR

public static final String KEY_SEPARATOR
See Also:
Constant Field Values

className

public static final String className
Method Detail

appendFullyQualifiedName

public StringBuffer appendFullyQualifiedName(StringBuffer sb)
Appends the library qualified name of the table, such as "mylibrary.mytable"


appendFullyQualifiedName

public static StringBuffer appendFullyQualifiedName(Table t,
                                                    StringBuffer sb)
Appends the library qualified name of the table, such as "mylibrary.mytable"


copyFieldDescriptors

public int copyFieldDescriptors(String newAlias)
                         throws CMException
Copies all of this table's FD's into another system alias. All of the field descriptors for this table that exist in the field data file are copied back into the field data with a new system alias. Any FD's that are not in the field data file are copied to the new alias, but are not stored in the field data file. The original FD's are not altered The number of FD's that were copied is returned

CMException

createFieldDescriptors

public void createFieldDescriptors()
                            throws CMException
This is to be overridden to allow Table subclasses to create their own unique FieldDescriptors. This method is called when the Table is created. Note: any FieldDescriptors created must also be added using the FieldDescriptorManager.

CMException

createTable

public static Table createTable(String systemAlias,
                                String libName,
                                String tblName)
Creates and returns a new Table using the given system alias, library name, and table name. If such a Table already exists, then that Table is returned (no new Tables are created).


createTable

public static Table createTable(String pSystemAlias,
                                String pLibraryName,
                                String pTableName,
                                Class pTableClass)
Creates and returns a new Table using the given system Alias, library name, and table name. If such a Table already exists and pReplace if false, then that Table is returned (no new Table is created).

Parameters:
pSystemAlias -
pLibraryName -
pTableName -
pTableClass -
Returns:
Table

createTableInDB

public boolean createTableInDB(SQLContext context,
                               boolean overwrite,
                               List fds)
                        throws CMException
Creates this table in the database specified in the SQLContext. This method only creates the table itself, no data is transferred.

Parameters:
overwrite - If the table already exists on the specified system, it is either deleted and recreated or an exception is thrown, depending on the value of this argument
Returns:
True if a new table was created, false otherwise
CMException

getAllOrderedColumnNames

public List getAllOrderedColumnNames()
                              throws CMException
Returns a List of column names in this Table. This method will go straight to the DB the first time it is invoked, and will get and cache the column names. Subsequent invocations will return the names from the cache. Field descriptors that do not already exist will be created. Note that though the returned List is will contain the names of all fields in the database, it may also contain the names of fields that are not in the database.

CMException

getAllOrderedColumnNames

public List getAllOrderedColumnNames(boolean pDatabaseOnly)
                              throws CMException
Returns a List of column names in this Table. This method will go straight to the DB the first time it is invoked, and will get and cache the column names. Subsequent invocations will return the names from the cache. Field descriptors that do not already exist will be created.

Parameters:
pDatabaseOnly - When this is false, the returned list may contain the names of logical columns not present in the database. When this is true, only the names of columns in the database will be returned
CMException

getAllRows

public RowCollection getAllRows()
                         throws CMException
Gets all the rows from the table

CMException

getAssociations

public RowCollection getAssociations()
                              throws CMException
Return a RowCollection of FieldDescriptorRows for this Table that have a Associations defined for them.

Returns:
RowCollection
CMException

getAutoIncrementFieldDescriptors

public List getAutoIncrementFieldDescriptors()
Returns a List containing all the FieldDescriptorRow objects which describe Auto-Increment fields in the table


getCreationSQL

public String getCreationSQL()
                      throws CMException
Gets the "CREATE TABLE" SQL statement that can be used to recreate this table. (Only the table definition is in the SQL statement, not any data.) If you wish to recreate the table on another system, use the version of this method which has 3 String arguments

CMException

getCreationSQL

public String getCreationSQL(String newSystem,
                             String newLibrary,
                             String newTable)
                      throws CMException
Gets the "CREATE TABLE" SQL statement that can be used to duplicate this table on another system. (Only the table definition is in the SQL statement, not any data.)

Parameters:
newSystem - The system on which the new table should be created
newLibrary - The library the new table should be created in. This may be null if the target database system does not require a library
newTable - The name of the new table
CMException

getCreationSQL

public String getCreationSQL(Table table)
                      throws CMException
Gets the "CREATE TABLE" SQL statement that can be used to duplicate this table on another system. (Only the table definition is in the SQL statement, not any data.)

Parameters:
table - The table specifing the system, library name, and table name for the new table
CMException

getCreationSQL

public String getCreationSQL(Table table,
                             List fieldDescriptors)
                      throws CMException
Gets the "CREATE TABLE" SQL statement that can be used to duplicate this table on another system. (Only the table definition is in the SQL statement, not any data.)

Parameters:
table - The table specifing the system, library name, and table name for the new table
fieldDescriptors - The field descriptors describing the fields that should be included in the SQL statement. If this is null, all of the fields that are in the database table described by the Table parameter will be included in the SQL statement. Otherwise, only those fields in this List of field descriptors (which may or may not be in the database table) will be included in the SQL.
CMException

getFieldDescriptor

public List getFieldDescriptor(Class pFldClass)
                        throws CMException
Returns an IFieldDescriptor for the specified Type

Returns:
List of FDRows
CMException

getFieldDescriptor

public FieldDescriptorRow getFieldDescriptor(String fldName)
                                      throws CMException
Returns a FieldDescriptorRow for the specified field name.

Parameters:
fldName - String
Returns:
IFieldDescriptor
CMException

getFieldDescriptorCollection

public FieldDescriptorCollection getFieldDescriptorCollection()
Returns a Map of FieldDescriptors for this table.

Returns:
Map

getFieldDescriptorCollection

public FieldDescriptorCollection getFieldDescriptorCollection(boolean pCreate)
                                                       throws CMException
Returns a Map of FieldDescriptors for this table. If they haven't been retrieved optionally create them

Returns:
Map
CMException

getFieldDescriptorsWithAssociations

public Iterator getFieldDescriptorsWithAssociations()
                                             throws CMException
Return a Collection of FieldDescriptorRow for this Table that have a Associations defined for them

Returns:
Iterator
CMException

getFieldDescriptorsWithUsageIdOverlap

public List getFieldDescriptorsWithUsageIdOverlap(Table t)
Gets the FD's in this table whose usageids equal the usageids in one or more fields of another table


getFieldNames

public List getFieldNames()
Returns a List of Field names in this Table. This method gets the field names based on the field descriptors that are currently associated with this table. The returned List will may include fields that are not physically in the database.

Returns:
List

getFullyQualifiedName

public String getFullyQualifiedName()
Returns the library qualified name of the table, such as "mylibrary.mytable"


getIPAddress

public byte[] getIPAddress()
Gets the IP address of the system containing this ITable

Specified by:
getIPAddress in interface ITable

getKeyFieldNames

public List getKeyFieldNames()
                      throws CMException
Returns a List of names of Fields that are part of the Table's key.

Returns:
List
CMException

getLastUpdated

public long getLastUpdated()
Gets when this table was last updated by the DataEngine, or when this table's metatdata was last invalidated - whichever is later. -1 is returned if the neither the last update time nor the last metadata invalidation time is known


getLibrary

public Library getLibrary()
Returns the Library to which this Table belongs to.

Returns:
Library

getLibraryName

public String getLibraryName()
Returns the name of the Library to which this Table belongs.

Specified by:
getLibraryName in interface ITable
Returns:
String

getLogicalFieldNames

public List getLogicalFieldNames()
Returns a List of Field names in this Table. This method gets the field names based on the field descriptors that are currently associated with this table. The returned List will only include fields that are not physically in the database.

Returns:
List

getMetadataInvalidationTime

public long getMetadataInvalidationTime()
Gets when this table's metadata was last invalidated. Changes to the metadata (like updating, adding, or deleting a field descriptor) cause the metadata to be invalidated. If a cached RowCollection has been read from the database and the metadata of that RowCollection's table is subsequently invalidated, then that RowCollection will be removed from the cache


getMetaDataSystemAlias

public String getMetaDataSystemAlias()
Gets the alias of the system this Table's Library's DBSystem uses for retrieving its meta data.

Returns:
String

getName

public String getName()
Description copied from interface: ITable
Gets the name of this ITable

Specified by:
getName in interface IDBObject

getPhysicalFieldNames

public List getPhysicalFieldNames()
Returns a List of Field names in this Table. This method gets the field names based on the field descriptors that are currently associated with this table. The returned List will only include fields that are physically in the database.

Returns:
List

getPhysicalTable

public PhysicalTable getPhysicalTable()
Gets information about the Table's location. If a single database table is accessed by two connections with different system aliases, there will be two separate and different Table objects created. Since both of those Table object point to the same physical database table, then the results of invoking this method on both of them will be equal.


getRow

public Row getRow(RowKey rowKey)
           throws CMException
Reads a row from the this table in the database with the specified key

CMException

getRowClass

public Class getRowClass()
Gets the subclass of Row that should be used for rows read from this table


getSystem

public DBSystem getSystem()
Returns the system of the Library to which this Table belongs.

Returns:
DBSystem

getSystemAlias

public String getSystemAlias()
Returns the system url of the Library to which this Table belongs (the Library gets the url from it's DBSystem).

Returns:
String

getSystemURL

public String getSystemURL()
Returns the system url of the Library to which this Table belongs (the Library gets the url from it's DBSystem).

Returns:
String

getTable

public static Table getTable(String pSystemAlias,
                             String pLibraryName,
                             String pTableName)
Get the Table for the given table name using the specified library name and system url. Returns null if the table doesn't exist.

Parameters:
pSystemAlias - String
pLibraryName - String
pTableName - String
Returns:
Table

getTable

public static Table getTable(String pSystemAlias,
                             String pLibraryName,
                             String pTableName,
                             boolean create)
Get the Table for the given table name using the specified library name and system url.

Parameters:
create - boolean
Returns:
Table

getTableDescriptor

public TableDescriptor getTableDescriptor()
                                   throws CMException
Gets the table descriptor

CMException

getXMLData

public StringBuffer getXMLData(StringBuffer pXMLData)
This returns a StringBuffer containing all necessary XML data for this object. Creation date: (1/22/2002 1:39:57 PM)

Specified by:
getXMLData in interface IXMLObject

isCheckedDataFileForFDs

public boolean isCheckedDataFileForFDs()
Return flag to indicate if Field data file has already been checked for FieldDescriptors.

Returns:
boolean

isExistenceConfirmed

public boolean isExistenceConfirmed()
Return whether or not this Table's existence in the database has been confirmed.

Returns:
boolean

isFDsReadFromDBMetadata

public boolean isFDsReadFromDBMetadata()
Return flag to indicate if FD's have been read from the database metadata

Returns:
boolean

isShared

public boolean isShared()
Tests if this table is a logical "shared" table


setCheckedDataFileForFDs

public void setCheckedDataFileForFDs(boolean pCheckedDataFileForFDs)
Set flag to indicate Field data file has already been checked for FieldDescriptors.

Parameters:
pCheckedDataFileForFDs - boolean

setFDsReadFromDBMetadata

public void setFDsReadFromDBMetadata(boolean pAllFDsRead)
Set flag to indicate FDs have been read from DB metadata


setLastUpdated

public void setLastUpdated(long newLastUpdated)
Sets when this table was last updated by DataEngine


setMetadataInvalidationTime

public void setMetadataInvalidationTime(long time)
Sets when this table's metadata was last invalidated. Changes to the metadata (like updating, adding or deleting a field descriptor) cause the metadata to be invalidated. If a cached RowCollection has been read from the database and the metadata of that RowCollection's table is subsequently invalidated, then that RowCollection will be removed from the cache.


toString

public String toString()
Returns the String representation of this Table.

Overrides:
toString in class Object
Returns:
String

toTableCollection

public TableCollection toTableCollection()
Returns a new TableCollection object containing this table