org.apache.torque.map
Class DatabaseMap

java.lang.Object
  extended by org.apache.torque.map.DatabaseMap
All Implemented Interfaces:
java.io.Serializable

public class DatabaseMap
extends java.lang.Object
implements java.io.Serializable

DatabaseMap is used to model a database.

Version:
$Id: DatabaseMap.java 476550 2006-11-18 16:08:37Z tfischer $
Author:
John D. McNally, Daniel Rall, Greg Monroe
See Also:
Serialized Form

Field Summary
protected static java.lang.String[] ERROR_MESSAGES_INIT
          Error Messages for initialisation.
static java.lang.String INIT_CLASS_NAME_FORMAT
          Format used to create create the class name for initializing a DB specific map
static char SCHEMA_SEPARATOR_CHAR
          The character which separates the schema name from the table name.
static char STD_SEPARATOR_CHAR
          The character used by most implementations as the separator between name elements.
 
Constructor Summary
DatabaseMap()
          Constructs a new DatabaseMap.
DatabaseMap(java.lang.String name)
          Deprecated. use DatabaseMap() instead. Will be removed in a future version of Torque.
DatabaseMap(java.lang.String name, int numberOfTables)
          Deprecated. use DatabaseMap() instead. Will be removed in a future version of Torque.
 
Method Summary
 void addIdGenerator(java.lang.String type, IdGenerator idGen)
          Deprecated. use DatabaseInfo.addGenerator() instead. Will be removed in a future version of Torque.
 void addTable(java.lang.String tableName)
          Add a new table to the database by name.
 void addTable(java.lang.String tableName, int numberOfColumns)
          Add a new table to the database by name.
 void addTable(TableMap map)
          Add a new TableMap to the database.
 boolean containsTable(java.lang.String name)
          Does this database contain this specific table?
 boolean containsTable(TableMap table)
          Does this database contain this specific table?
 IDBroker getIDBroker()
          Deprecated. Will be removed in a future version of Torque. Use DatabaseInfo#getIdBroker() instead to access the IDBroker.
 IdGenerator getIdGenerator(java.lang.String type)
          Deprecated. use DatabaseInfo.getIdGenerator() instead. Will be removed in a future version of Torque.
 TableMap getIdTable()
          Get the ID table for this database.
 java.lang.String getName()
          Deprecated. Will be removed in a future version of Torque. Use the name of the corresponding database instead.
 TableMap getTable(java.lang.String name)
          Get a TableMap for the table by name.
 TableMap[] getTables()
          Get a TableMap[] of all of the tables in the database.
 void initialize()
          Fully populate this DatabaseMap with all the TablesMaps.
protected  java.lang.String javanameMethod(java.lang.String schemaName)
          Converts a database schema name to java object name.
 void setIdTable(java.lang.String tableName)
          Set the ID table for this database.
 void setIdTable(TableMap idTable)
          Set the ID table for this database.
 boolean startIdBroker()
          Deprecated. Will be removed in a future version of Torque. Use DatabaseInfo.startIdBroker() instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STD_SEPARATOR_CHAR

public static final char STD_SEPARATOR_CHAR
The character used by most implementations as the separator between name elements.

See Also:
Constant Field Values

SCHEMA_SEPARATOR_CHAR

public static final char SCHEMA_SEPARATOR_CHAR
The character which separates the schema name from the table name.

See Also:
Constant Field Values

INIT_CLASS_NAME_FORMAT

public static final java.lang.String INIT_CLASS_NAME_FORMAT
Format used to create create the class name for initializing a DB specific map

See Also:
Constant Field Values

ERROR_MESSAGES_INIT

protected static final java.lang.String[] ERROR_MESSAGES_INIT
Error Messages for initialisation.

Constructor Detail

DatabaseMap

public DatabaseMap()
Constructs a new DatabaseMap.


DatabaseMap

public DatabaseMap(java.lang.String name,
                   int numberOfTables)
Deprecated. use DatabaseMap() instead. Will be removed in a future version of Torque.

Constructor.

Parameters:
name - Name of the database.
numberOfTables - Number of tables in the database.

DatabaseMap

public DatabaseMap(java.lang.String name)
Deprecated. use DatabaseMap() instead. Will be removed in a future version of Torque.

Constructor.

Parameters:
name - Name of the database.
Method Detail

containsTable

public boolean containsTable(TableMap table)
Does this database contain this specific table?

Parameters:
table - The TableMap representation of the table.
Returns:
True if the database contains the table.

containsTable

public boolean containsTable(java.lang.String name)
Does this database contain this specific table?

Parameters:
name - The String representation of the table.
Returns:
True if the database contains the table.

getIdTable

public TableMap getIdTable()
Get the ID table for this database.

Returns:
A TableMap.

getIDBroker

public IDBroker getIDBroker()
Deprecated. Will be removed in a future version of Torque. Use DatabaseInfo#getIdBroker() instead to access the IDBroker.

Get the IDBroker for this database.

Returns:
An IDBroker.

getName

public java.lang.String getName()
Deprecated. Will be removed in a future version of Torque. Use the name of the corresponding database instead.

Get the name of this database.

Returns:
A String.

getTable

public TableMap getTable(java.lang.String name)
Get a TableMap for the table by name.

Note that by default Torque uses lazy initialization to minimize memory usage and startup time. However, if an OM or PEER class has not called the table's MapBuilder class, it will not be here. See the optional initialize method if you need full OM Mapping.

Parameters:
name - Name of the table.
Returns:
A TableMap, null if the table was not found.

getTables

public TableMap[] getTables()
Get a TableMap[] of all of the tables in the database.

Note that by default Torque uses lazy initialization to minimize memory usage and startup time. However, if an OM or PEER class has not called the table's MapBuilder class, it will not be here. See the optional initialize method if you need full OM Mapping.

Returns:
A TableMap[].

addTable

public void addTable(java.lang.String tableName)
Add a new table to the database by name. It creates an empty TableMap that you need to populate.

Parameters:
tableName - The name of the table.

addTable

public void addTable(java.lang.String tableName,
                     int numberOfColumns)
Add a new table to the database by name. It creates an empty TableMap that you need to populate.

Parameters:
tableName - The name of the table.
numberOfColumns - The number of columns in the table.

addTable

public void addTable(TableMap map)
Add a new TableMap to the database.

Parameters:
map - The TableMap representation.

setIdTable

public void setIdTable(TableMap idTable)
Set the ID table for this database.

Parameters:
idTable - The TableMap representation for the ID table.

setIdTable

public void setIdTable(java.lang.String tableName)
Set the ID table for this database.

Parameters:
tableName - The name for the ID table.

addIdGenerator

public void addIdGenerator(java.lang.String type,
                           IdGenerator idGen)
Deprecated. use DatabaseInfo.addGenerator() instead. Will be removed in a future version of Torque.

Add a type of id generator for access by a TableMap.

Parameters:
type - a String value
idGen - an IdGenerator value

getIdGenerator

public IdGenerator getIdGenerator(java.lang.String type)
Deprecated. use DatabaseInfo.getIdGenerator() instead. Will be removed in a future version of Torque.

Get a type of id generator. Valid values are listed in the IDMethod interface.

Parameters:
type - a String value
Returns:
an IdGenerator value

startIdBroker

public boolean startIdBroker()
Deprecated. Will be removed in a future version of Torque. Use DatabaseInfo.startIdBroker() instead.

Creates the Idbroker for this DatabaseMap. If an IDBroker already exists for the DatabaseMap, the method does nothing.

Returns:
true if a new IdBroker was created, false otherwise.

initialize

public void initialize()
                throws TorqueException
Fully populate this DatabaseMap with all the TablesMaps. This is only needed if the application needs to use the complete OM mapping information. Otherwise, the OM Mapping information will be populated as needed by OM and Peer classes. An example of how to initialize the map info from the application:

DatabaseMap dbMap = Torque.getDatabaseMap( dbName ); try { dbMap.initialize(); } catch ( TorqueException e ) { ... error handling } Note that Torque database names are case sensitive and this DB map must be retrieved with the exact name used in the XML schema.

This uses Java reflection methods to locate and run the init() method of a class generated in the org.apache.torque.linkage package with a name based on the XML Database name value, e.g. org.apache.torque.linkage.DefaultMapInit

Some misconfiguration situations that could cause this method to fail are:

It was used with a Torque OM set of classes generated by V3.2 or older;
The class(es) in the org.apache.torque.linkage package were not included with the other generated class files (e.g. the jar file creation process only included com.* and not org.* files).

Throws:
TorqueException - If an error is encountered locating and calling the init method.

javanameMethod

protected java.lang.String javanameMethod(java.lang.String schemaName)
Converts a database schema name to java object name. Operates same as underscoreMethod but does not convert anything to lowercase. This must match the javaNameMethod in the JavaNameGenerator class in Generator code.

Parameters:
schemaName - name to be converted.
Returns:
converted name.
See Also:
org.apache.torque.engine.database.model.NameGenerator


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.