YaOg
YaOg

Reputation: 1768

dynamic reload in apache DatabaseConfiguration

Has anyone developed a dynamic reload mechanism for the apache commons database configuration object?

Upvotes: 2

Views: 3467

Answers (2)

rjdkolb
rjdkolb

Reputation: 11888

apache commons database configuration does not support caching.

I extend DatabaseConfiguration to support caching so it does not hit my database all the time. As for reloads, I instantiate my config where I need it and throw it away when I am done with it.

MyConfig cfg = new MyConfig("jdbc/configdatabase");


public class MyConfig extends DatabaseConfiguration {

    private WeakHashMap<String,Object> cache = new WeakHashMap<String,Object>();

    public MyConfig(String datasourceString,String section) throws NamingException {
        this((DataSource) new InitialContext().lookup(datasourceString),section);
    }

    protected MyConfig(DataSource datasource,String section) {
        super(datasource, "COMMON_CONFIG","PROP_SECTION", "PROP_KEY", "PROP_VALUE",section);
    }

    @Override
    public Object getProperty(String key){
        Object cachedValue = cache.get(key);
        if (cachedValue != null){
            return cachedValue;
        }
        Object databaseValue = super.getProperty(key);
        cache.put(key, databaseValue);
        return databaseValue;

    }
}

Upvotes: 0

Emmanuel Bourg
Emmanuel Bourg

Reputation: 11058

Actually this is not necessary because DatabaseConfiguration doesn't cache the values from the database. A request is performed every time a property is fetched. There is a RFE to cache the values for improved performance, and this will indeed require a reloading mechanism.

https://issues.apache.org/jira/browse/CONFIGURATION-180

Upvotes: 3

Related Questions