@Override protected CacheRemoveOperation createSimpleOperation() { CacheMethodDetails<CacheRemove> methodDetails = create(CacheRemove.class, SampleObject.class, "simpleRemove", Long.class); return new CacheRemoveOperation(methodDetails, defaultCacheResolver, defaultKeyGenerator); }
public CacheRemoveOperation( CacheMethodDetails<CacheRemove> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CacheRemove ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.evictFor(), ann.noEvictFor()); }
/** * Specify if the cache entry should be remove before invoking the method. By default, the * cache entry is removed after the method invocation. * @see javax.cache.annotation.CacheRemove#afterInvocation() */ public boolean isEarlyRemove() { return !getCacheAnnotation().afterInvocation(); }
@Override protected Object invoke( CacheOperationInvocationContext<CacheRemoveOperation> context, CacheOperationInvoker invoker) { CacheRemoveOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeValue(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeValue(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper wrapperException) { Throwable ex = wrapperException.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(ex.getClass())) { removeValue(context); } throw wrapperException; } }
@Test public void simpleRemove() { CacheRemoveOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L); assertEquals(1, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); }
@Override protected Object invoke( CacheOperationInvocationContext<CacheRemoveOperation> context, CacheOperationInvoker invoker) { CacheRemoveOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeValue(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeValue(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper wrapperException) { Throwable ex = wrapperException.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(ex.getClass())) { removeValue(context); } throw wrapperException; } }
@Override protected Object invoke(CacheOperationInvocationContext<CacheRemoveOperation> context, CacheOperationInvoker invoker) { CacheRemoveOperation operation = context.getOperation(); final boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeValue(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeValue(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper t) { Throwable ex = t.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(ex.getClass())) { removeValue(context); } throw t; } }
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); }
/** * Specify if the cache entry should be remove before invoking the method. By default, the * cache entry is removed after the method invocation. * @see javax.cache.annotation.CacheRemove#afterInvocation() */ public boolean isEarlyRemove() { return !getCacheAnnotation().afterInvocation(); }
public CacheRemoveOperation( CacheMethodDetails<CacheRemove> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CacheRemove ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.evictFor(), ann.noEvictFor()); }
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); }
/** * Specify if the cache entry should be remove before invoking the method. By default, the * cache entry is removed after the method invocation. * @see javax.cache.annotation.CacheRemove#afterInvocation() */ public boolean isEarlyRemove() { return !getCacheAnnotation().afterInvocation(); }
public CacheRemoveOperation( CacheMethodDetails<CacheRemove> methodDetails, CacheResolver cacheResolver, KeyGenerator keyGenerator) { super(methodDetails, cacheResolver, keyGenerator); CacheRemove ann = methodDetails.getCacheAnnotation(); this.exceptionTypeFilter = createExceptionTypeFilter(ann.evictFor(), ann.noEvictFor()); }
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); }