Java源码示例:org.springframework.cache.interceptor.CacheOperationInvoker

示例1
@Override
protected Object invokeOperation(CacheOperationInvoker invoker) {
	try {
		return super.invokeOperation(invoker);
	}
	catch (CacheOperationInvoker.ThrowableWrapper e) {
		Throwable original = e.getOriginal();
		if (original.getClass() == UnsupportedOperationException.class) {
			return 55L;
		}
		else {
			throw new CacheOperationInvoker.ThrowableWrapper(
					new RuntimeException("wrapping original", original));
		}
	}
}
 
示例2
/**
 * Rewrite the call stack of the specified {@code exception} so that it matches
 * the current call stack up to (included) the specified method invocation.
 * <p>Clone the specified exception. If the exception is not {@code serializable},
 * the original exception is returned. If no common ancestor can be found, returns
 * the original exception.
 * <p>Used to make sure that a cached exception has a valid invocation context.
 * @param exception the exception to merge with the current call stack
 * @param className the class name of the common ancestor
 * @param methodName the method name of the common ancestor
 * @return a clone exception with a rewritten call stack composed of the current call
 * stack up to (included) the common ancestor specified by the {@code className} and
 * {@code methodName} arguments, followed by stack trace elements of the specified
 * {@code exception} after the common ancestor.
 */
private static CacheOperationInvoker.ThrowableWrapper rewriteCallStack(
		Throwable exception, String className, String methodName) {

	Throwable clone = cloneException(exception);
	if (clone == null) {
		return new CacheOperationInvoker.ThrowableWrapper(exception);
	}

	StackTraceElement[] callStack = new Exception().getStackTrace();
	StackTraceElement[] cachedCallStack = exception.getStackTrace();

	int index = findCommonAncestorIndex(callStack, className, methodName);
	int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
	if (index == -1 || cachedIndex == -1) {
		return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
	}
	StackTraceElement[] result = new StackTraceElement[cachedIndex + callStack.length - index];
	System.arraycopy(cachedCallStack, 0, result, 0, cachedIndex);
	System.arraycopy(callStack, index, result, cachedIndex, callStack.length - index);

	clone.setStackTrace(result);
	return new CacheOperationInvoker.ThrowableWrapper(clone);
}
 
示例3
@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;
	}
}
 
示例4
@Override
@Nullable
public Object invoke(final MethodInvocation invocation) throws Throwable {
	Method method = invocation.getMethod();

	CacheOperationInvoker aopAllianceInvoker = () -> {
		try {
			return invocation.proceed();
		}
		catch (Throwable ex) {
			throw new CacheOperationInvoker.ThrowableWrapper(ex);
		}
	};

	try {
		return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
	}
	catch (CacheOperationInvoker.ThrowableWrapper th) {
		throw th.getOriginal();
	}
}
 
示例5
@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;
	}
}
 
示例6
@Override
protected Object invokeOperation(CacheOperationInvoker invoker) {
	try {
		return super.invokeOperation(invoker);
	}
	catch (CacheOperationInvoker.ThrowableWrapper e) {
		Throwable original = e.getOriginal();
		if (original.getClass() == UnsupportedOperationException.class) {
			return 55L;
		}
		else {
			throw new CacheOperationInvoker.ThrowableWrapper(
					new RuntimeException("wrapping original", original));
		}
	}
}
 
示例7
@Override
protected Object invokeOperation(CacheOperationInvoker invoker) {
	try {
		return super.invokeOperation(invoker);
	}
	catch (CacheOperationInvoker.ThrowableWrapper e) {
		Throwable original = e.getOriginal();
		if (original.getClass() == UnsupportedOperationException.class) {
			return 55L;
		}
		else {
			throw new CacheOperationInvoker.ThrowableWrapper(
					new RuntimeException("wrapping original", original));
		}
	}
}
 
示例8
/**
 * Rewrite the call stack of the specified {@code exception} so that it matches
 * the current call stack up to (included) the specified method invocation.
 * <p>Clone the specified exception. If the exception is not {@code serializable},
 * the original exception is returned. If no common ancestor can be found, returns
 * the original exception.
 * <p>Used to make sure that a cached exception has a valid invocation context.
 * @param exception the exception to merge with the current call stack
 * @param className the class name of the common ancestor
 * @param methodName the method name of the common ancestor
 * @return a clone exception with a rewritten call stack composed of the current call
 * stack up to (included) the common ancestor specified by the {@code className} and
 * {@code methodName} arguments, followed by stack trace elements of the specified
 * {@code exception} after the common ancestor.
 */
private static CacheOperationInvoker.ThrowableWrapper rewriteCallStack(
		Throwable exception, String className, String methodName) {

	Throwable clone = cloneException(exception);
	if (clone == null) {
		return new CacheOperationInvoker.ThrowableWrapper(exception);
	}

	StackTraceElement[] callStack = new Exception().getStackTrace();
	StackTraceElement[] cachedCallStack = exception.getStackTrace();

	int index = findCommonAncestorIndex(callStack, className, methodName);
	int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
	if (index == -1 || cachedIndex == -1) {
		return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
	}
	StackTraceElement[] result = new StackTraceElement[cachedIndex + callStack.length - index];
	System.arraycopy(cachedCallStack, 0, result, 0, cachedIndex);
	System.arraycopy(callStack, index, result, cachedIndex, callStack.length - index);

	clone.setStackTrace(result);
	return new CacheOperationInvoker.ThrowableWrapper(clone);
}
 
示例9
@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;
	}
}
 
示例10
@Override
@Nullable
public Object invoke(final MethodInvocation invocation) throws Throwable {
	Method method = invocation.getMethod();

	CacheOperationInvoker aopAllianceInvoker = () -> {
		try {
			return invocation.proceed();
		}
		catch (Throwable ex) {
			throw new CacheOperationInvoker.ThrowableWrapper(ex);
		}
	};

	try {
		return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
	}
	catch (CacheOperationInvoker.ThrowableWrapper th) {
		throw th.getOriginal();
	}
}
 
示例11
@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;
	}
}
 
示例12
@Override
protected Object invokeOperation(CacheOperationInvoker invoker) {
	try {
		return super.invokeOperation(invoker);
	}
	catch (CacheOperationInvoker.ThrowableWrapper e) {
		Throwable original = e.getOriginal();
		if (original.getClass() == UnsupportedOperationException.class) {
			return 55L;
		}
		else {
			throw new CacheOperationInvoker.ThrowableWrapper(
					new RuntimeException("wrapping original", original));
		}
	}
}
 
示例13
@SuppressWarnings("unchecked")
private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) {
	CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
	BasicOperation operation = context.getOperation();

	if (operation instanceof CacheResultOperation) {
		return this.cacheResultInterceptor.invoke(
				(CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
	}
	else if (operation instanceof CachePutOperation) {
		return this.cachePutInterceptor.invoke(
				(CacheOperationInvocationContext<CachePutOperation>) context, adapter);
	}
	else if (operation instanceof CacheRemoveOperation) {
		return this.cacheRemoveEntryInterceptor.invoke(
				(CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
	}
	else if (operation instanceof CacheRemoveAllOperation) {
		return this.cacheRemoveAllInterceptor.invoke(
				(CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
	}
	else {
		throw new IllegalArgumentException("Cannot handle " + operation);
	}
}
 
示例14
/**
 * Rewrite the call stack of the specified {@code exception} so that it matches
 * the current call stack up to (included) the specified method invocation.
 * <p>Clone the specified exception. If the exception is not {@code serializable},
 * the original exception is returned. If no common ancestor can be found, returns
 * the original exception.
 * <p>Used to make sure that a cached exception has a valid invocation context.
 * @param exception the exception to merge with the current call stack
 * @param className the class name of the common ancestor
 * @param methodName the method name of the common ancestor
 * @return a clone exception with a rewritten call stack composed of the current call
 * stack up to (included) the common ancestor specified by the {@code className} and
 * {@code methodName} arguments, followed by stack trace elements of the specified
 * {@code exception} after the common ancestor.
 */
private static CacheOperationInvoker.ThrowableWrapper rewriteCallStack(
		Throwable exception, String className, String methodName) {

	Throwable clone = cloneException(exception);
	if (clone == null) {
		return new CacheOperationInvoker.ThrowableWrapper(exception);
	}

	StackTraceElement[] callStack = new Exception().getStackTrace();
	StackTraceElement[] cachedCallStack = exception.getStackTrace();

	int index = findCommonAncestorIndex(callStack, className, methodName);
	int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
	if (index == -1 || cachedIndex == -1) {
		return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
	}
	StackTraceElement[] result = new StackTraceElement[cachedIndex + callStack.length - index];
	System.arraycopy(cachedCallStack, 0, result, 0, cachedIndex);
	System.arraycopy(callStack, index, result, cachedIndex, callStack.length - index);

	clone.setStackTrace(result);
	return new CacheOperationInvoker.ThrowableWrapper(clone);
}
 
示例15
@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;
	}
}
 
示例16
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
	Method method = invocation.getMethod();

	CacheOperationInvoker aopAllianceInvoker = new CacheOperationInvoker() {
		@Override
		public Object invoke() {
			try {
				return invocation.proceed();
			}
			catch (Throwable ex) {
				throw new ThrowableWrapper(ex);
			}
		}
	};

	try {
		return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
	}
	catch (CacheOperationInvoker.ThrowableWrapper th) {
		throw th.getOriginal();
	}
}
 
示例17
@Override
protected Object invokeOperation(CacheOperationInvoker invoker) {
	try {
		return super.invokeOperation(invoker);
	}
	catch (CacheOperationInvoker.ThrowableWrapper e) {
		Throwable original = e.getOriginal();
		if (original.getClass() == UnsupportedOperationException.class) {
			return 55L;
		}
		else {
			throw new CacheOperationInvoker.ThrowableWrapper(
					new RuntimeException("wrapping original", original));
		}
	}
}
 
示例18
@SuppressWarnings("unchecked")
private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) {
	CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
	BasicOperation operation = context.getOperation();

	if (operation instanceof CacheResultOperation) {
		return cacheResultInterceptor.invoke(
				(CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
	}
	else if (operation instanceof CachePutOperation) {
		return cachePutInterceptor.invoke(
				(CacheOperationInvocationContext<CachePutOperation>) context, adapter);
	}
	else if (operation instanceof CacheRemoveOperation) {
		return cacheRemoveEntryInterceptor.invoke(
				(CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
	}
	else if (operation instanceof CacheRemoveAllOperation) {
		return cacheRemoveAllInterceptor.invoke(
				(CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
	}
	else {
		throw new IllegalArgumentException("Could not handle " + operation);
	}
}
 
示例19
/**
 * Rewrite the call stack of the specified {@code exception} so that it matches
 * the current call stack up-to (included) the specified method invocation.
 * <p>Clone the specified exception. If the exception is not {@code serializable},
 * the original exception is returned. If no common ancestor can be found, returns
 * the original exception.
 * <p>Used to make sure that a cached exception has a valid invocation context.
 * @param exception the exception to merge with the current call stack
 * @param className the class name of the common ancestor
 * @param methodName the method name of the common ancestor
 * @return a clone exception with a rewritten call stack composed of the current
 * call stack up to (included) the common ancestor specified by the {@code className} and
 * {@code methodName} arguments, followed by stack trace elements of the specified
 * {@code exception} after the common ancestor.
 */
private static CacheOperationInvoker.ThrowableWrapper rewriteCallStack(
		Throwable exception, String className, String methodName) {

	Throwable clone = cloneException(exception);
	if (clone == null) {
		return new CacheOperationInvoker.ThrowableWrapper(exception);
	}

	StackTraceElement[] callStack = new Exception().getStackTrace();
	StackTraceElement[] cachedCallStack = exception.getStackTrace();

	int index = findCommonAncestorIndex(callStack, className, methodName);
	int cachedIndex = findCommonAncestorIndex(cachedCallStack, className, methodName);
	if (index == -1 || cachedIndex == -1) {
		return new CacheOperationInvoker.ThrowableWrapper(exception); // Cannot find common ancestor
	}
	StackTraceElement[] result = new StackTraceElement[cachedIndex + callStack.length - index];
	System.arraycopy(cachedCallStack, 0, result, 0, cachedIndex);
	System.arraycopy(callStack, index, result, cachedIndex, callStack.length - index);

	clone.setStackTrace(result);
	return new CacheOperationInvoker.ThrowableWrapper(clone);
}
 
示例20
@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;
	}
}
 
示例21
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
	Method method = invocation.getMethod();

	CacheOperationInvoker aopAllianceInvoker = new CacheOperationInvoker() {
		@Override
		public Object invoke() {
			try {
				return invocation.proceed();
			}
			catch (Throwable ex) {
				throw new ThrowableWrapper(ex);
			}
		}
	};

	try {
		return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
	}
	catch (CacheOperationInvoker.ThrowableWrapper th) {
		throw th.getOriginal();
	}
}
 
示例22
@Override
protected Object invokeOperation(CacheOperationInvoker invoker) {
	try {
		return super.invokeOperation(invoker);
	}
	catch (CacheOperationInvoker.ThrowableWrapper e) {
		Throwable original = e.getOriginal();
		if (original.getClass() == UnsupportedOperationException.class) {
			return 55L;
		}
		else {
			throw new CacheOperationInvoker.ThrowableWrapper(
					new RuntimeException("wrapping original", original));
		}
	}
}
 
示例23
@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();
}
 
示例24
@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);
	}
}
 
示例25
@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;
	}
}
 
示例26
@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;
	}
}
 
示例27
@Test
public void cacheResultReturnsProperType() throws Throwable {
	JCacheInterceptor interceptor = createInterceptor(createOperationSource(
			cacheManager, defaultCacheResolver, defaultExceptionCacheResolver, defaultKeyGenerator));

	AnnotatedJCacheableService service = new AnnotatedJCacheableService(cacheManager.getCache("default"));
	Method method = ReflectionUtils.findMethod(AnnotatedJCacheableService.class, "cache", String.class);

	CacheOperationInvoker invoker = new DummyInvoker(0L);
	Object execute = interceptor.execute(invoker, service, method, new Object[] {"myId"});
	assertNotNull("result cannot be null.", execute);
	assertEquals("Wrong result type", Long.class, execute.getClass());
	assertEquals("Wrong result", 0L, execute);
}
 
示例28
@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();
}
 
示例29
@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);
	}
}
 
示例30
@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;
	}
}