All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.robe.admin.util.SystemParameterCache Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.admin.util;

import io.robe.admin.hibernate.dao.SystemParameterDao;
import io.robe.admin.hibernate.entity.SystemParameter;
import io.robe.guice.GuiceBundle;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class SystemParameterCache {

    private static ConcurrentHashMap cache = new ConcurrentHashMap<>();


    public static void fillCache() {
        SystemParameterDao dao = GuiceBundle.getInjector().getInstance(SystemParameterDao.class);

        List parameters = dao.findAll();

        for (SystemParameter parameter : parameters)
            cache.put(parameter.getKey(), parameter.getValue());
    }


    public static Object get(String key, Object defaultValue) {
        if (cache.isEmpty()) {
            fillCache();
        }
        Object value = cache.get(key);
        return (value == null) ? defaultValue : value;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy