Class TableManager
- java.lang.Object
-
- de.aristaflow.adept2.base.registry.dbconfiguration.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 aDatabaseConfiguration
. 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 Summary
Fields Modifier and Type Field Description protected JDBCDataSource
dataSource
The data source storing the runtime configuration table.protected String
keyColumn
The name of the column for the keys of the runtime configuration.protected Logger
logger
The logger for problems creating or dropping the table.protected boolean
tableExists
Whether the table for the runtime configuration exists.protected String
tableName
The name of the table for the runtime configuration.protected String
valueColumn
The name of the column for the values of the runtime configuration.
-
Constructor Summary
Constructors Constructor Description TableManager(Logger logger, JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn)
Creates a new listener that creates and drops tables for runtime configurations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createOrUpdateTable(boolean create)
Creates or updates the table for the runtime configuration.protected void
dropTable()
Drops the table for the runtime configuration.void
onEvent(org.apache.commons.configuration2.event.ConfigurationEvent event)
-
-
-
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, anSQLException
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 interfaceorg.apache.commons.configuration2.event.EventListener<org.apache.commons.configuration2.event.ConfigurationEvent>
-
-