|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HibernateSessionAdapter | Line # 39 | 17 | 9.4% | 13 | 3 | 89.7% |
0.8965517
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (14) | |||
| Result | |||
|
0.6551724
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testDelete
|
1 PASS | |
|
0.6551724
|
org.perfectjpattern.jee.integration.dao.hibernate.TestExample.testHibernateGenericDao
org.perfectjpattern.jee.integration.dao.hibernate.TestExample.testHibernateGenericDao
|
1 PASS | |
|
0.51724136
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testUpdate
|
1 PASS | |
|
0.44827586
|
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao
org.perfectjpattern.jee.integration.dao.spring.TestExample.testSpringGenericDao
|
1 PASS | |
|
0.44827586
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByName
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByName
|
1 PASS | |
|
0.37931034
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testContains
|
1 PASS | |
|
0.37931034
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testCount
|
1 PASS | |
|
0.3448276
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindById
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindById
|
1 PASS | |
|
0.31034482
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByExample
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByExample
|
1 PASS | |
|
0.31034482
|
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByAge
org.perfectjpattern.jee.integration.dao.TestSpringGenericDao.testFindByAge
|
1 PASS | |
|
0.31034482
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testCreate
org.perfectjpattern.jee.integration.dao.TestHibernateGenericDao.testCreate
|
1 PASS | |
|
0.27586207
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindAll
|
1 PASS | |
|
0.27586207
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindById
|
1 PASS | |
|
0.2413793
|
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample
org.perfectjpattern.jee.integration.dao.TestHibernateGenericReadOnlyDao.testFindByExample
|
1 PASS | |
| 1 | //---------------------------------------------------------------------- | |
| 2 | // | |
| 3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
| 4 | // HibernateSessionAdapter.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.lang.reflect.*; | |
| 25 | ||
| 26 | import org.hibernate.*; | |
| 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 Hibernate's {@link Session} 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 HibernateSessionAdapter | |
| 40 | extends Adapter<ISession, Session> | |
| 41 | { | |
| 42 | //------------------------------------------------------------------------ | |
| 43 | // public | |
| 44 | //------------------------------------------------------------------------ | |
| 45 | /** | |
| 46 | * Constructs a {@link HibernateSessionAdapter} from the Adaptee | |
| 47 | * {@link Session} instance | |
| 48 | * | |
| 49 | * @param anAdaptee Adaptee Hibernate Transaction | |
| 50 | * @throws IllegalArgumentException | |
| 51 | */ | |
| 52 | 11 |
public |
| 53 | HibernateSessionAdapter(Session anAdaptee) | |
| 54 | throws IllegalArgumentException | |
| 55 | { | |
| 56 | 11 | super(ISession.class, anAdaptee); |
| 57 | } | |
| 58 | ||
| 59 | //------------------------------------------------------------------------ | |
| 60 | // protected | |
| 61 | //------------------------------------------------------------------------ | |
| 62 | /** | |
| 63 | * {@inheritDoc} | |
| 64 | */ | |
| 65 | 3 |
@Override |
| 66 | protected Object | |
| 67 | invokeUnderlying(Method aMethod, Object[] anArguments) | |
| 68 | throws Throwable | |
| 69 | { | |
| 70 | 3 | try |
| 71 | { | |
| 72 | 3 | 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 | 59 |
public ITransaction |
| 85 | getTransaction() | |
| 86 | { | |
| 87 | 59 | Transaction myAdaptee = getUnderlying().getTransaction(); |
| 88 | ||
| 89 | 59 | if (theTransactionAdapter == null || theTransactionAdapter. |
| 90 | getAdaptee() != myAdaptee) | |
| 91 | { | |
| 92 | 11 | theTransactionAdapter = new HibernateTransactionAdapter(myAdaptee); |
| 93 | } | |
| 94 | ||
| 95 | 59 | return theTransactionAdapter.getTarget(); |
| 96 | } | |
| 97 | ||
| 98 | //------------------------------------------------------------------------ | |
| 99 | 3 |
@SuppressWarnings("unchecked") |
| 100 | public <E> E | |
| 101 | find(Class<E> aPersistentClass, Object anId) | |
| 102 | { | |
| 103 | assert anId instanceof Serializable : "'anId' must be Serializable"; | |
| 104 | ||
| 105 | 3 | E myElement = (E) getUnderlying().load(aPersistentClass, |
| 106 | (Serializable) anId); | |
| 107 | ||
| 108 | 3 | return myElement; |
| 109 | } | |
| 110 | ||
| 111 | //------------------------------------------------------------------------ | |
| 112 | 9 |
public Session |
| 113 | getDelegate() | |
| 114 | { | |
| 115 | 9 | return getUnderlying(); |
| 116 | } | |
| 117 | ||
| 118 | //------------------------------------------------------------------------ | |
| 119 | 14 |
public IQuery |
| 120 | createQuery(String aSqlString) | |
| 121 | { | |
| 122 | 14 | IQuery myQuery = new HibernateQueryAdapter(getUnderlying().createQuery( |
| 123 | aSqlString)).getTarget(); | |
| 124 | ||
| 125 | 14 | return myQuery; |
| 126 | } | |
| 127 | ||
| 128 | //------------------------------------------------------------------------ | |
| 129 | 0 |
public IQuery |
| 130 | createNativeQuery(String aSqlString, Class<?> aPersistentClass) | |
| 131 | { | |
| 132 | 0 | IQuery myQuery = new HibernateQueryAdapter(getUnderlying(). |
| 133 | createSQLQuery(aSqlString)).getTarget(); | |
| 134 | ||
| 135 | 0 | return myQuery; |
| 136 | } | |
| 137 | ||
| 138 | //------------------------------------------------------------------------ | |
| 139 | 1 |
public void |
| 140 | remove(Object anObject) | |
| 141 | { | |
| 142 | 1 | getUnderlying().delete(anObject); |
| 143 | } | |
| 144 | ||
| 145 | //------------------------------------------------------------------------ | |
| 146 | 3 |
public void |
| 147 | update(Object anObject) | |
| 148 | { | |
| 149 | 3 | getUnderlying().saveOrUpdate(anObject); |
| 150 | } | |
| 151 | ||
| 152 | //------------------------------------------------------------------------ | |
| 153 | 18 |
@SuppressWarnings("unchecked") |
| 154 | public <Id> Id | |
| 155 | persist(Object anObject) | |
| 156 | { | |
| 157 | 18 | return (Id) getUnderlying().save(anObject); |
| 158 | } | |
| 159 | ||
| 160 | //------------------------------------------------------------------------ | |
| 161 | // members | |
| 162 | //------------------------------------------------------------------------ | |
| 163 | private IAdapter<ITransaction, Transaction> theTransactionAdapter; | |
| 164 | } | |
|
||||||||||||