@Override public Object generate(Object target, Method method, Object... params) { return generateKey(params); }
@Override public Object generate(Object target, Method method, Object... params) { return generateKey(params); }
private Object createKey(Object... params) { return SimpleKeyGenerator.generateKey(params); }
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
@Override @CacheRemove(afterInvocation = false) public void earlyRemove(String id) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper != null) { throw new AssertionError("Value with key " + key + " expected to be already remove from cache"); } }
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
@Override @CachePut(afterInvocation = false) public void earlyPut(String id, @CacheValue Object value) { Object key = SimpleKeyGenerator.generateKey(id); Cache.ValueWrapper valueWrapper = defaultCache.get(key); if (valueWrapper == null) { throw new AssertionError("Excepted value to be put in cache with key " + key); } Object actual = valueWrapper.get(); if (value != actual) { // instance check on purpose throw new AssertionError("Wrong value set in cache with key " + key + ". " + "Expected=" + value + ", but got=" + actual); } }
@Test public void evictFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).evict(key); this.simpleService.evict(0L); verify(this.errorHandler).handleCacheEvictError(exception, this.cache, key); }
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).get(key); this.simpleService.get(0L); verify(this.errorHandler).handleCacheGetError(exception, this.cache, key); }
@Test public void putFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).put(key, 234L); this.simpleService.put(0L, 234L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 234L); }
@Test public void getFailPutExceptionFail() { UnsupportedOperationException exceptionOnPut = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exceptionOnPut).given(this.errorCache).put(key, SimpleService.TEST_EXCEPTION); try { this.simpleService.getFail(0L); } catch (IllegalStateException ex) { assertEquals("Test exception", ex.getMessage()); } verify(this.errorHandler).handleCachePutError( exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION); }
@Test public void getPutNewElementFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exception).given(this.cache).put(key, 0L); this.simpleService.get(0L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 0L); }
@Override public Object generate(Object target, Method method, Object... params) { return generateKey(params); }
@Override // Exception squid:S923 - override @SuppressWarnings({ "squid:S923" }) public Object generate(final Object target, final Method method, final Object... params) { final String initialTenantCreation = createInitialTenant.get(); if (initialTenantCreation == null) { return SimpleKeyGenerator.generateKey(tenantAware.getCurrentTenant().toUpperCase(), tenantAware.getCurrentTenant().toUpperCase()); } return SimpleKeyGenerator.generateKey(initialTenantCreation.toUpperCase(), initialTenantCreation.toUpperCase()); } }
@Override // Exception squid:S923 - override @SuppressWarnings({ "squid:S923" }) public Object generate(final Object target, final Method method, final Object... params) { final String initialTenantCreation = createInitialTenant.get(); if (initialTenantCreation == null) { return SimpleKeyGenerator.generateKey(tenantAware.getCurrentTenant().toUpperCase(), tenantAware.getCurrentTenant().toUpperCase()); } return SimpleKeyGenerator.generateKey(initialTenantCreation.toUpperCase(), initialTenantCreation.toUpperCase()); } }
public static Node getResource(RenderContext renderContext, RequestContextImpl requestContext, String nodeName, Node docNode) throws Exception { Object key = SimpleKeyGenerator.generateKey(TransformerCallback.class.getName(), "getResource", nodeName); Node node = (Node)renderContext.getCallbackCache().get(key); if(node == null) { node = getResourceUncached(renderContext, requestContext, nodeName, docNode); renderContext.getCallbackCache().put(key, node); } return node; }
public static int isAccessible(RequestContextImpl requestcontext, TargetGenerator targetgen, String pagename) throws Exception { Object cacheKey = SimpleKeyGenerator.generateKey(TransformerCallback.class.getName(), "isAccessible", pagename); Integer cachedResult = (Integer)ExtensionFunctionUtils.getCacheValue(cacheKey); if(cachedResult != null) { return cachedResult; } else { int result = isAccessibleNoCache(requestcontext, targetgen, pagename); ExtensionFunctionUtils.setCacheValue(cacheKey, result); return result; } }
public static Node getIncludeInfo(XsltContext context, String path, String module, String search, String tenant, String language, String targetkey, TargetGenerator targetgen) throws Exception { if(NOTARGET.equals(targetkey) && targetgen.getCacheFactory().getExtensionCache() != null) { ConcurrentMap<Object, Object> cache = getExtensionCacheMap(context, targetgen); Object cacheKey = SimpleKeyGenerator.generateKey(IncludeDocumentExtension.class.getName(), "getIncludeInfo", path, module, search, tenant, language); Node cachedResult = (Node)cache.get(cacheKey); if(cachedResult != null) { return cachedResult; } else { Node result = getIncludeInfoNoCache(context, path, module, search, tenant, language); cache.put(cacheKey, result); return result; } } else { return getIncludeInfoNoCache(context, path, module, search, tenant, language); } }
public static final boolean exists(XsltContext context, String path_str, String part, TargetGenerator targetgen, String targetkey, String module, String search, String tenant, String language) throws Exception { if(NOTARGET.equals(targetkey) && targetgen.getCacheFactory().getExtensionCache() != null) { ConcurrentMap<Object, Object> cache = getExtensionCacheMap(context, targetgen); Object cacheKey = SimpleKeyGenerator.generateKey(IncludeDocumentExtension.class.getName(), "exists", path_str, part, module, search, tenant, language); Boolean cachedResult = (Boolean)cache.get(cacheKey); if(cachedResult != null) { return cachedResult; } else { boolean result = existsNoCache(context, path_str, part, targetgen, targetkey, module, search, tenant, language); cache.putIfAbsent(cacheKey, result); return result; } } else { return existsNoCache(context, path_str, part, targetgen, targetkey, module, search, tenant, language); } }
@Override public LocalizationAwareCacheKey generate(Object target, Method method, Object... params) { Object key = SimpleKeyGenerator.generateKey(params); return new LocalizationAwareCacheKey(localizationIdProvider.getId(), params.length == 1 ? new SimpleKey(key) : (Serializable) key); }