|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EntityManagerAdapter | Line # 39 | 12 | 13% | 9 | 3 | 85% |
0.85
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(9) | |||
Result | |||
0.65
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testUpdate
![]() |
1 PASS | |
0.55
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testContains
![]() |
1 PASS | |
0.55
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testCreate
![]() |
1 PASS | |
0.4
|
org.perfectjpattern.jee.integration.dao.jpa.TestExample.testJpaCmpGenericDao
![]() |
1 PASS | |
0.4
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testDelete
![]() |
1 PASS | |
0.4
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testFindById
![]() |
1 PASS | |
0.4
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testFindAll
![]() |
1 PASS | |
0.4
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testCount
![]() |
1 PASS | |
0.1
|
org.perfectjpattern.jee.integration.dao.TestJpaManagedSessionStrategy.testGetSession
![]() |
1 PASS | |
1 | //---------------------------------------------------------------------- | |
2 | // | |
3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
4 | // EntityManagerAdapter.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.lang.reflect.*; | |
24 | ||
25 | import javax.persistence.*; | |
26 | ||
27 | import org.perfectjpattern.core.api.structural.adapter.*; | |
28 | import org.perfectjpattern.core.structural.adapter.*; | |
29 | import org.perfectjpattern.jee.api.integration.dao.*; | |
30 | ||
31 | /** | |
32 | * Adapts JPA's {@link EntityManager} to the JPA implementation-free | |
33 | * PerfectJPattern's {@link ISession} definition | |
34 | * | |
35 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
36 | * @version $Revision: 1.0 $Date: Feb 10, 2009 8:26:06 PM $ | |
37 | */ | |
38 | public final | |
39 | class EntityManagerAdapter | |
40 | extends Adapter<ISession, EntityManager> | |
41 | { | |
42 | //------------------------------------------------------------------------ | |
43 | // public | |
44 | //------------------------------------------------------------------------ | |
45 | /** | |
46 | * Constructs a {@link EntityManagerAdapter} from the Adaptee | |
47 | * {@link EntityManager} instance | |
48 | * | |
49 | * @param anAdaptee The Adaptee {@link EntityManager} | |
50 | * @throws IllegalArgumentException 'anAdaptee' must not be null | |
51 | */ | |
52 | 4 |
![]() |
53 | EntityManagerAdapter(EntityManager anAdaptee) | |
54 | throws IllegalArgumentException | |
55 | { | |
56 | 4 | super(ISession.class, anAdaptee); |
57 | } | |
58 | ||
59 | //------------------------------------------------------------------------ | |
60 | // protected | |
61 | //------------------------------------------------------------------------ | |
62 | /** | |
63 | * {@inheritDoc} | |
64 | */ | |
65 | 15 |
![]() |
66 | protected Object | |
67 | invokeUnderlying(Method aMethod, Object[] anArguments) | |
68 | throws Throwable | |
69 | { | |
70 | 15 | try |
71 | { | |
72 | 15 | return super.invokeUnderlying(aMethod, anArguments); |
73 | } | |
74 | // CHECKSTYLE:OFF | |
75 | catch (Throwable anException) | |
76 | // CHECKSTYLE:ON | |
77 | { | |
78 | // make sure that Exceptions are properly chained | |
79 | throw new DaoException(anException); | |
80 | } | |
81 | } | |
82 | ||
83 | //------------------------------------------------------------------------ | |
84 | 1 |
![]() |
85 | update(Object anObject) | |
86 | { | |
87 | // approximation to update in JPA | |
88 | 1 | getUnderlying().merge(anObject); |
89 | } | |
90 | ||
91 | //------------------------------------------------------------------------ | |
92 | 15 |
![]() |
93 | createQuery(String aSqlString) | |
94 | { | |
95 | // adapts the Query | |
96 | 15 | IQuery myQuery = new JpaQueryAdapter(getUnderlying().createQuery( |
97 | aSqlString)).getTarget(); | |
98 | ||
99 | 15 | return myQuery; |
100 | } | |
101 | ||
102 | //------------------------------------------------------------------------ | |
103 | 0 |
![]() |
104 | createNativeQuery(String aSqlString, Class<?> aPersistentClass) | |
105 | { | |
106 | // adapts the Query | |
107 | 0 | IQuery myQuery = new JpaQueryAdapter(getUnderlying(). |
108 | createNativeQuery(aSqlString, aPersistentClass)).getTarget(); | |
109 | ||
110 | 0 | return myQuery; |
111 | } | |
112 | ||
113 | //------------------------------------------------------------------------ | |
114 | 30 |
![]() |
115 | getTransaction() | |
116 | { | |
117 | // adapts the EntityTransaction | |
118 | 30 | EntityTransaction myAdaptee = getUnderlying().getTransaction(); |
119 | ||
120 | 30 | if (theTransactionAdapter == null || theTransactionAdapter. |
121 | getAdaptee() != myAdaptee) | |
122 | { | |
123 | 1 | theTransactionAdapter = new EntityTransactionAdapter(myAdaptee); |
124 | } | |
125 | ||
126 | assert theTransactionAdapter != null : | |
127 | "Transaction Adapter must not be null"; | |
128 | ||
129 | 30 | return theTransactionAdapter.getTarget(); |
130 | } | |
131 | ||
132 | //------------------------------------------------------------------------ | |
133 | // members | |
134 | //------------------------------------------------------------------------ | |
135 | private IAdapter<ITransaction, EntityTransaction> theTransactionAdapter; | |
136 | } |
|