2004.04.29


com.jdc.rdb
Class Database

java.lang.Object
  |
  +--com.jdc.lang.Object
        |
        +--com.jdc.lang.SerializableObject
              |
              +--com.jdc.rdb.Database
All Implemented Interfaces:
Database, Serializable
Direct Known Subclasses:
Database

public abstract class Database
extends SerializableObject
implements Database

A default implementation of Database. All application database classes should subclass this Database class.

An application Database is defined by its database properties. The following represent properties of relational databases:

The database type is provided by one of the enumerated constants in the DatabaseType class. If not specified, the default type is IBM_DB2. The URL is derived from the database type and the database name.

A DataSource name may, optionally, be specified to take advantage of connection pooling. If specified, Username and Password are optional as they may be specified in the DataSource configuration.

An application database used to store and retrieve data. Database implements functionality common to all relational databases. However, this class is based on and has only been tested with the IBM DB2 Universal Database.

For related IBM DB2 documentation, see:

If a DataSource name is specified, a this class first attempts to obtain a database Connection from a DataSource. If a Connection is not obtained, this class then attempts to obtain a database Connection from the DriverManager.

Note: This class is immutable.

Version:
1.5
Author:
Jay Damon
See Also:
Connection, DataSource, Serialized Form

Nested Class Summary
 class Database.DataSource
          DataSource represents a DataSource object.
 class Database.Version
          Version represents the database version number.
 
Field Summary
protected  Connection connection
          The database Connection object.
 
Fields inherited from class com.jdc.lang.Object
string
 
Constructor Summary
protected Database(String name, String datasource, String username, String password)
          Constructs a new Database object for an IBM DB2 database with the specified database properties.
 
Method Summary
 boolean close()
          Closes the database connection, if open.
 boolean equals(Object object)
          Compares this Database object to the specified object.
protected  void finalize()
          Closes the database connection, if open, and cleans up system resources.
 String getAlias()
          Returns the database alias.
 Connection getConnection()
          Attempts to establish a connection to the database.
 Database.DataSource getDataSource()
          Returns the database DataSource object for this database object.
protected  DatabaseMetaData getMetaData()
          Returns the DatabaseMetaData for this database.
 String getName()
          Returns the database name.
 DatabaseType getType()
          Returns the database type.
 String getURL()
          Returns the database Uniform Resource Locator (URL).
protected  Database.Version getVersion()
          Returns the database Version object for this database object.
 int hashCode()
          Returns a hash code value for this Database object.
 boolean open()
          Attempts to open a connection to the database.
 String toString()
          Returns a String representing this Database object.
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

connection

protected Connection connection
The database Connection object. Once the Database has been successfully opened, i.e. if (open()), a subclass may reference this Connection field directly rather than invoking the getConnection() method.

Constructor Detail

Database

protected Database(String name,
                   String datasource,
                   String username,
                   String password)
Constructs a new Database object for an IBM DB2 database with the specified database properties.

Method Detail

close

public boolean close()
Description copied from interface: Database
Closes the database connection, if open. The database resources in use by this Connection are released immediately.

Specified by:
close in interface Database
Returns:
True if the database connection is successfully closed.
False if the database connection is not successfully closed.

equals

public boolean equals(Object object)
Compares this Database object to the specified object. Returns true if the specified object is equivalent to this database object.

Overrides:
equals in class Object
Returns:
True if a specified object is equal to this database object.
False if the specified object is not equal to this database object.

See Also:
hashCode()

finalize

protected void finalize()
Closes the database connection, if open, and cleans up system resources.

When garbage collection determines that there are no more references to this database object, it invokes this method to close the database connection, if open, and clean up system resources.

Overrides:
finalize in class Object

getAlias

public String getAlias()
Returns the database alias.

Specified by:
getAlias in interface Database
Returns:
The database alias.

getConnection

public Connection getConnection()
Attempts to establish a connection to the database. If the database is not already open, this method implicitly invokes the open() method to open a database connection. If a connection is already available, this method returns that database connection.

If available, a connection will be obtained from a DataSource. Otherwise, a connection will be obtained from the DriverManager.

Specified by:
getConnection in interface Database
Returns:
A Connection to the database.

getDataSource

public Database.DataSource getDataSource()
Returns the database DataSource object for this database object.

Returns:
The database codeDataSource object.

getMetaData

protected DatabaseMetaData getMetaData()
Returns the DatabaseMetaData for this database. Database metadata is information about the database.

Returns:
The DatabaseMetaData for this database.

getName

public String getName()
Returns the database name.

Specified by:
getName in interface Database
Returns:
The database name.

getType

public DatabaseType getType()
Returns the database type.

Specified by:
getType in interface Database
Returns:
The database type.

getURL

public String getURL()
Returns the database Uniform Resource Locator (URL).

Returns:
The database Uniform Resource Locator (URL}).

getVersion

protected Database.Version getVersion()
Returns the database Version object for this database object.

Returns:
The database Version object.

hashCode

public int hashCode()
Returns a hash code value for this Database object. This method is supported for the benefit of hashtables such as those provided by Hashtable.

Overrides:
hashCode in class Object
Returns:
A hash code value for this database object.

See Also:
equals(java.lang.Object)

open

public boolean open()
Attempts to open a connection to the database. If available, a connection will be obtained from a DataSource. Otherwise, a connection will be obtained from the DriverManager.

Specified by:
open in interface Database
Returns:
True if a database connection is successfully opened.
False if a database connection is not successfully opened.

toString

public String toString()
Returns a String representing this Database object.

Overrides:
toString in class Object
Returns:
A String representing this Database object.

2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.