|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HibernateCurrentSessionStrategy | Line # 44 | 12 | 10% | 8 | 0 | 100% |
1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (14) | |||
| Result | |||
|
1.0
|
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao
|
1 PASS | |
|
0.8333333
|
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.TestHibernateGenericDao.testDelete
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete
|
1 PASS | |
|
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount
|
1 PASS | |
|
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate
|
1 PASS | |
|
0.44444445
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByName
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByName
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByExample
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByExample
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindById
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindById
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample
|
1 PASS | |
|
0.33333334
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByAge
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByAge
|
1 PASS | |
|
0.33333334
|
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 | // HibernateCurrentSessionStrategy.java Copyright (c) 2009 | |
| 5 | // Giovanni Azua Garcia 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 org.apache.commons.lang.*; | |
| 24 | import org.hibernate.*; | |
| 25 | import org.hibernate.cfg.*; | |
| 26 | import org.perfectjpattern.core.api.structural.adapter.*; | |
| 27 | import org.perfectjpattern.jee.api.integration.dao.*; | |
| 28 | ||
| 29 | /** | |
| 30 | * Concrete simple implementation of {@link ISessionStrategy} corresponding to | |
| 31 | * {@link SessionFactory#getCurrentSession()} | |
| 32 | * <br/> | |
| 33 | * <br/> | |
| 34 | * This strategy is mandated by the Hibernate configuration value specified in | |
| 35 | * property <code>current_session_context_class</code> e.g. <code>thread</code> | |
| 36 | * value will default to using {@link org.hibernate.context. | |
| 37 | * ThreadLocalSessionContext} which is the default and preferred method in | |
| 38 | * Java SE environments. | |
| 39 | * | |
| 40 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
| 41 | * @version $Revision: 1.0 $Date: Feb 8, 2009 5:24:51 PM $ | |
| 42 | */ | |
| 43 | public final | |
| 44 | class HibernateCurrentSessionStrategy | |
| 45 | implements ISessionStrategy | |
| 46 | { | |
| 47 | //------------------------------------------------------------------------ | |
| 48 | // public | |
| 49 | //------------------------------------------------------------------------ | |
| 50 | 6 |
public |
| 51 | HibernateCurrentSessionStrategy() | |
| 52 | { | |
| 53 | 6 | try |
| 54 | { | |
| 55 | 6 | Configuration myConfiguration = new Configuration(); |
| 56 | 6 | myConfiguration.configure(); |
| 57 | ||
| 58 | 6 | theSessionFactory = myConfiguration.buildSessionFactory(); |
| 59 | } | |
| 60 | // CHECKSTYLE:OFF | |
| 61 | catch (Throwable anException) | |
| 62 | // CHECKSTYLE:ON | |
| 63 | { | |
| 64 | throw new DaoException(anException); | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | //------------------------------------------------------------------------ | |
| 69 | 2 |
public |
| 70 | HibernateCurrentSessionStrategy(SessionFactory aSessionFactory) | |
| 71 | { | |
| 72 | 2 | Validate.notNull(aSessionFactory, "'aSessionFactory' must not be null"); |
| 73 | ||
| 74 | 2 | theSessionFactory = aSessionFactory; |
| 75 | } | |
| 76 | ||
| 77 | //------------------------------------------------------------------------ | |
| 78 | /** | |
| 79 | * {@inheritDoc} | |
| 80 | */ | |
| 81 | 3 |
public void |
| 82 | shutdown() | |
| 83 | { | |
| 84 | 3 | theSessionFactory.close(); |
| 85 | } | |
| 86 | ||
| 87 | //------------------------------------------------------------------------ | |
| 88 | /** | |
| 89 | * {@inheritDoc} | |
| 90 | */ | |
| 91 | 110 |
public ISession |
| 92 | getSession() | |
| 93 | { | |
| 94 | 110 | try |
| 95 | { | |
| 96 | 110 | Session mySession = theSessionFactory.getCurrentSession(); |
| 97 | ||
| 98 | 110 | if (theSessionAdapter == null || theSessionAdapter.getAdaptee() |
| 99 | != mySession) | |
| 100 | { | |
| 101 | 11 | theSessionAdapter = new HibernateSessionAdapter(mySession); |
| 102 | } | |
| 103 | ||
| 104 | 110 | return theSessionAdapter.getTarget(); |
| 105 | } | |
| 106 | catch (HibernateException anException) | |
| 107 | { | |
| 108 | throw new DaoException(anException); | |
| 109 | } | |
| 110 | } | |
| 111 | ||
| 112 | //------------------------------------------------------------------------ | |
| 113 | // members | |
| 114 | //------------------------------------------------------------------------ | |
| 115 | private final SessionFactory theSessionFactory; | |
| 116 | private IAdapter<ISession, Session> theSessionAdapter; | |
| 117 | } | |
|
||||||||||||