use of org.cache2k.jcache.ExtendedMutableConfiguration 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;
}
}
}
use of org.cache2k.jcache.ExtendedMutableConfiguration in project cache2k by cache2k.
the class CacheManagerTest method create_config_cache2k_types.
@Test
@Ignore("not yet")
public void create_config_cache2k_types() {
CachingProvider p = Caching.getCachingProvider();
CacheManager cm = p.getCacheManager();
ExtendedMutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
mc.setCache2kConfiguration(new Cache2kBuilder<String, BigDecimal>() {
}.toConfiguration());
Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
assertEquals("aCache", c.getName());
assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
c.close();
}
use of org.cache2k.jcache.ExtendedMutableConfiguration in project cache2k by cache2k.
the class CacheManagerTest method create_empty_config.
@Test
public void create_empty_config() {
CachingProvider p = Caching.getCachingProvider();
CacheManager cm = p.getCacheManager();
MutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
mc.setTypes(String.class, BigDecimal.class);
Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
assertEquals("aCache", c.getName());
assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
c.close();
}
use of org.cache2k.jcache.ExtendedMutableConfiguration in project cache2k by cache2k.
the class XmlConfigurationTest method xmlConfigurationIsNotApplied.
@Test
public void xmlConfigurationIsNotApplied() {
CachingProvider p = Caching.getCachingProvider();
javax.cache.CacheManager cm = p.getCacheManager();
ExtendedMutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
mc.setTypes(String.class, BigDecimal.class);
javax.cache.Cache<String, BigDecimal> c = cm.createCache("unknownCache", mc);
assertTrue(mc.getCache2kConfiguration().isEternal());
c.close();
}
use of org.cache2k.jcache.ExtendedMutableConfiguration in project cache2k by cache2k.
the class XmlConfigurationTest method xmlConfigurationIsApplied.
@Test
public void xmlConfigurationIsApplied() throws Exception {
CachingProvider p = Caching.getCachingProvider();
javax.cache.CacheManager cm = p.getCacheManager(new URI(MANAGER_NAME), null);
ExtendedMutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
mc.setTypes(String.class, BigDecimal.class);
javax.cache.Cache<String, BigDecimal> c = cm.createCache("withExpiry", mc);
assertFalse(mc.getCache2kConfiguration().isEternal());
assertEquals(2000, mc.getCache2kConfiguration().getExpireAfterWrite());
c.close();
}
Aggregations