Search in sources :

Example 1 with JCacheConfiguration

use of org.cache2k.jcache.JCacheConfiguration in project cache2k by cache2k.

the class JCacheBuilder method setConfiguration.

public void setConfiguration(Configuration<K, V> cfg) {
    if (cfg instanceof CompleteConfiguration) {
        config = (CompleteConfiguration<K, V>) cfg;
        if (cfg instanceof ExtendedConfiguration) {
            cache2kConfiguration = ((ExtendedConfiguration<K, V>) cfg).getCache2kConfiguration();
            if (cache2kConfiguration != null) {
                if (cache2kConfiguration.getName() != null && !cache2kConfiguration.getName().equals(name)) {
                    throw new IllegalArgumentException("cache name mismatch.");
                }
                cache2kConfigurationWasProvided = true;
            }
        }
    } else {
        MutableConfiguration<K, V> _cfgCopy = new MutableConfiguration<K, V>();
        _cfgCopy.setTypes(cfg.getKeyType(), cfg.getValueType());
        _cfgCopy.setStoreByValue(cfg.isStoreByValue());
        config = _cfgCopy;
    }
    if (cache2kConfiguration == null) {
        cache2kConfiguration = CacheManagerImpl.PROVIDER.getDefaultConfiguration(manager.getCache2kManager());
        if (cfg instanceof ExtendedMutableConfiguration) {
            ((ExtendedMutableConfiguration) cfg).setCache2kConfiguration(cache2kConfiguration);
        }
    }
    cache2kConfiguration.setName(name);
    Cache2kCoreProviderImpl.augmentConfiguration(manager.getCache2kManager(), cache2kConfiguration);
    cache2kConfigurationWasProvided |= cache2kConfiguration.isExternalConfigurationPresent();
    if (cache2kConfigurationWasProvided) {
        extraConfiguration = CACHE2K_DEFAULTS;
        JCacheConfiguration _extraConfigurationSpecified = cache2kConfiguration.getSections().getSection(JCacheConfiguration.class);
        if (_extraConfigurationSpecified != null) {
            extraConfiguration = _extraConfigurationSpecified;
        }
    }
}
Also used : ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) JCacheConfiguration(org.cache2k.jcache.JCacheConfiguration) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) ExtendedConfiguration(org.cache2k.jcache.ExtendedConfiguration) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Aggregations

CompleteConfiguration (javax.cache.configuration.CompleteConfiguration)1 MutableConfiguration (javax.cache.configuration.MutableConfiguration)1 ExtendedConfiguration (org.cache2k.jcache.ExtendedConfiguration)1 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)1 JCacheConfiguration (org.cache2k.jcache.JCacheConfiguration)1