|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FinderIntroductionInterceptor | Line # 40 | 12 | 0% | 5 | 3 | 82.4% |
0.8235294
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(5) | |||
Result | |||
0.8235294
|
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao | 1 PASS | |
0.64705884
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByName org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByName | 1 PASS | |
0.64705884
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByAge org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByAge | 1 PASS | |
0.47058824
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByExample org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByExample | 1 PASS | |
0.47058824
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindById org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindById | 1 PASS | |
1 | //---------------------------------------------------------------------- | |
2 | // | |
3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
4 | // FinderIntroductionInterceptor.java Copyright (c) 2009 Giovanni Azua Garcia | |
5 | // bravegag@hotmail.com | |
6 | // | |
7 | // This program is free software; you can redistribute it and/or | |
8 | // modify it under the terms of the GNU General Public License | |
9 | // as published by the Free Software Foundation; either version 3 | |
10 | // of the License, or (at your option) any later version. | |
11 | // | |
12 | // This program is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
17 | // You should have received a copy of the GNU General Public License | |
18 | // along with this program; if not, see <http://www.gnu.org/licenses/>. | |
19 | // | |
20 | //---------------------------------------------------------------------- | |
21 | package org.perfectjpattern.jee.integration.dao; | |
22 | ||
23 | import java.util.SortedSet; | |
24 | import java.util.TreeSet; | |
25 | ||
26 | import org.aopalliance.intercept.MethodInvocation; | |
27 | import org.perfectjpattern.jee.api.integration.dao.*; | |
28 | import org.springframework.aop.IntroductionInterceptor; | |
29 | ||
30 | ||
31 | /** | |
32 | * Concrete implementation of {@link IntroductionInterceptor} that connects | |
33 | * Spring AOP with the Hibernate's based generic DAO. For any method | |
34 | * beginning with <code>findBy</code> this interceptor will use the | |
35 | * {@link IFinderExecutor} to call the corresponding Hibernate named query | |
36 | * | |
37 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
38 | * @version $ $Date: Nov 6, 2008 1:53:25 PM $ | |
39 | */ | |
40 | class FinderIntroductionInterceptor<Element> | |
41 | implements IntroductionInterceptor | |
42 | { | |
43 | //------------------------------------------------------------------------ | |
44 | // public | |
45 | //------------------------------------------------------------------------ | |
46 | /** | |
47 | * {@inheritDoc} | |
48 | */ | |
49 | 23 | @SuppressWarnings("unchecked") |
50 | public Object | |
51 | invoke(MethodInvocation anArgument) throws Throwable | |
52 | { | |
53 | 23 | IFinderExecutor<Element> myExecutor = (IFinderExecutor<Element>) |
54 | anArgument.getThis(); | |
55 | ||
56 | 23 | Object myResults = null; |
57 | ||
58 | 23 | String myMethodName = anArgument.getMethod().getName(); |
59 | 23 | if (myMethodName.startsWith("findBy") && !EXCLUDE_METHODS.contains( |
60 | myMethodName)) | |
61 | { | |
62 | 3 | Object[] myArguments = anArgument.getArguments(); |
63 | ||
64 | 3 | myResults = myExecutor.execute(anArgument.getMethod(), myArguments); |
65 | } | |
66 | else | |
67 | { | |
68 | 20 | myResults = anArgument.proceed(); |
69 | } | |
70 | ||
71 | 23 | return myResults; |
72 | } | |
73 | ||
74 | //------------------------------------------------------------------------ | |
75 | /** | |
76 | * {@inheritDoc} | |
77 | */ | |
78 | 0 | @SuppressWarnings("unchecked") |
79 | public boolean | |
80 | implementsInterface(Class anInterface) | |
81 | { | |
82 | 0 | boolean myResult = anInterface.isInterface() && IFinderExecutor.class. |
83 | isAssignableFrom(anInterface); | |
84 | ||
85 | 0 | return myResult; |
86 | } | |
87 | ||
88 | //------------------------------------------------------------------------ | |
89 | // members | |
90 | //------------------------------------------------------------------------ | |
91 | private static final SortedSet<String> EXCLUDE_METHODS = | |
92 | new TreeSet<String>(); | |
93 | ||
94 | //------------------------------------------------------------------------ | |
95 | // static initializers | |
96 | //------------------------------------------------------------------------ | |
97 | 2 | static |
98 | { | |
99 | 2 | EXCLUDE_METHODS.add("findById"); |
100 | 2 | EXCLUDE_METHODS.add("findByExample"); |
101 | } | |
102 | } |
|