javax.cache.annotation.CacheKey Java Examples

The following examples show how to use javax.cache.annotation.CacheKey. 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: AbstractJCacheOperation.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public CacheParameterDetail(Method method, int parameterPosition) {
	this.rawType = method.getParameterTypes()[parameterPosition];
	this.annotations = new LinkedHashSet<>();
	boolean foundKeyAnnotation = false;
	boolean foundValueAnnotation = false;
	for (Annotation annotation : method.getParameterAnnotations()[parameterPosition]) {
		this.annotations.add(annotation);
		if (CacheKey.class.isAssignableFrom(annotation.annotationType())) {
			foundKeyAnnotation = true;
		}
		if (CacheValue.class.isAssignableFrom(annotation.annotationType())) {
			foundValueAnnotation = true;
		}
	}
	this.parameterPosition = parameterPosition;
	this.isKey = foundKeyAnnotation;
	this.isValue = foundValueAnnotation;
}
 
Example #2
Source File: AbstractJCacheOperation.java    From java-technology-stack with MIT License 6 votes vote down vote up
public CacheParameterDetail(Method method, int parameterPosition) {
	this.rawType = method.getParameterTypes()[parameterPosition];
	this.annotations = new LinkedHashSet<>();
	boolean foundKeyAnnotation = false;
	boolean foundValueAnnotation = false;
	for (Annotation annotation : method.getParameterAnnotations()[parameterPosition]) {
		this.annotations.add(annotation);
		if (CacheKey.class.isAssignableFrom(annotation.annotationType())) {
			foundKeyAnnotation = true;
		}
		if (CacheValue.class.isAssignableFrom(annotation.annotationType())) {
			foundValueAnnotation = true;
		}
	}
	this.parameterPosition = parameterPosition;
	this.isKey = foundKeyAnnotation;
	this.isValue = foundValueAnnotation;
}
 
Example #3
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
private Integer[] getKeyParameters(final List<Set<Annotation>> annotations)
{
    final Collection<Integer> list = new ArrayList<>();
    int idx = 0;
    for (final Set<Annotation> set : annotations)
    {
        for (final Annotation a : set)
        {
            if (a.annotationType() == CacheKey.class)
            {
                list.add(idx);
            }
        }
        idx++;
    }
    if (list.isEmpty())
    {
        for (int i = 0; i < annotations.size(); i++)
        {
            list.add(i);
        }
    }
    return list.toArray(new Integer[list.size()]);
}
 
Example #4
Source File: AbstractJCacheOperation.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public CacheParameterDetail(Method method, int parameterPosition) {
	this.rawType = method.getParameterTypes()[parameterPosition];
	this.annotations = new LinkedHashSet<Annotation>();
	boolean foundKeyAnnotation = false;
	boolean foundValueAnnotation = false;
	for (Annotation annotation : method.getParameterAnnotations()[parameterPosition]) {
		this.annotations.add(annotation);
		if (CacheKey.class.isAssignableFrom(annotation.annotationType())) {
			foundKeyAnnotation = true;
		}
		if (CacheValue.class.isAssignableFrom(annotation.annotationType())) {
			foundValueAnnotation = true;
		}
	}
	this.parameterPosition = parameterPosition;
	this.isKey = foundKeyAnnotation;
	this.isValue = foundValueAnnotation;
}
 
Example #5
Source File: AbstractJCacheOperation.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
public CacheParameterDetail(Method method, int parameterPosition) {
	this.rawType = method.getParameterTypes()[parameterPosition];
	this.annotations = new LinkedHashSet<Annotation>();
	boolean foundKeyAnnotation = false;
	boolean foundValueAnnotation = false;
	for (Annotation annotation : method.getParameterAnnotations()[parameterPosition]) {
		this.annotations.add(annotation);
		if (CacheKey.class.isAssignableFrom(annotation.annotationType())) {
			foundKeyAnnotation = true;
		}
		if (CacheValue.class.isAssignableFrom(annotation.annotationType())) {
			foundValueAnnotation = true;
		}
	}
	this.parameterPosition = parameterPosition;
	this.isKey = foundKeyAnnotation;
	this.isValue = foundValueAnnotation;
}
 
Example #6
Source File: CacheResultOperationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void annotatedGet() {
	CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class,
			SampleObject.class, "annotatedGet", Long.class, String.class);
	CacheResultOperation operation = createDefaultOperation(methodDetails);
	CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo");

	Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations();
	assertEquals(1, firstParameterAnnotations.size());
	assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType());

	Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations();
	assertEquals(1, secondParameterAnnotations.size());
	assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType());
}
 
Example #7
Source File: CacheResultOperationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void annotatedGet() {
	CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class,
			SampleObject.class, "annotatedGet", Long.class, String.class);
	CacheResultOperation operation = createDefaultOperation(methodDetails);
	CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo");

	Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations();
	assertEquals(1, firstParameterAnnotations.size());
	assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType());

	Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations();
	assertEquals(1, secondParameterAnnotations.size());
	assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType());
}
 
Example #8
Source File: CacheResultOperationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void annotatedGet() {
	CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class,
			SampleObject.class, "annotatedGet", Long.class, String.class);
	CacheResultOperation operation = createDefaultOperation(methodDetails);
	CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo");

	Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations();
	assertEquals(1, firstParameterAnnotations.size());
	assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType());

	Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations();
	assertEquals(1, secondParameterAnnotations.size());
	assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType());
}
 
Example #9
Source File: UsingDefaultCacheNameBlogManagerImpl.java    From cache2k with Apache License 2.0 4 votes vote down vote up
/**
 * Have to specify the cache name here, the generated name is:
 * manager.UsingDefaultCacheNameBlogManagerImpl.getEntryCached(java.lang.String,java.lang.String,java.lang.String)
 */
@CacheResult(cacheName = "manager.UsingDefaultCacheNameBlogManagerImpl.getEntryCached(java.lang.String)")
public Blog getEntryCached(String randomArg, @CacheKey String title, String randomArg2) {
  return map.get(title);
}
 
Example #10
Source File: SampleObject.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@CachePut(cacheName = "simpleCache", afterInvocation = false,
		cacheFor = Exception.class, noCacheFor = RuntimeException.class)
public void fullPutConfig(@CacheKey Long id, @CacheValue SampleObject instance) {
}
 
Example #11
Source File: CacheNameOnEachMethodBlogManagerImpl.java    From cache2k with Apache License 2.0 4 votes vote down vote up
/**
 *
 */
@CacheResult(cacheName = "blogManager")
public Blog getEntryCached(String randomArg, @CacheKey String title, String randomArg2) {
  return map.get(title);
}
 
Example #12
Source File: ClassLevelCacheConfigBlogManagerImpl.java    From cache2k with Apache License 2.0 4 votes vote down vote up
@CacheResult
public Blog getEntryCached(String randomArg, @CacheKey String title,
                           String randomArg2) {
  return map.get(title);
}
 
Example #13
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CacheRemove(afterInvocation = false, evictFor = UnsupportedOperationException.class)
public void earlyRemoveWithException(@CacheKey String id, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #14
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CacheRemove(noEvictFor = NullPointerException.class)
public void removeWithException(@CacheKey String id, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #15
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CachePut(afterInvocation = false)
public void earlyPutWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #16
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CachePut(cacheFor = UnsupportedOperationException.class)
public void putWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #17
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CacheResult
public Long cacheWithPartialKey(@CacheKey String id, boolean notUsed) {
	return counter.getAndIncrement();
}
 
Example #18
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CachePut(cacheFor = UnsupportedOperationException.class)
public void putWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #19
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CachePut(afterInvocation = false)
public void earlyPutWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #20
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CacheResult(exceptionCacheName = "exception", nonCachedExceptions = NullPointerException.class)
public Long cacheWithCheckedException(@CacheKey String id, boolean matchFilter) throws IOException {
	throwCheckedException(matchFilter);
	return 0L; // Never reached
}
 
Example #21
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CacheResult(exceptionCacheName = "exception", nonCachedExceptions = NullPointerException.class)
public Long cacheWithException(@CacheKey String id, boolean matchFilter) {
	throwException(matchFilter);
	return 0L; // Never reached
}
 
Example #22
Source File: AnnotatedJCacheableService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
@CacheResult
public Long cacheWithPartialKey(@CacheKey String id, boolean notUsed) {
	return counter.getAndIncrement();
}
 
Example #23
Source File: SampleObject.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@CacheResult(cacheName = "simpleCache", skipGet = true,
		cachedExceptions = Exception.class, nonCachedExceptions = RuntimeException.class)
public SampleObject fullGetConfig(@CacheKey Long id) {
	return null;
}
 
Example #24
Source File: SampleObject.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@CacheResult(cacheName = "simpleCache")
public SampleObject annotatedGet(@CacheKey Long id, @Value("${foo}") String foo) {
	return null;
}
 
Example #25
Source File: SampleObject.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@CacheResult
public SampleObject multiKeysGet(@CacheKey Long id, Boolean notUsed,
		@CacheKey String domain) {
	return null;
}
 
Example #26
Source File: AnnotatedJCacheableService.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@CacheRemove(afterInvocation = false, evictFor = UnsupportedOperationException.class)
public void earlyRemoveWithException(@CacheKey String id, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #27
Source File: AnnotatedJCacheableService.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@CacheRemove(noEvictFor = NullPointerException.class)
public void removeWithException(@CacheKey String id, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #28
Source File: AnnotatedJCacheableService.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@CachePut(afterInvocation = false)
public void earlyPutWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #29
Source File: AnnotatedJCacheableService.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@CachePut(cacheFor = UnsupportedOperationException.class)
public void putWithException(@CacheKey String id, @CacheValue Object value, boolean matchFilter) {
	throwException(matchFilter);
}
 
Example #30
Source File: AnnotatedJCacheableService.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@CacheResult
public Long cacheWithPartialKey(@CacheKey String id, boolean notUsed) {
	return counter.getAndIncrement();
}