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 StringaddColumn(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.StringconstructJoinExprForTables(List<Table> tables)Construct a SQL FROM clause joining the given tables to the primary table.TablefindTableByVisibleColumn(String colName)Find the table which has a visible column named 'colName'DatabaseSchemagetDatabaseSchema()Return the database schema.static DatabaseSchemaConfiggetInstance()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.TablegetPrimaryTable()This method is used to find the table that should drive the construction of the join clauses between all table in the from clause.LockgetReadLock()TablegetTableByName(String name)Find a table using its name as the search key.intgetTableCount()Return a count of the number of tables defined.LockgetWriteLock()static voidinit()Load the config from the default config file and create the singleton instance of this factory.static voidreload()Reload the config from the default config filestatic voidsetInstance(DatabaseSchemaConfig instance)setInstance
-
-
-
Constructor Detail
-
DatabaseSchemaConfigFactory
public DatabaseSchemaConfigFactory() throws IOException- Throws:
IOException
-
DatabaseSchemaConfigFactory
public DatabaseSchemaConfigFactory(InputStream is) throws IOException
Constructor for DatabaseSchemaConfigFactory.
- Parameters:
is- aInputStreamobject.- Throws:
IOException
-
-
Method Detail
-
getReadLock
public Lock getReadLock()
-
getWriteLock
public Lock getWriteLock()
-
init
public static void init() throws IOExceptionLoad 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 IOExceptionReload 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.DatabaseSchemaConfigobject.
-
getDatabaseSchema
public DatabaseSchema getDatabaseSchema()
Return the database schema.- Specified by:
getDatabaseSchemain 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:
getPrimaryTablein 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:
getTableByNamein 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:
findTableByVisibleColumnin interfaceDatabaseSchemaConfig- Parameters:
colName- aStringobject.- 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:
getTableCountin 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:
getJoinTablesin 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:
constructJoinExprForTablesin 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:
addColumnin 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
-
-