Class DatabaseConfiguration

  • All Implemented Interfaces:
    org.apache.commons.configuration2.Configuration, org.apache.commons.configuration2.event.EventSource, org.apache.commons.configuration2.ImmutableConfiguration, org.apache.commons.configuration2.sync.SynchronizerSupport

    public class DatabaseConfiguration
    extends org.apache.commons.configuration2.DatabaseConfiguration
    This DatabaseConfiguration checks whether the corresponding table exists before it executes a query or a statement. Some DBMS log a warning or even an error when parsing an SQL that refers to unknown entities or tables.

    While this is a rather simple extension, a lot of code has to be copied since DatabaseConfiguration.JdbcOperation is a private inner instance class.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  DatabaseConfiguration.JdbcOperation<T>
      An internally used helper class for simplifying database access through plain JDBC.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected JDBCDataSource dataSource
      The data source (possibly) providing the table containing the database configuration.
    • Constructor Summary

      Constructors 
      Constructor Description
      DatabaseConfiguration​(JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn)
      Creates a new DatabaseConfiguration with the designated properties and the designated JDBCDataSource (possibly) providing the table containing the database configuration.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addPropertyDirect​(String key, Object obj)  
      protected void clearInternal()  
      protected void clearPropertyDirect​(String key)  
      protected boolean containsKeyInternal​(String key)  
      protected Iterator<String> getKeysInternal()  
      protected Object getPropertyInternal​(String key)  
      protected boolean isEmptyInternal()  
      static DatabaseConfiguration newDatabaseConfiguration​(Logger logger, JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn)
      Creates a new DatabaseConfiguration using the designated table and columns to store the configuration in the designated data source.
      • Methods inherited from class org.apache.commons.configuration2.DatabaseConfiguration

        addPropertyInternal, close, extractPropertyValue, getConfigurationName, getConfigurationNameColumn, getDatasource, getDataSource, getKeyColumn, getTable, getValueColumn, isAutoCommit, setAutoCommit, setConfigurationName, setConfigurationNameColumn, setDataSource, setKeyColumn, setTable, setValueColumn
      • Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration

        addErrorLogListener, addProperty, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, setThrowExceptionOnMissing, size, sizeInternal, subset, unlock
      • Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource

        addEventListener, clearErrorListeners, clearEventListeners, clone, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
      • Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration

        getEnum, getEnum
    • Field Detail

      • dataSource

        protected final JDBCDataSource dataSource
        The data source (possibly) providing the table containing the database configuration.
    • Constructor Detail

      • DatabaseConfiguration

        public DatabaseConfiguration​(JDBCDataSource dataSource,
                                     String tableName,
                                     String keyColumn,
                                     String valueColumn)
        Creates a new DatabaseConfiguration with the designated properties and the designated JDBCDataSource (possibly) providing the table containing the database configuration.
        Parameters:
        dataSource - The data source (possibly) providing the table containing the database configuration.
        tableName - The name of the table containing configuration data.
        keyColumn - The name of the column containing the configuration keys.
        valueColumn - The name of the column containing the configuration values.
    • Method Detail

      • getPropertyInternal

        protected Object getPropertyInternal​(String key)
        Overrides:
        getPropertyInternal in class org.apache.commons.configuration2.DatabaseConfiguration
      • addPropertyDirect

        protected void addPropertyDirect​(String key,
                                         Object obj)
        Overrides:
        addPropertyDirect in class org.apache.commons.configuration2.DatabaseConfiguration
      • isEmptyInternal

        protected boolean isEmptyInternal()
        Overrides:
        isEmptyInternal in class org.apache.commons.configuration2.DatabaseConfiguration
      • containsKeyInternal

        protected boolean containsKeyInternal​(String key)
        Overrides:
        containsKeyInternal in class org.apache.commons.configuration2.DatabaseConfiguration
      • clearPropertyDirect

        protected void clearPropertyDirect​(String key)
        Overrides:
        clearPropertyDirect in class org.apache.commons.configuration2.DatabaseConfiguration
      • clearInternal

        protected void clearInternal()
        Overrides:
        clearInternal in class org.apache.commons.configuration2.DatabaseConfiguration
      • getKeysInternal

        protected Iterator<String> getKeysInternal()
        Overrides:
        getKeysInternal in class org.apache.commons.configuration2.DatabaseConfiguration
      • newDatabaseConfiguration

        public static DatabaseConfiguration newDatabaseConfiguration​(Logger logger,
                                                                     JDBCDataSource dataSource,
                                                                     String tableName,
                                                                     String keyColumn,
                                                                     String valueColumn)
                                                              throws org.apache.commons.configuration2.ex.ConfigurationException,
                                                                     SQLException
        Creates a new DatabaseConfiguration using the designated table and columns to store the configuration in the designated data source. This also creates a table manager for creating and deleting the table appropriately.
        This also registers logging errors occurring with the database configuration whereas most critical logs are problems when adding or changing properties.
        Parameters:
        logger - The logger for problems creating or dropping the table.
        dataSource - The datasource which stores the configuration.
        tableName - The name of the table containing the configuration values.
        keyColumn - The name of the column containing the configuration keys.
        valueColumn - The name of the column containing the configuration values.
        Returns:
        A new database configuration.
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If creating the configuration fails, a ConfigurationException will be thrown.
        SQLException - If detecting whether the table exists or not fails, an SQLException will be thrown.