@Test public void testInvoke() throws Exception { final String parentKey = null; expect(mockDao.put(parentKey, 1L, "1")).andReturn(1L).once(); mockDao.delete(parentKey, 1L); expect(mockDao.get(parentKey, 1L)).andReturn(null).times(1); expect(mockDao.put(parentKey, 1L, "1")).andReturn(1L).once(); replay(mockDao); Long id = dao.put(parentKey, 1L, "1"); assertTrue(id.equals(1L)); String value = dao.get(parentKey, 1L); assertTrue("1".equals(value)); dao.delete(parentKey, 1L); value = dao.get(parentKey, 1L); assertTrue(null == value); value = dao.get(parentKey, 1L); assertTrue(null == value); id = dao.put(parentKey, 1L, "1"); assertTrue(id.equals(1L)); value = dao.get(parentKey, 1L); assertTrue("1".equals(value)); }
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemove annotation = method.getAnnotation(CacheRemove.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemove> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator()); final GeneratedCacheKey key = keyGenerator.generateCacheKey(context); if (!annotation.afterInvocation()) { invalidateCache(key, cache); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { invalidateCache(key, cache); } return result; }
CacheRemoveEntityMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemove annotation = method.getAnnotation(CacheRemove.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemove> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator()); final GeneratedCacheKey key = keyGenerator.generateCacheKey(context); if (!annotation.afterInvocation()) { invalidateCache(key, cache); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { invalidateCache(key, cache); } return result; } }
CacheRemoveEntityMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemove annotation = method.getAnnotation(CacheRemove.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemove> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator()); final GeneratedCacheKey key = keyGenerator.generateCacheKey(context); if (!annotation.afterInvocation()) { invalidateCache(key, cache); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { invalidateCache(key, cache); } return result; } @Inject  CacheRemoveEntityMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider); }
CacheRemoveEntityMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemove annotation = method.getAnnotation(CacheRemove.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemove> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator()); final GeneratedCacheKey key = keyGenerator.generateCacheKey(context); if (!annotation.afterInvocation()) { invalidateCache(key, cache); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { invalidateCache(key, cache); } return result; } @Inject  CacheRemoveEntityMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider); @Override Object invoke(MethodInvocation methodInvocation); }
CacheRemoveEntityMethodInterceptor extends AbstractCacheMethodInterceptor { @Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { final Method method = methodInvocation.getMethod(); final CacheRemove annotation = method.getAnnotation(CacheRemove.class); checkNotNull(annotation); final CacheKeyInvocationContext<CacheRemove> context = new GuiceCacheKeyInvocationContext<>(methodInvocation, annotation, annotation.cacheName()); LOGGER.trace("Cache REMOVE {}", context.getMethod().getName()); final Cache<GeneratedCacheKey, Optional<?>> cache = getCache(context, methodInvocation); final CacheKeyGenerator keyGenerator = getCacheKeyGenerator(methodInvocation, annotation.cacheKeyGenerator()); final GeneratedCacheKey key = keyGenerator.generateCacheKey(context); if (!annotation.afterInvocation()) { invalidateCache(key, cache); } final Object result = methodInvocation.proceed(); if (annotation.afterInvocation()) { invalidateCache(key, cache); } return result; } @Inject  CacheRemoveEntityMethodInterceptor(Provider<CacheResolver> cacheResolverProvider, Provider<CacheKeyGenerator> defaultCacheKeyGeneratorProvider); @Override Object invoke(MethodInvocation methodInvocation);  }