org.opennms.netmgt.config
Class DatabaseSchemaConfigFactory

java.lang.Object
  extended by org.opennms.netmgt.config.DatabaseSchemaConfigFactory

public final class DatabaseSchemaConfigFactory
extends java.lang.Object

This is the singleton class used to load the configuration for the OpenNMS database schemafor the filters from the database-schema xml file. Note: Users of this class should make sure the init() is called before calling any other method to ensure the config is loaded before accessing other convenience methods.

Author:
Sowmya Nataraj , OpenNMS

Constructor Summary
DatabaseSchemaConfigFactory(java.io.Reader reader)
           
 
Method Summary
 java.lang.String constructJoinExprForTable(Table t)
          Construct a joining expression necessary to join the given table to the primary table.
 Table findTableByVisableColumn(java.lang.String colName)
          Find the table which has a visible column named 'colName'
 DatabaseSchema getDatabaseSchema()
          Return the database schema.
static DatabaseSchemaConfigFactory getInstance()
          Return the singleton instance of this factory.
 java.lang.String[] getJoinTablesForTable(Table t)
          Returns an array of the names of tables involved in a join of the given table and the primary.
 Join[] getPrimaryJoinsForTable(Table t)
          Get the sequence of joins that are necessary to joint table t to the primary table.
 Table getPrimaryTable()
          This method is used to find the table that should drive the construction of the join clauses between all table in the from clause.
 Table getTableByName(java.lang.String name)
          Find a table using its name as the search key.
 int getTableCount()
          Return a count of the number of tables defined.
static void init()
          Load the config from the default config file and create the singleton instance of this factory.
static void reload()
          Reload the config from the default config file
static void setInstance(DatabaseSchemaConfigFactory instance)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseSchemaConfigFactory

public DatabaseSchemaConfigFactory(java.io.Reader reader)
                            throws java.io.IOException,
                                   org.exolab.castor.xml.MarshalException,
                                   org.exolab.castor.xml.ValidationException
Throws:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
Method Detail

init

public static void init()
                 throws java.io.IOException,
                        org.exolab.castor.xml.MarshalException,
                        org.exolab.castor.xml.ValidationException
Load the config from the default config file and create the singleton instance of this factory.

Throws:
java.io.IOException - Thrown if the specified config file cannot be read
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.

reload

public static void reload()
                   throws java.io.IOException,
                          org.exolab.castor.xml.MarshalException,
                          org.exolab.castor.xml.ValidationException
Reload the config from the default config file

Throws:
java.io.IOException - Thrown if the specified config file cannot be read/loaded
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.

getInstance

public static DatabaseSchemaConfigFactory getInstance()
Return the singleton instance of this factory.

Returns:
The current factory instance.
Throws:
java.lang.IllegalStateException - Thrown if the factory has not yet been initialized.

setInstance

public static void setInstance(DatabaseSchemaConfigFactory instance)

getDatabaseSchema

public DatabaseSchema getDatabaseSchema()
Return the database schema.

Returns:
the database schema

getPrimaryTable

public Table getPrimaryTable()
This method is used to find the table that should drive the construction of the join clauses between all table in the from clause. At least one table has to be designated as the driver table.

Returns:
The name of the driver table

getTableByName

public Table getTableByName(java.lang.String name)
Find a table using its name as the search key.

Parameters:
name - the name of the table to find
Returns:
the table if it is found, null otherwise.

findTableByVisableColumn

public Table findTableByVisableColumn(java.lang.String colName)
Find the table which has a visible column named 'colName'

Parameters:
the - name of the column to search for
Returns:
the table containing column 'colName', null if colName is not a valid column or if is not visible.

getTableCount

public int getTableCount()
Return a count of the number of tables defined.

Returns:
the number of tables in the schema

constructJoinExprForTable

public java.lang.String constructJoinExprForTable(Table t)
Construct a joining expression necessary to join the given table to the primary table.

Parameters:
t - the table to create the expression for
Returns:
a string representing the joining expression or "" if no expression is found

getJoinTablesForTable

public java.lang.String[] getJoinTablesForTable(Table t)
Returns an array of the names of tables involved in a join of the given table and the primary. The tables are listing in order starting with primary and moving 'toward' the given table.

Parameters:
t - the Table to join
Returns:
an array containing the names of the tables involved. If t is the primary or there is no join that reaches the primary table from t, then join list is a zero-length aarray

getPrimaryJoinsForTable

public Join[] getPrimaryJoinsForTable(Table t)
Get the sequence of joins that are necessary to joint table t to the primary table.

Parameters:
t - the table to join
Returns:
a list of the join objects for all the tables between the given table and the primary or a zero-length array if t is the primary or no join exists.


Copyright © 2007. All Rights Reserved.