DELTASPIKE-823 Reimplement Partial-Bean module - Documentation

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/f7944066
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/f7944066
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/f7944066

Branch: refs/heads/master
Commit: f79440661d98edf502cd63b3386b8ff4e75770cb
Parents: 0f99663
Author: tandraschko <[email protected]>
Authored: Fri Feb 13 16:47:43 2015 +0100
Committer: tandraschko <[email protected]>
Committed: Fri Feb 13 16:47:43 2015 +0100

----------------------------------------------------------------------
 .../src/main/asciidoc/partial-bean.adoc         | 54 +++++++++++++++++---
 1 file changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f7944066/documentation/src/main/asciidoc/partial-bean.adoc
----------------------------------------------------------------------
diff --git a/documentation/src/main/asciidoc/partial-bean.adoc 
b/documentation/src/main/asciidoc/partial-bean.adoc
index 97467d0..5f449e8 100644
--- a/documentation/src/main/asciidoc/partial-bean.adoc
+++ b/documentation/src/main/asciidoc/partial-bean.adoc
@@ -32,7 +32,8 @@ Add the Partial-Bean module to the list of dependencies in 
the project `pom.xml`
 
 == Use the Module Features
 
-IMPORTANT: Currently CDI Interceptors cannot be used for partial-beans.
+IMPORTANT: Currently CDI Interceptors can only by applied to beans which will 
be registred via the PartialBeanProvider.
+
 
 === @PartialBeanBinding
 
@@ -45,20 +46,25 @@ interface (/abstract class) to generic handler binding.
 [source,java]
 
-------------------------------------------------------------------------------------
 @PartialBeanBinding
-
 @Retention(RUNTIME)
 @Target(TYPE)
 public @interface MyPartialBeanBinding {}
+-------------------------------------------------------------------------------------
 
-@MyPartialBeanBinding
+[source,java]
+-------------------------------------------------------------------------------------
 //scope is optional
+@MyPartialBeanBinding
 public interface PartialBean
 {
     String getValue();
 }
+-------------------------------------------------------------------------------------
 
+[source,java]
+-------------------------------------------------------------------------------------
+//scope is optional
 @MyPartialBeanBinding
-@Dependent
 public class MyPartialBeanHandler implements 
java.lang.reflect.InvocationHandler
 {
     public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable
@@ -68,5 +74,41 @@ public class MyPartialBeanHandler implements 
java.lang.reflect.InvocationHandler
 }
 
-------------------------------------------------------------------------------------
 
-Using an abstract class as partial-bean requires javassist as an
-additional dependency and allows to implement some methods manually.
+
+=== PartialBeanProvider
+
+Due the CDI nature, to support CDI Interceptors, we need to register the 
partial beans in BeforeBeanDiscovery as a completely new AnnotatedType.
+
+This is possible if you provide a PartialBeanProvider via the ServiceLoader 
approach.
+
+The following example shows how to enable your repositories to support 
interceptors like @Transactional:
+
+
+[source,java]
+-------------------------------------------------------------------------------------
+package de.test;
+
+public class RepositoryPartialBeanProvider extends AbstractPartialBeanProvider
+{
+    public RepositoryPartialBeanProvider()
+    {
+               PartialBeanBuilder partialBeanBuilder = new PartialBeanBuilder(
+                       org.apache.deltaspike.data.api.Repository.class,
+                       
org.apache.deltaspike.data.impl.handler.QueryHandler.class);
+               partialBeanBuilder.addClasses(UserRepository.class, 
CompanyRepository.class, CountryRepository.class);
+        add(partialBeanBuilder);
+    }
+}
+-------------------------------------------------------------------------------------
+
+
+Config file 
`#META-INF/services/org.apache.deltaspike.partialbean.spi.PartialBeanProvider`:
+
+[source]
+-------------------------------------------------------------------------------------
+de.test.RepositoryPartialBeanProvider
+-------------------------------------------------------------------------------------
+
+Custom implementations might use a classpath scanner like xbeans-finder, 
scannotations, reflections.
+
+We didn't found an completely portable way, therefore we didn't include it 
directly in DeltaSpike.

Reply via email to