|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AbstractDaoFactory | Line # 38 | 21 | 16.2% | 8 | 2 | 93.5% |
0.9354839
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (17) | |||
| Result | |||
|
0.7096774
|
org.perfectjpattern.jee.integration.dao.hibernate.TestExample.testHibernateGenericDao
org.perfectjpattern.jee.integration.dao.hibernate.TestExample.testHibernateGenericDao
|
1 PASS | |
|
0.41935483
|
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao
|
1 PASS | |
|
0.41935483
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testContains
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testContains
|
1 PASS | |
|
0.41935483
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testFindAll
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testFindAll
|
1 PASS | |
|
0.41935483
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testCount
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testCount
|
1 PASS | |
|
0.41935483
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testFindById
org.perfectjpattern.jee.integration.dao.TestJpaGenericReadOnlyDao.testFindById
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testDelete
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testDelete
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testCreate
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testCreate
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testUpdate
org.perfectjpattern.jee.integration.dao.TestJpaGenericDao.testUpdate
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate
|
1 PASS | |
|
0.2580645
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample
|
1 PASS | |
|
0.2580645
|
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 | // AbstractDaoFactory.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 | import java.util.*; | |
| 25 | ||
| 26 | import org.apache.commons.lang.*; | |
| 27 | import org.perfectjpattern.core.api.creational.singleton.*; | |
| 28 | import org.perfectjpattern.jee.api.integration.dao.*; | |
| 29 | ||
| 30 | /** | |
| 31 | * Abstract reusable base partial implementation for {@link IBaseDaoFactory} | |
| 32 | * concrete implementations | |
| 33 | * | |
| 34 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
| 35 | * @version $Revision: 1.0 $Date: Feb 19, 2009 12:16:49 PM $ | |
| 36 | */ | |
| 37 | public abstract | |
| 38 | class AbstractDaoFactory | |
| 39 | implements IBaseDaoFactory, ISingleton | |
| 40 | { | |
| 41 | //------------------------------------------------------------------------ | |
| 42 | // public | |
| 43 | //------------------------------------------------------------------------ | |
| 44 | /** | |
| 45 | * {@inheritDoc} | |
| 46 | */ | |
| 47 | 5 |
public void |
| 48 | setDaoSessionStrategy(ISessionStrategy aSessionStrategy) | |
| 49 | throws IllegalArgumentException | |
| 50 | { | |
| 51 | 5 | Validate.notNull(aSessionStrategy, |
| 52 | "'aDaoSessionStrategy' must not be null"); | |
| 53 | ||
| 54 | // shutdown existing | |
| 55 | 5 | if (theSessionStrategy != null) |
| 56 | { | |
| 57 | 0 | shutdown(); |
| 58 | } | |
| 59 | ||
| 60 | 5 | theSessionStrategy = aSessionStrategy; |
| 61 | } | |
| 62 | ||
| 63 | //------------------------------------------------------------------------ | |
| 64 | /** | |
| 65 | * {@inheritDoc} | |
| 66 | */ | |
| 67 | 5 |
public void |
| 68 | setDaoTransactionStrategy(ITransactionStrategy aTransactionStrategy) | |
| 69 | throws IllegalArgumentException | |
| 70 | { | |
| 71 | 5 | Validate.notNull(aTransactionStrategy, |
| 72 | "'aTransactionFactory' must not be null"); | |
| 73 | ||
| 74 | 5 | theTransactionStrategy = aTransactionStrategy; |
| 75 | } | |
| 76 | ||
| 77 | //------------------------------------------------------------------------ | |
| 78 | /** | |
| 79 | * {@inheritDoc} | |
| 80 | */ | |
| 81 | 3 |
public void |
| 82 | shutdown() | |
| 83 | throws DaoException | |
| 84 | { | |
| 85 | assert theSessionStrategy != null : | |
| 86 | "'theSessionStrategy' must not be null"; | |
| 87 | ||
| 88 | 3 | theSessionStrategy.shutdown(); |
| 89 | ||
| 90 | 3 | theSessionStrategy = null; |
| 91 | } | |
| 92 | ||
| 93 | //------------------------------------------------------------------------ | |
| 94 | /** | |
| 95 | * {@inheritDoc} | |
| 96 | */ | |
| 97 | 4 |
@SuppressWarnings("unchecked") |
| 98 | public <Id extends Serializable, Element> IBaseReadOnlyDao<Id, Element> | |
| 99 | createReadOnlyDao(Class<Element> aPersistentClass) | |
| 100 | throws IllegalArgumentException | |
| 101 | { | |
| 102 | 4 | Validate.notNull(aPersistentClass, |
| 103 | "'aPersistentClass' must not be null"); | |
| 104 | 4 | Validate.isTrue(!aPersistentClass.isInterface(), |
| 105 | "'aPersistentClass' must be a class type"); | |
| 106 | ||
| 107 | 4 | IBaseReadOnlyDao<Id, Element> myBaseReadOnlyDao = createDao( |
| 108 | aPersistentClass); | |
| 109 | ||
| 110 | assert myBaseReadOnlyDao != null : | |
| 111 | "myBaseReadOnlyDao must not be null"; | |
| 112 | ||
| 113 | 4 | return myBaseReadOnlyDao; |
| 114 | } | |
| 115 | ||
| 116 | //------------------------------------------------------------------------ | |
| 117 | /** | |
| 118 | * {@inheritDoc} | |
| 119 | */ | |
| 120 | 33 |
@SuppressWarnings("unchecked") |
| 121 | public <Id extends Serializable, Element> IBaseDao<Id, Element> | |
| 122 | createDao(Class<Element> aPersistentClass) | |
| 123 | throws IllegalArgumentException | |
| 124 | { | |
| 125 | 33 | Validate.notNull(aPersistentClass, |
| 126 | "'aPersistentClass' must not be null"); | |
| 127 | 33 | Validate.isTrue(!aPersistentClass.getClass().isInterface(), |
| 128 | "'aPersistentClass' must be a class type"); | |
| 129 | ||
| 130 | 33 | IBaseDao<Id, Element> myBaseDao = null; |
| 131 | ||
| 132 | 33 | if (theBaseDaoMap.containsKey(aPersistentClass)) |
| 133 | { | |
| 134 | // just reuse the existing instance | |
| 135 | 29 | myBaseDao = (IBaseDao<Id, Element>) theBaseDaoMap.get( |
| 136 | aPersistentClass); | |
| 137 | } | |
| 138 | else | |
| 139 | { | |
| 140 | // create new instance and make it available for future calls | |
| 141 | 4 | myBaseDao = createDao(aPersistentClass, |
| 142 | theSessionStrategy, theTransactionStrategy); | |
| 143 | 4 | theBaseDaoMap.put(aPersistentClass, myBaseDao); |
| 144 | } | |
| 145 | ||
| 146 | assert myBaseDao != null : "myBaseDao must not be null"; | |
| 147 | ||
| 148 | 33 | return myBaseDao; |
| 149 | } | |
| 150 | ||
| 151 | //------------------------------------------------------------------------ | |
| 152 | // protected | |
| 153 | //------------------------------------------------------------------------ | |
| 154 | 4 |
protected |
| 155 | AbstractDaoFactory() | |
| 156 | { | |
| 157 | 4 | theBaseDaoMap = new HashMap<Class<?>, IBaseDao<?, ?>>(); |
| 158 | } | |
| 159 | ||
| 160 | //------------------------------------------------------------------------ | |
| 161 | protected abstract <Id extends Serializable, Element> IBaseDao<Id, Element> | |
| 162 | createDao(Class<Element> aPersistentClass, | |
| 163 | ISessionStrategy aSessionStrategy, | |
| 164 | ITransactionStrategy aTransactionStrategy); | |
| 165 | ||
| 166 | //------------------------------------------------------------------------ | |
| 167 | // members | |
| 168 | //------------------------------------------------------------------------ | |
| 169 | private ISessionStrategy theSessionStrategy; | |
| 170 | private ITransactionStrategy theTransactionStrategy; | |
| 171 | private final Map<Class<?>, IBaseDao<?, ?>> theBaseDaoMap; | |
| 172 | } | |
|
||||||||||||