当前位置: 首页>>代码示例>>Java>>正文


Java CacheOperationInvocationContext.getOperation方法代码示例

本文整理汇总了Java中org.springframework.cache.interceptor.CacheOperationInvocationContext.getOperation方法的典型用法代码示例。如果您正苦于以下问题:Java CacheOperationInvocationContext.getOperation方法的具体用法?Java CacheOperationInvocationContext.getOperation怎么用?Java CacheOperationInvocationContext.getOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.cache.interceptor.CacheOperationInvocationContext的用法示例。


在下文中一共展示了CacheOperationInvocationContext.getOperation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
@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);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JCacheAspectSupport.java

示例2: invoke

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
@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;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:CacheRemoveEntryInterceptor.java

示例3: resolveCache

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
/**
 * Resolve the cache to use.
 * @param context the invocation context
 * @return the cache to use (never null)
 */
protected Cache resolveCache(CacheOperationInvocationContext<O> context) {
	Collection<? extends Cache> caches = context.getOperation().getCacheResolver().resolveCaches(context);
	Cache cache = extractFrom(caches);
	if (cache == null) {
		throw new IllegalStateException("Cache could not have been resolved for " + context.getOperation());
	}
	return cache;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AbstractCacheInterceptor.java

示例4: invoke

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
@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();
		cache.put(cacheKey, invocationResult);
		return invocationResult;
	}
	catch (CacheOperationInvoker.ThrowableWrapper ex) {
		Throwable original = ex.getOriginal();
		cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original);
		throw ex;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:CacheResultInterceptor.java

示例5: getCacheNames

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
	BasicOperation operation = context.getOperation();
	if (!(operation instanceof CacheResultOperation)) {
		throw new IllegalStateException("Could not extract exception cache name from " + operation);
	}
	CacheResultOperation cacheResultOperation = (CacheResultOperation) operation;
	String exceptionCacheName = cacheResultOperation.getExceptionCacheName();
	if (exceptionCacheName != null) {
		return Collections.singleton(exceptionCacheName);
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:SimpleExceptionCacheResolver.java

示例6: invoke

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
@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;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:CacheRemoveAllInterceptor.java

示例7: invoke

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
@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;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:CachePutInterceptor.java

示例8: createCacheKeyInvocationContext

import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入方法依赖的package包/类
/**
 * Create a {@link CacheKeyInvocationContext} based on the specified invocation.
 * @param context the context of the invocation.
 * @return the related {@code CacheKeyInvocationContext}
 */
protected CacheKeyInvocationContext<A> createCacheKeyInvocationContext(
		CacheOperationInvocationContext<O> context) {
	return new DefaultCacheKeyInvocationContext<A>(context.getOperation(), context.getTarget(), context.getArgs());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:AbstractKeyCacheInterceptor.java


注:本文中的org.springframework.cache.interceptor.CacheOperationInvocationContext.getOperation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。