Class 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
    • 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 read
        IOException - 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/loaded
        IOException - 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 - a org.opennms.netmgt.config.DatabaseSchemaConfig object.
      • 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 interface DatabaseSchemaConfig
        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 interface DatabaseSchemaConfig
        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 interface DatabaseSchemaConfig
        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.
        Specified by:
        getTableCount in interface DatabaseSchemaConfig
        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 interface DatabaseSchemaConfig
        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 interface DatabaseSchemaConfig
        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 interface DatabaseSchemaConfig
        Parameters:
        tables - a list of tables to add the column's table to
        column - the column to add
        Returns:
        table.column string
        Throws:
        FilterParseException - if the column is not found in the schema