java.lang.Object
de.aristaflow.adept2.base.registry.dbconfiguration.TableManager
All Implemented Interfaces:
EventListener<ConfigurationEvent>

public class TableManager extends Object implements EventListener<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 Details

    • 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 Details

    • 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 Details

    • 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(ConfigurationEvent event)
      Specified by:
      onEvent in interface EventListener<ConfigurationEvent>