Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 918772 Details for
Bug 1119780
CDI annotations
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
Preliminary patch
0001-BZ1119780-Move-CDI-JCache-interceptor-back-to-origin.patch (text/plain), 127.75 KB, created by
Galder Zamarreño
on 2014-07-17 15:22:58 UTC
(
hide
)
Description:
Preliminary patch
Filename:
MIME Type:
Creator:
Galder Zamarreño
Created:
2014-07-17 15:22:58 UTC
Size:
127.75 KB
patch
obsolete
>From 6a9147140948220d30d2e018144dfaee86bc64c9 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= <galder@zamarreno.com> >Date: Wed, 16 Jul 2014 19:28:12 +0200 >Subject: [PATCH] BZ1119780 Move CDI/JCache interceptor back to original > package > >--- > cdi/extension/pom.xml | 2 - > .../interceptor/AbstractCachePutInterceptor.java | 64 +++++++ > .../AbstractCacheRemoveAllInterceptor.java | 67 +++++++ > .../AbstractCacheRemoveEntryInterceptor.java | 71 ++++++++ > .../AbstractCacheResultInterceptor.java | 81 +++++++++ > .../interceptor/AggregatedParameterMetaData.java | 52 ++++++ > .../interceptor/CacheInvocationParameterImpl.java | 54 ++++++ > .../CacheKeyInvocationContextFactory.java | 193 +++++++++++++++++++++ > .../interceptor/CacheKeyInvocationContextImpl.java | 123 +++++++++++++ > .../cdi/interceptor/CacheLookupHelper.java | 123 +++++++++++++ > .../cdi/interceptor/CachePutInterceptor.java | 40 +++++ > .../cdi/interceptor/CacheRemoveAllInterceptor.java | 45 +++++ > .../interceptor/CacheRemoveEntryInterceptor.java | 48 +++++ > .../cdi/interceptor/CacheResultInterceptor.java | 55 ++++++ > .../cdi/interceptor/DefaultCacheKey.java | 50 ++++++ > .../cdi/interceptor/DefaultCacheKeyGenerator.java | 37 ++++ > .../cdi/interceptor/DefaultCacheResolver.java | 57 ++++++ > .../infinispan/cdi/interceptor/MethodMetaData.java | 85 +++++++++ > .../cdi/interceptor/ParameterMetaData.java | 51 ++++++ > .../org/infinispan/cdi/util/CollectionsHelper.java | 34 ++++ > .../java/org/infinispan/cdi/util/logging/Log.java | 20 +++ > jcache/src/it/tck-runner/pom.xml | 2 +- > .../annotation/AbstractCachePutInterceptor.java | 64 ------- > .../AbstractCacheRemoveAllInterceptor.java | 68 -------- > .../AbstractCacheRemoveEntryInterceptor.java | 71 -------- > .../annotation/AbstractCacheResultInterceptor.java | 82 --------- > .../annotation/AggregatedParameterMetaData.java | 50 ------ > .../annotation/CacheInvocationParameterImpl.java | 52 ------ > .../CacheKeyInvocationContextFactory.java | 193 --------------------- > .../annotation/CacheKeyInvocationContextImpl.java | 123 ------------- > .../jcache/annotation/CacheLookupHelper.java | 123 ------------- > .../jcache/annotation/CachePutInterceptor.java | 40 ----- > .../annotation/CacheRemoveAllInterceptor.java | 45 ----- > .../annotation/CacheRemoveEntryInterceptor.java | 48 ----- > .../jcache/annotation/CacheResultInterceptor.java | 55 ------ > .../jcache/annotation/CollectionsHelper.java | 34 ---- > .../jcache/annotation/DefaultCacheKey.java | 50 ------ > .../annotation/DefaultCacheKeyGenerator.java | 37 ---- > .../jcache/annotation/DefaultCacheResolver.java | 57 ------ > .../annotation/InjectedCachePutInterceptor.java | 3 +- > .../InjectedCacheRemoveAllInterceptor.java | 2 + > .../InjectedCacheRemoveEntryInterceptor.java | 2 + > .../annotation/InjectedCacheResultInterceptor.java | 2 + > .../jcache/annotation/MethodMetaData.java | 85 --------- > .../jcache/annotation/ParameterMetaData.java | 51 ------ > jcache/src/main/resources/META-INF/beans.xml | 8 +- > server/integration/testsuite/pom.xml | 11 -- > 47 files changed, 1363 insertions(+), 1347 deletions(-) > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCachePutInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveAllInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveEntryInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheResultInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AggregatedParameterMetaData.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheInvocationParameterImpl.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextFactory.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextImpl.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheLookupHelper.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CachePutInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveAllInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveEntryInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheResultInterceptor.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKey.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKeyGenerator.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheResolver.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/MethodMetaData.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/interceptor/ParameterMetaData.java > create mode 100644 cdi/extension/src/main/java/org/infinispan/cdi/util/CollectionsHelper.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCachePutInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveAllInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveEntryInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheResultInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/AggregatedParameterMetaData.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheInvocationParameterImpl.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextFactory.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextImpl.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheLookupHelper.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CachePutInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveAllInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveEntryInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CacheResultInterceptor.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/CollectionsHelper.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKey.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKeyGenerator.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheResolver.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/MethodMetaData.java > delete mode 100644 jcache/src/main/java/org/infinispan/jcache/annotation/ParameterMetaData.java > >diff --git a/cdi/extension/pom.xml b/cdi/extension/pom.xml >index 75ca586..2396c1c 100644 >--- a/cdi/extension/pom.xml >+++ b/cdi/extension/pom.xml >@@ -45,7 +45,6 @@ > <artifactId>infinispan-client-hotrod</artifactId> > </dependency> > >- > <dependency> > <groupId>org.jboss.logging</groupId> > <artifactId>jboss-logging</artifactId> >@@ -99,7 +98,6 @@ > <dependency> > <groupId>javax.cache</groupId> > <artifactId>cache-api</artifactId> >- <scope>test</scope> > </dependency> > </dependencies> > <build> >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCachePutInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCachePutInterceptor.java >new file mode 100644 >index 0000000..6707905 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCachePutInterceptor.java >@@ -0,0 +1,64 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+ >+import javax.cache.Cache; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.cache.annotation.CachePut; >+import javax.cache.annotation.CacheResolver; >+import javax.cache.annotation.GeneratedCacheKey; >+import javax.interceptor.InvocationContext; >+import java.io.Serializable; >+ >+/** >+ * Base {@link javax.cache.annotation.CachePut} interceptor implementation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+public abstract class AbstractCachePutInterceptor implements Serializable { >+ >+ private final CacheResolver cacheResolver; >+ private final CacheKeyInvocationContextFactory contextFactory; >+ >+ public AbstractCachePutInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >+ this.cacheResolver = cacheResolver; >+ this.contextFactory = contextFactory; >+ } >+ >+ public Object cachePut(InvocationContext invocationContext) throws Exception { >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >+ } >+ >+ final CacheKeyInvocationContext<CachePut> cacheKeyInvocationContext = contextFactory.getCacheKeyInvocationContext(invocationContext); >+ final CacheKeyGenerator cacheKeyGenerator = cacheKeyInvocationContext.unwrap(CacheKeyInvocationContextImpl.class).getCacheKeyGenerator(); >+ final CachePut cachePut = cacheKeyInvocationContext.getCacheAnnotation(); >+ final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); >+ final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >+ >+ final Object valueToCache = cacheKeyInvocationContext.getValueParameter().getValue(); >+ >+ if (!cachePut.afterInvocation() && valueToCache != null) { >+ cache.put(cacheKey, valueToCache); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Value '%s' cached in cache '%s' with key '%s' before method invocation", valueToCache, cache.getName(), cacheKey); >+ } >+ } >+ >+ final Object result = invocationContext.proceed(); >+ >+ if (cachePut.afterInvocation() && valueToCache != null) { >+ cache.put(cacheKey, valueToCache); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Value '%s' cached in cache '%s' with key '%s' after method invocation", valueToCache, cache.getName(), cacheKey); >+ } >+ } >+ >+ return result; >+ } >+ >+ protected abstract Log getLog(); >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveAllInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveAllInterceptor.java >new file mode 100644 >index 0000000..663c4e4 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveAllInterceptor.java >@@ -0,0 +1,67 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+ >+import javax.cache.Cache; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.cache.annotation.CacheRemoveAll; >+import javax.cache.annotation.CacheResolver; >+import javax.cache.annotation.GeneratedCacheKey; >+import javax.interceptor.InvocationContext; >+import java.io.Serializable; >+ >+/** >+ * <p>{@link javax.cache.annotation.CacheRemoveAll} interceptor implementation. This interceptor uses the following algorithm describes in >+ * JSR-107.</p> >+ * >+ * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveAll} must do the following, remove all >+ * entries associated with the cache. The removeAll occurs after the method body is executed. This can be overridden by >+ * specifying a afterInvocation attribute value of false. If afterInvocation is true and the annotated method throws an >+ * exception, the removeAll will not happen.</p> >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+public abstract class AbstractCacheRemoveAllInterceptor implements Serializable { >+ >+ private static final long serialVersionUID = -8763819640664021763L; >+ >+ private final CacheResolver cacheResolver; >+ private final CacheKeyInvocationContextFactory contextFactory; >+ >+ public AbstractCacheRemoveAllInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >+ this.cacheResolver = cacheResolver; >+ this.contextFactory = contextFactory; >+ } >+ >+ public Object cacheRemoveAll(InvocationContext invocationContext) throws Exception { >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >+ } >+ >+ final CacheKeyInvocationContext<CacheRemoveAll> cacheKeyInvocationContext = >+ contextFactory.getCacheKeyInvocationContext(invocationContext); >+ final CacheRemoveAll cacheRemoveAll = cacheKeyInvocationContext.getCacheAnnotation(); >+ final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >+ >+ if (!cacheRemoveAll.afterInvocation()) { >+ cache.clear(); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Clear cache '%s' before method invocation", cache.getName()); >+ } >+ } >+ >+ final Object result = invocationContext.proceed(); >+ >+ if (cacheRemoveAll.afterInvocation()) { >+ cache.clear(); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Clear cache '%s' after method invocation", cache.getName()); >+ } >+ } >+ >+ return result; >+ } >+ >+ protected abstract Log getLog(); >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveEntryInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveEntryInterceptor.java >new file mode 100644 >index 0000000..dc0a84c >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheRemoveEntryInterceptor.java >@@ -0,0 +1,71 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+ >+import javax.cache.Cache; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.cache.annotation.CacheRemove; >+import javax.cache.annotation.CacheResolver; >+import javax.cache.annotation.GeneratedCacheKey; >+import javax.interceptor.InvocationContext; >+import java.io.Serializable; >+ >+/** >+ * <p>{@link javax.cache.annotation.CacheRemove} interceptor implementation.This interceptor uses the following algorithm describes in >+ * JSR-107.</p> >+ * >+ * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveEntry} must do the following, generate a >+ * key based on InvocationContext using the specified {@link javax.cache.annotation.CacheKeyGenerator}, use this key to remove the entry in the >+ * cache. The remove occurs after the method body is executed. This can be overridden by specifying a afterInvocation >+ * attribute value of false. If afterInvocation is true and the annotated method throws an exception the remove will not >+ * happen.</p> >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+public abstract class AbstractCacheRemoveEntryInterceptor implements Serializable { >+ >+ private static final long serialVersionUID = -9079291622309963969L; >+ >+ private final CacheResolver cacheResolver; >+ private final CacheKeyInvocationContextFactory contextFactory; >+ >+ public AbstractCacheRemoveEntryInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >+ this.cacheResolver = cacheResolver; >+ this.contextFactory = contextFactory; >+ } >+ >+ public Object cacheRemoveEntry(InvocationContext invocationContext) throws Exception { >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >+ } >+ >+ final CacheKeyInvocationContext<CacheRemove> cacheKeyInvocationContext = contextFactory.getCacheKeyInvocationContext(invocationContext); >+ final CacheKeyGenerator cacheKeyGenerator = cacheKeyInvocationContext.unwrap(CacheKeyInvocationContextImpl.class).getCacheKeyGenerator(); >+ final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >+ final CacheRemove cacheRemoveEntry = cacheKeyInvocationContext.getCacheAnnotation(); >+ final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); >+ >+ if (!cacheRemoveEntry.afterInvocation()) { >+ cache.remove(cacheKey); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Remove entry with key '%s' in cache '%s' before method invocation", cacheKey, cache.getName()); >+ } >+ } >+ >+ final Object result = invocationContext.proceed(); >+ >+ if (cacheRemoveEntry.afterInvocation()) { >+ cache.remove(cacheKey); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Remove entry with key '%s' in cache '%s' after method invocation", cacheKey, cache.getName()); >+ } >+ } >+ >+ return result; >+ } >+ >+ protected abstract Log getLog(); >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheResultInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheResultInterceptor.java >new file mode 100644 >index 0000000..3374234 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AbstractCacheResultInterceptor.java >@@ -0,0 +1,81 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+ >+import javax.cache.Cache; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.cache.annotation.CacheResolver; >+import javax.cache.annotation.CacheResult; >+import javax.cache.annotation.GeneratedCacheKey; >+import javax.interceptor.InvocationContext; >+import java.io.Serializable; >+ >+/** >+ * <p>{@link javax.cache.annotation.CacheResult} interceptor implementation. This interceptor uses the following algorithm describes in >+ * JSR-107.</p> >+ * >+ * <p>When a method annotated with {@link javax.cache.annotation.CacheResult} is invoked the following must occur. >+ * <ol> >+ * <li>Generate a key based on InvocationContext using the specified {@linkplain javax.cache.annotation.CacheKeyGenerator}.</li> >+ * <li>Use this key to look up the entry in the cache.</li> >+ * <li>If an entry is found return it as the result and do not call the annotated method.</li> >+ * <li>If no entry is found invoke the method.</li> >+ * <li>Use the result to populate the cache with this key/result pair.</li> >+ * </ol> >+ * >+ * There is a skipGet attribute which if set to true will cause the method body to always be invoked and the return >+ * value put into the cache. The cache is not checked for the key before method body invocation, skipping steps 2 and 3 >+ * from the list above. This can be used for annotating methods that do a cache.put() with no other consequences.</p> >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+public abstract class AbstractCacheResultInterceptor implements Serializable { >+ >+ private static final long serialVersionUID = 5275055951121834315L; >+ >+ private final CacheResolver cacheResolver; >+ private final CacheKeyInvocationContextFactory contextFactory; >+ >+ public AbstractCacheResultInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >+ this.cacheResolver = cacheResolver; >+ this.contextFactory = contextFactory; >+ } >+ >+ public Object cacheResult(InvocationContext invocationContext) throws Exception { >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >+ } >+ >+ final CacheKeyInvocationContext<CacheResult> cacheKeyInvocationContext = contextFactory.getCacheKeyInvocationContext(invocationContext); >+ final CacheKeyGenerator cacheKeyGenerator = cacheKeyInvocationContext.unwrap(CacheKeyInvocationContextImpl.class).getCacheKeyGenerator(); >+ final CacheResult cacheResult = cacheKeyInvocationContext.getCacheAnnotation(); >+ final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); >+ final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >+ >+ Object result = null; >+ >+ if (!cacheResult.skipGet()) { >+ result = cache.get(cacheKey); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Entry with value '%s' has been found in cache '%s' with key '%s'", result, cache.getName(), cacheKey); >+ } >+ } >+ >+ if (result == null) { >+ result = invocationContext.proceed(); >+ if (result != null) { >+ cache.put(cacheKey, result); >+ if (getLog().isTraceEnabled()) { >+ getLog().tracef("Value '%s' cached in cache '%s' with key '%s'", result, cache.getName(), cacheKey); >+ } >+ } >+ } >+ >+ return result; >+ } >+ >+ protected abstract Log getLog(); >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AggregatedParameterMetaData.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AggregatedParameterMetaData.java >new file mode 100644 >index 0000000..bfc352d >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/AggregatedParameterMetaData.java >@@ -0,0 +1,52 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.interceptor.ParameterMetaData; >+ >+import java.util.List; >+ >+import static java.util.Collections.unmodifiableList; >+ >+/** >+ * Contains all parameters metadata for a method annotated with a cache annotation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+public class AggregatedParameterMetaData { >+ >+ private final List<ParameterMetaData> parameters; >+ private final List<ParameterMetaData> keyParameters; >+ private final ParameterMetaData valueParameter; >+ >+ public AggregatedParameterMetaData(List<ParameterMetaData> parameters, >+ List<ParameterMetaData> keyParameters, >+ ParameterMetaData valueParameter) { >+ >+ this.parameters = unmodifiableList(parameters); >+ this.keyParameters = unmodifiableList(keyParameters); >+ this.valueParameter = valueParameter; >+ } >+ >+ public List<ParameterMetaData> getParameters() { >+ return parameters; >+ } >+ >+ public List<ParameterMetaData> getKeyParameters() { >+ return keyParameters; >+ } >+ >+ public ParameterMetaData getValueParameter() { >+ return valueParameter; >+ } >+ >+ @Override >+ public String toString() { >+ return new StringBuilder() >+ .append("AggregatedParameterMetaData{") >+ .append("parameters=").append(parameters) >+ .append(", keyParameters=").append(keyParameters) >+ .append(", valueParameter=").append(valueParameter) >+ .append('}') >+ .toString(); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheInvocationParameterImpl.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheInvocationParameterImpl.java >new file mode 100644 >index 0000000..2e233ef >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheInvocationParameterImpl.java >@@ -0,0 +1,54 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.interceptor.ParameterMetaData; >+ >+import javax.cache.annotation.CacheInvocationParameter; >+import java.lang.annotation.Annotation; >+import java.util.Set; >+ >+/** >+ * The {@link javax.cache.annotation.CacheInvocationParameter} implementation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+public class CacheInvocationParameterImpl implements CacheInvocationParameter { >+ >+ private final ParameterMetaData parameterMetaData; >+ private final Object parameterValue; >+ >+ public CacheInvocationParameterImpl(ParameterMetaData parameterMetaData, Object parameterValue) { >+ this.parameterMetaData = parameterMetaData; >+ this.parameterValue = parameterValue; >+ } >+ >+ @Override >+ public Class<?> getRawType() { >+ return parameterMetaData.getRawType(); >+ } >+ >+ @Override >+ public Object getValue() { >+ return parameterValue; >+ } >+ >+ @Override >+ public Set<Annotation> getAnnotations() { >+ return parameterMetaData.getAnnotations(); >+ } >+ >+ @Override >+ public int getParameterPosition() { >+ return parameterMetaData.getPosition(); >+ } >+ >+ @Override >+ public String toString() { >+ return new StringBuilder() >+ .append("CacheInvocationParameterImpl{") >+ .append("parameterMetaData=").append(parameterMetaData) >+ .append(", parameterValue=").append(parameterValue) >+ .append('}') >+ .toString(); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextFactory.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextFactory.java >new file mode 100644 >index 0000000..bfd9eb8 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextFactory.java >@@ -0,0 +1,193 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.commons.util.CollectionFactory; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CacheDefaults; >+import javax.cache.annotation.CacheKey; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.cache.annotation.CachePut; >+import javax.cache.annotation.CacheRemoveAll; >+import javax.cache.annotation.CacheRemove; >+import javax.cache.annotation.CacheResult; >+import javax.cache.annotation.CacheValue; >+import javax.enterprise.context.ApplicationScoped; >+import javax.enterprise.inject.spi.BeanManager; >+import javax.inject.Inject; >+import javax.interceptor.InvocationContext; >+import java.lang.annotation.Annotation; >+import java.lang.reflect.Method; >+import java.util.ArrayList; >+import java.util.List; >+import java.util.Set; >+import java.util.concurrent.ConcurrentMap; >+ >+import static org.infinispan.cdi.interceptor.CacheLookupHelper.getCacheKeyGenerator; >+import static org.infinispan.cdi.interceptor.CacheLookupHelper.getCacheName; >+import static org.infinispan.cdi.util.CollectionsHelper.asSet; >+import static org.infinispan.cdi.util.Contracts.assertNotNull; >+ >+/** >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+@ApplicationScoped >+public class CacheKeyInvocationContextFactory { >+ >+ private static final Log log = LogFactory.getLog(CacheKeyInvocationContextFactory.class, Log.class); >+ >+ private BeanManager beanManager; >+ private ConcurrentMap<Method, MethodMetaData<? extends Annotation>> methodMetaDataCache; >+ >+ @Inject >+ public CacheKeyInvocationContextFactory(BeanManager beanManager) { >+ this.beanManager = beanManager; >+ this.methodMetaDataCache = CollectionFactory.makeConcurrentMap(); >+ } >+ >+ // for proxy. >+ protected CacheKeyInvocationContextFactory() { >+ } >+ >+ /** >+ * Returns the cache key invocation context corresponding to the given invocation context. >+ * >+ * @param invocationContext the {@link javax.interceptor.InvocationContext}. >+ * @return an instance of {@link javax.cache.annotation.CacheKeyInvocationContext} corresponding to the given {@link javax.interceptor.InvocationContext}. >+ */ >+ public <A extends Annotation> CacheKeyInvocationContext<A> getCacheKeyInvocationContext(InvocationContext invocationContext) { >+ assertNotNull(invocationContext, "invocationContext parameter must not be null"); >+ >+ final MethodMetaData<A> methodMetaData = (MethodMetaData<A>) getMethodMetaData(invocationContext.getMethod()); >+ return new CacheKeyInvocationContextImpl<A>(invocationContext, methodMetaData); >+ } >+ >+ /** >+ * Returns the method meta data for the given method. >+ * >+ * @param method the method. >+ * @return an instance of {@link MethodMetaData}. >+ */ >+ private MethodMetaData<? extends Annotation> getMethodMetaData(Method method) { >+ MethodMetaData<? extends Annotation> methodMetaData = methodMetaDataCache.get(method); >+ >+ if (methodMetaData == null) { >+ final String cacheName; >+ final Annotation cacheAnnotation; >+ final AggregatedParameterMetaData aggregatedParameterMetaData; >+ final CacheKeyGenerator cacheKeyGenerator; >+ final CacheDefaults cacheDefaultsAnnotation = method.getDeclaringClass().getAnnotation(CacheDefaults.class); >+ >+ if (method.isAnnotationPresent(CacheResult.class)) { >+ final CacheResult cacheResultAnnotation = method.getAnnotation(CacheResult.class); >+ cacheKeyGenerator = CacheLookupHelper.getCacheKeyGenerator(beanManager, cacheResultAnnotation.cacheKeyGenerator(), cacheDefaultsAnnotation); >+ cacheName = CacheLookupHelper.getCacheName(method, cacheResultAnnotation.cacheName(), cacheDefaultsAnnotation, true); >+ aggregatedParameterMetaData = getAggregatedParameterMetaData(method, false); >+ cacheAnnotation = cacheResultAnnotation; >+ >+ } else if (method.isAnnotationPresent(CacheRemove.class)) { >+ final CacheRemove cacheRemoveEntryAnnotation = method.getAnnotation(CacheRemove.class); >+ cacheKeyGenerator = CacheLookupHelper.getCacheKeyGenerator(beanManager, cacheRemoveEntryAnnotation.cacheKeyGenerator(), cacheDefaultsAnnotation); >+ cacheName = CacheLookupHelper.getCacheName(method, cacheRemoveEntryAnnotation.cacheName(), cacheDefaultsAnnotation, false); >+ aggregatedParameterMetaData = getAggregatedParameterMetaData(method, false); >+ cacheAnnotation = cacheRemoveEntryAnnotation; >+ >+ if (cacheName.isEmpty()) { >+ throw log.cacheRemoveEntryMethodWithoutCacheName(method.getName()); >+ } >+ >+ } else if (method.isAnnotationPresent(CacheRemoveAll.class)) { >+ final CacheRemoveAll cacheRemoveAllAnnotation = method.getAnnotation(CacheRemoveAll.class); >+ cacheKeyGenerator = null; >+ cacheName = CacheLookupHelper.getCacheName(method, cacheRemoveAllAnnotation.cacheName(), cacheDefaultsAnnotation, false); >+ aggregatedParameterMetaData = getAggregatedParameterMetaData(method, false); >+ cacheAnnotation = cacheRemoveAllAnnotation; >+ >+ if (cacheName.isEmpty()) { >+ throw log.cacheRemoveAllMethodWithoutCacheName(method.getName()); >+ } >+ >+ } else if (method.isAnnotationPresent(CachePut.class)) { >+ final CachePut cachePutAnnotation = method.getAnnotation(CachePut.class); >+ cacheKeyGenerator = CacheLookupHelper.getCacheKeyGenerator(beanManager, cachePutAnnotation.cacheKeyGenerator(), cacheDefaultsAnnotation); >+ cacheName = CacheLookupHelper.getCacheName(method, cachePutAnnotation.cacheName(), cacheDefaultsAnnotation, true); >+ aggregatedParameterMetaData = getAggregatedParameterMetaData(method, true); >+ cacheAnnotation = cachePutAnnotation; >+ >+ } else { >+ throw log.methodWithoutCacheAnnotation(method.getName()); >+ } >+ >+ final MethodMetaData<? extends Annotation> newCacheMethodMetaData = new MethodMetaData<Annotation>( >+ method, >+ aggregatedParameterMetaData, >+ asSet(method.getAnnotations()), >+ cacheKeyGenerator, >+ cacheAnnotation, >+ cacheName >+ ); >+ >+ methodMetaData = methodMetaDataCache.putIfAbsent(method, newCacheMethodMetaData); >+ if (methodMetaData == null) { >+ methodMetaData = newCacheMethodMetaData; >+ } >+ } >+ >+ return methodMetaData; >+ } >+ >+ /** >+ * Returns the aggregated parameter meta data for the given method. >+ * >+ * @param method the method. >+ * @param cacheValueAllowed {@code true} if the {@link javax.cache.annotation.CacheValue} annotation is allowed on a method parameter. >+ * @return an instance of {@link AggregatedParameterMetaData}. >+ */ >+ private AggregatedParameterMetaData getAggregatedParameterMetaData(Method method, boolean cacheValueAllowed) { >+ final Class<?>[] parameterTypes = method.getParameterTypes(); >+ final Annotation[][] parameterAnnotations = method.getParameterAnnotations(); >+ final List<ParameterMetaData> parameters = new ArrayList<ParameterMetaData>(); >+ final List<ParameterMetaData> keyParameters = new ArrayList<ParameterMetaData>(); >+ ParameterMetaData valueParameter = null; >+ >+ for (int i = 0; i < parameterTypes.length; i++) { >+ final Set<Annotation> annotations = asSet(parameterAnnotations[i]); >+ final ParameterMetaData parameterMetaData = new ParameterMetaData(parameterTypes[i], i, annotations); >+ >+ for (Annotation oneAnnotation : annotations) { >+ final Class<?> type = oneAnnotation.annotationType(); >+ >+ if (CacheKey.class.equals(type)) { >+ keyParameters.add(parameterMetaData); >+ >+ } else if (cacheValueAllowed && CacheValue.class.equals(type)) { >+ if (valueParameter != null) { >+ throw log.cachePutMethodWithMoreThanOneCacheValueParameter(method.getName()); >+ } >+ valueParameter = parameterMetaData; >+ } >+ } >+ >+ parameters.add(parameterMetaData); >+ } >+ >+ if (cacheValueAllowed && valueParameter == null) { >+ if (parameters.size() > 1) { >+ throw log.cachePutMethodWithoutCacheValueParameter(method.getName()); >+ } >+ valueParameter = parameters.get(0); >+ } >+ >+ if (keyParameters.isEmpty()) { >+ keyParameters.addAll(parameters); >+ } >+ >+ if (valueParameter != null && keyParameters.size() > 1) { >+ keyParameters.remove(valueParameter); >+ } >+ >+ return new AggregatedParameterMetaData(parameters, keyParameters, valueParameter); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextImpl.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextImpl.java >new file mode 100644 >index 0000000..fd2c0ec >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheKeyInvocationContextImpl.java >@@ -0,0 +1,123 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.commons.util.ReflectionUtil; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CacheInvocationParameter; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.interceptor.InvocationContext; >+import java.lang.annotation.Annotation; >+import java.lang.reflect.Method; >+import java.util.List; >+import java.util.Set; >+ >+import static java.util.Arrays.copyOf; >+import static java.util.Arrays.deepToString; >+ >+/** >+ * The {@link javax.cache.annotation.CacheKeyInvocationContext} implementation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+public class CacheKeyInvocationContextImpl<A extends Annotation> implements CacheKeyInvocationContext<A> { >+ >+ private static final Log log = LogFactory.getLog(CacheKeyInvocationContextImpl.class, Log.class); >+ >+ private final InvocationContext invocationContext; >+ private final MethodMetaData<A> methodMetaData; >+ private final CacheInvocationParameter[] allParameters; >+ private final CacheInvocationParameter[] keyParameters; >+ private final CacheInvocationParameter valueParameter; >+ >+ public CacheKeyInvocationContextImpl(InvocationContext invocationContext, MethodMetaData<A> methodMetaData) { >+ this.invocationContext = invocationContext; >+ this.methodMetaData = methodMetaData; >+ >+ // populate the de parameters >+ final Object[] parameters = invocationContext.getParameters(); >+ final List<ParameterMetaData> parametersMetaData = methodMetaData.getParameters(); >+ this.allParameters = new CacheInvocationParameter[parameters.length]; >+ >+ for (int i = 0; i < parameters.length; i++) { >+ this.allParameters[i] = new CacheInvocationParameterImpl(parametersMetaData.get(i), parameters[i]); >+ } >+ >+ // populate the key parameters >+ final List<ParameterMetaData> keyParametersMetaData = methodMetaData.getKeyParameters(); >+ >+ int i = 0; >+ this.keyParameters = new CacheInvocationParameter[keyParametersMetaData.size()]; >+ for (ParameterMetaData oneKeyParameterMetaData : keyParametersMetaData) { >+ this.keyParameters[i] = allParameters[oneKeyParameterMetaData.getPosition()]; >+ i++; >+ } >+ >+ // initialize the value parameter >+ final ParameterMetaData valueParameterMetaData = methodMetaData.getValueParameter(); >+ this.valueParameter = valueParameterMetaData != null ? allParameters[valueParameterMetaData.getPosition()] : null; >+ } >+ >+ @Override >+ public Object getTarget() { >+ return invocationContext.getTarget(); >+ } >+ >+ @Override >+ public CacheInvocationParameter[] getAllParameters() { >+ return copyOf(allParameters, allParameters.length); >+ } >+ >+ @Override >+ public CacheInvocationParameter[] getKeyParameters() { >+ return copyOf(keyParameters, keyParameters.length); >+ } >+ >+ @Override >+ public CacheInvocationParameter getValueParameter() { >+ return valueParameter; >+ } >+ >+ @Override >+ public <T> T unwrap(Class<T> clazz) { >+ return ReflectionUtil.unwrap(this, clazz); >+ } >+ >+ @Override >+ public Method getMethod() { >+ return methodMetaData.getMethod(); >+ } >+ >+ @Override >+ public Set<Annotation> getAnnotations() { >+ return methodMetaData.getAnnotations(); >+ } >+ >+ @Override >+ public A getCacheAnnotation() { >+ return methodMetaData.getCacheAnnotation(); >+ } >+ >+ @Override >+ public String getCacheName() { >+ return methodMetaData.getCacheName(); >+ } >+ >+ public CacheKeyGenerator getCacheKeyGenerator() { >+ return methodMetaData.getCacheKeyGenerator(); >+ } >+ >+ @Override >+ public String toString() { >+ return new StringBuilder() >+ .append("CacheKeyInvocationContextImpl{") >+ .append("invocationContext=").append(invocationContext) >+ .append(", methodMetaData=").append(methodMetaData) >+ .append(", allParameters=").append(deepToString(allParameters)) >+ .append(", keyParameters=").append(deepToString(keyParameters)) >+ .append(", valueParameter=").append(valueParameter) >+ .append('}') >+ .toString(); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheLookupHelper.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheLookupHelper.java >new file mode 100644 >index 0000000..1e1d532 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheLookupHelper.java >@@ -0,0 +1,123 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CacheDefaults; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.enterprise.context.spi.CreationalContext; >+import javax.enterprise.inject.spi.Bean; >+import javax.enterprise.inject.spi.BeanManager; >+import java.lang.reflect.Method; >+import java.util.Set; >+ >+import static org.infinispan.cdi.util.Contracts.assertNotNull; >+ >+/** >+ * An helper class providing useful methods for cache lookup. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+public final class CacheLookupHelper { >+ >+ private static final Log log = LogFactory.getLog(CacheLookupHelper.class, Log.class); >+ >+ /** >+ * Disable instantiation. >+ */ >+ private CacheLookupHelper() { >+ } >+ >+ /** >+ * Resolves the cache name of a method annotated with a JCACHE annotation. >+ * >+ * @param method the annotated method. >+ * @param methodCacheName the cache name defined on the JCACHE annotation. >+ * @param cacheDefaultsAnnotation the {@link javax.cache.annotation.CacheDefaults} annotation instance. >+ * @param generate {@code true} if the default cache name has to be returned if none is specified. >+ * @return the resolved cache name. >+ * @throws NullPointerException if method or methodCacheName parameter is {@code null}. >+ */ >+ public static String getCacheName(Method method, String methodCacheName, CacheDefaults cacheDefaultsAnnotation, boolean generate) { >+ assertNotNull(method, "method parameter must not be null"); >+ assertNotNull(methodCacheName, "methodCacheName parameter must not be null"); >+ >+ String cacheName = methodCacheName.trim(); >+ >+ if (cacheName.isEmpty() && cacheDefaultsAnnotation != null) { >+ cacheName = cacheDefaultsAnnotation.cacheName().trim(); >+ } >+ >+ if (cacheName.isEmpty() && generate) { >+ cacheName = getDefaultMethodCacheName(method); >+ } >+ >+ return cacheName; >+ } >+ >+ /** >+ * Resolves and creates an instance of {@link javax.cache.annotation.CacheKeyGenerator}. To resolve the cache key generator class the >+ * algorithm defined in JCACHE specification is used. >+ * >+ * @param beanManager the bean manager instance. >+ * @param methodCacheKeyGeneratorClass the {@link javax.cache.annotation.CacheKeyGenerator} class declared in the cache annotation. >+ * @param cacheDefaultsAnnotation the {@link javax.cache.annotation.CacheDefaults} annotation instance. >+ * @return the {@link javax.cache.annotation.CacheKeyGenerator} instance. >+ * @throws NullPointerException if beanManager parameter is {@code null}. >+ */ >+ public static CacheKeyGenerator getCacheKeyGenerator(BeanManager beanManager, Class<? extends CacheKeyGenerator> methodCacheKeyGeneratorClass, CacheDefaults cacheDefaultsAnnotation) { >+ assertNotNull(beanManager, "beanManager parameter must not be null"); >+ >+ Class<? extends CacheKeyGenerator> cacheKeyGeneratorClass = DefaultCacheKeyGenerator.class; >+ if (!CacheKeyGenerator.class.equals(methodCacheKeyGeneratorClass)) { >+ cacheKeyGeneratorClass = methodCacheKeyGeneratorClass; >+ } else if (cacheDefaultsAnnotation != null && !CacheKeyGenerator.class.equals(cacheDefaultsAnnotation.cacheKeyGenerator())) { >+ cacheKeyGeneratorClass = cacheDefaultsAnnotation.cacheKeyGenerator(); >+ } >+ >+ final CreationalContext<?> creationalContext = beanManager.createCreationalContext(null); >+ final Set<Bean<?>> beans = beanManager.getBeans(cacheKeyGeneratorClass); >+ if (!beans.isEmpty()) { >+ final Bean<?> bean = beanManager.resolve(beans); >+ return (CacheKeyGenerator) beanManager.getReference(bean, CacheKeyGenerator.class, creationalContext); >+ } >+ >+ // the CacheKeyGenerator implementation is not managed by CDI >+ try { >+ >+ return cacheKeyGeneratorClass.newInstance(); >+ >+ } catch (InstantiationException e) { >+ throw log.unableToInstantiateCacheKeyGenerator(cacheKeyGeneratorClass, e); >+ } catch (IllegalAccessException e) { >+ throw log.unableToInstantiateCacheKeyGenerator(cacheKeyGeneratorClass, e); >+ } >+ } >+ >+ /** >+ * Returns the default cache name associated to the given method according to JSR-107. >+ * >+ * @param method the method. >+ * @return the default cache name for the given method. >+ */ >+ private static String getDefaultMethodCacheName(Method method) { >+ int i = 0; >+ int nbParameters = method.getParameterTypes().length; >+ >+ StringBuilder cacheName = new StringBuilder() >+ .append(method.getDeclaringClass().getName()) >+ .append(".") >+ .append(method.getName()) >+ .append("("); >+ >+ for (Class<?> oneParameterType : method.getParameterTypes()) { >+ cacheName.append(oneParameterType.getName()); >+ if (i < (nbParameters - 1)) { >+ cacheName.append(","); >+ } >+ i++; >+ } >+ >+ return cacheName.append(")").toString(); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CachePutInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CachePutInterceptor.java >new file mode 100644 >index 0000000..3b65a03 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CachePutInterceptor.java >@@ -0,0 +1,40 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CachePut; >+import javax.inject.Inject; >+import javax.interceptor.AroundInvoke; >+import javax.interceptor.Interceptor; >+import javax.interceptor.InvocationContext; >+ >+/** >+ * {@link javax.cache.annotation.CachePut} interceptor implementation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+@Interceptor >+@CachePut >+public class CachePutInterceptor extends AbstractCachePutInterceptor { >+ >+ private static final Log log = LogFactory.getLog(CachePutInterceptor.class, Log.class); >+ >+ @Inject >+ public CachePutInterceptor(DefaultCacheResolver cacheResolver, >+ CacheKeyInvocationContextFactory contextFactory) { >+ super(cacheResolver, contextFactory); >+ } >+ >+ @AroundInvoke >+ public Object cachePut(InvocationContext invocationContext) throws Exception { >+ return super.cachePut(invocationContext); >+ } >+ >+ @Override >+ protected Log getLog() { >+ return log; >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveAllInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveAllInterceptor.java >new file mode 100644 >index 0000000..1f59038 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveAllInterceptor.java >@@ -0,0 +1,45 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CacheRemoveAll; >+import javax.inject.Inject; >+import javax.interceptor.AroundInvoke; >+import javax.interceptor.Interceptor; >+import javax.interceptor.InvocationContext; >+ >+/** >+ * <p>{@link javax.cache.annotation.CacheRemoveAll} interceptor implementation. This interceptor uses the following algorithm describes in >+ * JSR-107.</p> >+ * >+ * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveAll} must do the following, remove all >+ * entries associated with the cache. The removeAll occurs after the method body is executed. This can be overridden by >+ * specifying a afterInvocation attribute value of false. If afterInvocation is true and the annotated method throws an >+ * exception, the removeAll will not happen.</p> >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+@Interceptor >+@CacheRemoveAll >+public class CacheRemoveAllInterceptor extends AbstractCacheRemoveAllInterceptor { >+ >+ private static final Log log = LogFactory.getLog(CacheRemoveAllInterceptor.class, Log.class); >+ >+ @Inject >+ public CacheRemoveAllInterceptor(DefaultCacheResolver cacheResolver, >+ CacheKeyInvocationContextFactory contextFactory) { >+ super(cacheResolver, contextFactory); >+ } >+ >+ @AroundInvoke >+ public Object cacheRemoveAll(InvocationContext invocationContext) throws Exception { >+ return super.cacheRemoveAll(invocationContext); >+ } >+ >+ @Override >+ protected Log getLog() { >+ return log; >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveEntryInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveEntryInterceptor.java >new file mode 100644 >index 0000000..6933624 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheRemoveEntryInterceptor.java >@@ -0,0 +1,48 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CacheRemove; >+import javax.inject.Inject; >+import javax.interceptor.AroundInvoke; >+import javax.interceptor.Interceptor; >+import javax.interceptor.InvocationContext; >+ >+/** >+ * <p>{@link javax.cache.annotation.CacheRemove} interceptor implementation.This interceptor uses the following algorithm describes in >+ * JSR-107.</p> >+ * >+ * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveEntry} must do the following, generate a >+ * key based on InvocationContext using the specified {@link javax.cache.annotation.CacheKeyGenerator}, use this key to remove the entry in the >+ * cache. The remove occurs after the method body is executed. This can be overridden by specifying a afterInvocation >+ * attribute value of false. If afterInvocation is true and the annotated method throws an exception the remove will not >+ * happen.</p> >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+@Interceptor >+@CacheRemove >+public class CacheRemoveEntryInterceptor extends AbstractCacheRemoveEntryInterceptor { >+ >+ private static final Log log = LogFactory.getLog(CacheRemoveEntryInterceptor.class, Log.class); >+ >+ @Inject >+ public CacheRemoveEntryInterceptor(DefaultCacheResolver cacheResolver, >+ CacheKeyInvocationContextFactory contextFactory) { >+ super(cacheResolver, contextFactory); >+ } >+ >+ @Override >+ @AroundInvoke >+ public Object cacheRemoveEntry(InvocationContext invocationContext) throws Exception { >+ return super.cacheRemoveEntry(invocationContext); >+ } >+ >+ @Override >+ protected Log getLog() { >+ return log; >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheResultInterceptor.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheResultInterceptor.java >new file mode 100644 >index 0000000..b57a17b >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/CacheResultInterceptor.java >@@ -0,0 +1,55 @@ >+package org.infinispan.cdi.interceptor; >+ >+import org.infinispan.cdi.util.logging.Log; >+import org.infinispan.util.logging.LogFactory; >+ >+import javax.cache.annotation.CacheResult; >+import javax.inject.Inject; >+import javax.interceptor.AroundInvoke; >+import javax.interceptor.Interceptor; >+import javax.interceptor.InvocationContext; >+ >+/** >+ * <p>{@link javax.cache.annotation.CacheResult} interceptor implementation. This interceptor uses the following algorithm describes in >+ * JSR-107.</p> >+ * >+ * <p>When a method annotated with {@link javax.cache.annotation.CacheResult} is invoked the following must occur. >+ * <ol> >+ * <li>Generate a key based on InvocationContext using the specified {@linkplain javax.cache.annotation.CacheKeyGenerator}.</li> >+ * <li>Use this key to look up the entry in the cache.</li> >+ * <li>If an entry is found return it as the result and do not call the annotated method.</li> >+ * <li>If no entry is found invoke the method.</li> >+ * <li>Use the result to populate the cache with this key/result pair.</li> >+ * </ol> >+ * >+ * There is a skipGet attribute which if set to true will cause the method body to always be invoked and the return >+ * value put into the cache. The cache is not checked for the key before method body invocation, skipping steps 2 and 3 >+ * from the list above. This can be used for annotating methods that do a cache.put() with no other consequences.</p> >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+@Interceptor >+@CacheResult >+public class CacheResultInterceptor extends AbstractCacheResultInterceptor { >+ >+ private static final long serialVersionUID = 5275055951121834315L; >+ private static final Log log = LogFactory.getLog(CacheResultInterceptor.class, Log.class); >+ >+ @Inject >+ public CacheResultInterceptor(DefaultCacheResolver cacheResolver, >+ CacheKeyInvocationContextFactory contextFactory) { >+ super(cacheResolver, contextFactory); >+ } >+ >+ @AroundInvoke >+ public Object cacheResult(InvocationContext invocationContext) throws Exception { >+ return super.cacheResult(invocationContext); >+ } >+ >+ @Override >+ protected Log getLog() { >+ return log; >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKey.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKey.java >new file mode 100644 >index 0000000..1605ae4 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKey.java >@@ -0,0 +1,50 @@ >+package org.infinispan.cdi.interceptor; >+ >+import javax.cache.annotation.GeneratedCacheKey; >+ >+import static java.util.Arrays.*; >+ >+/** >+ * Default {@link javax.cache.annotation.GeneratedCacheKey} implementation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+public class DefaultCacheKey implements GeneratedCacheKey { >+ >+ private static final long serialVersionUID = 4410523928649671768L; >+ >+ private final Object[] parameters; >+ private final int hashCode; >+ >+ public DefaultCacheKey(Object[] parameters) { >+ this.parameters = parameters; >+ this.hashCode = deepHashCode(parameters); >+ } >+ >+ @Override >+ public boolean equals(Object o) { >+ if (this == o) return true; >+ if (o == null || getClass() != o.getClass()) return false; >+ >+ DefaultCacheKey that = (DefaultCacheKey) o; >+ >+ return deepEquals(parameters, that.parameters); >+ } >+ >+ @Override >+ public int hashCode() { >+ return this.hashCode; >+ } >+ >+ @Override >+ public String toString() { >+ return new StringBuilder() >+ .append("DefaultCacheKey{") >+ .append("parameters=").append(parameters == null ? null : deepToString(parameters)) >+ .append(", hashCode=").append(hashCode) >+ .append('}') >+ .toString(); >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKeyGenerator.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKeyGenerator.java >new file mode 100644 >index 0000000..10cbc99 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheKeyGenerator.java >@@ -0,0 +1,37 @@ >+package org.infinispan.cdi.interceptor; >+ >+import javax.cache.annotation.CacheInvocationParameter; >+import javax.cache.annotation.CacheKeyGenerator; >+import javax.cache.annotation.CacheKeyInvocationContext; >+import javax.cache.annotation.GeneratedCacheKey; >+import javax.enterprise.context.ApplicationScoped; >+import java.lang.annotation.Annotation; >+ >+import static org.infinispan.cdi.util.Contracts.assertNotNull; >+ >+/** >+ * Default {@link javax.cache.annotation.CacheKeyGenerator} implementation. >+ * By default all key parameters of the intercepted method compose the >+ * {@link javax.cache.annotation.CacheKey}. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+@ApplicationScoped >+public class DefaultCacheKeyGenerator implements CacheKeyGenerator { >+ >+ @Override >+ public GeneratedCacheKey generateCacheKey(CacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext) { >+ assertNotNull(cacheKeyInvocationContext, "cacheKeyInvocationContext parameter must not be null"); >+ >+ final CacheInvocationParameter[] keyParameters = cacheKeyInvocationContext.getKeyParameters(); >+ final Object[] keyValues = new Object[keyParameters.length]; >+ >+ for (int i = 0 ; i < keyParameters.length ; i++) { >+ keyValues[i] = keyParameters[i].getValue(); >+ } >+ >+ return new DefaultCacheKey(keyValues); >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheResolver.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheResolver.java >new file mode 100644 >index 0000000..e25938d >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/DefaultCacheResolver.java >@@ -0,0 +1,57 @@ >+package org.infinispan.cdi.interceptor; >+ >+import javax.cache.Cache; >+import javax.cache.CacheManager; >+import javax.cache.Caching; >+import javax.cache.annotation.CacheInvocationContext; >+import javax.cache.annotation.CacheResolver; >+import javax.cache.spi.CachingProvider; >+import javax.enterprise.context.ApplicationScoped; >+import java.lang.annotation.Annotation; >+ >+import static org.infinispan.cdi.util.Contracts.assertNotNull; >+ >+/** >+ * Default {@link javax.cache.annotation.CacheResolver} implementation for >+ * standalone environments, where no Cache/CacheManagers are injected via CDI. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ * @author Galder Zamarreño >+ */ >+@ApplicationScoped >+public class DefaultCacheResolver implements CacheResolver { >+ >+ private CacheManager defaultCacheManager; >+ >+ // Created by proxy >+ @SuppressWarnings("unused") >+ DefaultCacheResolver() { >+ CachingProvider provider = Caching.getCachingProvider(); >+ defaultCacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()); >+ } >+ >+ @Override >+ public <K, V> Cache<K, V> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext) { >+ assertNotNull(cacheInvocationContext, "cacheInvocationContext parameter must not be null"); >+ >+ final String cacheName = cacheInvocationContext.getCacheName(); >+ >+ // If cache name is empty, default cache of default cache manager is returned >+ if (cacheName.trim().isEmpty()) { >+ return defaultCacheManager.createCache(cacheName, >+ new javax.cache.configuration.MutableConfiguration<K, V>()); >+ } >+ >+ for (String name : defaultCacheManager.getCacheNames()) { >+ if (name.equals(cacheName)) >+ return defaultCacheManager.getCache(cacheName); >+ } >+ >+ // If the cache has not been defined in the default cache manager or >+ // in a specific one a new cache is created in the default cache manager >+ // with the default configuration. >+ return defaultCacheManager.createCache(cacheName, >+ new javax.cache.configuration.MutableConfiguration<K, V>()); >+ } >+ >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/MethodMetaData.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/MethodMetaData.java >new file mode 100644 >index 0000000..df9ff82 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/MethodMetaData.java >@@ -0,0 +1,85 @@ >+package org.infinispan.cdi.interceptor; >+ >+import javax.cache.annotation.CacheKeyGenerator; >+import java.lang.annotation.Annotation; >+import java.lang.reflect.Method; >+import java.util.List; >+import java.util.Set; >+ >+import static java.util.Collections.unmodifiableSet; >+ >+/** >+ * Metadata associated to a method annotated with a cache annotation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+public class MethodMetaData<A extends Annotation> { >+ >+ private final Method method; >+ private final Set<Annotation> annotations; >+ private final A cacheAnnotation; >+ private final String cacheName; >+ private final AggregatedParameterMetaData aggregatedParameterMetaData; >+ private final CacheKeyGenerator cacheKeyGenerator; >+ >+ public MethodMetaData(Method method, >+ AggregatedParameterMetaData aggregatedParameterMetaData, >+ Set<Annotation> annotations, >+ CacheKeyGenerator cacheKeyGenerator, >+ A cacheAnnotation, >+ String cacheName) { >+ >+ this.method = method; >+ this.aggregatedParameterMetaData = aggregatedParameterMetaData; >+ this.annotations = unmodifiableSet(annotations); >+ this.cacheKeyGenerator = cacheKeyGenerator; >+ this.cacheAnnotation = cacheAnnotation; >+ this.cacheName = cacheName; >+ } >+ >+ public Method getMethod() { >+ return method; >+ } >+ >+ public Set<Annotation> getAnnotations() { >+ return annotations; >+ } >+ >+ public A getCacheAnnotation() { >+ return cacheAnnotation; >+ } >+ >+ public String getCacheName() { >+ return cacheName; >+ } >+ >+ public CacheKeyGenerator getCacheKeyGenerator() { >+ return cacheKeyGenerator; >+ } >+ >+ public List<ParameterMetaData> getParameters() { >+ return aggregatedParameterMetaData.getParameters(); >+ } >+ >+ public List<ParameterMetaData> getKeyParameters() { >+ return aggregatedParameterMetaData.getKeyParameters(); >+ } >+ >+ public ParameterMetaData getValueParameter() { >+ return aggregatedParameterMetaData.getValueParameter(); >+ } >+ >+ @Override >+ public String toString() { >+ return new StringBuilder() >+ .append("MethodMetaData{") >+ .append("method=").append(method) >+ .append(", annotations=").append(annotations) >+ .append(", cacheAnnotation=").append(cacheAnnotation) >+ .append(", cacheName='").append(cacheName).append('\'') >+ .append(", aggregatedParameterMetaData=").append(aggregatedParameterMetaData) >+ .append(", cacheKeyGenerator=").append(cacheKeyGenerator) >+ .append('}') >+ .toString(); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/ParameterMetaData.java b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/ParameterMetaData.java >new file mode 100644 >index 0000000..eeec340 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/interceptor/ParameterMetaData.java >@@ -0,0 +1,51 @@ >+package org.infinispan.cdi.interceptor; >+ >+import java.lang.annotation.Annotation; >+import java.lang.reflect.Type; >+import java.util.Set; >+ >+import static java.util.Collections.unmodifiableSet; >+ >+/** >+ * Contains the metadata for a parameter of a method annotated with A JCACHE annotation. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+public class ParameterMetaData { >+ >+ private final Type baseType; >+ private final Class<?> rawType; >+ private final int position; >+ private final Set<Annotation> annotations; >+ >+ public ParameterMetaData(Class<?> type, int position, Set<Annotation> annotations) { >+ this.baseType = type.getGenericSuperclass(); >+ this.rawType = type; >+ this.position = position; >+ this.annotations = unmodifiableSet(annotations); >+ } >+ >+ public Class<?> getRawType() { >+ return rawType; >+ } >+ >+ public int getPosition() { >+ return position; >+ } >+ >+ public Set<Annotation> getAnnotations() { >+ return annotations; >+ } >+ >+ @Override >+ public String toString() { >+ return new StringBuilder() >+ .append("ParameterMetaData{") >+ .append("baseType=").append(baseType) >+ .append(", rawType=").append(rawType) >+ .append(", position=").append(position) >+ .append(", annotations=").append(annotations) >+ .append('}') >+ .toString(); >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/util/CollectionsHelper.java b/cdi/extension/src/main/java/org/infinispan/cdi/util/CollectionsHelper.java >new file mode 100644 >index 0000000..60f05b9 >--- /dev/null >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/util/CollectionsHelper.java >@@ -0,0 +1,34 @@ >+package org.infinispan.cdi.util; >+ >+import java.util.LinkedHashSet; >+import java.util.Set; >+ >+import static java.util.Collections.addAll; >+ >+/** >+ * An helper class providing useful methods to work with JDK collections. >+ * >+ * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >+ */ >+public final class CollectionsHelper { >+ /** >+ * Disable instantiation. >+ */ >+ private CollectionsHelper() { >+ } >+ >+ /** >+ * Creates a {@link java.util.Set} with the given elements. >+ * >+ * @param elements the elements. >+ * @param <T> the element type. >+ * @return a new {@link java.util.Set} instance containing the given elements. >+ * @throws NullPointerException if parameter elements is {@code null}. >+ */ >+ public static <T> Set<T> asSet(T... elements) { >+ final Set<T> resultSet = new LinkedHashSet<T>(); >+ addAll(resultSet, elements); >+ >+ return resultSet; >+ } >+} >diff --git a/cdi/extension/src/main/java/org/infinispan/cdi/util/logging/Log.java b/cdi/extension/src/main/java/org/infinispan/cdi/util/logging/Log.java >index 3575b41..9254542 100644 >--- a/cdi/extension/src/main/java/org/infinispan/cdi/util/logging/Log.java >+++ b/cdi/extension/src/main/java/org/infinispan/cdi/util/logging/Log.java >@@ -7,6 +7,8 @@ > import org.jboss.logging.annotations.Message; > import org.jboss.logging.annotations.MessageLogger; > >+import javax.cache.CacheException; >+ > import static org.jboss.logging.Logger.Level.INFO; > > /** >@@ -29,4 +31,22 @@ > @Message(value = "%s parameter must not be null", id = 17003) > IllegalArgumentException parameterMustNotBeNull(String parameterName); > >+ @Message(value = "Unable to instantiate CacheKeyGenerator with type '%s'", id = 17004) >+ CacheException unableToInstantiateCacheKeyGenerator(Class<?> type, @Cause Throwable cause); >+ >+ @Message(value = "Method named '%s' is annotated with CacheRemoveEntry but doesn't specify a cache name", id = 17005) >+ CacheException cacheRemoveEntryMethodWithoutCacheName(String methodName); >+ >+ @Message(value = "Method named '%s' is annotated with CacheRemoveAll but doesn't specify a cache name", id = 17006) >+ CacheException cacheRemoveAllMethodWithoutCacheName(String methodName); >+ >+ @Message(value = "Method named '%s' is not annotated with CacheResult, CachePut, CacheRemoveEntry or CacheRemoveAll", id = 17007) >+ IllegalArgumentException methodWithoutCacheAnnotation(String methodName); >+ >+ @Message(value = "Method named '%s' must have only one parameter annotated with @CacheValue", id = 17008) >+ CacheException cachePutMethodWithMoreThanOneCacheValueParameter(String methodName); >+ >+ @Message(value = "Method named '%s' must have at least one parameter annotated with @CacheValue", id = 17009) >+ CacheException cachePutMethodWithoutCacheValueParameter(String methodName); >+ > } >diff --git a/jcache/src/it/tck-runner/pom.xml b/jcache/src/it/tck-runner/pom.xml >index 6fe1b68..03e759f 100644 >--- a/jcache/src/it/tck-runner/pom.xml >+++ b/jcache/src/it/tck-runner/pom.xml >@@ -20,7 +20,7 @@ > > <CacheManagerImpl>org.infinispan.jcache.JCacheManager</CacheManagerImpl> > <CacheImpl>org.infinispan.jcache.JCache</CacheImpl> >- <CacheInvocationContextImpl>org.infinispan.jcache.annotation.CacheKeyInvocationContextImpl</CacheInvocationContextImpl> >+ <CacheInvocationContextImpl>org.infinispan.cdi.interceptor.CacheKeyInvocationContextImpl</CacheInvocationContextImpl> > </properties> > > <dependencies> >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCachePutInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCachePutInterceptor.java >deleted file mode 100644 >index 6bd11a7..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCachePutInterceptor.java >+++ /dev/null >@@ -1,64 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >- >-import javax.cache.Cache; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.cache.annotation.CachePut; >-import javax.cache.annotation.CacheResolver; >-import javax.cache.annotation.GeneratedCacheKey; >-import javax.interceptor.InvocationContext; >-import java.io.Serializable; >- >-/** >- * Base {@link javax.cache.annotation.CachePut} interceptor implementation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-public abstract class AbstractCachePutInterceptor implements Serializable { >- >- private final CacheResolver cacheResolver; >- private final CacheKeyInvocationContextFactory contextFactory; >- >- public AbstractCachePutInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >- this.cacheResolver = cacheResolver; >- this.contextFactory = contextFactory; >- } >- >- public Object cachePut(InvocationContext invocationContext) throws Exception { >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >- } >- >- final CacheKeyInvocationContext<CachePut> cacheKeyInvocationContext = contextFactory.getCacheKeyInvocationContext(invocationContext); >- final CacheKeyGenerator cacheKeyGenerator = cacheKeyInvocationContext.unwrap(CacheKeyInvocationContextImpl.class).getCacheKeyGenerator(); >- final CachePut cachePut = cacheKeyInvocationContext.getCacheAnnotation(); >- final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); >- final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >- >- final Object valueToCache = cacheKeyInvocationContext.getValueParameter().getValue(); >- >- if (!cachePut.afterInvocation() && valueToCache != null) { >- cache.put(cacheKey, valueToCache); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Value '%s' cached in cache '%s' with key '%s' before method invocation", valueToCache, cache.getName(), cacheKey); >- } >- } >- >- final Object result = invocationContext.proceed(); >- >- if (cachePut.afterInvocation() && valueToCache != null) { >- cache.put(cacheKey, valueToCache); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Value '%s' cached in cache '%s' with key '%s' after method invocation", valueToCache, cache.getName(), cacheKey); >- } >- } >- >- return result; >- } >- >- protected abstract Log getLog(); >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveAllInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveAllInterceptor.java >deleted file mode 100644 >index 7cef21c..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveAllInterceptor.java >+++ /dev/null >@@ -1,68 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.Cache; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.cache.annotation.CacheRemoveAll; >-import javax.cache.annotation.CacheResolver; >-import javax.cache.annotation.GeneratedCacheKey; >-import javax.interceptor.InvocationContext; >-import java.io.Serializable; >- >-/** >- * <p>{@link javax.cache.annotation.CacheRemoveAll} interceptor implementation. This interceptor uses the following algorithm describes in >- * JSR-107.</p> >- * >- * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveAll} must do the following, remove all >- * entries associated with the cache. The removeAll occurs after the method body is executed. This can be overridden by >- * specifying a afterInvocation attribute value of false. If afterInvocation is true and the annotated method throws an >- * exception, the removeAll will not happen.</p> >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-public abstract class AbstractCacheRemoveAllInterceptor implements Serializable { >- >- private static final long serialVersionUID = -8763819640664021763L; >- >- private final CacheResolver cacheResolver; >- private final CacheKeyInvocationContextFactory contextFactory; >- >- public AbstractCacheRemoveAllInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >- this.cacheResolver = cacheResolver; >- this.contextFactory = contextFactory; >- } >- >- public Object cacheRemoveAll(InvocationContext invocationContext) throws Exception { >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >- } >- >- final CacheKeyInvocationContext<CacheRemoveAll> cacheKeyInvocationContext = >- contextFactory.getCacheKeyInvocationContext(invocationContext); >- final CacheRemoveAll cacheRemoveAll = cacheKeyInvocationContext.getCacheAnnotation(); >- final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >- >- if (!cacheRemoveAll.afterInvocation()) { >- cache.clear(); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Clear cache '%s' before method invocation", cache.getName()); >- } >- } >- >- final Object result = invocationContext.proceed(); >- >- if (cacheRemoveAll.afterInvocation()) { >- cache.clear(); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Clear cache '%s' after method invocation", cache.getName()); >- } >- } >- >- return result; >- } >- >- protected abstract Log getLog(); >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveEntryInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveEntryInterceptor.java >deleted file mode 100644 >index 9bc4857..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheRemoveEntryInterceptor.java >+++ /dev/null >@@ -1,71 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >- >-import javax.cache.Cache; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.cache.annotation.CacheRemove; >-import javax.cache.annotation.CacheResolver; >-import javax.cache.annotation.GeneratedCacheKey; >-import javax.interceptor.InvocationContext; >-import java.io.Serializable; >- >-/** >- * <p>{@link javax.cache.annotation.CacheRemove} interceptor implementation.This interceptor uses the following algorithm describes in >- * JSR-107.</p> >- * >- * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveEntry} must do the following, generate a >- * key based on InvocationContext using the specified {@link javax.cache.annotation.CacheKeyGenerator}, use this key to remove the entry in the >- * cache. The remove occurs after the method body is executed. This can be overridden by specifying a afterInvocation >- * attribute value of false. If afterInvocation is true and the annotated method throws an exception the remove will not >- * happen.</p> >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-public abstract class AbstractCacheRemoveEntryInterceptor implements Serializable { >- >- private static final long serialVersionUID = -9079291622309963969L; >- >- private final CacheResolver cacheResolver; >- private final CacheKeyInvocationContextFactory contextFactory; >- >- public AbstractCacheRemoveEntryInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >- this.cacheResolver = cacheResolver; >- this.contextFactory = contextFactory; >- } >- >- public Object cacheRemoveEntry(InvocationContext invocationContext) throws Exception { >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >- } >- >- final CacheKeyInvocationContext<CacheRemove> cacheKeyInvocationContext = contextFactory.getCacheKeyInvocationContext(invocationContext); >- final CacheKeyGenerator cacheKeyGenerator = cacheKeyInvocationContext.unwrap(CacheKeyInvocationContextImpl.class).getCacheKeyGenerator(); >- final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >- final CacheRemove cacheRemoveEntry = cacheKeyInvocationContext.getCacheAnnotation(); >- final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); >- >- if (!cacheRemoveEntry.afterInvocation()) { >- cache.remove(cacheKey); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Remove entry with key '%s' in cache '%s' before method invocation", cacheKey, cache.getName()); >- } >- } >- >- final Object result = invocationContext.proceed(); >- >- if (cacheRemoveEntry.afterInvocation()) { >- cache.remove(cacheKey); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Remove entry with key '%s' in cache '%s' after method invocation", cacheKey, cache.getName()); >- } >- } >- >- return result; >- } >- >- protected abstract Log getLog(); >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheResultInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheResultInterceptor.java >deleted file mode 100644 >index e63db4e..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/AbstractCacheResultInterceptor.java >+++ /dev/null >@@ -1,82 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.Cache; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.cache.annotation.CacheResolver; >-import javax.cache.annotation.CacheResult; >-import javax.cache.annotation.GeneratedCacheKey; >-import javax.interceptor.InvocationContext; >-import java.io.Serializable; >- >-/** >- * <p>{@link javax.cache.annotation.CacheResult} interceptor implementation. This interceptor uses the following algorithm describes in >- * JSR-107.</p> >- * >- * <p>When a method annotated with {@link javax.cache.annotation.CacheResult} is invoked the following must occur. >- * <ol> >- * <li>Generate a key based on InvocationContext using the specified {@linkplain javax.cache.annotation.CacheKeyGenerator}.</li> >- * <li>Use this key to look up the entry in the cache.</li> >- * <li>If an entry is found return it as the result and do not call the annotated method.</li> >- * <li>If no entry is found invoke the method.</li> >- * <li>Use the result to populate the cache with this key/result pair.</li> >- * </ol> >- * >- * There is a skipGet attribute which if set to true will cause the method body to always be invoked and the return >- * value put into the cache. The cache is not checked for the key before method body invocation, skipping steps 2 and 3 >- * from the list above. This can be used for annotating methods that do a cache.put() with no other consequences.</p> >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-public abstract class AbstractCacheResultInterceptor implements Serializable { >- >- private static final long serialVersionUID = 5275055951121834315L; >- >- private final CacheResolver cacheResolver; >- private final CacheKeyInvocationContextFactory contextFactory; >- >- public AbstractCacheResultInterceptor(CacheResolver cacheResolver, CacheKeyInvocationContextFactory contextFactory) { >- this.cacheResolver = cacheResolver; >- this.contextFactory = contextFactory; >- } >- >- public Object cacheResult(InvocationContext invocationContext) throws Exception { >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Interception of method named '%s'", invocationContext.getMethod().getName()); >- } >- >- final CacheKeyInvocationContext<CacheResult> cacheKeyInvocationContext = contextFactory.getCacheKeyInvocationContext(invocationContext); >- final CacheKeyGenerator cacheKeyGenerator = cacheKeyInvocationContext.unwrap(CacheKeyInvocationContextImpl.class).getCacheKeyGenerator(); >- final CacheResult cacheResult = cacheKeyInvocationContext.getCacheAnnotation(); >- final GeneratedCacheKey cacheKey = cacheKeyGenerator.generateCacheKey(cacheKeyInvocationContext); >- final Cache<GeneratedCacheKey, Object> cache = cacheResolver.resolveCache(cacheKeyInvocationContext); >- >- Object result = null; >- >- if (!cacheResult.skipGet()) { >- result = cache.get(cacheKey); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Entry with value '%s' has been found in cache '%s' with key '%s'", result, cache.getName(), cacheKey); >- } >- } >- >- if (result == null) { >- result = invocationContext.proceed(); >- if (result != null) { >- cache.put(cacheKey, result); >- if (getLog().isTraceEnabled()) { >- getLog().tracef("Value '%s' cached in cache '%s' with key '%s'", result, cache.getName(), cacheKey); >- } >- } >- } >- >- return result; >- } >- >- protected abstract Log getLog(); >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/AggregatedParameterMetaData.java b/jcache/src/main/java/org/infinispan/jcache/annotation/AggregatedParameterMetaData.java >deleted file mode 100644 >index e3f5614..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/AggregatedParameterMetaData.java >+++ /dev/null >@@ -1,50 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import java.util.List; >- >-import static java.util.Collections.unmodifiableList; >- >-/** >- * Contains all parameters metadata for a method annotated with a cache annotation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-public class AggregatedParameterMetaData { >- >- private final List<ParameterMetaData> parameters; >- private final List<ParameterMetaData> keyParameters; >- private final ParameterMetaData valueParameter; >- >- public AggregatedParameterMetaData(List<ParameterMetaData> parameters, >- List<ParameterMetaData> keyParameters, >- ParameterMetaData valueParameter) { >- >- this.parameters = unmodifiableList(parameters); >- this.keyParameters = unmodifiableList(keyParameters); >- this.valueParameter = valueParameter; >- } >- >- public List<ParameterMetaData> getParameters() { >- return parameters; >- } >- >- public List<ParameterMetaData> getKeyParameters() { >- return keyParameters; >- } >- >- public ParameterMetaData getValueParameter() { >- return valueParameter; >- } >- >- @Override >- public String toString() { >- return new StringBuilder() >- .append("AggregatedParameterMetaData{") >- .append("parameters=").append(parameters) >- .append(", keyParameters=").append(keyParameters) >- .append(", valueParameter=").append(valueParameter) >- .append('}') >- .toString(); >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheInvocationParameterImpl.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheInvocationParameterImpl.java >deleted file mode 100644 >index e9b4826..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheInvocationParameterImpl.java >+++ /dev/null >@@ -1,52 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import javax.cache.annotation.CacheInvocationParameter; >-import java.lang.annotation.Annotation; >-import java.util.Set; >- >-/** >- * The {@link javax.cache.annotation.CacheInvocationParameter} implementation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-public class CacheInvocationParameterImpl implements CacheInvocationParameter { >- >- private final ParameterMetaData parameterMetaData; >- private final Object parameterValue; >- >- public CacheInvocationParameterImpl(ParameterMetaData parameterMetaData, Object parameterValue) { >- this.parameterMetaData = parameterMetaData; >- this.parameterValue = parameterValue; >- } >- >- @Override >- public Class<?> getRawType() { >- return parameterMetaData.getRawType(); >- } >- >- @Override >- public Object getValue() { >- return parameterValue; >- } >- >- @Override >- public Set<Annotation> getAnnotations() { >- return parameterMetaData.getAnnotations(); >- } >- >- @Override >- public int getParameterPosition() { >- return parameterMetaData.getPosition(); >- } >- >- @Override >- public String toString() { >- return new StringBuilder() >- .append("CacheInvocationParameterImpl{") >- .append("parameterMetaData=").append(parameterMetaData) >- .append(", parameterValue=").append(parameterValue) >- .append('}') >- .toString(); >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextFactory.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextFactory.java >deleted file mode 100644 >index 0860ad7..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextFactory.java >+++ /dev/null >@@ -1,193 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.commons.util.CollectionFactory; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CacheDefaults; >-import javax.cache.annotation.CacheKey; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.cache.annotation.CachePut; >-import javax.cache.annotation.CacheRemoveAll; >-import javax.cache.annotation.CacheRemove; >-import javax.cache.annotation.CacheResult; >-import javax.cache.annotation.CacheValue; >-import javax.enterprise.context.ApplicationScoped; >-import javax.enterprise.inject.spi.BeanManager; >-import javax.inject.Inject; >-import javax.interceptor.InvocationContext; >-import java.lang.annotation.Annotation; >-import java.lang.reflect.Method; >-import java.util.ArrayList; >-import java.util.List; >-import java.util.Set; >-import java.util.concurrent.ConcurrentMap; >- >-import static org.infinispan.jcache.annotation.CacheLookupHelper.getCacheKeyGenerator; >-import static org.infinispan.jcache.annotation.CacheLookupHelper.getCacheName; >-import static org.infinispan.jcache.annotation.CollectionsHelper.asSet; >-import static org.infinispan.jcache.annotation.Contracts.assertNotNull; >- >-/** >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-@ApplicationScoped >-public class CacheKeyInvocationContextFactory { >- >- private static final Log log = LogFactory.getLog(CacheKeyInvocationContextFactory.class, Log.class); >- >- private BeanManager beanManager; >- private ConcurrentMap<Method, MethodMetaData<? extends Annotation>> methodMetaDataCache; >- >- @Inject >- public CacheKeyInvocationContextFactory(BeanManager beanManager) { >- this.beanManager = beanManager; >- this.methodMetaDataCache = CollectionFactory.makeConcurrentMap(); >- } >- >- // for proxy. >- protected CacheKeyInvocationContextFactory() { >- } >- >- /** >- * Returns the cache key invocation context corresponding to the given invocation context. >- * >- * @param invocationContext the {@link javax.interceptor.InvocationContext}. >- * @return an instance of {@link javax.cache.annotation.CacheKeyInvocationContext} corresponding to the given {@link javax.interceptor.InvocationContext}. >- */ >- public <A extends Annotation> CacheKeyInvocationContext<A> getCacheKeyInvocationContext(InvocationContext invocationContext) { >- assertNotNull(invocationContext, "invocationContext parameter must not be null"); >- >- final MethodMetaData<A> methodMetaData = (MethodMetaData<A>) getMethodMetaData(invocationContext.getMethod()); >- return new CacheKeyInvocationContextImpl<A>(invocationContext, methodMetaData); >- } >- >- /** >- * Returns the method meta data for the given method. >- * >- * @param method the method. >- * @return an instance of {@link MethodMetaData}. >- */ >- private MethodMetaData<? extends Annotation> getMethodMetaData(Method method) { >- MethodMetaData<? extends Annotation> methodMetaData = methodMetaDataCache.get(method); >- >- if (methodMetaData == null) { >- final String cacheName; >- final Annotation cacheAnnotation; >- final AggregatedParameterMetaData aggregatedParameterMetaData; >- final CacheKeyGenerator cacheKeyGenerator; >- final CacheDefaults cacheDefaultsAnnotation = method.getDeclaringClass().getAnnotation(CacheDefaults.class); >- >- if (method.isAnnotationPresent(CacheResult.class)) { >- final CacheResult cacheResultAnnotation = method.getAnnotation(CacheResult.class); >- cacheKeyGenerator = getCacheKeyGenerator(beanManager, cacheResultAnnotation.cacheKeyGenerator(), cacheDefaultsAnnotation); >- cacheName = getCacheName(method, cacheResultAnnotation.cacheName(), cacheDefaultsAnnotation, true); >- aggregatedParameterMetaData = getAggregatedParameterMetaData(method, false); >- cacheAnnotation = cacheResultAnnotation; >- >- } else if (method.isAnnotationPresent(CacheRemove.class)) { >- final CacheRemove cacheRemoveEntryAnnotation = method.getAnnotation(CacheRemove.class); >- cacheKeyGenerator = getCacheKeyGenerator(beanManager, cacheRemoveEntryAnnotation.cacheKeyGenerator(), cacheDefaultsAnnotation); >- cacheName = getCacheName(method, cacheRemoveEntryAnnotation.cacheName(), cacheDefaultsAnnotation, false); >- aggregatedParameterMetaData = getAggregatedParameterMetaData(method, false); >- cacheAnnotation = cacheRemoveEntryAnnotation; >- >- if (cacheName.isEmpty()) { >- throw log.cacheRemoveEntryMethodWithoutCacheName(method.getName()); >- } >- >- } else if (method.isAnnotationPresent(CacheRemoveAll.class)) { >- final CacheRemoveAll cacheRemoveAllAnnotation = method.getAnnotation(CacheRemoveAll.class); >- cacheKeyGenerator = null; >- cacheName = getCacheName(method, cacheRemoveAllAnnotation.cacheName(), cacheDefaultsAnnotation, false); >- aggregatedParameterMetaData = getAggregatedParameterMetaData(method, false); >- cacheAnnotation = cacheRemoveAllAnnotation; >- >- if (cacheName.isEmpty()) { >- throw log.cacheRemoveAllMethodWithoutCacheName(method.getName()); >- } >- >- } else if (method.isAnnotationPresent(CachePut.class)) { >- final CachePut cachePutAnnotation = method.getAnnotation(CachePut.class); >- cacheKeyGenerator = getCacheKeyGenerator(beanManager, cachePutAnnotation.cacheKeyGenerator(), cacheDefaultsAnnotation); >- cacheName = getCacheName(method, cachePutAnnotation.cacheName(), cacheDefaultsAnnotation, true); >- aggregatedParameterMetaData = getAggregatedParameterMetaData(method, true); >- cacheAnnotation = cachePutAnnotation; >- >- } else { >- throw log.methodWithoutCacheAnnotation(method.getName()); >- } >- >- final MethodMetaData<? extends Annotation> newCacheMethodMetaData = new MethodMetaData<Annotation>( >- method, >- aggregatedParameterMetaData, >- asSet(method.getAnnotations()), >- cacheKeyGenerator, >- cacheAnnotation, >- cacheName >- ); >- >- methodMetaData = methodMetaDataCache.putIfAbsent(method, newCacheMethodMetaData); >- if (methodMetaData == null) { >- methodMetaData = newCacheMethodMetaData; >- } >- } >- >- return methodMetaData; >- } >- >- /** >- * Returns the aggregated parameter meta data for the given method. >- * >- * @param method the method. >- * @param cacheValueAllowed {@code true} if the {@link javax.cache.annotation.CacheValue} annotation is allowed on a method parameter. >- * @return an instance of {@link AggregatedParameterMetaData}. >- */ >- private AggregatedParameterMetaData getAggregatedParameterMetaData(Method method, boolean cacheValueAllowed) { >- final Class<?>[] parameterTypes = method.getParameterTypes(); >- final Annotation[][] parameterAnnotations = method.getParameterAnnotations(); >- final List<ParameterMetaData> parameters = new ArrayList<ParameterMetaData>(); >- final List<ParameterMetaData> keyParameters = new ArrayList<ParameterMetaData>(); >- ParameterMetaData valueParameter = null; >- >- for (int i = 0; i < parameterTypes.length; i++) { >- final Set<Annotation> annotations = asSet(parameterAnnotations[i]); >- final ParameterMetaData parameterMetaData = new ParameterMetaData(parameterTypes[i], i, annotations); >- >- for (Annotation oneAnnotation : annotations) { >- final Class<?> type = oneAnnotation.annotationType(); >- >- if (CacheKey.class.equals(type)) { >- keyParameters.add(parameterMetaData); >- >- } else if (cacheValueAllowed && CacheValue.class.equals(type)) { >- if (valueParameter != null) { >- throw log.cachePutMethodWithMoreThanOneCacheValueParameter(method.getName()); >- } >- valueParameter = parameterMetaData; >- } >- } >- >- parameters.add(parameterMetaData); >- } >- >- if (cacheValueAllowed && valueParameter == null) { >- if (parameters.size() > 1) { >- throw log.cachePutMethodWithoutCacheValueParameter(method.getName()); >- } >- valueParameter = parameters.get(0); >- } >- >- if (keyParameters.isEmpty()) { >- keyParameters.addAll(parameters); >- } >- >- if (valueParameter != null && keyParameters.size() > 1) { >- keyParameters.remove(valueParameter); >- } >- >- return new AggregatedParameterMetaData(parameters, keyParameters, valueParameter); >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextImpl.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextImpl.java >deleted file mode 100644 >index 65fbf77..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheKeyInvocationContextImpl.java >+++ /dev/null >@@ -1,123 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.commons.util.ReflectionUtil; >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CacheInvocationParameter; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.interceptor.InvocationContext; >-import java.lang.annotation.Annotation; >-import java.lang.reflect.Method; >-import java.util.List; >-import java.util.Set; >- >-import static java.util.Arrays.copyOf; >-import static java.util.Arrays.deepToString; >- >-/** >- * The {@link javax.cache.annotation.CacheKeyInvocationContext} implementation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-public class CacheKeyInvocationContextImpl<A extends Annotation> implements CacheKeyInvocationContext<A> { >- >- private static final Log log = LogFactory.getLog(CacheKeyInvocationContextImpl.class, Log.class); >- >- private final InvocationContext invocationContext; >- private final MethodMetaData<A> methodMetaData; >- private final CacheInvocationParameter[] allParameters; >- private final CacheInvocationParameter[] keyParameters; >- private final CacheInvocationParameter valueParameter; >- >- public CacheKeyInvocationContextImpl(InvocationContext invocationContext, MethodMetaData<A> methodMetaData) { >- this.invocationContext = invocationContext; >- this.methodMetaData = methodMetaData; >- >- // populate the de parameters >- final Object[] parameters = invocationContext.getParameters(); >- final List<ParameterMetaData> parametersMetaData = methodMetaData.getParameters(); >- this.allParameters = new CacheInvocationParameter[parameters.length]; >- >- for (int i = 0; i < parameters.length; i++) { >- this.allParameters[i] = new CacheInvocationParameterImpl(parametersMetaData.get(i), parameters[i]); >- } >- >- // populate the key parameters >- final List<ParameterMetaData> keyParametersMetaData = methodMetaData.getKeyParameters(); >- >- int i = 0; >- this.keyParameters = new CacheInvocationParameter[keyParametersMetaData.size()]; >- for (ParameterMetaData oneKeyParameterMetaData : keyParametersMetaData) { >- this.keyParameters[i] = allParameters[oneKeyParameterMetaData.getPosition()]; >- i++; >- } >- >- // initialize the value parameter >- final ParameterMetaData valueParameterMetaData = methodMetaData.getValueParameter(); >- this.valueParameter = valueParameterMetaData != null ? allParameters[valueParameterMetaData.getPosition()] : null; >- } >- >- @Override >- public Object getTarget() { >- return invocationContext.getTarget(); >- } >- >- @Override >- public CacheInvocationParameter[] getAllParameters() { >- return copyOf(allParameters, allParameters.length); >- } >- >- @Override >- public CacheInvocationParameter[] getKeyParameters() { >- return copyOf(keyParameters, keyParameters.length); >- } >- >- @Override >- public CacheInvocationParameter getValueParameter() { >- return valueParameter; >- } >- >- @Override >- public <T> T unwrap(Class<T> clazz) { >- return ReflectionUtil.unwrap(this, clazz); >- } >- >- @Override >- public Method getMethod() { >- return methodMetaData.getMethod(); >- } >- >- @Override >- public Set<Annotation> getAnnotations() { >- return methodMetaData.getAnnotations(); >- } >- >- @Override >- public A getCacheAnnotation() { >- return methodMetaData.getCacheAnnotation(); >- } >- >- @Override >- public String getCacheName() { >- return methodMetaData.getCacheName(); >- } >- >- public CacheKeyGenerator getCacheKeyGenerator() { >- return methodMetaData.getCacheKeyGenerator(); >- } >- >- @Override >- public String toString() { >- return new StringBuilder() >- .append("CacheKeyInvocationContextImpl{") >- .append("invocationContext=").append(invocationContext) >- .append(", methodMetaData=").append(methodMetaData) >- .append(", allParameters=").append(deepToString(allParameters)) >- .append(", keyParameters=").append(deepToString(keyParameters)) >- .append(", valueParameter=").append(valueParameter) >- .append('}') >- .toString(); >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheLookupHelper.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheLookupHelper.java >deleted file mode 100644 >index 7bd3172..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheLookupHelper.java >+++ /dev/null >@@ -1,123 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CacheDefaults; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.enterprise.context.spi.CreationalContext; >-import javax.enterprise.inject.spi.Bean; >-import javax.enterprise.inject.spi.BeanManager; >-import java.lang.reflect.Method; >-import java.util.Set; >- >-import static org.infinispan.jcache.annotation.Contracts.assertNotNull; >- >-/** >- * An helper class providing useful methods for cache lookup. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-public final class CacheLookupHelper { >- >- private static final Log log = LogFactory.getLog(CacheLookupHelper.class, Log.class); >- >- /** >- * Disable instantiation. >- */ >- private CacheLookupHelper() { >- } >- >- /** >- * Resolves the cache name of a method annotated with a JCACHE annotation. >- * >- * @param method the annotated method. >- * @param methodCacheName the cache name defined on the JCACHE annotation. >- * @param cacheDefaultsAnnotation the {@link javax.cache.annotation.CacheDefaults} annotation instance. >- * @param generate {@code true} if the default cache name has to be returned if none is specified. >- * @return the resolved cache name. >- * @throws NullPointerException if method or methodCacheName parameter is {@code null}. >- */ >- public static String getCacheName(Method method, String methodCacheName, CacheDefaults cacheDefaultsAnnotation, boolean generate) { >- assertNotNull(method, "method parameter must not be null"); >- assertNotNull(methodCacheName, "methodCacheName parameter must not be null"); >- >- String cacheName = methodCacheName.trim(); >- >- if (cacheName.isEmpty() && cacheDefaultsAnnotation != null) { >- cacheName = cacheDefaultsAnnotation.cacheName().trim(); >- } >- >- if (cacheName.isEmpty() && generate) { >- cacheName = getDefaultMethodCacheName(method); >- } >- >- return cacheName; >- } >- >- /** >- * Resolves and creates an instance of {@link javax.cache.annotation.CacheKeyGenerator}. To resolve the cache key generator class the >- * algorithm defined in JCACHE specification is used. >- * >- * @param beanManager the bean manager instance. >- * @param methodCacheKeyGeneratorClass the {@link javax.cache.annotation.CacheKeyGenerator} class declared in the cache annotation. >- * @param cacheDefaultsAnnotation the {@link javax.cache.annotation.CacheDefaults} annotation instance. >- * @return the {@link javax.cache.annotation.CacheKeyGenerator} instance. >- * @throws NullPointerException if beanManager parameter is {@code null}. >- */ >- public static CacheKeyGenerator getCacheKeyGenerator(BeanManager beanManager, Class<? extends CacheKeyGenerator> methodCacheKeyGeneratorClass, CacheDefaults cacheDefaultsAnnotation) { >- assertNotNull(beanManager, "beanManager parameter must not be null"); >- >- Class<? extends CacheKeyGenerator> cacheKeyGeneratorClass = DefaultCacheKeyGenerator.class; >- if (!CacheKeyGenerator.class.equals(methodCacheKeyGeneratorClass)) { >- cacheKeyGeneratorClass = methodCacheKeyGeneratorClass; >- } else if (cacheDefaultsAnnotation != null && !CacheKeyGenerator.class.equals(cacheDefaultsAnnotation.cacheKeyGenerator())) { >- cacheKeyGeneratorClass = cacheDefaultsAnnotation.cacheKeyGenerator(); >- } >- >- final CreationalContext<?> creationalContext = beanManager.createCreationalContext(null); >- final Set<Bean<?>> beans = beanManager.getBeans(cacheKeyGeneratorClass); >- if (!beans.isEmpty()) { >- final Bean<?> bean = beanManager.resolve(beans); >- return (CacheKeyGenerator) beanManager.getReference(bean, CacheKeyGenerator.class, creationalContext); >- } >- >- // the CacheKeyGenerator implementation is not managed by CDI >- try { >- >- return cacheKeyGeneratorClass.newInstance(); >- >- } catch (InstantiationException e) { >- throw log.unableToInstantiateCacheKeyGenerator(cacheKeyGeneratorClass, e); >- } catch (IllegalAccessException e) { >- throw log.unableToInstantiateCacheKeyGenerator(cacheKeyGeneratorClass, e); >- } >- } >- >- /** >- * Returns the default cache name associated to the given method according to JSR-107. >- * >- * @param method the method. >- * @return the default cache name for the given method. >- */ >- private static String getDefaultMethodCacheName(Method method) { >- int i = 0; >- int nbParameters = method.getParameterTypes().length; >- >- StringBuilder cacheName = new StringBuilder() >- .append(method.getDeclaringClass().getName()) >- .append(".") >- .append(method.getName()) >- .append("("); >- >- for (Class<?> oneParameterType : method.getParameterTypes()) { >- cacheName.append(oneParameterType.getName()); >- if (i < (nbParameters - 1)) { >- cacheName.append(","); >- } >- i++; >- } >- >- return cacheName.append(")").toString(); >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CachePutInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CachePutInterceptor.java >deleted file mode 100644 >index 494e285..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CachePutInterceptor.java >+++ /dev/null >@@ -1,40 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CachePut; >-import javax.inject.Inject; >-import javax.interceptor.AroundInvoke; >-import javax.interceptor.Interceptor; >-import javax.interceptor.InvocationContext; >- >-/** >- * {@link javax.cache.annotation.CachePut} interceptor implementation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-@Interceptor >-@CachePut >-public class CachePutInterceptor extends AbstractCachePutInterceptor { >- >- private static final Log log = LogFactory.getLog(CachePutInterceptor.class, Log.class); >- >- @Inject >- public CachePutInterceptor(DefaultCacheResolver cacheResolver, >- CacheKeyInvocationContextFactory contextFactory) { >- super(cacheResolver, contextFactory); >- } >- >- @AroundInvoke >- public Object cachePut(InvocationContext invocationContext) throws Exception { >- return super.cachePut(invocationContext); >- } >- >- @Override >- protected Log getLog() { >- return log; >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveAllInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveAllInterceptor.java >deleted file mode 100644 >index e0c0ada..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveAllInterceptor.java >+++ /dev/null >@@ -1,45 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CacheRemoveAll; >-import javax.inject.Inject; >-import javax.interceptor.AroundInvoke; >-import javax.interceptor.Interceptor; >-import javax.interceptor.InvocationContext; >- >-/** >- * <p>{@link javax.cache.annotation.CacheRemoveAll} interceptor implementation. This interceptor uses the following algorithm describes in >- * JSR-107.</p> >- * >- * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveAll} must do the following, remove all >- * entries associated with the cache. The removeAll occurs after the method body is executed. This can be overridden by >- * specifying a afterInvocation attribute value of false. If afterInvocation is true and the annotated method throws an >- * exception, the removeAll will not happen.</p> >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-@Interceptor >-@CacheRemoveAll >-public class CacheRemoveAllInterceptor extends AbstractCacheRemoveAllInterceptor { >- >- private static final Log log = LogFactory.getLog(CacheRemoveAllInterceptor.class, Log.class); >- >- @Inject >- public CacheRemoveAllInterceptor(DefaultCacheResolver cacheResolver, >- CacheKeyInvocationContextFactory contextFactory) { >- super(cacheResolver, contextFactory); >- } >- >- @AroundInvoke >- public Object cacheRemoveAll(InvocationContext invocationContext) throws Exception { >- return super.cacheRemoveAll(invocationContext); >- } >- >- @Override >- protected Log getLog() { >- return log; >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveEntryInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveEntryInterceptor.java >deleted file mode 100644 >index 0001d00..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheRemoveEntryInterceptor.java >+++ /dev/null >@@ -1,48 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CacheRemove; >-import javax.inject.Inject; >-import javax.interceptor.AroundInvoke; >-import javax.interceptor.Interceptor; >-import javax.interceptor.InvocationContext; >- >-/** >- * <p>{@link javax.cache.annotation.CacheRemove} interceptor implementation.This interceptor uses the following algorithm describes in >- * JSR-107.</p> >- * >- * <p>The interceptor that intercepts method annotated with {@code @CacheRemoveEntry} must do the following, generate a >- * key based on InvocationContext using the specified {@link javax.cache.annotation.CacheKeyGenerator}, use this key to remove the entry in the >- * cache. The remove occurs after the method body is executed. This can be overridden by specifying a afterInvocation >- * attribute value of false. If afterInvocation is true and the annotated method throws an exception the remove will not >- * happen.</p> >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-@Interceptor >-@CacheRemove >-public class CacheRemoveEntryInterceptor extends AbstractCacheRemoveEntryInterceptor { >- >- private static final Log log = LogFactory.getLog(CacheRemoveEntryInterceptor.class, Log.class); >- >- @Inject >- public CacheRemoveEntryInterceptor(DefaultCacheResolver cacheResolver, >- CacheKeyInvocationContextFactory contextFactory) { >- super(cacheResolver, contextFactory); >- } >- >- @Override >- @AroundInvoke >- public Object cacheRemoveEntry(InvocationContext invocationContext) throws Exception { >- return super.cacheRemoveEntry(invocationContext); >- } >- >- @Override >- protected Log getLog() { >- return log; >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheResultInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CacheResultInterceptor.java >deleted file mode 100644 >index 3008c0d..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CacheResultInterceptor.java >+++ /dev/null >@@ -1,55 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import org.infinispan.jcache.logging.Log; >-import org.infinispan.util.logging.LogFactory; >- >-import javax.cache.annotation.CacheResult; >-import javax.inject.Inject; >-import javax.interceptor.AroundInvoke; >-import javax.interceptor.Interceptor; >-import javax.interceptor.InvocationContext; >- >-/** >- * <p>{@link javax.cache.annotation.CacheResult} interceptor implementation. This interceptor uses the following algorithm describes in >- * JSR-107.</p> >- * >- * <p>When a method annotated with {@link javax.cache.annotation.CacheResult} is invoked the following must occur. >- * <ol> >- * <li>Generate a key based on InvocationContext using the specified {@linkplain javax.cache.annotation.CacheKeyGenerator}.</li> >- * <li>Use this key to look up the entry in the cache.</li> >- * <li>If an entry is found return it as the result and do not call the annotated method.</li> >- * <li>If no entry is found invoke the method.</li> >- * <li>Use the result to populate the cache with this key/result pair.</li> >- * </ol> >- * >- * There is a skipGet attribute which if set to true will cause the method body to always be invoked and the return >- * value put into the cache. The cache is not checked for the key before method body invocation, skipping steps 2 and 3 >- * from the list above. This can be used for annotating methods that do a cache.put() with no other consequences.</p> >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-@Interceptor >-@CacheResult >-public class CacheResultInterceptor extends AbstractCacheResultInterceptor { >- >- private static final long serialVersionUID = 5275055951121834315L; >- private static final Log log = LogFactory.getLog(CacheResultInterceptor.class, Log.class); >- >- @Inject >- public CacheResultInterceptor(DefaultCacheResolver cacheResolver, >- CacheKeyInvocationContextFactory contextFactory) { >- super(cacheResolver, contextFactory); >- } >- >- @AroundInvoke >- public Object cacheResult(InvocationContext invocationContext) throws Exception { >- return super.cacheResult(invocationContext); >- } >- >- @Override >- protected Log getLog() { >- return log; >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/CollectionsHelper.java b/jcache/src/main/java/org/infinispan/jcache/annotation/CollectionsHelper.java >deleted file mode 100644 >index aac293d..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/CollectionsHelper.java >+++ /dev/null >@@ -1,34 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import java.util.LinkedHashSet; >-import java.util.Set; >- >-import static java.util.Collections.addAll; >- >-/** >- * An helper class providing useful methods to work with JDK collections. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-public final class CollectionsHelper { >- /** >- * Disable instantiation. >- */ >- private CollectionsHelper() { >- } >- >- /** >- * Creates a {@link java.util.Set} with the given elements. >- * >- * @param elements the elements. >- * @param <T> the element type. >- * @return a new {@link java.util.Set} instance containing the given elements. >- * @throws NullPointerException if parameter elements is {@code null}. >- */ >- public static <T> Set<T> asSet(T... elements) { >- final Set<T> resultSet = new LinkedHashSet<T>(); >- addAll(resultSet, elements); >- >- return resultSet; >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKey.java b/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKey.java >deleted file mode 100644 >index 449a3df..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKey.java >+++ /dev/null >@@ -1,50 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import javax.cache.annotation.GeneratedCacheKey; >- >-import static java.util.Arrays.*; >- >-/** >- * Default {@link javax.cache.annotation.GeneratedCacheKey} implementation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-public class DefaultCacheKey implements GeneratedCacheKey { >- >- private static final long serialVersionUID = 4410523928649671768L; >- >- private final Object[] parameters; >- private final int hashCode; >- >- public DefaultCacheKey(Object[] parameters) { >- this.parameters = parameters; >- this.hashCode = deepHashCode(parameters); >- } >- >- @Override >- public boolean equals(Object o) { >- if (this == o) return true; >- if (o == null || getClass() != o.getClass()) return false; >- >- DefaultCacheKey that = (DefaultCacheKey) o; >- >- return deepEquals(parameters, that.parameters); >- } >- >- @Override >- public int hashCode() { >- return this.hashCode; >- } >- >- @Override >- public String toString() { >- return new StringBuilder() >- .append("DefaultCacheKey{") >- .append("parameters=").append(parameters == null ? null : deepToString(parameters)) >- .append(", hashCode=").append(hashCode) >- .append('}') >- .toString(); >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKeyGenerator.java b/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKeyGenerator.java >deleted file mode 100644 >index f0c710f..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheKeyGenerator.java >+++ /dev/null >@@ -1,37 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import javax.cache.annotation.CacheInvocationParameter; >-import javax.cache.annotation.CacheKeyGenerator; >-import javax.cache.annotation.CacheKeyInvocationContext; >-import javax.cache.annotation.GeneratedCacheKey; >-import javax.enterprise.context.ApplicationScoped; >-import java.lang.annotation.Annotation; >- >-import static org.infinispan.jcache.annotation.Contracts.assertNotNull; >- >-/** >- * Default {@link javax.cache.annotation.CacheKeyGenerator} implementation. >- * By default all key parameters of the intercepted method compose the >- * {@link javax.cache.annotation.CacheKey}. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-@ApplicationScoped >-public class DefaultCacheKeyGenerator implements CacheKeyGenerator { >- >- @Override >- public GeneratedCacheKey generateCacheKey(CacheKeyInvocationContext<? extends Annotation> cacheKeyInvocationContext) { >- assertNotNull(cacheKeyInvocationContext, "cacheKeyInvocationContext parameter must not be null"); >- >- final CacheInvocationParameter[] keyParameters = cacheKeyInvocationContext.getKeyParameters(); >- final Object[] keyValues = new Object[keyParameters.length]; >- >- for (int i = 0 ; i < keyParameters.length ; i++) { >- keyValues[i] = keyParameters[i].getValue(); >- } >- >- return new DefaultCacheKey(keyValues); >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheResolver.java b/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheResolver.java >deleted file mode 100644 >index 504e414..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/DefaultCacheResolver.java >+++ /dev/null >@@ -1,57 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import javax.cache.Cache; >-import javax.cache.CacheManager; >-import javax.cache.Caching; >-import javax.cache.annotation.CacheInvocationContext; >-import javax.cache.annotation.CacheResolver; >-import javax.cache.spi.CachingProvider; >-import javax.enterprise.context.ApplicationScoped; >-import java.lang.annotation.Annotation; >- >-import static org.infinispan.jcache.annotation.Contracts.assertNotNull; >- >-/** >- * Default {@link javax.cache.annotation.CacheResolver} implementation for >- * standalone environments, where no Cache/CacheManagers are injected via CDI. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- * @author Galder Zamarreño >- */ >-@ApplicationScoped >-public class DefaultCacheResolver implements CacheResolver { >- >- private CacheManager defaultCacheManager; >- >- // Created by proxy >- @SuppressWarnings("unused") >- DefaultCacheResolver() { >- CachingProvider provider = Caching.getCachingProvider(); >- defaultCacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()); >- } >- >- @Override >- public <K, V> Cache<K, V> resolveCache(CacheInvocationContext<? extends Annotation> cacheInvocationContext) { >- assertNotNull(cacheInvocationContext, "cacheInvocationContext parameter must not be null"); >- >- final String cacheName = cacheInvocationContext.getCacheName(); >- >- // If cache name is empty, default cache of default cache manager is returned >- if (cacheName.trim().isEmpty()) { >- return defaultCacheManager.createCache(cacheName, >- new javax.cache.configuration.MutableConfiguration<K, V>()); >- } >- >- for (String name : defaultCacheManager.getCacheNames()) { >- if (name.equals(cacheName)) >- return defaultCacheManager.getCache(cacheName); >- } >- >- // If the cache has not been defined in the default cache manager or >- // in a specific one a new cache is created in the default cache manager >- // with the default configuration. >- return defaultCacheManager.createCache(cacheName, >- new javax.cache.configuration.MutableConfiguration<K, V>()); >- } >- >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCachePutInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCachePutInterceptor.java >index 352ce69..7cef321 100644 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCachePutInterceptor.java >+++ b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCachePutInterceptor.java >@@ -1,6 +1,7 @@ > package org.infinispan.jcache.annotation; > >-import org.infinispan.cdi.InfinispanExtension; >+import org.infinispan.cdi.interceptor.AbstractCachePutInterceptor; >+import org.infinispan.cdi.interceptor.CacheKeyInvocationContextFactory; > import org.infinispan.jcache.logging.Log; > import org.infinispan.util.logging.LogFactory; > >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveAllInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveAllInterceptor.java >index c2e082b..0a7e2d4 100644 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveAllInterceptor.java >+++ b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveAllInterceptor.java >@@ -1,5 +1,7 @@ > package org.infinispan.jcache.annotation; > >+import org.infinispan.cdi.interceptor.AbstractCacheRemoveAllInterceptor; >+import org.infinispan.cdi.interceptor.CacheKeyInvocationContextFactory; > import org.infinispan.jcache.logging.Log; > import org.infinispan.util.logging.LogFactory; > >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveEntryInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveEntryInterceptor.java >index 61cd689..71c32b8 100644 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveEntryInterceptor.java >+++ b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheRemoveEntryInterceptor.java >@@ -1,5 +1,7 @@ > package org.infinispan.jcache.annotation; > >+import org.infinispan.cdi.interceptor.AbstractCacheRemoveEntryInterceptor; >+import org.infinispan.cdi.interceptor.CacheKeyInvocationContextFactory; > import org.infinispan.jcache.logging.Log; > import org.infinispan.util.logging.LogFactory; > >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheResultInterceptor.java b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheResultInterceptor.java >index 928625e..ee9079d 100644 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheResultInterceptor.java >+++ b/jcache/src/main/java/org/infinispan/jcache/annotation/InjectedCacheResultInterceptor.java >@@ -1,5 +1,7 @@ > package org.infinispan.jcache.annotation; > >+import org.infinispan.cdi.interceptor.AbstractCacheResultInterceptor; >+import org.infinispan.cdi.interceptor.CacheKeyInvocationContextFactory; > import org.infinispan.jcache.logging.Log; > import org.infinispan.util.logging.LogFactory; > >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/MethodMetaData.java b/jcache/src/main/java/org/infinispan/jcache/annotation/MethodMetaData.java >deleted file mode 100644 >index 83e98cc..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/MethodMetaData.java >+++ /dev/null >@@ -1,85 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import javax.cache.annotation.CacheKeyGenerator; >-import java.lang.annotation.Annotation; >-import java.lang.reflect.Method; >-import java.util.List; >-import java.util.Set; >- >-import static java.util.Collections.unmodifiableSet; >- >-/** >- * Metadata associated to a method annotated with a cache annotation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-public class MethodMetaData<A extends Annotation> { >- >- private final Method method; >- private final Set<Annotation> annotations; >- private final A cacheAnnotation; >- private final String cacheName; >- private final AggregatedParameterMetaData aggregatedParameterMetaData; >- private final CacheKeyGenerator cacheKeyGenerator; >- >- public MethodMetaData(Method method, >- AggregatedParameterMetaData aggregatedParameterMetaData, >- Set<Annotation> annotations, >- CacheKeyGenerator cacheKeyGenerator, >- A cacheAnnotation, >- String cacheName) { >- >- this.method = method; >- this.aggregatedParameterMetaData = aggregatedParameterMetaData; >- this.annotations = unmodifiableSet(annotations); >- this.cacheKeyGenerator = cacheKeyGenerator; >- this.cacheAnnotation = cacheAnnotation; >- this.cacheName = cacheName; >- } >- >- public Method getMethod() { >- return method; >- } >- >- public Set<Annotation> getAnnotations() { >- return annotations; >- } >- >- public A getCacheAnnotation() { >- return cacheAnnotation; >- } >- >- public String getCacheName() { >- return cacheName; >- } >- >- public CacheKeyGenerator getCacheKeyGenerator() { >- return cacheKeyGenerator; >- } >- >- public List<ParameterMetaData> getParameters() { >- return aggregatedParameterMetaData.getParameters(); >- } >- >- public List<ParameterMetaData> getKeyParameters() { >- return aggregatedParameterMetaData.getKeyParameters(); >- } >- >- public ParameterMetaData getValueParameter() { >- return aggregatedParameterMetaData.getValueParameter(); >- } >- >- @Override >- public String toString() { >- return new StringBuilder() >- .append("MethodMetaData{") >- .append("method=").append(method) >- .append(", annotations=").append(annotations) >- .append(", cacheAnnotation=").append(cacheAnnotation) >- .append(", cacheName='").append(cacheName).append('\'') >- .append(", aggregatedParameterMetaData=").append(aggregatedParameterMetaData) >- .append(", cacheKeyGenerator=").append(cacheKeyGenerator) >- .append('}') >- .toString(); >- } >-} >diff --git a/jcache/src/main/java/org/infinispan/jcache/annotation/ParameterMetaData.java b/jcache/src/main/java/org/infinispan/jcache/annotation/ParameterMetaData.java >deleted file mode 100644 >index e311021..0000000 >--- a/jcache/src/main/java/org/infinispan/jcache/annotation/ParameterMetaData.java >+++ /dev/null >@@ -1,51 +0,0 @@ >-package org.infinispan.jcache.annotation; >- >-import java.lang.annotation.Annotation; >-import java.lang.reflect.Type; >-import java.util.Set; >- >-import static java.util.Collections.unmodifiableSet; >- >-/** >- * Contains the metadata for a parameter of a method annotated with A JCACHE annotation. >- * >- * @author Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI >- */ >-public class ParameterMetaData { >- >- private final Type baseType; >- private final Class<?> rawType; >- private final int position; >- private final Set<Annotation> annotations; >- >- public ParameterMetaData(Class<?> type, int position, Set<Annotation> annotations) { >- this.baseType = type.getGenericSuperclass(); >- this.rawType = type; >- this.position = position; >- this.annotations = unmodifiableSet(annotations); >- } >- >- public Class<?> getRawType() { >- return rawType; >- } >- >- public int getPosition() { >- return position; >- } >- >- public Set<Annotation> getAnnotations() { >- return annotations; >- } >- >- @Override >- public String toString() { >- return new StringBuilder() >- .append("ParameterMetaData{") >- .append("baseType=").append(baseType) >- .append(", rawType=").append(rawType) >- .append(", position=").append(position) >- .append(", annotations=").append(annotations) >- .append('}') >- .toString(); >- } >-} >diff --git a/jcache/src/main/resources/META-INF/beans.xml b/jcache/src/main/resources/META-INF/beans.xml >index a0c6e21..0415342 100644 >--- a/jcache/src/main/resources/META-INF/beans.xml >+++ b/jcache/src/main/resources/META-INF/beans.xml >@@ -4,10 +4,10 @@ > xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> > > <interceptors> >- <class>org.infinispan.jcache.annotation.CacheResultInterceptor</class> >- <class>org.infinispan.jcache.annotation.CachePutInterceptor</class> >- <class>org.infinispan.jcache.annotation.CacheRemoveEntryInterceptor</class> >- <class>org.infinispan.jcache.annotation.CacheRemoveAllInterceptor</class> >+ <class>org.infinispan.cdi.interceptor.CacheResultInterceptor</class> >+ <class>org.infinispan.cdi.interceptor.CachePutInterceptor</class> >+ <class>org.infinispan.cdi.interceptor.CacheRemoveEntryInterceptor</class> >+ <class>org.infinispan.cdi.interceptor.CacheRemoveAllInterceptor</class> > </interceptors> > > </beans> >diff --git a/server/integration/testsuite/pom.xml b/server/integration/testsuite/pom.xml >index 57fdbc3..960b1aa 100644 >--- a/server/integration/testsuite/pom.xml >+++ b/server/integration/testsuite/pom.xml >@@ -119,17 +119,6 @@ > <groupId>org.apache.directory.server</groupId> > <artifactId>apacheds-all</artifactId> > <scope>test</scope> >- </dependency> >- <dependency> >- <groupId>org.infinispan</groupId> >- <artifactId>infinispan-security-integrationtests</artifactId> >- <classifier>tests</classifier> >- <scope>test</scope> >- </dependency> >- <dependency> >- <groupId>org.apache.directory.server</groupId> >- <artifactId>apacheds-all</artifactId> >- <scope>test</scope> > </dependency> > <dependency> > <groupId>org.iq80.leveldb</groupId> >-- >1.8.5.2 (Apple Git-48) >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1119780
: 918772