Package org.opennms.netmgt.config
Class DatabaseSchemaConfigFactory
- java.lang.Object
-
- org.opennms.netmgt.config.DatabaseSchemaConfigFactory
-
- All Implemented Interfaces:
DatabaseSchemaConfig
public final class DatabaseSchemaConfigFactory extends Object implements DatabaseSchemaConfig
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.- Author:
- Sowmya Nataraj
-
-
Constructor Summary
Constructors Constructor Description DatabaseSchemaConfigFactory()
DatabaseSchemaConfigFactory(InputStream is)
Constructor for DatabaseSchemaConfigFactory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
addColumn(List<Table> tables, String column)
Validate that a column is in the schema, add it's table to a list of tables, and return the full table.column name of the column.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 DatabaseSchemaConfig
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.Lock
getReadLock()
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.Lock
getWriteLock()
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 filestatic void
setInstance(DatabaseSchemaConfig instance)
setInstance
-
-
-
Constructor Detail
-
DatabaseSchemaConfigFactory
public DatabaseSchemaConfigFactory() throws IOException
- Throws:
IOException
-
DatabaseSchemaConfigFactory
public DatabaseSchemaConfigFactory(InputStream is) throws IOException
Constructor for DatabaseSchemaConfigFactory.
- Parameters:
is
- aInputStream
object.- Throws:
IOException
-
-
Method Detail
-
getReadLock
public Lock getReadLock()
-
getWriteLock
public Lock getWriteLock()
-
init
public static void init() throws IOException
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 readIOException
- if any.
-
reload
public static void reload() throws IOException
Reload the config from the default config file- Throws:
IOException
- Thrown if the specified config file cannot be read/loadedIOException
- if any.
-
getInstance
public static DatabaseSchemaConfig 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(DatabaseSchemaConfig instance)
setInstance
- Parameters:
instance
- aorg.opennms.netmgt.config.DatabaseSchemaConfig
object.
-
getDatabaseSchema
public DatabaseSchema getDatabaseSchema()
Return the database schema.- Specified by:
getDatabaseSchema
in interfaceDatabaseSchemaConfig
- 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.- Specified by:
getPrimaryTable
in interfaceDatabaseSchemaConfig
- Returns:
- The name of the driver table
-
getTableByName
public Table getTableByName(String name)
Find a table using its name as the search key.- Specified by:
getTableByName
in interfaceDatabaseSchemaConfig
- 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'- Specified by:
findTableByVisibleColumn
in interfaceDatabaseSchemaConfig
- Parameters:
colName
- aString
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.- Specified by:
getTableCount
in interfaceDatabaseSchemaConfig
- 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.- Specified by:
getJoinTables
in interfaceDatabaseSchemaConfig
- 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.- Specified by:
constructJoinExprForTables
in interfaceDatabaseSchemaConfig
- Parameters:
tables
- list of Tables to join- Returns:
- an SQL FROM clause or "" if no expression is found
-
addColumn
public String addColumn(List<Table> tables, String column) throws FilterParseException
Validate that a column is in the schema, add it's table to a list of tables, and return the full table.column name of the column.- Specified by:
addColumn
in interfaceDatabaseSchemaConfig
- Parameters:
tables
- a list of tables to add the column's table tocolumn
- the column to add- Returns:
- table.column string
- Throws:
FilterParseException
- if the column is not found in the schema
-
-