Class DatabaseConfiguration
- java.lang.Object
-
- org.apache.commons.configuration2.event.BaseEventSource
-
- org.apache.commons.configuration2.AbstractConfiguration
-
- org.apache.commons.configuration2.DatabaseConfiguration
-
- de.aristaflow.adept2.base.registry.dbconfiguration.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.DatabaseConfigurationThisDatabaseConfigurationchecks 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.JdbcOperationis a private inner instance class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDatabaseConfiguration.JdbcOperation<T>An internally used helper class for simplifying database access through plain JDBC.
-
Field Summary
Fields Modifier and Type Field Description protected JDBCDataSourcedataSourceThe 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 newDatabaseConfigurationwith the designated properties and the designatedJDBCDataSource(possibly) providing the table containing the database configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddPropertyDirect(String key, Object obj)protected voidclearInternal()protected voidclearPropertyDirect(String key)protected booleancontainsKeyInternal(String key)protected Iterator<String>getKeysInternal()protected ObjectgetPropertyInternal(String key)protected booleanisEmptyInternal()static DatabaseConfigurationnewDatabaseConfiguration(Logger logger, JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn)Creates a newDatabaseConfigurationusing 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
-
-
-
-
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 newDatabaseConfigurationwith the designated properties and the designatedJDBCDataSource(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:
getPropertyInternalin classorg.apache.commons.configuration2.DatabaseConfiguration
-
addPropertyDirect
protected void addPropertyDirect(String key, Object obj)
- Overrides:
addPropertyDirectin classorg.apache.commons.configuration2.DatabaseConfiguration
-
isEmptyInternal
protected boolean isEmptyInternal()
- Overrides:
isEmptyInternalin classorg.apache.commons.configuration2.DatabaseConfiguration
-
containsKeyInternal
protected boolean containsKeyInternal(String key)
- Overrides:
containsKeyInternalin classorg.apache.commons.configuration2.DatabaseConfiguration
-
clearPropertyDirect
protected void clearPropertyDirect(String key)
- Overrides:
clearPropertyDirectin classorg.apache.commons.configuration2.DatabaseConfiguration
-
clearInternal
protected void clearInternal()
- Overrides:
clearInternalin classorg.apache.commons.configuration2.DatabaseConfiguration
-
getKeysInternal
protected Iterator<String> getKeysInternal()
- Overrides:
getKeysInternalin classorg.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 newDatabaseConfigurationusing 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, aConfigurationExceptionwill be thrown.SQLException- If detecting whether the table exists or not fails, anSQLExceptionwill be thrown.
-
-