本文整理汇总了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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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());
}