javax.cache.annotation.CachePut Java Examples
The following examples show how to use
javax.cache.annotation.CachePut.
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: CachePutOperation.java From spring-analysis-note with MIT License | 6 votes |
public CachePutOperation( CacheMethodDetails<CachePut> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CachePut ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.cacheFor(), ann.noCacheFor()); CacheParameterDetail valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), this.allParameterDetails); if (valueParameterDetail == null) { throw new IllegalArgumentException("No parameter annotated with @CacheValue was found for " + methodDetails.getMethod()); } this.valueParameterDetail = valueParameterDetail; }
Example #2
Source File: CachePutOperation.java From java-technology-stack with MIT License | 6 votes |
public CachePutOperation( CacheMethodDetails<CachePut> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CachePut ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.cacheFor(), ann.noCacheFor()); CacheParameterDetail valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), this.allParameterDetails); if (valueParameterDetail == null) { throw new IllegalArgumentException("No parameter annotated with @CacheValue was found for " + methodDetails.getMethod()); } this.valueParameterDetail = valueParameterDetail; }
Example #3
Source File: CachePutOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void noCacheValue() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "noCacheValue", Long.class); thrown.expect(IllegalArgumentException.class); createDefaultOperation(methodDetails); }
Example #4
Source File: AnnotatedJCacheableService.java From spring-analysis-note with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #5
Source File: AnnotationJCacheOperationSource.java From spring-analysis-note 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 #6
Source File: CachePutInterceptor.java From spring-analysis-note with MIT License | 5 votes |
@Override protected Object invoke( CacheOperationInvocationContext<CachePutOperation> context, CacheOperationInvoker invoker) { CachePutOperation operation = context.getOperation(); CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context); boolean earlyPut = operation.isEarlyPut(); Object value = invocationContext.getValueParameter().getValue(); if (earlyPut) { cacheValue(context, value); } try { Object result = invoker.invoke(); if (!earlyPut) { cacheValue(context, value); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) { cacheValue(context, value); } throw ex; } }
Example #7
Source File: AnnotationJCacheOperationSource.java From spring-analysis-note with MIT License | 5 votes |
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: CachePutOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void noCacheValue() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "noCacheValue", Long.class); assertThatIllegalArgumentException().isThrownBy(() -> createDefaultOperation(methodDetails)); }
Example #9
Source File: CachePutOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void multiCacheValues() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "multiCacheValues", Long.class, SampleObject.class, SampleObject.class); assertThatIllegalArgumentException().isThrownBy(() -> createDefaultOperation(methodDetails)); }
Example #10
Source File: CachePutOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void fullPutConfig() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "fullPutConfig", Long.class, SampleObject.class); CachePutOperation operation = createDefaultOperation(methodDetails); assertTrue(operation.isEarlyPut()); assertNotNull(operation.getExceptionTypeFilter()); assertTrue(operation.getExceptionTypeFilter().match(IOException.class)); assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class)); }
Example #11
Source File: AnnotatedJCacheableService.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #12
Source File: JpaConferenceRepositoryImpl.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override @CachePut(cacheName = "conference" ) public Conference save(final Conference conference) { if (conference.isNew()) { entityManager.persist(conference); entityManager.flush(); return conference; } else { Conference conf = entityManager.merge(conference); entityManager.flush(); return conf; } }
Example #13
Source File: CachePutInterceptor.java From java-technology-stack with MIT License | 5 votes |
@Override protected Object invoke( CacheOperationInvocationContext<CachePutOperation> context, CacheOperationInvoker invoker) { CachePutOperation operation = context.getOperation(); CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context); boolean earlyPut = operation.isEarlyPut(); Object value = invocationContext.getValueParameter().getValue(); if (earlyPut) { cacheValue(context, value); } try { Object result = invoker.invoke(); if (!earlyPut) { cacheValue(context, value); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) { cacheValue(context, value); } throw ex; } }
Example #14
Source File: AnnotationJCacheOperationSource.java From java-technology-stack with MIT License | 5 votes |
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 #15
Source File: CachePutOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void fullPutConfig() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "fullPutConfig", Long.class, SampleObject.class); CachePutOperation operation = createDefaultOperation(methodDetails); assertTrue(operation.isEarlyPut()); assertNotNull(operation.getExceptionTypeFilter()); assertTrue(operation.getExceptionTypeFilter().match(IOException.class)); assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class)); }
Example #16
Source File: CachePutOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void multiCacheValues() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "multiCacheValues", Long.class, SampleObject.class, SampleObject.class); thrown.expect(IllegalArgumentException.class); createDefaultOperation(methodDetails); }
Example #17
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 #18
Source File: CachePutOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void noCacheValue() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "noCacheValue", Long.class); thrown.expect(IllegalArgumentException.class); createDefaultOperation(methodDetails); }
Example #19
Source File: CachePutOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void multiCacheValues() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "multiCacheValues", Long.class, SampleObject.class, SampleObject.class); thrown.expect(IllegalArgumentException.class); createDefaultOperation(methodDetails); }
Example #20
Source File: CachePutOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void fullPutConfig() { CacheMethodDetails<CachePut> methodDetails = create(CachePut.class, SampleObject.class, "fullPutConfig", Long.class, SampleObject.class); CachePutOperation operation = createDefaultOperation(methodDetails); assertTrue(operation.isEarlyPut()); assertNotNull(operation.getExceptionTypeFilter()); assertTrue(operation.getExceptionTypeFilter().match(IOException.class)); assertFalse(operation.getExceptionTypeFilter().match(NullPointerException.class)); }
Example #21
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #22
Source File: AnnotationJCacheOperationSource.java From spring4-understanding with Apache License 2.0 | 5 votes |
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 #23
Source File: AnnotationJCacheOperationSource.java From spring4-understanding with Apache License 2.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: CachePutInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected Object invoke(CacheOperationInvocationContext<CachePutOperation> context, CacheOperationInvoker invoker) { CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context); CachePutOperation operation = context.getOperation(); boolean earlyPut = operation.isEarlyPut(); Object value = invocationContext.getValueParameter().getValue(); if (earlyPut) { cacheValue(context, value); } try { Object result = invoker.invoke(); if (!earlyPut) { cacheValue(context, value); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) { cacheValue(context, value); } throw ex; } }
Example #25
Source File: AnnotatedJCacheableService.java From java-technology-stack with MIT License | 5 votes |
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
Example #26
Source File: CachePutOperation.java From spring4-understanding with Apache License 2.0 | 5 votes |
public CachePutOperation( CacheMethodDetails<CachePut> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CachePut ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.cacheFor(), ann.noCacheFor()); this.valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), this.allParameterDetails); if (this.valueParameterDetail == null) { throw new IllegalArgumentException("No parameter annotated with @CacheValue was found for " + "" + methodDetails.getMethod()); } }
Example #27
Source File: CachePutOperation.java From lams with GNU General Public License v2.0 | 5 votes |
public CachePutOperation( CacheMethodDetails<CachePut> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CachePut ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.cacheFor(), ann.noCacheFor()); this.valueParameterDetail = initializeValueParameterDetail(methodDetails.getMethod(), this.allParameterDetails); if (this.valueParameterDetail == null) { throw new IllegalArgumentException("No parameter annotated with @CacheValue was found for " + "" + methodDetails.getMethod()); } }
Example #28
Source File: CachePutInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected Object invoke(CacheOperationInvocationContext<CachePutOperation> context, CacheOperationInvoker invoker) { CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context); CachePutOperation operation = context.getOperation(); boolean earlyPut = operation.isEarlyPut(); Object value = invocationContext.getValueParameter().getValue(); if (earlyPut) { cacheValue(context, value); } try { Object result = invoker.invoke(); if (!earlyPut) { cacheValue(context, value); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) { cacheValue(context, value); } throw ex; } }
Example #29
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 #30
Source File: AnnotationJCacheOperationSource.java From lams with GNU General Public License v2.0 | 5 votes |
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); }