javax.cache.annotation.CacheResult Java Examples
The following examples show how to use
javax.cache.annotation.CacheResult.
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 java-technology-stack with MIT License | 6 votes |
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: AnnotationJCacheOperationSource.java From lams with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: AnnotationJCacheOperationSource.java From java-technology-stack with MIT License | 5 votes |
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 #4
Source File: CacheResolverAdapterTests.java From java-technology-stack with MIT License | 5 votes |
protected DefaultCacheInvocationContext<?> createDummyContext() throws Exception { Method method = Sample.class.getMethod("get", String.class); CacheResult cacheAnnotation = method.getAnnotation(CacheResult.class); CacheMethodDetails<CacheResult> methodDetails = new DefaultCacheMethodDetails<>(method, cacheAnnotation, "test"); CacheResultOperation operation = new CacheResultOperation(methodDetails, defaultCacheResolver, defaultKeyGenerator, defaultExceptionCacheResolver); return new DefaultCacheInvocationContext<>(operation, new Sample(), new Object[] {"id"}); }
Example #5
Source File: ComponentResourceProxy.java From component-runtime with Apache License 2.0 | 5 votes |
@GET @Path("icon/{id}") @Produces({ APPLICATION_JSON, APPLICATION_OCTET_STREAM, "image/svg+xml" }) @CacheResult public CompletionStage<Response> icon() { return handler.forward(); }
Example #6
Source File: TalendComponentKitService.java From component-runtime with Apache License 2.0 | 5 votes |
@CacheResult CompletionStage<ActionList> getActions() { return client .path("action/index") .queryParam("language", "en") .request(APPLICATION_JSON_TYPE) .rx() .get(ActionList.class); }
Example #7
Source File: JpaConferenceRepositoryImpl.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override @CacheResult(cacheName = "conference") public Conference findBySlug(String slug) { List<Conference> all = entityManager .createQuery("from Conference where slug=:slug", Conference.class).setParameter("slug", slug) .getResultList(); if (!all.isEmpty()) { return all.get(0); } return null; }
Example #8
Source File: ComponentResourceProxy.java From component-runtime with Apache License 2.0 | 5 votes |
@GET @Path("icon/family/{id}") @CacheResult @Produces({ APPLICATION_JSON, APPLICATION_OCTET_STREAM, "image/svg+xml" }) public CompletionStage<Response> familyIcon() { return handler.forward(); }
Example #9
Source File: CacheResolverFactoryImpl.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public CacheResolver getExceptionCacheResolver(final CacheMethodDetails<CacheResult> cacheMethodDetails) { final String exceptionCacheName = cacheMethodDetails.getCacheAnnotation().exceptionCacheName(); if (exceptionCacheName == null || exceptionCacheName.isEmpty()) { throw new IllegalArgumentException("CacheResult.exceptionCacheName() not specified"); } return findCacheResolver(exceptionCacheName); }
Example #10
Source File: CacheResultOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void tooManyKeyValues() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "anotherSimpleGet", String.class, Long.class); CacheResultOperation operation = createDefaultOperation(methodDetails); // missing one argument assertThatIllegalStateException().isThrownBy(() -> operation.getKeyParameters("bar")); }
Example #11
Source File: CacheResultOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@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 #12
Source File: CacheResultOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void fullGetConfig() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "fullGetConfig", Long.class); CacheResultOperation operation = createDefaultOperation(methodDetails); assertTrue(operation.isAlwaysInvoked()); assertNotNull(operation.getExceptionTypeFilter()); assertTrue(operation.getExceptionTypeFilter().match(IOException.class)); assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class)); }
Example #13
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void fullGetConfig() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "fullGetConfig", Long.class); CacheResultOperation operation = createDefaultOperation(methodDetails); assertTrue(operation.isAlwaysInvoked()); assertNotNull(operation.getExceptionTypeFilter()); assertTrue(operation.getExceptionTypeFilter().match(IOException.class)); assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class)); }
Example #14
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 5 votes |
@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 #15
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void invokeWithWrongParameters() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "anotherSimpleGet", String.class, Long.class); CacheResultOperation operation = createDefaultOperation(methodDetails); thrown.expect(IllegalStateException.class); operation.getAllParameters("bar"); // missing one argument }
Example #16
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Override protected CacheResultOperation createSimpleOperation() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "simpleGet", Long.class); return new CacheResultOperation(methodDetails, defaultCacheResolver, defaultKeyGenerator, defaultExceptionCacheResolver); }
Example #17
Source File: AnnotationJCacheOperationSource.java From lams with GNU General Public License v2.0 | 5 votes |
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 #18
Source File: CacheResultOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void tooManyKeyValues() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "anotherSimpleGet", String.class, Long.class); CacheResultOperation operation = createDefaultOperation(methodDetails); thrown.expect(IllegalStateException.class); operation.getKeyParameters("bar"); // missing one argument }
Example #19
Source File: CacheResultOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void multiParameterKey() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "multiKeysGet", Long.class, Boolean.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(3L, Boolean.TRUE, "Foo"); assertEquals(2, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 3L, 0); assertCacheInvocationParameter(keyParameters[1], String.class, "Foo", 2); }
Example #20
Source File: CacheResolverAdapterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected DefaultCacheInvocationContext<?> createDummyContext() { Method method = ReflectionUtils.findMethod(Sample.class, "get", String.class); Assert.notNull(method); CacheResult cacheAnnotation = method.getAnnotation(CacheResult.class); CacheMethodDetails<CacheResult> methodDetails = new DefaultCacheMethodDetails<>(method, cacheAnnotation, "test"); CacheResultOperation operation = new CacheResultOperation(methodDetails, defaultCacheResolver, defaultKeyGenerator, defaultExceptionCacheResolver); return new DefaultCacheInvocationContext<CacheResult>(operation, new Sample(), new Object[] {"id"}); }
Example #21
Source File: CacheResultOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void invokeWithWrongParameters() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "anotherSimpleGet", String.class, Long.class); CacheResultOperation operation = createDefaultOperation(methodDetails); thrown.expect(IllegalStateException.class); operation.getAllParameters("bar"); // missing one argument }
Example #22
Source File: AnnotationJCacheOperationSource.java From spring4-understanding with Apache License 2.0 | 5 votes |
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 #23
Source File: AnnotationJCacheOperationSource.java From lams with GNU General Public License v2.0 | 5 votes |
@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 #24
Source File: AnnotationJCacheOperationSource.java From java-technology-stack with MIT License | 5 votes |
@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); } }
Example #25
Source File: CDIJCacheHelper.java From commons-jcs with Apache License 2.0 | 5 votes |
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 #26
Source File: SampleObject.java From java-technology-stack with MIT License | 4 votes |
@CacheResult(cacheName = "testSimple") public SampleObject anotherSimpleGet(String foo, Long bar) { return null; }
Example #27
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 4 votes |
@Override @CacheResult(skipGet = true) public Long cacheAlwaysInvoke(String id) { return counter.getAndIncrement(); }
Example #28
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 4 votes |
@Override @CacheResult public Long cacheWithPartialKey(@CacheKey String id, boolean notUsed) { return counter.getAndIncrement(); }
Example #29
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 4 votes |
@Override @CacheResult(cacheResolverFactory = TestableCacheResolverFactory.class) public Long cacheWithCustomCacheResolver(String id) { return counter.getAndIncrement(); }
Example #30
Source File: ComponentResourceProxy.java From component-runtime with Apache License 2.0 | 4 votes |
@GET @Path("details") @CacheResult public CompletionStage<Response> getDetail() { return handler.forward(); }