@SuppressWarnings("unchecked") @Nullable private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) { CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker); BasicOperation operation = context.getOperation(); if (operation instanceof CacheResultOperation) { Assert.state(this.cacheResultInterceptor != null, "No CacheResultInterceptor"); return this.cacheResultInterceptor.invoke( (CacheOperationInvocationContext<CacheResultOperation>) context, adapter); } else if (operation instanceof CachePutOperation) { Assert.state(this.cachePutInterceptor != null, "No CachePutInterceptor"); return this.cachePutInterceptor.invoke( (CacheOperationInvocationContext<CachePutOperation>) context, adapter); } else if (operation instanceof CacheRemoveOperation) { Assert.state(this.cacheRemoveEntryInterceptor != null, "No CacheRemoveEntryInterceptor"); return this.cacheRemoveEntryInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter); } else if (operation instanceof CacheRemoveAllOperation) { Assert.state(this.cacheRemoveAllInterceptor != null, "No CacheRemoveAllInterceptor"); return this.cacheRemoveAllInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter); } else { throw new IllegalArgumentException("Cannot handle " + operation); } }
@SuppressWarnings("unchecked") @Nullable private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) { CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker); BasicOperation operation = context.getOperation(); if (operation instanceof CacheResultOperation) { Assert.state(this.cacheResultInterceptor != null, "No CacheResultInterceptor"); return this.cacheResultInterceptor.invoke( (CacheOperationInvocationContext<CacheResultOperation>) context, adapter); } else if (operation instanceof CachePutOperation) { Assert.state(this.cachePutInterceptor != null, "No CachePutInterceptor"); return this.cachePutInterceptor.invoke( (CacheOperationInvocationContext<CachePutOperation>) context, adapter); } else if (operation instanceof CacheRemoveOperation) { Assert.state(this.cacheRemoveEntryInterceptor != null, "No CacheRemoveEntryInterceptor"); return this.cacheRemoveEntryInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter); } else if (operation instanceof CacheRemoveAllOperation) { Assert.state(this.cacheRemoveAllInterceptor != null, "No CacheRemoveAllInterceptor"); return this.cacheRemoveAllInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter); } else { throw new IllegalArgumentException("Cannot handle " + operation); } }
/** * 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(); }