Class TableManager

  • All Implemented Interfaces:
    org.apache.commons.configuration2.event.EventListener<org.apache.commons.configuration2.event.ConfigurationEvent>

    public class TableManager
    extends Object
    implements org.apache.commons.configuration2.event.EventListener<org.apache.commons.configuration2.event.ConfigurationEvent>
    This class creates and drops tables for a DatabaseConfiguration. This way there are no superfluous tables for runtime configurations.
    A table is created as soon as the corresponding configuration gets a value and it will be removed as soon as the table is cleared.

    This implementation creates tables having 50 characters for the key and 1000 characters for the value.

    • Field Detail

      • logger

        protected final Logger logger
        The logger for problems creating or dropping the table.
      • dataSource

        protected final JDBCDataSource dataSource
        The data source storing the runtime configuration table.
      • tableName

        protected final String tableName
        The name of the table for the runtime configuration.
      • keyColumn

        protected final String keyColumn
        The name of the column for the keys of the runtime configuration.
      • valueColumn

        protected final String valueColumn
        The name of the column for the values of the runtime configuration.
      • tableExists

        protected boolean tableExists
        Whether the table for the runtime configuration exists.
    • Constructor Detail

      • TableManager

        public TableManager​(Logger logger,
                            JDBCDataSource dataSource,
                            String tableName,
                            String keyColumn,
                            String valueColumn)
                     throws SQLException
        Creates a new listener that creates and drops tables for runtime configurations. The constructor checks whether the table already exists.
        Parameters:
        logger - The logger for problems creating or dropping the table.
        dataSource - The data source storing the runtime configuration table.
        tableName - The name of the table for the runtime configuration.
        keyColumn - The name of the column for the keys of the runtime configuration.
        valueColumn - The name of the column for the values of the runtime configuration.
        Throws:
        SQLException - If detecting whether the table exists or not fails, an SQLException will be thrown.
    • Method Detail

      • createOrUpdateTable

        protected void createOrUpdateTable​(boolean create)
        Creates or updates the table for the runtime configuration. Creating only applies the initial update.
        Parameters:
        create - Whether to create the table (instead of updating).
      • dropTable

        protected void dropTable()
        Drops the table for the runtime configuration.
      • onEvent

        public void onEvent​(org.apache.commons.configuration2.event.ConfigurationEvent event)
        Specified by:
        onEvent in interface org.apache.commons.configuration2.event.EventListener<org.apache.commons.configuration2.event.ConfigurationEvent>