Skip to content

Commit

Permalink
Use name from CacheDefaults when injecting JCache (#1126)
Browse files Browse the repository at this point in the history
Use name from CacheDefaults when injecting JCache (PAYARA-1106)
  • Loading branch information
jerrinot authored and smillidge committed Oct 11, 2016
1 parent c7fad32 commit 52c8756
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ and Distribution License("CDDL") (collectively, the "License"). You
import fish.payara.nucleus.hazelcast.HazelcastCore;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.annotation.CacheDefaults;
import javax.cache.configuration.Factory;
import javax.cache.configuration.FactoryBuilder;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.spi.CachingProvider;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;

/**
Expand Down Expand Up @@ -123,6 +125,17 @@ public Cache createCache(InjectionPoint ip) {
result = manager.createCache(cacheName, config);
}
} else { // configure a "raw" cache
Bean<?> bean = ip.getBean();
if (bean != null) {
Class<?> beanClass = bean.getBeanClass();
CacheDefaults defaults = beanClass.getAnnotation(CacheDefaults.class);
if (defaults != null) {
String cacheNameFromAnnotation = defaults.cacheName();
if (!"".equals(cacheNameFromAnnotation)) {
cacheName = cacheNameFromAnnotation;
}
}
}
result = manager.getCache(cacheName);
if (result == null) {
MutableConfiguration<Object, Object> config = new MutableConfiguration<>();
Expand Down

0 comments on commit 52c8756

Please sign in to comment.