/** * Execute the underlying operation (typically in case of cache miss) and return * the result of the invocation. If an exception occurs it will be wrapped in * a {@link CacheOperationInvoker.ThrowableWrapper}: the exception can be handled * or modified but it <em>must</em> be wrapped in a * {@link CacheOperationInvoker.ThrowableWrapper} as well. * @param invoker the invoker handling the operation being cached * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ protected Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); }
/** * Execute the underlying operation (typically in case of cache miss) and return * the result of the invocation. If an exception occurs it will be wrapped in * a {@code ThrowableWrapper}: the exception can be handled or modified but it * <em>must</em> be wrapped in a {@code ThrowableWrapper} as well. * @param invoker the invoker handling the operation being cached * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ protected Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); }
/** * Execute the underlying operation (typically in case of cache miss) and return * the result of the invocation. If an exception occurs it will be wrapped in * a {@link CacheOperationInvoker.ThrowableWrapper}: the exception can be handled * or modified but it <em>must</em> be wrapped in a * {@link CacheOperationInvoker.ThrowableWrapper} as well. * @param invoker the invoker handling the operation being cached * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ protected Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); }
/** * Execute the underlying operation (typically in case of cache miss) and return * the result of the invocation. If an exception occurs it will be wrapped in * a {@code ThrowableWrapper}: the exception can be handled or modified but it * <em>must</em> be wrapped in a {@code ThrowableWrapper} as well. * @param invoker the invoker handling the operation being cached * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ protected Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); }
@Nullable protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { // Check whether aspect is enabled (to cope with cases where the AJ is pulled in automatically) if (this.initialized) { Class<?> targetClass = getTargetClass(target); CacheOperationSource cacheOperationSource = getCacheOperationSource(); if (cacheOperationSource != null) { Collection<CacheOperation> operations = cacheOperationSource.getCacheOperations(method, targetClass); if (!CollectionUtils.isEmpty(operations)) { return execute(invoker, method, new CacheOperationContexts(operations, method, args, target, targetClass)); } } } return invoker.invoke(); }
@Nullable protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { // Check whether aspect is enabled to cope with cases where the AJ is pulled in automatically if (this.initialized) { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target); JCacheOperation<?> operation = getCacheOperationSource().getCacheOperation(method, targetClass); if (operation != null) { CacheOperationInvocationContext<?> context = createCacheOperationInvocationContext(target, args, operation); return execute(context, invoker); } } return invoker.invoke(); }
@Nullable protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { // Check whether aspect is enabled (to cope with cases where the AJ is pulled in automatically) if (this.initialized) { Class<?> targetClass = getTargetClass(target); CacheOperationSource cacheOperationSource = getCacheOperationSource(); if (cacheOperationSource != null) { Collection<CacheOperation> operations = cacheOperationSource.getCacheOperations(method, targetClass); if (!CollectionUtils.isEmpty(operations)) { return execute(invoker, method, new CacheOperationContexts(operations, method, args, target, targetClass)); } } } return invoker.invoke(); }
@Nullable protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { // Check whether aspect is enabled to cope with cases where the AJ is pulled in automatically if (this.initialized) { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target); JCacheOperation<?> operation = getCacheOperationSource().getCacheOperation(method, targetClass); if (operation != null) { CacheOperationInvocationContext<?> context = createCacheOperationInvocationContext(target, args, operation); return execute(context, invoker); } } return invoker.invoke(); }
@Override protected Object invoke( CacheOperationInvocationContext<CacheRemoveAllOperation> context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeAll(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeAll(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(original.getClass())) { removeAll(context); } throw ex; } }
@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<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; } }
@Override @Nullable protected Object invoke( CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); Object cacheKey = generateKey(context); Cache cache = resolveCache(context); Cache exceptionCache = resolveExceptionCache(context); if (!operation.isAlwaysInvoked()) { Cache.ValueWrapper cachedValue = doGet(cache, cacheKey); if (cachedValue != null) { return cachedValue.get(); } checkForCachedException(exceptionCache, cacheKey); } try { Object invocationResult = invoker.invoke(); doPut(cache, cacheKey, invocationResult); return invocationResult; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original); throw ex; } }
@Override protected Object invoke( CacheOperationInvocationContext<CacheRemoveAllOperation> context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeAll(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeAll(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(original.getClass())) { removeAll(context); } throw ex; } }
@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<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; } }
@Override @Nullable protected Object invoke( CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); Object cacheKey = generateKey(context); Cache cache = resolveCache(context); Cache exceptionCache = resolveExceptionCache(context); if (!operation.isAlwaysInvoked()) { Cache.ValueWrapper cachedValue = doGet(cache, cacheKey); if (cachedValue != null) { return cachedValue.get(); } checkForCachedException(exceptionCache, cacheKey); } try { Object invocationResult = invoker.invoke(); doPut(cache, cacheKey, invocationResult); return invocationResult; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original); throw ex; } }
@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; } }
@Override protected Object invoke(CacheOperationInvocationContext<CacheRemoveAllOperation> context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeAll(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeAll(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(original.getClass())) { removeAll(context); } throw ex; } }
@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; } }
@Override protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); Object cacheKey = generateKey(context); Cache cache = resolveCache(context); Cache exceptionCache = resolveExceptionCache(context); if (!operation.isAlwaysInvoked()) { Cache.ValueWrapper cachedValue = doGet(cache, cacheKey); if (cachedValue != null) { return cachedValue.get(); } checkForCachedException(exceptionCache, cacheKey); } try { Object invocationResult = invoker.invoke(); doPut(cache, cacheKey, invocationResult); return invocationResult; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original); throw ex; } }