|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
HibernateDaoFactory | Line # 34 | 12 | 35.7% | 6 | 3 | 83.3% |
0.8333333
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(10) | |||
Result | |||
0.6666667
|
org.perfectjpattern.jee.integration.dao.hibernate.TestExample.testHibernateGenericDao org.perfectjpattern.jee.integration.dao.hibernate.TestExample.testHibernateGenericDao | 1 PASS | |
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains | 1 PASS | |
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample | 1 PASS | |
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll | 1 PASS | |
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById | 1 PASS | |
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount | 1 PASS | |
0.2777778
|
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao | 1 PASS | |
0.2777778
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete | 1 PASS | |
0.2777778
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate | 1 PASS | |
0.2777778
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testCreate org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testCreate | 1 PASS | |
1 | //---------------------------------------------------------------------- | |
2 | // | |
3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
4 | // HibernateDaoFactory.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.io.*; | |
24 | ||
25 | import org.perfectjpattern.jee.api.integration.dao.*; | |
26 | ||
27 | /** | |
28 | * Concrete implementation for {@link IGenericDaoFactory} | |
29 | * | |
30 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
31 | * @version $ $Date: Dec 5, 2008 5:11:45 PM $ | |
32 | */ | |
33 | public | |
34 | class HibernateDaoFactory | |
35 | extends AbstractDaoFactory | |
36 | implements IGenericDaoFactory | |
37 | { | |
38 | //------------------------------------------------------------------------ | |
39 | // public | |
40 | //------------------------------------------------------------------------ | |
41 | /** | |
42 | * Returns Singleton instance of {@link HibernateDaoFactory} | |
43 | * | |
44 | * @return Singleton instance of {@link HibernateDaoFactory} | |
45 | */ | |
46 | 20 | public static HibernateDaoFactory |
47 | getInstance() | |
48 | { | |
49 | 20 | return INSTANCE; |
50 | } | |
51 | ||
52 | //------------------------------------------------------------------------ | |
53 | /** | |
54 | * {@inheritDoc} | |
55 | */ | |
56 | 5 | @Override |
57 | public <Id extends Serializable, Element> IGenericReadOnlyDao<Id, Element> | |
58 | createReadOnlyDao(Class<Element> aPersistentClass) | |
59 | throws IllegalArgumentException | |
60 | { | |
61 | 5 | IGenericReadOnlyDao<Id, Element> myGenericReadOnlyDao = createDao( |
62 | aPersistentClass); | |
63 | ||
64 | assert myGenericReadOnlyDao != null : | |
65 | "myGenericReadOnlyDao must not be null"; | |
66 | ||
67 | 5 | return myGenericReadOnlyDao; |
68 | } | |
69 | ||
70 | //------------------------------------------------------------------------ | |
71 | /** | |
72 | * {@inheritDoc} | |
73 | */ | |
74 | 19 | @SuppressWarnings("unchecked") |
75 | @Override | |
76 | public <Id extends Serializable, Element> IGenericDao<Id, Element> | |
77 | createDao(Class<Element> aPersistentClass) | |
78 | throws IllegalArgumentException | |
79 | { | |
80 | 19 | IGenericDao<Id, Element> myGenericDao = (IGenericDao<Id, Element>) |
81 | super.createDao(aPersistentClass); | |
82 | ||
83 | assert myGenericDao != null : "myGenericDao must not be null"; | |
84 | ||
85 | 19 | return myGenericDao; |
86 | } | |
87 | ||
88 | //------------------------------------------------------------------------ | |
89 | // protected | |
90 | //------------------------------------------------------------------------ | |
91 | /** | |
92 | * Constructs {@link HibernateDaoFactory} to consume Session instances | |
93 | * from the given {@link ISessionStrategy} and Transaction instances from | |
94 | * the {@link ITransactionStrategy} | |
95 | * | |
96 | * @param aSessionStrategy {@link ISessionStrategy} to consume | |
97 | * Session instances from | |
98 | * @param aTransactionStrategy {@link ITransactionStrategy} to | |
99 | * consume Transaction instances from | |
100 | * @throws IllegalArgumentException 'aDaoSessionStrategy' must not be null | |
101 | * @throws IllegalArgumentException 'aDaoTransactionStrategy' must not | |
102 | * be null | |
103 | */ | |
104 | 0 | protected |
105 | HibernateDaoFactory(ISessionStrategy aSessionStrategy, | |
106 | ITransactionStrategy aTransactionStrategy) | |
107 | throws IllegalArgumentException | |
108 | { | |
109 | 0 | setDaoSessionStrategy(aSessionStrategy); |
110 | 0 | setDaoTransactionStrategy(aTransactionStrategy); |
111 | } | |
112 | ||
113 | //------------------------------------------------------------------------ | |
114 | /** | |
115 | * Defaults to JSE mode | |
116 | */ | |
117 | 5 | protected |
118 | HibernateDaoFactory() | |
119 | { | |
120 | 5 | ISessionStrategy myDaoSessionStrategy = |
121 | new HibernateCurrentSessionStrategy(); | |
122 | 5 | ITransactionStrategy myDaoTransactionStrategy = |
123 | new HibernateConfiguredTransactionStrategy(myDaoSessionStrategy); | |
124 | ||
125 | 5 | setDaoSessionStrategy(myDaoSessionStrategy); |
126 | 5 | setDaoTransactionStrategy(myDaoTransactionStrategy); |
127 | } | |
128 | ||
129 | //------------------------------------------------------------------------ | |
130 | // protected | |
131 | //------------------------------------------------------------------------ | |
132 | 3 | @Override |
133 | protected <Id extends Serializable, Element> IGenericDao<Id, Element> | |
134 | createDao(Class<Element> aPersistentClass, | |
135 | ISessionStrategy aSessionStrategy, | |
136 | ITransactionStrategy aTransactionStrategy) | |
137 | { | |
138 | assert aPersistentClass != null : "'aPersistentClass' must not be null"; | |
139 | assert aSessionStrategy != null : "'aSessionStrategy' must not be null"; | |
140 | assert aTransactionStrategy != null : | |
141 | "'aTransactionStrategy' must not be null"; | |
142 | ||
143 | 3 | return new HibernateGenericDao<Id, Element>(aPersistentClass, |
144 | aSessionStrategy, aTransactionStrategy); | |
145 | } | |
146 | ||
147 | //------------------------------------------------------------------------ | |
148 | // members | |
149 | //------------------------------------------------------------------------ | |
150 | private static final HibernateDaoFactory INSTANCE = | |
151 | new HibernateDaoFactory(); | |
152 | } |
|