javax.cache.annotation.CacheResolverFactory Java Examples

The following examples show how to use javax.cache.annotation.CacheResolverFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected CacheResultOperation createCacheResultOperation(Method method, @Nullable CacheDefaults defaults, CacheResult ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);

	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	CacheResolver exceptionCacheResolver = null;
	final String exceptionCacheName = ann.exceptionCacheName();
	if (StringUtils.hasText(exceptionCacheName)) {
		exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
	}

	return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
 
Example #2
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
private CacheResolverFactory cacheResolverFactoryFor(final CacheDefaults defaults, final Class<? extends CacheResolverFactory> cacheResolverFactory)
{
    if (!CacheResolverFactory.class.equals(cacheResolverFactory))
    {
        return instance(cacheResolverFactory);
    }
    if (defaults != null)
    {
        final Class<? extends CacheResolverFactory> defaultCacheResolverFactory = defaults.cacheResolverFactory();
        if (!CacheResolverFactory.class.equals(defaultCacheResolverFactory))
        {
            return instance(defaultCacheResolverFactory);
        }
    }
    return defaultCacheResolverFactory();
}
 
Example #3
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected CacheResultOperation createCacheResultOperation(Method method, CacheDefaults defaults, CacheResult ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);

	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	CacheResolver exceptionCacheResolver = null;
	final String exceptionCacheName = ann.exceptionCacheName();
	if (StringUtils.hasText(exceptionCacheName)) {
		exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
	}

	return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
 
Example #4
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected CacheResultOperation createCacheResultOperation(Method method, @Nullable CacheDefaults defaults, CacheResult ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);

	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	CacheResolver exceptionCacheResolver = null;
	final String exceptionCacheName = ann.exceptionCacheName();
	if (StringUtils.hasText(exceptionCacheName)) {
		exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
	}

	return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
 
Example #5
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected CacheResultOperation createCacheResultOperation(Method method, CacheDefaults defaults, CacheResult ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);

	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	CacheResolver exceptionCacheResolver = null;
	final String exceptionCacheName = ann.exceptionCacheName();
	if (StringUtils.hasText(exceptionCacheName)) {
		exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
	}

	return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
 
Example #6
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected CacheResolver getCacheResolver(CacheResolverFactory factory, CacheMethodDetails<?> details) {
	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultCacheResolver();
	}
}
 
Example #7
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected CachePutOperation createCachePutOperation(Method method, @Nullable CacheDefaults defaults, CachePut ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CachePut> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CachePutOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #8
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected CacheResolver getExceptionCacheResolver(CacheResolverFactory factory,
		CacheMethodDetails<CacheResult> details) {

	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getExceptionCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultExceptionCacheResolver();
	}
}
 
Example #9
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected CacheResolverFactory determineCacheResolverFactory(CacheDefaults defaults,
		Class<? extends CacheResolverFactory> candidate) {

	if (CacheResolverFactory.class != candidate) {
		return getBean(candidate);
	}
	else if (defaults != null && CacheResolverFactory.class != defaults.cacheResolverFactory()) {
		return getBean(defaults.cacheResolverFactory());
	}
	else {
		return null;
	}
}
 
Example #10
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CachePutOperation createCachePutOperation(Method method, CacheDefaults defaults, CachePut ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CachePut> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CachePutOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #11
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CacheRemoveOperation createCacheRemoveOperation(Method method, CacheDefaults defaults, CacheRemove ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheRemove> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #12
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CacheRemoveAllOperation createCacheRemoveAllOperation(Method method, CacheDefaults defaults, CacheRemoveAll ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());

	CacheMethodDetails<CacheRemoveAll> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveAllOperation(methodDetails, cacheResolver);
}
 
Example #13
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CacheResolver getCacheResolver(CacheResolverFactory factory, CacheMethodDetails<?> details) {
	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultCacheResolver();
	}
}
 
Example #14
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CacheResolver getExceptionCacheResolver(CacheResolverFactory factory,
		CacheMethodDetails<CacheResult> details) {

	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getExceptionCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultExceptionCacheResolver();
	}
}
 
Example #15
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CacheResolverFactory determineCacheResolverFactory(CacheDefaults defaults,
		Class<? extends CacheResolverFactory> candidate) {

	if (CacheResolverFactory.class != candidate) {
		return getBean(candidate);
	}
	else if (defaults != null && CacheResolverFactory.class != defaults.cacheResolverFactory()) {
		return getBean(defaults.cacheResolverFactory());
	}
	else {
		return null;
	}
}
 
Example #16
Source File: JCacheGuiceTest.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Resolves the annotations to the provider as multiple are on the IDE's classpath. */
void configureCachingProvider() {
  CachingProvider provider = Caching.getCachingProvider(
      CaffeineCachingProvider.class.getName());
  CacheManager cacheManager = provider.getCacheManager(
      provider.getDefaultURI(), provider.getDefaultClassLoader());
  bind(CacheResolverFactory.class).toInstance(new DefaultCacheResolverFactory(cacheManager));
  bind(CacheManager.class).toInstance(cacheManager);
}
 
Example #17
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
private <T> T instance(final Class<T> type)
{
    final Set<Bean<?>> beans = beanManager.getBeans(type);
    if (beans.isEmpty())
    {
        if (CacheKeyGenerator.class == type) {
            return (T) defaultCacheKeyGenerator;
        }
        if (CacheResolverFactory.class == type) {
            return (T) defaultCacheResolverFactory();
        }
        return null;
    }
    final Bean<?> bean = beanManager.resolve(beans);
    final CreationalContext<?> context = beanManager.createCreationalContext(bean);
    final Class<? extends Annotation> scope = bean.getScope();
    final boolean normalScope = beanManager.isNormalScope(scope);
    try
    {
        final Object reference = beanManager.getReference(bean, bean.getBeanClass(), context);
        if (!normalScope)
        {
            toRelease.add(context);
        }
        return (T) reference;
    }
    finally
    {
        if (normalScope)
        { // TODO: release at the right moment, @PreDestroy? question is: do we assume it is thread safe?
            context.release();
        }
    }
}
 
Example #18
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
public MethodMeta(Class<?>[] parameterTypes, List<Set<Annotation>> parameterAnnotations, Set<Annotation>
        annotations, Integer[] keysIndices, Integer valueIndex, Integer[] parameterIndices, String
        cacheResultCacheName, CacheResolverFactory cacheResultResolverFactory, CacheKeyGenerator
        cacheResultKeyGenerator, CacheResult cacheResult, String cachePutCacheName, CacheResolverFactory
        cachePutResolverFactory, CacheKeyGenerator cachePutKeyGenerator, boolean cachePutAfter, CachePut cachePut, String
        cacheRemoveCacheName, CacheResolverFactory cacheRemoveResolverFactory, CacheKeyGenerator
        cacheRemoveKeyGenerator, boolean cacheRemoveAfter, CacheRemove cacheRemove, String cacheRemoveAllCacheName,
                  CacheResolverFactory cacheRemoveAllResolverFactory, boolean
                          cacheRemoveAllAfter, CacheRemoveAll cacheRemoveAll)
{
    this.parameterTypes = parameterTypes;
    this.parameterAnnotations = parameterAnnotations;
    this.annotations = annotations;
    this.keysIndices = keysIndices;
    this.valueIndex = valueIndex;
    this.parameterIndices = parameterIndices;
    this.cacheResultCacheName = cacheResultCacheName;
    this.cacheResultResolverFactory = cacheResultResolverFactory;
    this.cacheResultKeyGenerator = cacheResultKeyGenerator;
    this.cacheResult = cacheResult;
    this.cachePutCacheName = cachePutCacheName;
    this.cachePutResolverFactory = cachePutResolverFactory;
    this.cachePutKeyGenerator = cachePutKeyGenerator;
    this.cachePutAfter = cachePutAfter;
    this.cachePut = cachePut;
    this.cacheRemoveCacheName = cacheRemoveCacheName;
    this.cacheRemoveResolverFactory = cacheRemoveResolverFactory;
    this.cacheRemoveKeyGenerator = cacheRemoveKeyGenerator;
    this.cacheRemoveAfter = cacheRemoveAfter;
    this.cacheRemove = cacheRemove;
    this.cacheRemoveAllCacheName = cacheRemoveAllCacheName;
    this.cacheRemoveAllResolverFactory = cacheRemoveAllResolverFactory;
    this.cacheRemoveAllAfter = cacheRemoveAllAfter;
    this.cacheRemoveAll = cacheRemoveAll;
}
 
Example #19
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected CacheRemoveOperation createCacheRemoveOperation(Method method, CacheDefaults defaults, CacheRemove ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheRemove> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #20
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected CacheRemoveOperation createCacheRemoveOperation(Method method, @Nullable CacheDefaults defaults, CacheRemove ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheRemove> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #21
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected CacheRemoveAllOperation createCacheRemoveAllOperation(Method method, @Nullable CacheDefaults defaults, CacheRemoveAll ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());

	CacheMethodDetails<CacheRemoveAll> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveAllOperation(methodDetails, cacheResolver);
}
 
Example #22
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected CacheResolver getCacheResolver(
		@Nullable CacheResolverFactory factory, CacheMethodDetails<?> details) {

	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultCacheResolver();
	}
}
 
Example #23
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected CacheResolver getExceptionCacheResolver(
		@Nullable CacheResolverFactory factory, CacheMethodDetails<CacheResult> details) {

	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getExceptionCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultExceptionCacheResolver();
	}
}
 
Example #24
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
protected CacheResolverFactory determineCacheResolverFactory(
		@Nullable CacheDefaults defaults, Class<? extends CacheResolverFactory> candidate) {

	if (candidate != CacheResolverFactory.class) {
		return getBean(candidate);
	}
	else if (defaults != null && defaults.cacheResolverFactory() != CacheResolverFactory.class) {
		return getBean(defaults.cacheResolverFactory());
	}
	else {
		return null;
	}
}
 
Example #25
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected CachePutOperation createCachePutOperation(Method method, @Nullable CacheDefaults defaults, CachePut ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CachePut> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CachePutOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #26
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected CacheRemoveOperation createCacheRemoveOperation(Method method, @Nullable CacheDefaults defaults, CacheRemove ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
	KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());

	CacheMethodDetails<CacheRemove> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveOperation(methodDetails, cacheResolver, keyGenerator);
}
 
Example #27
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected CacheRemoveAllOperation createCacheRemoveAllOperation(Method method, @Nullable CacheDefaults defaults, CacheRemoveAll ann) {
	String cacheName = determineCacheName(method, defaults, ann.cacheName());
	CacheResolverFactory cacheResolverFactory =
			determineCacheResolverFactory(defaults, ann.cacheResolverFactory());

	CacheMethodDetails<CacheRemoveAll> methodDetails = createMethodDetails(method, ann, cacheName);
	CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
	return new CacheRemoveAllOperation(methodDetails, cacheResolver);
}
 
Example #28
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected CacheResolver getCacheResolver(
		@Nullable CacheResolverFactory factory, CacheMethodDetails<?> details) {

	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultCacheResolver();
	}
}
 
Example #29
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected CacheResolver getExceptionCacheResolver(
		@Nullable CacheResolverFactory factory, CacheMethodDetails<CacheResult> details) {

	if (factory != null) {
		javax.cache.annotation.CacheResolver cacheResolver = factory.getExceptionCacheResolver(details);
		return new CacheResolverAdapter(cacheResolver);
	}
	else {
		return getDefaultExceptionCacheResolver();
	}
}
 
Example #30
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
protected CacheResolverFactory determineCacheResolverFactory(
		@Nullable CacheDefaults defaults, Class<? extends CacheResolverFactory> candidate) {

	if (candidate != CacheResolverFactory.class) {
		return getBean(candidate);
	}
	else if (defaults != null && defaults.cacheResolverFactory() != CacheResolverFactory.class) {
		return getBean(defaults.cacheResolverFactory());
	}
	else {
		return null;
	}
}