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:
Configuration,EventSource,ImmutableConfiguration,SynchronizerSupport
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
org.apache.commons.configuration2.DatabaseConfiguration.JdbcOperation is a private inner
instance class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAn internally used helper class for simplifying database access through plain JDBC. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JDBCDataSourceThe data source (possibly) providing the table containing the database configuration. -
Constructor Summary
ConstructorsConstructorDescriptionDatabaseConfiguration(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
Modifier and TypeMethodDescriptionprotected voidaddPropertyDirect(String key, Object obj) protected voidprotected voidprotected booleanprotected Objectprotected booleanstatic 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, containsValueInternal, extractPropertyValue, getConfigurationName, getConfigurationNameColumn, getDatasource, getDataSource, getKeyColumn, getTable, getValueColumn, isAutoCommit, setAutoCommit, setConfigurationName, setConfigurationNameColumn, setDataSource, setKeyColumn, setTable, setValueColumnMethods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, contains, containsKey, containsValue, 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, getKeys, getKeysInternal, 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, unlockMethods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, clone, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
entrySet, forEach, getEnum, getEnum
-
Field Details
-
dataSource
The data source (possibly) providing the table containing the database configuration.
-
-
Constructor Details
-
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 Details
-
getPropertyInternal
- Overrides:
getPropertyInternalin classDatabaseConfiguration
-
addPropertyDirect
- Overrides:
addPropertyDirectin classDatabaseConfiguration
-
isEmptyInternal
protected boolean isEmptyInternal()- Overrides:
isEmptyInternalin classDatabaseConfiguration
-
containsKeyInternal
- Overrides:
containsKeyInternalin classDatabaseConfiguration
-
clearPropertyDirect
- Overrides:
clearPropertyDirectin classDatabaseConfiguration
-
clearInternal
protected void clearInternal()- Overrides:
clearInternalin classDatabaseConfiguration
-
getKeysInternal
- Overrides:
getKeysInternalin classDatabaseConfiguration
-
newDatabaseConfiguration
public static DatabaseConfiguration newDatabaseConfiguration(Logger logger, JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn) throws 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:
ConfigurationException- If creating the configuration fails, aConfigurationExceptionwill be thrown.SQLException- If detecting whether the table exists or not fails, anSQLExceptionwill be thrown.
-