javax.cache.annotation.CacheKeyGenerator Java Examples

The following examples show how to use javax.cache.annotation.CacheKeyGenerator. 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: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
private CacheKeyGenerator cacheKeyGeneratorFor(final CacheDefaults defaults, final Class<? extends CacheKeyGenerator> cacheKeyGenerator)
{
    if (!CacheKeyGenerator.class.equals(cacheKeyGenerator))
    {
        return instance(cacheKeyGenerator);
    }
    if (defaults != null)
    {
        final Class<? extends CacheKeyGenerator> defaultCacheKeyGenerator = defaults.cacheKeyGenerator();
        if (!CacheKeyGenerator.class.equals(defaultCacheKeyGenerator))
        {
            return instance(defaultCacheKeyGenerator);
        }
    }
    return defaultCacheKeyGenerator;
}
 
Example #2
Source File: AnnotationJCacheOperationSource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(
		@Nullable CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {

	if (candidate != CacheKeyGenerator.class) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #3
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
public MethodMeta(Class<?>[] parameterTypes, List<Set<Annotation>> parameterAnnotations, Set<Annotation>
        annotations, Integer[] keysIndices, Integer valueIndex, Integer[] parameterIndices, String
        cacheResultCacheName, CacheResolverFactory cacheResultResolverFactory, CacheKeyGenerator
        cacheResultKeyGenerator, CacheResult cacheResult, String cachePutCacheName, CacheResolverFactory
        cachePutResolverFactory, CacheKeyGenerator cachePutKeyGenerator, boolean cachePutAfter, CachePut cachePut, String
        cacheRemoveCacheName, CacheResolverFactory cacheRemoveResolverFactory, CacheKeyGenerator
        cacheRemoveKeyGenerator, boolean cacheRemoveAfter, CacheRemove cacheRemove, String cacheRemoveAllCacheName,
                  CacheResolverFactory cacheRemoveAllResolverFactory, boolean
                          cacheRemoveAllAfter, CacheRemoveAll cacheRemoveAll)
{
    this.parameterTypes = parameterTypes;
    this.parameterAnnotations = parameterAnnotations;
    this.annotations = annotations;
    this.keysIndices = keysIndices;
    this.valueIndex = valueIndex;
    this.parameterIndices = parameterIndices;
    this.cacheResultCacheName = cacheResultCacheName;
    this.cacheResultResolverFactory = cacheResultResolverFactory;
    this.cacheResultKeyGenerator = cacheResultKeyGenerator;
    this.cacheResult = cacheResult;
    this.cachePutCacheName = cachePutCacheName;
    this.cachePutResolverFactory = cachePutResolverFactory;
    this.cachePutKeyGenerator = cachePutKeyGenerator;
    this.cachePutAfter = cachePutAfter;
    this.cachePut = cachePut;
    this.cacheRemoveCacheName = cacheRemoveCacheName;
    this.cacheRemoveResolverFactory = cacheRemoveResolverFactory;
    this.cacheRemoveKeyGenerator = cacheRemoveKeyGenerator;
    this.cacheRemoveAfter = cacheRemoveAfter;
    this.cacheRemove = cacheRemove;
    this.cacheRemoveAllCacheName = cacheRemoveAllCacheName;
    this.cacheRemoveAllResolverFactory = cacheRemoveAllResolverFactory;
    this.cacheRemoveAllAfter = cacheRemoveAllAfter;
    this.cacheRemoveAll = cacheRemoveAll;
}
 
Example #4
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
private <T> T instance(final Class<T> type)
{
    final Set<Bean<?>> beans = beanManager.getBeans(type);
    if (beans.isEmpty())
    {
        if (CacheKeyGenerator.class == type) {
            return (T) defaultCacheKeyGenerator;
        }
        if (CacheResolverFactory.class == type) {
            return (T) defaultCacheResolverFactory();
        }
        return null;
    }
    final Bean<?> bean = beanManager.resolve(beans);
    final CreationalContext<?> context = beanManager.createCreationalContext(bean);
    final Class<? extends Annotation> scope = bean.getScope();
    final boolean normalScope = beanManager.isNormalScope(scope);
    try
    {
        final Object reference = beanManager.getReference(bean, bean.getBeanClass(), context);
        if (!normalScope)
        {
            toRelease.add(context);
        }
        return (T) reference;
    }
    finally
    {
        if (normalScope)
        { // TODO: release at the right moment, @PreDestroy? question is: do we assume it is thread safe?
            context.release();
        }
    }
}
 
Example #5
Source File: AnnotationJCacheOperationSource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {
	if (CacheKeyGenerator.class != candidate) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #6
Source File: KeyGeneratorAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}.
 */
public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) {
	Assert.notNull(cacheOperationSource, "cacheOperationSource must not be null.");
	Assert.notNull(target, "KeyGenerator must not be null");
	this.cacheOperationSource = cacheOperationSource;
	this.cacheKeyGenerator = target;
}
 
Example #7
Source File: AnnotationJCacheOperationSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {
	if (CacheKeyGenerator.class != candidate) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #8
Source File: KeyGeneratorAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}.
 */
public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) {
	Assert.notNull(cacheOperationSource, "cacheOperationSource must not be null.");
	Assert.notNull(target, "KeyGenerator must not be null");
	this.cacheOperationSource = cacheOperationSource;
	this.cacheKeyGenerator = target;
}
 
Example #9
Source File: AnnotationJCacheOperationSource.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected KeyGenerator determineKeyGenerator(
		@Nullable CacheDefaults defaults, Class<? extends CacheKeyGenerator> candidate) {

	if (candidate != CacheKeyGenerator.class) {
		return new KeyGeneratorAdapter(this, getBean(candidate));
	}
	else if (defaults != null && CacheKeyGenerator.class != defaults.cacheKeyGenerator()) {
		return new KeyGeneratorAdapter(this, getBean(defaults.cacheKeyGenerator()));
	}
	else {
		return getDefaultKeyGenerator();
	}
}
 
Example #10
Source File: KeyGeneratorAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}.
 */
public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) {
	Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null");
	Assert.notNull(target, "CacheKeyGenerator must not be null");
	this.cacheOperationSource = cacheOperationSource;
	this.cacheKeyGenerator = target;
}
 
Example #11
Source File: KeyGeneratorAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create an instance used to wrap the specified {@link javax.cache.annotation.CacheKeyGenerator}.
 */
public KeyGeneratorAdapter(JCacheOperationSource cacheOperationSource, CacheKeyGenerator target) {
	Assert.notNull(cacheOperationSource, "JCacheOperationSource must not be null");
	Assert.notNull(target, "CacheKeyGenerator must not be null");
	this.cacheOperationSource = cacheOperationSource;
	this.cacheKeyGenerator = target;
}
 
Example #12
Source File: AnnotationCacheOperationSourceTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void assertCacheKeyGenerator(KeyGenerator actual,
		Class<? extends CacheKeyGenerator> expectedTargetType) {
	assertEquals("Wrong cache resolver implementation", KeyGeneratorAdapter.class, actual.getClass());
	KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) actual;
	assertEquals("Wrong target CacheKeyGenerator implementation", expectedTargetType, adapter.getTarget().getClass());
}
 
Example #13
Source File: AnnotationCacheOperationSourceTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void assertCacheKeyGenerator(KeyGenerator actual,
		Class<? extends CacheKeyGenerator> expectedTargetType) {
	assertEquals("Wrong cache resolver implementation", KeyGeneratorAdapter.class, actual.getClass());
	KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) actual;
	assertEquals("Wrong target CacheKeyGenerator implementation", expectedTargetType, adapter.getTarget().getClass());
}
 
Example #14
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
private MethodMeta createMeta(final InvocationContext ic)
{
    final CacheDefaults defaults = findDefaults(ic.getTarget() == null ? null : ic.getTarget()
                                                  .getClass(), ic.getMethod());

    final Class<?>[] parameterTypes = ic.getMethod().getParameterTypes();
    final Annotation[][] parameterAnnotations = ic.getMethod().getParameterAnnotations();
    final List<Set<Annotation>> annotations = new ArrayList<>();
    for (final Annotation[] parameterAnnotation : parameterAnnotations)
    {
        final Set<Annotation> set = new HashSet<>(parameterAnnotation.length);
        set.addAll(Arrays.asList(parameterAnnotation));
        annotations.add(set);
    }

    final Set<Annotation> mtdAnnotations = new HashSet<>();
    mtdAnnotations.addAll(Arrays.asList(ic.getMethod().getAnnotations()));

    final CacheResult cacheResult = ic.getMethod().getAnnotation(CacheResult.class);
    final String cacheResultCacheResultName = cacheResult == null ? null : defaultName(ic.getMethod(), defaults, cacheResult.cacheName());
    final CacheResolverFactory cacheResultCacheResolverFactory = cacheResult == null ?
            null : cacheResolverFactoryFor(defaults, cacheResult.cacheResolverFactory());
    final CacheKeyGenerator cacheResultCacheKeyGenerator = cacheResult == null ?
            null : cacheKeyGeneratorFor(defaults, cacheResult.cacheKeyGenerator());

    final CachePut cachePut = ic.getMethod().getAnnotation(CachePut.class);
    final String cachePutCachePutName = cachePut == null ? null : defaultName(ic.getMethod(), defaults, cachePut.cacheName());
    final CacheResolverFactory cachePutCacheResolverFactory = cachePut == null ?
            null : cacheResolverFactoryFor(defaults, cachePut.cacheResolverFactory());
    final CacheKeyGenerator cachePutCacheKeyGenerator = cachePut == null ?
            null : cacheKeyGeneratorFor(defaults, cachePut.cacheKeyGenerator());

    final CacheRemove cacheRemove = ic.getMethod().getAnnotation(CacheRemove.class);
    final String cacheRemoveCacheRemoveName = cacheRemove == null ? null : defaultName(ic.getMethod(), defaults, cacheRemove.cacheName());
    final CacheResolverFactory cacheRemoveCacheResolverFactory = cacheRemove == null ?
            null : cacheResolverFactoryFor(defaults, cacheRemove.cacheResolverFactory());
    final CacheKeyGenerator cacheRemoveCacheKeyGenerator = cacheRemove == null ?
            null : cacheKeyGeneratorFor(defaults, cacheRemove.cacheKeyGenerator());

    final CacheRemoveAll cacheRemoveAll = ic.getMethod().getAnnotation(CacheRemoveAll.class);
    final String cacheRemoveAllCacheRemoveAllName = cacheRemoveAll == null ? null : defaultName(ic.getMethod(), defaults, cacheRemoveAll.cacheName());
    final CacheResolverFactory cacheRemoveAllCacheResolverFactory = cacheRemoveAll == null ?
            null : cacheResolverFactoryFor(defaults, cacheRemoveAll.cacheResolverFactory());

    return new MethodMeta(
            parameterTypes,
            annotations,
            mtdAnnotations,
            keyParameterIndexes(ic.getMethod()),
            getValueParameter(annotations),
            getKeyParameters(annotations),
            cacheResultCacheResultName,
            cacheResultCacheResolverFactory,
            cacheResultCacheKeyGenerator,
            cacheResult,
            cachePutCachePutName,
            cachePutCacheResolverFactory,
            cachePutCacheKeyGenerator,
            cachePut != null && cachePut.afterInvocation(),
            cachePut,
            cacheRemoveCacheRemoveName,
            cacheRemoveCacheResolverFactory,
            cacheRemoveCacheKeyGenerator,
            cacheRemove != null && cacheRemove.afterInvocation(),
            cacheRemove,
            cacheRemoveAllCacheRemoveAllName,
            cacheRemoveAllCacheResolverFactory,
            cacheRemoveAll != null && cacheRemoveAll.afterInvocation(),
            cacheRemoveAll);
}
 
Example #15
Source File: AnnotationCacheOperationSourceTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void assertCacheKeyGenerator(KeyGenerator actual,
		Class<? extends CacheKeyGenerator> expectedTargetType) {
	assertEquals("Wrong cache resolver implementation", KeyGeneratorAdapter.class, actual.getClass());
	KeyGeneratorAdapter adapter = (KeyGeneratorAdapter) actual;
	assertEquals("Wrong target CacheKeyGenerator implementation", expectedTargetType, adapter.getTarget().getClass());
}
 
Example #16
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
public CacheKeyGenerator getCacheResultKeyGenerator()
{
    return cacheResultKeyGenerator;
}
 
Example #17
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
public CacheKeyGenerator getCachePutKeyGenerator()
{
    return cachePutKeyGenerator;
}
 
Example #18
Source File: CDIJCacheHelper.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
public CacheKeyGenerator getCacheRemoveKeyGenerator()
{
    return cacheRemoveKeyGenerator;
}