Return-Path: X-Original-To: apmail-deltaspike-commits-archive@www.apache.org Delivered-To: apmail-deltaspike-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A58B8178ED for ; Fri, 13 Feb 2015 15:49:58 +0000 (UTC) Received: (qmail 84276 invoked by uid 500); 13 Feb 2015 15:49:58 -0000 Delivered-To: apmail-deltaspike-commits-archive@deltaspike.apache.org Received: (qmail 84236 invoked by uid 500); 13 Feb 2015 15:49:58 -0000 Mailing-List: contact commits-help@deltaspike.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltaspike.apache.org Delivered-To: mailing list commits@deltaspike.apache.org Received: (qmail 84227 invoked by uid 99); 13 Feb 2015 15:49:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2015 15:49:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3827DE0540; Fri, 13 Feb 2015 15:49:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tandraschko@apache.org To: commits@deltaspike.apache.org Date: Fri, 13 Feb 2015 15:49:59 -0000 Message-Id: In-Reply-To: <7a5b39aa6be34469badbd6339138bf11@git.apache.org> References: <7a5b39aa6be34469badbd6339138bf11@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] deltaspike git commit: DELTASPIKE-823 Reimplement Partial-Bean module - Documentation 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 Authored: Fri Feb 13 16:47:43 2015 +0100 Committer: tandraschko 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.