org.afcs.warts.db
Class AccountConfiguration

java.lang.Object
  extended byorg.afcs.warts.db.AccountConfiguration

public final class AccountConfiguration
extends java.lang.Object

A AccountConfiguration instance contains the information needed to connect to a database and retrieve a set of tables. The information is configured in a Java properties file.

This class is responsible for making use of database metadata to obtain information about both tables (in the event that the tables to load specified in the configuration contains a '*') and the columns in each table in a database-independent way.

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 15 October 2003
Author:
Warren Hedley ( whedley at sdsc dot edu )

Method Summary
 boolean equals(java.lang.Object otherObj)
          Returns true if the specified object is a AccountConfiguration instance with the same database, username and table specs as this one.
 java.sql.Connection getConnection()
          Returns a database connection to the database account configured in this instance.
 java.lang.String getDatabaseUri()
          Returns the database URI that is used to obtain a connection to the database.
 java.lang.String getDisplayName()
          Returns a display name for the account, which is of the format 'username/instancename@machineName'.
 java.lang.String getInstanceName()
          Returns the name of the instance that we're connecting to, which is given by the last part of the URI (the text after the last colon).
 TableDescription getTableDescription(java.lang.String tableName)
          Returns the table description for the specified table name (which should be one of the names returned by getTableNames(), or null if the description can not be loaded.
 java.util.List getTableDescriptions()
          Returns a list of all of the table descriptions configured in this account.
 java.util.List getTableNames()
          This method converts the table names that were specified in the account configuration file into a list of tablenames in an 'owner.tablename' format.
 java.lang.String getUsername()
          Returns the username used to log into this account.
 int hashCode()
          Returns a hashcode for this instance that obeys the general contract.
 boolean isUtf8Encoded()
          Returns true if the account configuration specified that this account was in a UTF-8 encoded database.
static java.util.List loadFromProperties(java.util.Properties properties)
          This method initialises and returns a list of AccountConfiguration instances which are created by processing the specified properties, which have been presumably been loaded from a account configuration file.
 java.lang.String toString()
          Returns a string suitable for use in debugging.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getConnection

public java.sql.Connection getConnection()
Returns a database connection to the database account configured in this instance. If a connection cannot be obtained, then a stack trace is printed and System.exit(1) is called. This is primitive but prevents the user from doing anything odd without having properly configured accounts.

Returns:
A database connection to the database account configured in this instance.

getDatabaseUri

public java.lang.String getDatabaseUri()
Returns the database URI that is used to obtain a connection to the database. This is specified in configuration file.

Returns:
The database URI that is used to obtain a connection to the database.

getDisplayName

public java.lang.String getDisplayName()
Returns a display name for the account, which is of the format 'username/instancename@machineName'.

Returns:
A display name for the account.

getInstanceName

public java.lang.String getInstanceName()
Returns the name of the instance that we're connecting to, which is given by the last part of the URI (the text after the last colon).

Returns:
The name of the instance that we're connecting to.

getUsername

public java.lang.String getUsername()
Returns the username used to log into this account. The tables accessible do not necessarily belong to this user.

Returns:
The username used to log into this account.

isUtf8Encoded

public boolean isUtf8Encoded()
Returns true if the account configuration specified that this account was in a UTF-8 encoded database. This affects the way in which CLOB data is retrieved from the database.

Returns:
True if the account configuration specified that this account was in a UTF-8 encoded database.

getTableNames

public java.util.List getTableNames()
This method converts the table names that were specified in the account configuration file into a list of tablenames in an 'owner.tablename' format. The corresponding table description can then be loaded using getTableDescription(java.lang.String). The owner and tablename are both case- sensitive strings. The java.sql.DatabaseMetadata class is used to obtain tablenames in a database-independent manner in the event that any of the table names in the configuration included a '*'. The list is left in the same order that the configuration specified, so that tables will be processed in the specified order when running in batch mode.

Returns:
A list of tablenames accessible from the current account in an 'owner.tablename' format.

getTableDescription

public TableDescription getTableDescription(java.lang.String tableName)
Returns the table description for the specified table name (which should be one of the names returned by getTableNames(), or null if the description can not be loaded.

Parameters:
tableName - The name of the table to obtain a description of.
Returns:
The description of the specified table.
Throws:
java.lang.NullPointerException - If tableName is null.

getTableDescriptions

public java.util.List getTableDescriptions()
Returns a list of all of the table descriptions configured in this account.

Returns:
A list of all of the table descriptions configured in this account.

toString

public java.lang.String toString()
Returns a string suitable for use in debugging.

Returns:
A string suitable for use in debugging.

equals

public boolean equals(java.lang.Object otherObj)
Returns true if the specified object is a AccountConfiguration instance with the same database, username and table specs as this one. Having the same database implies the same user name, port, and machine name.

Parameters:
otherObj - The object to compare to this one.
Returns:
True if the specified object is a AccountConfiguration instance with the same database, username and tables as this one.

hashCode

public int hashCode()
Returns a hashcode for this instance that obeys the general contract.

Returns:
A hashcode for this instance.

loadFromProperties

public static java.util.List loadFromProperties(java.util.Properties properties)
This method initialises and returns a list of AccountConfiguration instances which are created by processing the specified properties, which have been presumably been loaded from a account configuration file.

Parameters:
properties - The set of properties that define the account configuration information.
Returns:
A list of account configuration instances.
Throws:
java.lang.NullPointerException - If properties is null.