javax.cache.annotation.CacheDefaults Java Examples

The following examples show how to use javax.cache.annotation.CacheDefaults. 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 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 #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: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
private CacheKeyGenerator cacheKeyGeneratorFor(final CacheDefaults defaults, final Class<? extends CacheKeyGenerator> cacheKeyGenerator)
{
    if (!CacheKeyGenerator.class.equals(cacheKeyGenerator))
    {
        return instance(cacheKeyGenerator);
    }
    if (defaults != null)
    {
        final Class<? extends CacheKeyGenerator> defaultCacheKeyGenerator = defaults.cacheKeyGenerator();
        if (!CacheKeyGenerator.class.equals(defaultCacheKeyGenerator))
        {
            return instance(defaultCacheKeyGenerator);
        }
    }
    return defaultCacheKeyGenerator;
}
 
Example #4
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
private CacheDefaults findDefaults(final Class<?> targetType, final Method method)
{
    if (Proxy.isProxyClass(targetType)) // target doesnt hold annotations
    {
        final Class<?> api = method.getDeclaringClass();
        for (final Class<?> type : targetType
                                     .getInterfaces())
        {
            if (!api.isAssignableFrom(type))
            {
                continue;
            }
            return extractDefaults(type);
        }
    }
    return extractDefaults(targetType);
}
 
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 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 #7
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 #8
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 #9
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 #10
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 #11
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {
	if (CacheKeyGenerator.class != candidate) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #12
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected String determineCacheName(Method method, CacheDefaults defaults, String candidate) {
	if (StringUtils.hasText(candidate)) {
		return candidate;
	}
	if (defaults != null && StringUtils.hasText(defaults.cacheName())) {
		return defaults.cacheName();
	}
	return generateDefaultCacheName(method);
}
 
Example #13
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected JCacheOperation<?> findCacheOperation(Method method, Class<?> targetType) {
	CacheResult cacheResult = method.getAnnotation(CacheResult.class);
	CachePut cachePut = method.getAnnotation(CachePut.class);
	CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
	CacheRemoveAll cacheRemoveAll = method.getAnnotation(CacheRemoveAll.class);

	int found = countNonNull(cacheResult, cachePut, cacheRemove, cacheRemoveAll);
	if (found == 0) {
		return null;
	}
	if (found > 1) {
		throw new IllegalStateException("More than one cache annotation found on '" + method + "'");
	}

	CacheDefaults defaults = getCacheDefaults(method, targetType);
	if (cacheResult != null) {
		return createCacheResultOperation(method, defaults, cacheResult);
	}
	else if (cachePut != null) {
		return createCachePutOperation(method, defaults, cachePut);
	}
	else if (cacheRemove != null) {
		return createCacheRemoveOperation(method, defaults, cacheRemove);
	}
	else {
		return createCacheRemoveAllOperation(method, defaults, cacheRemoveAll);
	}
}
 
Example #14
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected CacheDefaults getCacheDefaults(Method method, Class<?> targetType) {
	CacheDefaults annotation = method.getDeclaringClass().getAnnotation(CacheDefaults.class);
	if (annotation != null) {
		return annotation;
	}
	return targetType.getAnnotation(CacheDefaults.class);
}
 
Example #15
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 #16
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 #17
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 #18
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.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 #19
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 #20
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {
	if (CacheKeyGenerator.class != candidate) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #21
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected String determineCacheName(Method method, CacheDefaults defaults, String candidate) {
	if (StringUtils.hasText(candidate)) {
		return candidate;
	}
	if (defaults != null && StringUtils.hasText(defaults.cacheName())) {
		return defaults.cacheName();
	}
	return generateDefaultCacheName(method);
}
 
Example #22
Source File: AnnotationCacheOperationSourceTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultCacheNameWithDefaults() {
	Method method = ReflectionUtils.findMethod(Object.class, "toString");
	CacheDefaults mock = mock(CacheDefaults.class);
	given(mock.cacheName()).willReturn("");
	assertEquals("java.lang.Object.toString()", source.determineCacheName(method, mock, ""));
}
 
Example #23
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 #24
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
private CacheDefaults extractDefaults(final Class<?> type)
{
    CacheDefaults annotation = null;
    Class<?> clazz = type;
    while (clazz != null && clazz != Object.class)
    {
        annotation = clazz.getAnnotation(CacheDefaults.class);
        if (annotation != null)
        {
            break;
        }
        clazz = clazz.getSuperclass();
    }
    return annotation;
}
 
Example #25
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
protected CacheDefaults getCacheDefaults(Method method, @Nullable Class<?> targetType) {
	CacheDefaults annotation = method.getDeclaringClass().getAnnotation(CacheDefaults.class);
	if (annotation != null) {
		return annotation;
	}
	return (targetType != null ? targetType.getAnnotation(CacheDefaults.class) : null);
}
 
Example #26
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 #27
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(
		@Nullable CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {

	if (candidate != CacheKeyGenerator.class) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #28
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected String determineCacheName(Method method, @Nullable CacheDefaults defaults, String candidate) {
	if (StringUtils.hasText(candidate)) {
		return candidate;
	}
	if (defaults != null && StringUtils.hasText(defaults.cacheName())) {
		return defaults.cacheName();
	}
	return generateDefaultCacheName(method);
}
 
Example #29
Source File: AnnotationCacheOperationSourceTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void defaultCacheNameWithDefaults() {
	Method method = ReflectionUtils.findMethod(Object.class, "toString");
	CacheDefaults mock = mock(CacheDefaults.class);
	given(mock.cacheName()).willReturn("");
	assertEquals("java.lang.Object.toString()", source.determineCacheName(method, mock, ""));
}
 
Example #30
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected JCacheOperation<?> findCacheOperation(Method method, @Nullable Class<?> targetType) {
	CacheResult cacheResult = method.getAnnotation(CacheResult.class);
	CachePut cachePut = method.getAnnotation(CachePut.class);
	CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
	CacheRemoveAll cacheRemoveAll = method.getAnnotation(CacheRemoveAll.class);

	int found = countNonNull(cacheResult, cachePut, cacheRemove, cacheRemoveAll);
	if (found == 0) {
		return null;
	}
	if (found > 1) {
		throw new IllegalStateException("More than one cache annotation found on '" + method + "'");
	}

	CacheDefaults defaults = getCacheDefaults(method, targetType);
	if (cacheResult != null) {
		return createCacheResultOperation(method, defaults, cacheResult);
	}
	else if (cachePut != null) {
		return createCachePutOperation(method, defaults, cachePut);
	}
	else if (cacheRemove != null) {
		return createCacheRemoveOperation(method, defaults, cacheRemove);
	}
	else {
		return createCacheRemoveAllOperation(method, defaults, cacheRemoveAll);
	}
}