Example usage for org.springframework.cache.interceptor CacheOperationInvocationContext getOperation

List of usage examples for org.springframework.cache.interceptor CacheOperationInvocationContext getOperation

Introduction

In this page you can find the example usage for org.springframework.cache.interceptor CacheOperationInvocationContext getOperation.

Prototype

O getOperation();

Source Link

Document

Return the cache operation.

Usage

From source file:com.hp.autonomy.hod.caching.AbstractHodCacheResolver.java

@Override
protected Collection<String> getCacheNames(final CacheOperationInvocationContext<?> context) {
    final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    if (!(authentication instanceof HodAuthentication)) {
        throw new IllegalStateException("There is no HOD authentication token in the security context holder");
    }//w  ww  .j a  v  a2 s  .  c  o m

    final HodAuthenticationPrincipal principal = ((HodAuthentication) authentication).getPrincipal();

    final Set<String> contextCacheNames = context.getOperation().getCacheNames();
    final Collection<String> resolvedCacheNames = new HashSet<>();

    for (final String cacheName : contextCacheNames) {
        resolvedCacheNames.add(resolveName(cacheName, principal));
    }

    return resolvedCacheNames;
}

From source file:org.springframework.cache.interceptor.CacheAspectSupport.java

protected Collection<? extends Cache> getCaches(CacheOperationInvocationContext<CacheOperation> context,
        CacheResolver cacheResolver) {//from w w  w  . jav  a  2  s  .  c om

    Collection<? extends Cache> caches = cacheResolver.resolveCaches(context);
    if (caches.isEmpty()) {
        throw new IllegalStateException(
                "No cache could be resolved for '" + context.getOperation() + "' using resolver '"
                        + cacheResolver + "'. At least one cache should be provided per cache operation.");
    }
    return caches;
}

From source file:org.springframework.cache.jcache.interceptor.AbstractCacheInterceptor.java

/**
 * Resolve the cache to use./*from  w  w w .  jav a  2s.  c  o  m*/
 * @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;
}

From source file:org.springframework.cache.jcache.interceptor.JCacheAspectSupport.java

@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);// w ww.  ja  v a2 s.c om
    } 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);
    }
}