org.opennms.netmgt.config
Class DatabaseSchemaConfigFactory

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

public final class DatabaseSchemaConfigFactory
extends Object

This is the singleton class used to load the configuration for the OpenNMS database schema for 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.

Version:
$Id: $
Author:
Sowmya Nataraj , OpenNMS , Sowmya Nataraj , OpenNMS

Constructor Summary
DatabaseSchemaConfigFactory(InputStream is)
          Constructor for DatabaseSchemaConfigFactory.
DatabaseSchemaConfigFactory(Reader reader)
          Deprecated. 
 
Method Summary
 String constructJoinExprForTables(List<Table> tables)
          Construct a SQL FROM clause joining the given tables to the primary table.
 Table findTableByVisibleColumn(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.
 List<String> getJoinTables(List<Table> tables)
          Return the sequence of tables necessary to join the primary table to the given tables.
 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(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)
          setInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseSchemaConfigFactory

@Deprecated
public DatabaseSchemaConfigFactory(Reader reader)
                            throws IOException,
                                   org.exolab.castor.xml.MarshalException,
                                   org.exolab.castor.xml.ValidationException
Deprecated. 

Constructor for DatabaseSchemaConfigFactory.

Parameters:
reader - a Reader object.
Throws:
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

DatabaseSchemaConfigFactory

public DatabaseSchemaConfigFactory(InputStream is)
                            throws org.exolab.castor.xml.MarshalException,
                                   org.exolab.castor.xml.ValidationException

Constructor for DatabaseSchemaConfigFactory.

Parameters:
is - a InputStream object.
Throws:
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.
Method Detail

init

public static void init()
                 throws 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:
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.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

reload

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

Throws:
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.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

getInstance

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

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

setInstance

public static void setInstance(DatabaseSchemaConfigFactory instance)

setInstance

Parameters:
instance - a DatabaseSchemaConfigFactory object.

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(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.

findTableByVisibleColumn

public Table findTableByVisibleColumn(String colName)
Find the table which has a visible column named 'colName'

Parameters:
colName - a String object.
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

getJoinTables

public List<String> getJoinTables(List<Table> tables)
Return the sequence of tables necessary to join the primary table to the given tables.

Parameters:
tables - list of Tables to join
Returns:
a list of table names, starting with the primary table, going to each of the given tables, or a zero-length array if no join exists or only the primary table was specified

constructJoinExprForTables

public String constructJoinExprForTables(List<Table> tables)
Construct a SQL FROM clause joining the given tables to the primary table.

Parameters:
tables - list of Tables to join
Returns:
an SQL FROM clause or "" if no expression is found


Copyright © 2011. All Rights Reserved.