public class DatabaseConfiguration
extends org.apache.commons.configuration.DatabaseConfiguration
CREATE TABLE myconfig (
`key` VARCHAR NOT NULL PRIMARY KEY,
`value` VARCHAR
);
INSERT INTO myconfig (key, value) VALUES ('foo', 'bar');
Configuration config = new DatabaseConfiguration(datasource, "myconfig", "key", "value");
String value = config.getString("foo");
Example 2 - Multiple configurations per table
CREATE TABLE myconfigs (
`name` VARCHAR NOT NULL,
`key` VARCHAR NOT NULL,
`value` VARCHAR,
CONSTRAINT sys_pk_myconfigs PRIMARY KEY (`name`, `key`)
);
INSERT INTO myconfigs (name, key, value) VALUES ('config1', 'key1', 'value1');
INSERT INTO myconfigs (name, key, value) VALUES ('config2', 'key2', 'value2');
Configuration config1 = new DatabaseConfiguration(datasource, "myconfigs", "name", "key", "value", "config1");
String value1 = conf.getString("key1");
Configuration config2 = new DatabaseConfiguration(datasource, "myconfigs", "name", "key", "value", "config2");
String value2 = conf.getString("key2");
The configuration can be instructed to perform commits after database updates. This is achieved by setting the
commits parameter of the constructors to true. If commits should not be performed (which is the
default behavior), it should be ensured that the connections returned by the DataSource are in
auto-commit mode. | Constructor and Description |
|---|
DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String keyColumn,
java.lang.String valueColumn)
Build a configuration from a table.
|
DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String keyColumn,
java.lang.String valueColumn,
boolean commits)
Creates a new instance of
DatabaseConfiguration that operates on a database table containing a
single configuration only. |
DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String nameColumn,
java.lang.String keyColumn,
java.lang.String valueColumn,
java.lang.String name)
Build a configuration from a table containing multiple configurations.
|
DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String nameColumn,
java.lang.String keyColumn,
java.lang.String valueColumn,
java.lang.String name,
boolean commits)
Creates a new instance of
DatabaseConfiguration that operates on a database table containing
multiple configurations. |
| Modifier and Type | Method and Description |
|---|---|
void |
_performRetry(ConfigurationObject configuration,
SyncedUpdateHandlerInterface handler,
boolean loaded,
boolean updated,
boolean committed) |
void |
_performSyncedUpdateDB2(ConfigurationObject configuration,
SyncedUpdateHandlerInterface handler) |
void |
_performSyncedUpdateMSSQL(ConfigurationObject configuration,
SyncedUpdateHandlerInterface handler) |
void |
_performSyncedUpdateOracle(ConfigurationObject configuration,
SyncedUpdateHandlerInterface handler) |
void |
addErrorLogListener()
Adds a special org.apache.commons.configuration.event.ConfigurationErrorListener object to this configuration that will log all internal errors.
|
protected void |
addPropertyDirect(java.lang.String key,
java.lang.Object obj) |
protected void |
clearPropertyDirect(java.lang.String key) |
java.lang.Object |
getProperty(java.lang.String key)
Returns the value of the specified property.
|
void |
performSyncedUpdate(ConfigurationObject configuration,
SyncedUpdateHandlerInterface handler)
This call will lock the record referenced by the configuration object, call the handler's update method, passing
in the locked record, and then commit the changes, if "true" is returned from the update handler.
|
addProperty, clear, containsKey, getConnection, getDatasource, getKeys, isDoCommits, isEmptyappend, clearProperty, copy, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getList, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolate, interpolate, interpolatedConfiguration, interpolateHelper, isDelimiterParsingDisabled, isScalarValue, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setProperty, setThrowExceptionOnMissing, subsetaddConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, clone, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEventspublic DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String nameColumn,
java.lang.String keyColumn,
java.lang.String valueColumn,
java.lang.String name)
datasource - the datasource to connect to the databasetable - the name of the table containing the configurationsnameColumn - the column containing the name of the configurationkeyColumn - the column containing the keys of the configurationvalueColumn - the column containing the values of the configurationname - the name of the configurationpublic DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String nameColumn,
java.lang.String keyColumn,
java.lang.String valueColumn,
java.lang.String name,
boolean commits)
DatabaseConfiguration that operates on a database table containing
multiple configurations.datasource - the DataSource to connect to the databasetable - the name of the table containing the configurationsnameColumn - the column containing the name of the configurationkeyColumn - the column containing the keys of the configurationvalueColumn - the column containing the values of the configurationname - the name of the configurationcommits - a flag whether the configuration should perform a commit after a database updatepublic DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String keyColumn,
java.lang.String valueColumn)
datasource - the datasource to connect to the databasetable - the name of the table containing the configurationskeyColumn - the column containing the keys of the configurationvalueColumn - the column containing the values of the configurationpublic DatabaseConfiguration(javax.sql.DataSource datasource,
java.lang.String table,
java.lang.String keyColumn,
java.lang.String valueColumn,
boolean commits)
DatabaseConfiguration that operates on a database table containing a
single configuration only.datasource - the DataSource to connect to the databasetable - the name of the table containing the configurationskeyColumn - the column containing the keys of the configurationvalueColumn - the column containing the values of the configurationcommits - a flag whether the configuration should perform a commit after a database updateprotected void addPropertyDirect(java.lang.String key,
java.lang.Object obj)
addPropertyDirect in class org.apache.commons.configuration.DatabaseConfigurationprotected void clearPropertyDirect(java.lang.String key)
clearPropertyDirect in class org.apache.commons.configuration.DatabaseConfigurationpublic void _performSyncedUpdateMSSQL(ConfigurationObject configuration, SyncedUpdateHandlerInterface handler)
public void _performSyncedUpdateDB2(ConfigurationObject configuration, SyncedUpdateHandlerInterface handler)
public void _performSyncedUpdateOracle(ConfigurationObject configuration, SyncedUpdateHandlerInterface handler)
public void addErrorLogListener()
addErrorLogListener in class org.apache.commons.configuration.AbstractConfigurationpublic void _performRetry(ConfigurationObject configuration, SyncedUpdateHandlerInterface handler, boolean loaded, boolean updated, boolean committed)
public void performSyncedUpdate(ConfigurationObject configuration, SyncedUpdateHandlerInterface handler)
handler - The update handler that performs updates for this record.public java.lang.Object getProperty(java.lang.String key)
EVENT_READ_PROPERTY with the causing exception. The event's propertyName is set to
the passed in property key, the propertyValue is undefined.getProperty in interface org.apache.commons.configuration.ConfigurationgetProperty in class org.apache.commons.configuration.DatabaseConfigurationkey - the key of the desired property