org.apache.ddlutils.model
Class Database

java.lang.Object
  extended by org.apache.ddlutils.model.Database
All Implemented Interfaces:
Serializable, Cloneable

public class Database
extends Object
implements Serializable, Cloneable

Represents the database model, ie. the tables in the database. It also contains the corresponding dyna classes for creating dyna beans for the objects stored in the tables.

Version:
$Revision: 504014 $
See Also:
Serialized Form

Constructor Summary
Database()
           
 
Method Summary
 void addTable(int idx, Table table)
          Adds a table at the specified position.
 void addTable(Table table)
          Adds a table.
 void addTables(Collection tables)
          Adds the given tables.
 Object clone()
          
 DynaBean createDynaBeanFor(String tableName, boolean caseSensitive)
          Convenience method that combines createDynaBeanFor(Table) and findTable(String, boolean).
 DynaBean createDynaBeanFor(Table table)
          Creates a new dyna bean for the given table.
 boolean equals(Object obj)
          
 Table findTable(String name)
          Finds the table with the specified name, using case insensitive matching.
 Table findTable(String name, boolean caseSensitive)
          Finds the table with the specified name, using case insensitive matching.
 SqlDynaClass getDynaClassFor(DynaBean bean)
          Returns the SqlDynaClass for the given dyna bean.
 SqlDynaClass getDynaClassFor(String tableName)
          Returns the SqlDynaClass for the given table name.
 String getIdMethod()
          Returns the method for generating primary key values.
 String getName()
          Returns the name of this database model.
 Table getTable(int idx)
          Returns the table at the specified position.
 int getTableCount()
          Returns the number of tables in this model.
 Table[] getTables()
          Returns the tables in this model.
 String getVersion()
          Returns the version of this database model.
 int hashCode()
          
 void initialize()
          Initializes the model by establishing the relationships between elements in this model encoded eg.
 void mergeWith(Database otherDb)
          Adds all tables from the other database to this database.
 void removeTable(int idx)
          Removes the indicated table.
 void removeTable(Table table)
          Removes the given table.
 void resetDynaClassCache()
          Resets the dyna class cache.
 void setIdMethod(String idMethod)
          Sets the method for generating primary key values.
 void setName(String name)
          Sets the name of this database model.
 void setVersion(String version)
          Sets the version of this database model.
 String toString()
          
 String toVerboseString()
          Returns a verbose string representation of this database.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Database

public Database()
Method Detail

mergeWith

public void mergeWith(Database otherDb)
               throws ModelException
Adds all tables from the other database to this database. Note that the other database is not changed.

Parameters:
otherDb - The other database model
Throws:
ModelException

getName

public String getName()
Returns the name of this database model.

Returns:
The name

setName

public void setName(String name)
Sets the name of this database model.

Parameters:
name - The name

getVersion

public String getVersion()
Returns the version of this database model.

Returns:
The version

setVersion

public void setVersion(String version)
Sets the version of this database model.

Parameters:
version - The version

getIdMethod

public String getIdMethod()
Returns the method for generating primary key values.

Returns:
The method

setIdMethod

public void setIdMethod(String idMethod)
Sets the method for generating primary key values. Note that this value is ignored by DdlUtils and only for compatibility with Torque.

Parameters:
idMethod - The method

getTableCount

public int getTableCount()
Returns the number of tables in this model.

Returns:
The number of tables

getTables

public Table[] getTables()
Returns the tables in this model.

Returns:
The tables

getTable

public Table getTable(int idx)
Returns the table at the specified position.

Parameters:
idx - The index of the table
Returns:
The table

addTable

public void addTable(Table table)
Adds a table.

Parameters:
table - The table to add

addTable

public void addTable(int idx,
                     Table table)
Adds a table at the specified position.

Parameters:
idx - The index where to insert the table
table - The table to add

addTables

public void addTables(Collection tables)
Adds the given tables.

Parameters:
tables - The tables to add

removeTable

public void removeTable(Table table)
Removes the given table.

Parameters:
table - The table to remove

removeTable

public void removeTable(int idx)
Removes the indicated table.

Parameters:
idx - The index of the table to remove

initialize

public void initialize()
                throws ModelException
Initializes the model by establishing the relationships between elements in this model encoded eg. in foreign keys etc. Also checks that the model elements are valid (table and columns have a name, foreign keys rference existing tables etc.)

Throws:
ModelException

findTable

public Table findTable(String name)
Finds the table with the specified name, using case insensitive matching. Note that this method is not called getTable to avoid introspection problems.

Parameters:
name - The name of the table to find
Returns:
The table or null if there is no such table

findTable

public Table findTable(String name,
                       boolean caseSensitive)
Finds the table with the specified name, using case insensitive matching. Note that this method is not called getTable) to avoid introspection problems.

Parameters:
name - The name of the table to find
caseSensitive - Whether case matters for the names
Returns:
The table or null if there is no such table

resetDynaClassCache

public void resetDynaClassCache()
Resets the dyna class cache. This should be done for instance when a column has been added or removed to a table.


getDynaClassFor

public SqlDynaClass getDynaClassFor(String tableName)
Returns the SqlDynaClass for the given table name. If the it does not exist yet, a new one will be created based on the Table definition.

Parameters:
tableName - The name of the table to create the bean for
Returns:
The SqlDynaClass for the indicated table or null if the model contains no such table

getDynaClassFor

public SqlDynaClass getDynaClassFor(DynaBean bean)
Returns the SqlDynaClass for the given dyna bean.

Parameters:
bean - The dyna bean
Returns:
The SqlDynaClass for the given bean

createDynaBeanFor

public DynaBean createDynaBeanFor(Table table)
                           throws SqlDynaException
Creates a new dyna bean for the given table.

Parameters:
table - The table to create the bean for
Returns:
The new dyna bean
Throws:
SqlDynaException

createDynaBeanFor

public DynaBean createDynaBeanFor(String tableName,
                                  boolean caseSensitive)
                           throws SqlDynaException
Convenience method that combines createDynaBeanFor(Table) and findTable(String, boolean).

Parameters:
tableName - The name of the table to create the bean for
caseSensitive - Whether case matters for the names
Returns:
The new dyna bean
Throws:
SqlDynaException

clone

public Object clone()
             throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object

toVerboseString

public String toVerboseString()
Returns a verbose string representation of this database.

Returns:
The string representation


Copyright © 2005-2007 Apache Software Foundation. All Rights Reserved.