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 972DE1047C for ; Sat, 19 Apr 2014 17:21:11 +0000 (UTC) Received: (qmail 28370 invoked by uid 500); 19 Apr 2014 17:21:11 -0000 Delivered-To: apmail-deltaspike-commits-archive@deltaspike.apache.org Received: (qmail 28344 invoked by uid 500); 19 Apr 2014 17:21:10 -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 28337 invoked by uid 99); 19 Apr 2014 17:21:10 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Apr 2014 17:21:10 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 613989901A3; Sat, 19 Apr 2014 17:21:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gpetracek@apache.org To: commits@deltaspike.apache.org Message-Id: <9bdcdca3aa6c4aa6bb4b61842143a99c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: DELTASPIKE-579 AnnotationUtils Date: Sat, 19 Apr 2014 17:21:10 +0000 (UTC) Repository: deltaspike Updated Branches: refs/heads/master cd518d880 -> 4f217a0bf DELTASPIKE-579 AnnotationUtils Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/4f217a0b Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/4f217a0b Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/4f217a0b Branch: refs/heads/master Commit: 4f217a0bff420f119d8584efc50444445d1433a6 Parents: cd518d8 Author: gpetracek Authored: Sat Apr 19 19:19:49 2014 +0200 Committer: gpetracek Committed: Sat Apr 19 19:19:49 2014 +0200 ---------------------------------------------------------------------- .../deltaspike/core/util/AnnotationUtils.java | 78 ++++++++++++++++++++ .../transaction/TransactionStrategyHelper.java | 41 +--------- 2 files changed, 81 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4f217a0b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java new file mode 100644 index 0000000..49267a7 --- /dev/null +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AnnotationUtils.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.deltaspike.core.util; + +import javax.enterprise.inject.Typed; +import javax.enterprise.inject.spi.BeanManager; +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +@Typed() +public abstract class AnnotationUtils +{ + private AnnotationUtils() + { + // prevent instantiation + } + + public static T extractAnnotationFromMethodOrClass( + BeanManager beanManager, Method targetMethod, Class targetAnnotationType) + { + T result = extractAnnotationFromMethod(beanManager, targetMethod, targetAnnotationType); + + if (result == null) + { + //see DELTASPIKE-517 + Class targetClass = ProxyUtils.getUnproxiedClass(targetMethod.getDeclaringClass()); + + // and if not found search on the class + result = findAnnotation(beanManager, targetClass.getAnnotations(), targetAnnotationType); + } + return result; + } + + public static T extractAnnotationFromMethod( + BeanManager beanManager, Method targetMethod, Class targetAnnotationType) + { + return findAnnotation(beanManager, targetMethod.getAnnotations(), targetAnnotationType); + } + + public static T findAnnotation( + BeanManager beanManager, Annotation[] annotations, Class targetAnnotationType) + { + for (Annotation annotation : annotations) + { + if (targetAnnotationType.equals(annotation.annotationType())) + { + return (T) annotation; + } + if (beanManager.isStereotype(annotation.annotationType())) + { + T result = findAnnotation( + beanManager, annotation.annotationType().getAnnotations(), targetAnnotationType); + if (result != null) + { + return result; + } + } + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/4f217a0b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/TransactionStrategyHelper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/TransactionStrategyHelper.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/TransactionStrategyHelper.java index 9025139..c6ec253 100644 --- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/TransactionStrategyHelper.java +++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/TransactionStrategyHelper.java @@ -18,7 +18,7 @@ */ package org.apache.deltaspike.jpa.impl.transaction; -import org.apache.deltaspike.core.util.ProxyUtils; +import org.apache.deltaspike.core.util.AnnotationUtils; import org.apache.deltaspike.jpa.api.transaction.Transactional; import javax.enterprise.context.Dependent; @@ -154,42 +154,7 @@ public class TransactionStrategyHelper implements Serializable */ protected Transactional extractTransactionalAnnotation(InvocationContext context) { - // try to detect the interceptor on the method - Transactional transactionalAnnotation = extractTransactionalAnnotation(context.getMethod().getAnnotations()); - - if (transactionalAnnotation == null) - { - Class targetClass = ProxyUtils.getUnproxiedClass(context.getTarget().getClass()); //see DELTASPIKE-517 - - // and if not found search on the class - transactionalAnnotation = extractTransactionalAnnotation(targetClass.getAnnotations()); - } - return transactionalAnnotation; - } - - /** - * @return a @Transactional annotation extracted from the list of given annotations - * or null if none present. - */ - private Transactional extractTransactionalAnnotation(Annotation[] annotations) - { - for (Annotation annotation : annotations) - { - if (Transactional.class.equals(annotation.annotationType())) - { - return (Transactional) annotation; - } - if (beanManager.isStereotype(annotation.annotationType())) - { - Transactional transactionalAnnotation = - extractTransactionalAnnotation(annotation.annotationType().getAnnotations()); - if (transactionalAnnotation != null) - { - return transactionalAnnotation; - } - } - } - - return null; + return AnnotationUtils + .extractAnnotationFromMethodOrClass(this.beanManager, context.getMethod(), Transactional.class); } }