javax.cache.annotation.CacheKeyInvocationContext Java Examples
The following examples show how to use
javax.cache.annotation.CacheKeyInvocationContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyGeneratorAdapter.java From spring4-understanding with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { List<Object> parameters = new ArrayList<Object>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && context.getMethod().isVarArgs()) { parameters.addAll((List<Object>) CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray(new Object[parameters.size()])); }
Example #2
Source File: KeyGeneratorAdapter.java From java-technology-stack with MIT License | 6 votes |
@Override public Object generate(Object target, Method method, Object... params) { JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(AbstractJCacheKeyOperation.class.isInstance(operation))) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); } CacheKeyInvocationContext<?> invocationContext = createCacheKeyInvocationContext(target, operation, params); if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator.generateCacheKey(invocationContext); } else { Assert.state(this.keyGenerator != null, "No key generator"); return doGenerate(this.keyGenerator, invocationContext); } }
Example #3
Source File: KeyGeneratorAdapter.java From lams with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { List<Object> parameters = new ArrayList<Object>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && context.getMethod().isVarArgs()) { parameters.addAll((List<Object>) CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray(new Object[parameters.size()])); }
Example #4
Source File: KeyGeneratorAdapter.java From spring-analysis-note with MIT License | 6 votes |
@Override public Object generate(Object target, Method method, Object... params) { JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(AbstractJCacheKeyOperation.class.isInstance(operation))) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); } CacheKeyInvocationContext<?> invocationContext = createCacheKeyInvocationContext(target, operation, params); if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator.generateCacheKey(invocationContext); } else { Assert.state(this.keyGenerator != null, "No key generator"); return doGenerate(this.keyGenerator, invocationContext); } }
Example #5
Source File: KeyGeneratorAdapter.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Object generate(Object target, Method method, Object... params) { JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(AbstractJCacheKeyOperation.class.isInstance(operation))) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); } CacheKeyInvocationContext<?> invocationContext = createCacheKeyInvocationContext(target, operation, params); if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator.generateCacheKey(invocationContext); } else { return doGenerate(this.keyGenerator, invocationContext); } }
Example #6
Source File: CacheKeyGeneratorImpl.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public GeneratedCacheKey generateCacheKey(final CacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext) { final CacheInvocationParameter[] keyParameters = cacheKeyInvocationContext.getKeyParameters(); final Object[] parameters = new Object[keyParameters.length]; for (int index = 0; index < keyParameters.length; index++) { parameters[index] = keyParameters[index].getValue(); } return new GeneratedCacheKeyImpl(parameters); }
Example #7
Source File: CachePutInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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; } }
Example #8
Source File: KeyGeneratorAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Object generate(Object target, Method method, Object... params) { JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(AbstractJCacheKeyOperation.class.isInstance(operation))) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); } CacheKeyInvocationContext<?> invocationContext = createCacheKeyInvocationContext(target, operation, params); if (this.cacheKeyGenerator != null) { return this.cacheKeyGenerator.generateCacheKey(invocationContext); } else { return doGenerate(this.keyGenerator, invocationContext); } }
Example #9
Source File: VaultProxyCacheKeyGenerator.java From component-runtime with Apache License 2.0 | 5 votes |
@Override public GeneratedCacheKey generateCacheKey(final CacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext) { return new GeneratedCacheKeyImpl(Stream .concat(Stream.of(cacheKeyInvocationContext.getKeyParameters()).map(CacheInvocationParameter::getValue), getContextualKeys()) .toArray(Object[]::new)); }
Example #10
Source File: CachePutInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
@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; } }
Example #11
Source File: CachePutInterceptor.java From java-technology-stack with MIT License | 5 votes |
@Override protected Object invoke( CacheOperationInvocationContext<CachePutOperation> context, CacheOperationInvoker invoker) { CachePutOperation operation = context.getOperation(); CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context); 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; } }
Example #12
Source File: KeyGeneratorAdapter.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("unchecked") private CacheKeyInvocationContext<?> createCacheKeyInvocationContext( Object target, JCacheOperation<?> operation, Object[] params) { AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation; return new DefaultCacheKeyInvocationContext<>(keyCacheOperation, target, params); }
Example #13
Source File: KeyGeneratorAdapter.java From java-technology-stack with MIT License | 5 votes |
@SuppressWarnings("unchecked") private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { List<Object> parameters = new ArrayList<>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && context.getMethod().isVarArgs()) { parameters.addAll((List<Object>) CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray()); }
Example #14
Source File: CachePutInterceptor.java From spring-analysis-note with MIT License | 5 votes |
@Override protected Object invoke( CacheOperationInvocationContext<CachePutOperation> context, CacheOperationInvoker invoker) { CachePutOperation operation = context.getOperation(); CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context); 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; } }
Example #15
Source File: KeyGeneratorAdapter.java From spring-analysis-note with MIT License | 5 votes |
@SuppressWarnings("unchecked") private CacheKeyInvocationContext<?> createCacheKeyInvocationContext( Object target, JCacheOperation<?> operation, Object[] params) { AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation; return new DefaultCacheKeyInvocationContext<>(keyCacheOperation, target, params); }
Example #16
Source File: KeyGeneratorAdapter.java From spring-analysis-note with MIT License | 5 votes |
@SuppressWarnings("unchecked") private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { List<Object> parameters = new ArrayList<>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && context.getMethod().isVarArgs()) { parameters.addAll((List<Object>) CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray()); }
Example #17
Source File: TestableCacheKeyGenerator.java From java-technology-stack with MIT License | 4 votes |
@Override public GeneratedCacheKey generateCacheKey(CacheKeyInvocationContext<? extends Annotation> context) { return new SimpleGeneratedCacheKey(context.getKeyParameters()[0]); }
Example #18
Source File: KeyGeneratorAdapter.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") private CacheKeyInvocationContext<?> createCacheKeyInvocationContext(Object target, JCacheOperation<?> operation, Object[] params) { AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation; return new DefaultCacheKeyInvocationContext<Annotation>(keyCacheOperation, target, params); }
Example #19
Source File: TestableCacheKeyGenerator.java From spring-analysis-note with MIT License | 4 votes |
@Override public GeneratedCacheKey generateCacheKey(CacheKeyInvocationContext<? extends Annotation> context) { return new SimpleGeneratedCacheKey(context.getKeyParameters()[0]); }
Example #20
Source File: KeyGeneratorAdapter.java From spring4-understanding with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private CacheKeyInvocationContext<?> createCacheKeyInvocationContext(Object target, JCacheOperation<?> operation, Object[] params) { AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation; return new DefaultCacheKeyInvocationContext<Annotation>(keyCacheOperation, target, params); }
Example #21
Source File: TestableCacheKeyGenerator.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public GeneratedCacheKey generateCacheKey(CacheKeyInvocationContext<? extends Annotation> context) { return new SimpleGeneratedCacheKey(context.getKeyParameters()[0]); }
Example #22
Source File: AbstractKeyCacheInterceptor.java From java-technology-stack with MIT License | 2 votes |
/** * 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<>(context.getOperation(), context.getTarget(), context.getArgs()); }
Example #23
Source File: AbstractKeyCacheInterceptor.java From lams with GNU General Public License v2.0 | 2 votes |
/** * 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()); }
Example #24
Source File: AbstractKeyCacheInterceptor.java From spring-analysis-note with MIT License | 2 votes |
/** * 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<>(context.getOperation(), context.getTarget(), context.getArgs()); }
Example #25
Source File: AbstractKeyCacheInterceptor.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * 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()); }