Package org.opennms.netmgt.config
Class DatabaseSchemaConfigFactory
- java.lang.Object
-
- org.opennms.netmgt.config.DatabaseSchemaConfigFactory
-
- All Implemented Interfaces:
DatabaseSchemaConfig
public final class DatabaseSchemaConfigFactory extends java.lang.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(java.io.InputStream is)
Constructor for DatabaseSchemaConfigFactory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
addColumn(java.util.List<Table> tables, java.lang.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.java.lang.String
constructJoinExprForTables(java.util.List<Table> tables)
Construct a SQL FROM clause joining the given tables to the primary table.Table
findTableByVisibleColumn(java.lang.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.java.util.List<java.lang.String>
getJoinTables(java.util.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.java.util.concurrent.locks.Lock
getReadLock()
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.java.util.concurrent.locks.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 java.io.IOException
- Throws:
java.io.IOException
-
DatabaseSchemaConfigFactory
public DatabaseSchemaConfigFactory(java.io.InputStream is) throws java.io.IOException
Constructor for DatabaseSchemaConfigFactory.
- Parameters:
is
- aInputStream
object.- Throws:
java.io.IOException
-
-
Method Detail
-
getReadLock
public java.util.concurrent.locks.Lock getReadLock()
-
getWriteLock
public java.util.concurrent.locks.Lock getWriteLock()
-
init
public static void init() throws java.io.IOException
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 readjava.io.IOException
- if any.
-
reload
public static void reload() throws java.io.IOException
Reload the config from the default config file- Throws:
java.io.IOException
- Thrown if the specified config file cannot be read/loadedjava.io.IOException
- if any.
-
getInstance
public static DatabaseSchemaConfig 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(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(java.lang.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(java.lang.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 java.util.List<java.lang.String> getJoinTables(java.util.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 java.lang.String constructJoinExprForTables(java.util.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 java.lang.String addColumn(java.util.List<Table> tables, java.lang.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
-
-