javatools.db
Class DbDatabase

java.lang.Object
  |
  +--javatools.db.DbDatabase
Direct Known Subclasses:
DbDatabaseAdmin

public class DbDatabase
extends java.lang.Object

A class that represents a particular database. A DbDatabase basically consists of some connection parameters plus we keep track of the open connections. The constructor is not public. Use DbManager.getDatabase().


Field Summary
protected  boolean checkStatement
          A flag indicating if a DBMS supports check clauses in its constraints.
protected  boolean foreignKey
          A flag indicating if a DBMS supports foreign keys.
protected  boolean onDeleteCascade
          A flag indicating if a DBMS supports ON DELETE CASCADE clauses in its constraints.
protected  boolean onDeleteSetDefault
          A flag indicating if a DBMS supports ON DELETE SET DEFAULT clauses in its constraints.
protected  boolean onDeleteSetNull
          A flag indicating if a DBMS supports ON DELETE SET NULL clauses in its constraints.
protected  boolean onUpdateCascade
          A flag indicating if a DBMS supports ON UPDATE CASCADE clauses in its constraints.
protected  boolean onUpdateSetDefault
          A flag indicating if a DBMS supports ON UPDATE SET DEFAULT clauses in its constraints.
protected  boolean onUpdateSetNull
          A flag indicating if a DBMS supports ON UPDATE SET NULL clauses in its constraints.
 
Constructor Summary
DbDatabase()
          Builds a new DbDatabase empty object.
DbDatabase(DbManager manager, java.lang.String name, java.lang.String driver, java.lang.String connectString, java.lang.String userName, java.lang.String password)
          Builds a new DbDatabase object.
 
Method Summary
 boolean equals(java.lang.Object o)
          Checks if a DbDatabase object equals this one.
 DbExpr falseExpr()
          Return an expression representing an SQL false expression.
 boolean getCheckStatement()
          Returns the capability of DBMS to handle check statements.
 DbConnection getExistingThreadConnection()
          Get a DbConnection that will be associated with this Thread, but only if one exists already.
 boolean getForeignKey()
          Returns the capability of DBMS to handle foreign keys.
 DbJoinedTable getJoinedTable(DbAbstractTable tableLeft, DbAbstractTable tableRight, int joinType, DbExpr joinCondition)
          Returns a joined table.
 DbConnection getNewConnection()
          Return a brand new DbConnection.
 boolean getOnDeleteCascade()
          Returns the capability of DBMS to handle ON DELETE CASCADE clauses.
 boolean getOnDeleteSetDefault()
          Returns the capability of DBMS to handle ON DELETE SET DEFAULT clauses.
 boolean getOnDeleteSetNull()
          Returns the capability of DBMS to handle ON DELETE SET NULL clauses.
 boolean getOnUpdateCascade()
          Returns the capability of DBMS to handle ON UPDATE CASCADE clauses.
 boolean getOnUpdateSetDefault()
          Returns the capability of DBMS to handle ON UPDATE SET DEFAULT clauses.
 boolean getOnUpdateSetNull()
          Returns the capability of DBMS to handle ON UPDATE SET NULL clauses.
 java.lang.String getProperty(java.lang.String pname)
          A database can have a set of properties associated with it.
 DbSequence getSequence(java.lang.String name)
          Ahem... uncommented.
 DbTable getTable(java.lang.String name)
          Return an object representing a particular table in the database.
 DbConnection getThreadConnection()
          Get a DbConnection that will be associated with this Thread.
 boolean hasThreadConnection()
          Does this thread have a default connection associated with it?
 DbSelector selector()
          Create a new DbSelector.
 void setAutoCommit(boolean pAutoCommit)
          Sets autocommit property.
 void setProperty(java.lang.String pname, java.lang.String value)
          Set a property for this database.
 java.lang.String toString()
          A database to a string?
 DbExpr trueExpr()
          Return an expression representing an SQL true expression.
 DbExpr valueList(java.util.Collection col)
          Returns a value list.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

foreignKey

protected boolean foreignKey
A flag indicating if a DBMS supports foreign keys. true: the DBMS supports foreign keys; false: otherwise.


checkStatement

protected boolean checkStatement
A flag indicating if a DBMS supports check clauses in its constraints. true: the DBMS supports check clauses; false: otherwise.


onDeleteCascade

protected boolean onDeleteCascade
A flag indicating if a DBMS supports ON DELETE CASCADE clauses in its constraints. true: the DBMS supports ON DELETE CASCADE clauses; false: otherwise.


onDeleteSetDefault

protected boolean onDeleteSetDefault
A flag indicating if a DBMS supports ON DELETE SET DEFAULT clauses in its constraints. true: the DBMS supports ON DELETE SET DEFAULT clauses; false: otherwise.


onDeleteSetNull

protected boolean onDeleteSetNull
A flag indicating if a DBMS supports ON DELETE SET NULL clauses in its constraints. true: the DBMS supports ON DELETE SET NULL clauses; false: otherwise.


onUpdateCascade

protected boolean onUpdateCascade
A flag indicating if a DBMS supports ON UPDATE CASCADE clauses in its constraints. true: the DBMS supports ON UPDATE CASCADE clauses; false: otherwise.


onUpdateSetDefault

protected boolean onUpdateSetDefault
A flag indicating if a DBMS supports ON UPDATE SET DEFAULT clauses in its constraints. true: the DBMS supports ON UPDATE SET DEFAULT clauses; false: otherwise.


onUpdateSetNull

protected boolean onUpdateSetNull
A flag indicating if a DBMS supports ON UPDATE SET NULL clauses in its constraints. true: the DBMS supports ON UPDATE SET NULL clauses; false: otherwise.

Constructor Detail

DbDatabase

public DbDatabase()
Builds a new DbDatabase empty object.


DbDatabase

public DbDatabase(DbManager manager,
                  java.lang.String name,
                  java.lang.String driver,
                  java.lang.String connectString,
                  java.lang.String userName,
                  java.lang.String password)
Builds a new DbDatabase object.

Parameters:
manager - The manager of all databases.
name - The name of DBMS.
driver - The JDBC driver for this DBMS.
connectString - The connection string to connect the DBMS to.
userName - the user name to be used in connection.
password - The password to be used in connection.
Method Detail

setAutoCommit

public void setAutoCommit(boolean pAutoCommit)
Sets autocommit property.

Parameters:
pAutoCommit - true: each database update is autocommitted; false: commit must be made manually.

setProperty

public void setProperty(java.lang.String pname,
                        java.lang.String value)
                 throws DbException
Set a property for this database.

Parameters:
pname - The new property name
value - The new property value
Throws:
DbException - If something goes wrong.

getProperty

public java.lang.String getProperty(java.lang.String pname)
                             throws DbException
A database can have a set of properties associated with it. We use . in a properties file and by default we use "driver", "userId", "password" and "connect".

Parameters:
pname - The name of the property.
Returns:
The property value
Throws:
DbException - If something goes wrong.

getTable

public DbTable getTable(java.lang.String name)
                 throws DbException
Return an object representing a particular table in the database.

Parameters:
name - The name of the table.
Returns:
The table value
Throws:
DbException - If something goes wrong.

getJoinedTable

public DbJoinedTable getJoinedTable(DbAbstractTable tableLeft,
                                    DbAbstractTable tableRight,
                                    int joinType,
                                    DbExpr joinCondition)
                             throws DbException
Returns a joined table.

Parameters:
tableLeft - The table to be joined on the left.
tableRight - The table to be joined on the right.
joinType - The type of joining.
joinCondition - The join condition.
Returns:
The joined table.
Throws:
DbException - If something goes wrong.

getSequence

public DbSequence getSequence(java.lang.String name)
Ahem... uncommented. It is obscure, call Chris Bitmead.

Parameters:
name - A name?
Returns:
A DbSequence.

getThreadConnection

public DbConnection getThreadConnection()
                                 throws DbException
Get a DbConnection that will be associated with this Thread.

Returns:
The threadConnection value
Throws:
DbException - If something goes wrong.

getExistingThreadConnection

public DbConnection getExistingThreadConnection()
                                         throws DbException
Get a DbConnection that will be associated with this Thread, but only if one exists already.

Returns:
The existingThreadConnection value
Throws:
DbException - If something goes wrong.

getNewConnection

public DbConnection getNewConnection()
                              throws DbException
Return a brand new DbConnection.

Returns:
The newConnection value
Throws:
DbException - If something goes wrong.

equals

public boolean equals(java.lang.Object o)
Checks if a DbDatabase object equals this one.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare to.
Returns:
true: the objects are equal; false: otherwise.

selector

public DbSelector selector()
                    throws DbException
Create a new DbSelector.

Returns:
A selector to perform SELECT operation.
Throws:
DbException - If something goes wrong.

hasThreadConnection

public boolean hasThreadConnection()
Does this thread have a default connection associated with it? (i.e. has this Thread called getThreadConnection()).

Returns:
true: Yes it does; false: No it does not.

trueExpr

public DbExpr trueExpr()
Return an expression representing an SQL true expression. We use the expression "0 = 0" for this purpose. This is handy when using complex code to construct a big conditional clause, it can be easier to start with a true expression and "AND" expressions onto the end.

Returns:
A true expression.

falseExpr

public DbExpr falseExpr()
Return an expression representing an SQL false expression. We use the expression "0 = 1" for this purpose. This is handy when using complex code to construct a big conditional clause, it can be easier to start with a false expression and "OR" expressions onto the end.

Returns:
A false expression.

valueList

public DbExpr valueList(java.util.Collection col)
Returns a value list.

Parameters:
col - The collection containing the value list.
Returns:
The value list.

toString

public java.lang.String toString()
A database to a string? Ok if you want it...

Overrides:
toString in class java.lang.Object
Returns:
A string representing the database.

getForeignKey

public boolean getForeignKey()
Returns the capability of DBMS to handle foreign keys.

Returns:
true: the DBMS supports foreign keys; false: otherwise.

getCheckStatement

public boolean getCheckStatement()
Returns the capability of DBMS to handle check statements.

Returns:
true: the DBMS supports check clauses; false: otherwise.

getOnDeleteCascade

public boolean getOnDeleteCascade()
Returns the capability of DBMS to handle ON DELETE CASCADE clauses.

Returns:
true: the DBMS supports ON DELETE CASCADE clauses; false: otherwise.

getOnDeleteSetDefault

public boolean getOnDeleteSetDefault()
Returns the capability of DBMS to handle ON DELETE SET DEFAULT clauses.

Returns:
true: the DBMS supports ON DELETE SET DEFAULT clauses; false: otherwise.

getOnDeleteSetNull

public boolean getOnDeleteSetNull()
Returns the capability of DBMS to handle ON DELETE SET NULL clauses.

Returns:
true: the DBMS supports ON DELETE SET NULL clauses; false: otherwise.

getOnUpdateCascade

public boolean getOnUpdateCascade()
Returns the capability of DBMS to handle ON UPDATE CASCADE clauses.

Returns:
true: the DBMS supports ON UPDATE CASCADE clauses; false: otherwise.

getOnUpdateSetDefault

public boolean getOnUpdateSetDefault()
Returns the capability of DBMS to handle ON UPDATE SET DEFAULT clauses.

Returns:
true: the DBMS supports ON UPDATE SET DEFAULT clauses; false: otherwise.

getOnUpdateSetNull

public boolean getOnUpdateSetNull()
Returns the capability of DBMS to handle ON UPDATE SET NULL clauses.

Returns:
true: the DBMS supports ON UPDATE SET NULL clauses; false: otherwise.