javax.cache.annotation.CacheInvocationParameter Java Examples
The following examples show how to use
javax.cache.annotation.CacheInvocationParameter.
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 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 #3
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void simpleGet() { CacheResultOperation operation = createSimpleOperation(); assertNotNull(operation.getKeyGenerator()); assertNotNull(operation.getExceptionCacheResolver()); assertNull(operation.getExceptionCacheName()); assertEquals(defaultExceptionCacheResolver, operation.getExceptionCacheResolver()); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L); assertEquals(1, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(2L); assertEquals(1, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 2L, 0); }
Example #4
Source File: CacheResultOperationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void simpleGet() { CacheResultOperation operation = createSimpleOperation(); assertNotNull(operation.getKeyGenerator()); assertNotNull(operation.getExceptionCacheResolver()); assertNull(operation.getExceptionCacheName()); assertEquals(defaultExceptionCacheResolver, operation.getExceptionCacheResolver()); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L); assertEquals(1, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(2L); assertEquals(1, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 2L, 0); }
Example #5
Source File: CacheResultOperationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void simpleGet() { CacheResultOperation operation = createSimpleOperation(); assertNotNull(operation.getKeyGenerator()); assertNotNull(operation.getExceptionCacheResolver()); assertNull(operation.getExceptionCacheName()); assertEquals(defaultExceptionCacheResolver, operation.getExceptionCacheResolver()); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L); assertEquals(1, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(2L); assertEquals(1, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 2L, 0); }
Example #6
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void annotatedGet() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "annotatedGet", Long.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo"); Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations(); assertEquals(1, firstParameterAnnotations.size()); assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType()); Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations(); assertEquals(1, secondParameterAnnotations.size()); assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType()); }
Example #7
Source File: AbstractJCacheOperation.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public CacheInvocationParameter[] getAllParameters(Object... values) { if (this.allParameterDetails.size() != values.length) { throw new IllegalStateException("Values mismatch, operation has " + this.allParameterDetails.size() + " parameter(s) but got " + values.length + " value(s)"); } List<CacheInvocationParameter> result = new ArrayList<CacheInvocationParameter>(); for (int i = 0; i < this.allParameterDetails.size(); i++) { result.add(this.allParameterDetails.get(i).toCacheInvocationParameter(values[i])); } return result.toArray(new CacheInvocationParameter[result.size()]); }
Example #8
Source File: AbstractJCacheKeyOperation.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return the {@link CacheInvocationParameter} for the parameters that are to be * used to compute the key. * <p>Per the spec, if some method parameters are annotated with * {@link javax.cache.annotation.CacheKey}, only those parameters should be part * of the key. If none are annotated, all parameters except the parameter annotated * with {@link javax.cache.annotation.CacheValue} should be part of the key. * <p>The method arguments must match the signature of the related method invocation * @param values the parameters value for a particular invocation * @return the {@link CacheInvocationParameter} instances for the parameters to be * used to compute the key */ public CacheInvocationParameter[] getKeyParameters(Object... values) { List<CacheInvocationParameter> result = new ArrayList<CacheInvocationParameter>(); for (CacheParameterDetail keyParameterDetail : this.keyParameterDetails) { int parameterPosition = keyParameterDetail.getParameterPosition(); if (parameterPosition >= values.length) { throw new IllegalStateException("Values mismatch, key parameter at position " + parameterPosition + " cannot be matched against " + values.length + " value(s)"); } result.add(keyParameterDetail.toCacheInvocationParameter(values[parameterPosition])); } return result.toArray(new CacheInvocationParameter[result.size()]); }
Example #9
Source File: CachePutOperation.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return the {@link CacheInvocationParameter} for the parameter holding the value * to cache. * <p>The method arguments must match the signature of the related method invocation * @param values the parameters value for a particular invocation * @return the {@link CacheInvocationParameter} instance for the value parameter */ public CacheInvocationParameter getValueParameter(Object... values) { int parameterPosition = this.valueParameterDetail.getParameterPosition(); if (parameterPosition >= values.length) { throw new IllegalStateException("Values mismatch, value parameter at position " + parameterPosition + " cannot be matched against " + values.length + " value(s)"); } return this.valueParameterDetail.toCacheInvocationParameter(values[parameterPosition]); }
Example #10
Source File: CacheRemoveOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void simpleRemove() { CacheRemoveOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L); assertEquals(1, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); }
Example #11
Source File: CachePutOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void simplePut() { CachePutOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L, sampleInstance); assertEquals(2, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); assertCacheInvocationParameter(allParameters[1], SampleObject.class, sampleInstance, 1); CacheInvocationParameter valueParameter = operation.getValueParameter(2L, sampleInstance); assertNotNull(valueParameter); assertCacheInvocationParameter(valueParameter, SampleObject.class, sampleInstance, 1); }
Example #12
Source File: CacheResultOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void multiParameterKey() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "multiKeysGet", Long.class, Boolean.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(3L, Boolean.TRUE, "Foo"); assertEquals(2, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 3L, 0); assertCacheInvocationParameter(keyParameters[1], String.class, "Foo", 2); }
Example #13
Source File: CachePutOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void simplePut() { CachePutOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L, sampleInstance); assertEquals(2, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); assertCacheInvocationParameter(allParameters[1], SampleObject.class, sampleInstance, 1); CacheInvocationParameter valueParameter = operation.getValueParameter(2L, sampleInstance); assertNotNull(valueParameter); assertCacheInvocationParameter(valueParameter, SampleObject.class, sampleInstance, 1); }
Example #14
Source File: CacheRemoveAllOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void simpleRemoveAll() { CacheRemoveAllOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(); assertEquals(0, allParameters.length); }
Example #15
Source File: CacheResultOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void multiParameterKey() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "multiKeysGet", Long.class, Boolean.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(3L, Boolean.TRUE, "Foo"); assertEquals(2, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 3L, 0); assertCacheInvocationParameter(keyParameters[1], String.class, "Foo", 2); }
Example #16
Source File: CacheResultOperationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void annotatedGet() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "annotatedGet", Long.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo"); Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations(); assertEquals(1, firstParameterAnnotations.size()); assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType()); Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations(); assertEquals(1, secondParameterAnnotations.size()); assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType()); }
Example #17
Source File: CacheRemoveAllOperationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void simpleRemoveAll() { CacheRemoveAllOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(); assertEquals(0, allParameters.length); }
Example #18
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 #19
Source File: CachePutOperation.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return the {@link CacheInvocationParameter} for the parameter holding the value * to cache. * <p>The method arguments must match the signature of the related method invocation * @param values the parameters value for a particular invocation * @return the {@link CacheInvocationParameter} instance for the value parameter */ public CacheInvocationParameter getValueParameter(Object... values) { int parameterPosition = this.valueParameterDetail.getParameterPosition(); if (parameterPosition >= values.length) { throw new IllegalStateException("Values mismatch, value parameter at position " + parameterPosition + " cannot be matched against " + values.length + " value(s)"); } return this.valueParameterDetail.toCacheInvocationParameter(values[parameterPosition]); }
Example #20
Source File: AbstractJCacheKeyOperation.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return the {@link CacheInvocationParameter} for the parameters that are to be * used to compute the key. * <p>Per the spec, if some method parameters are annotated with * {@link javax.cache.annotation.CacheKey}, only those parameters should be part * of the key. If none are annotated, all parameters except the parameter annotated * with {@link javax.cache.annotation.CacheValue} should be part of the key. * <p>The method arguments must match the signature of the related method invocation * @param values the parameters value for a particular invocation * @return the {@link CacheInvocationParameter} instances for the parameters to be * used to compute the key */ public CacheInvocationParameter[] getKeyParameters(Object... values) { List<CacheInvocationParameter> result = new ArrayList<CacheInvocationParameter>(); for (CacheParameterDetail keyParameterDetail : this.keyParameterDetails) { int parameterPosition = keyParameterDetail.getParameterPosition(); if (parameterPosition >= values.length) { throw new IllegalStateException("Values mismatch, key parameter at position " + parameterPosition + " cannot be matched against " + values.length + " value(s)"); } result.add(keyParameterDetail.toCacheInvocationParameter(values[parameterPosition])); } return result.toArray(new CacheInvocationParameter[result.size()]); }
Example #21
Source File: AbstractJCacheOperation.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public CacheInvocationParameter[] getAllParameters(Object... values) { if (this.allParameterDetails.size() != values.length) { throw new IllegalStateException("Values mismatch, operation has " + this.allParameterDetails.size() + " parameter(s) but got " + values.length + " value(s)"); } List<CacheInvocationParameter> result = new ArrayList<CacheInvocationParameter>(); for (int i = 0; i < this.allParameterDetails.size(); i++) { result.add(this.allParameterDetails.get(i).toCacheInvocationParameter(values[i])); } return result.toArray(new CacheInvocationParameter[result.size()]); }
Example #22
Source File: CachePutOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void simplePut() { CachePutOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L, sampleInstance); assertEquals(2, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); assertCacheInvocationParameter(allParameters[1], SampleObject.class, sampleInstance, 1); CacheInvocationParameter valueParameter = operation.getValueParameter(2L, sampleInstance); assertNotNull(valueParameter); assertCacheInvocationParameter(valueParameter, SampleObject.class, sampleInstance, 1); }
Example #23
Source File: CacheResultOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void multiParameterKey() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "multiKeysGet", Long.class, Boolean.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] keyParameters = operation.getKeyParameters(3L, Boolean.TRUE, "Foo"); assertEquals(2, keyParameters.length); assertCacheInvocationParameter(keyParameters[0], Long.class, 3L, 0); assertCacheInvocationParameter(keyParameters[1], String.class, "Foo", 2); }
Example #24
Source File: CacheResultOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void annotatedGet() { CacheMethodDetails<CacheResult> methodDetails = create(CacheResult.class, SampleObject.class, "annotatedGet", Long.class, String.class); CacheResultOperation operation = createDefaultOperation(methodDetails); CacheInvocationParameter[] parameters = operation.getAllParameters(2L, "foo"); Set<Annotation> firstParameterAnnotations = parameters[0].getAnnotations(); assertEquals(1, firstParameterAnnotations.size()); assertEquals(CacheKey.class, firstParameterAnnotations.iterator().next().annotationType()); Set<Annotation> secondParameterAnnotations = parameters[1].getAnnotations(); assertEquals(1, secondParameterAnnotations.size()); assertEquals(Value.class, secondParameterAnnotations.iterator().next().annotationType()); }
Example #25
Source File: CacheRemoveOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void simpleRemove() { CacheRemoveOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(2L); assertEquals(1, allParameters.length); assertCacheInvocationParameter(allParameters[0], Long.class, 2L, 0); }
Example #26
Source File: CacheRemoveAllOperationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void simpleRemoveAll() { CacheRemoveAllOperation operation = createSimpleOperation(); CacheInvocationParameter[] allParameters = operation.getAllParameters(); assertEquals(0, allParameters.length); }
Example #27
Source File: CacheInvocationContextImpl.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public CacheInvocationParameter[] getAllParameters() { if (parameters == null) { parameters = doGetAllParameters(null); } return parameters; }
Example #28
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 #29
Source File: CacheKeyInvocationContextImpl.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public CacheInvocationParameter[] getKeyParameters() { if (keyParams == null) { keyParams = doGetAllParameters(meta.getKeysIndices()); } return keyParams; }
Example #30
Source File: CacheKeyInvocationContextImpl.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public CacheInvocationParameter getValueParameter() { if (valueParam == null) { valueParam = meta.getValueIndex() >= 0 ? doGetAllParameters(new Integer[]{meta.getValueIndex()})[0] : null; } return valueParam; }