Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
../../../../../img/srcFileCovDistChart9.png 84% of files have more coverage
12   152   6   2
0   69   0.5   6
6     1  
1    
35.7% of code in this file is excluded from these metrics.
 
  HibernateDaoFactory       Line # 34 12 35.7% 6 3 83.3% 0.8333333
 
  (10)
 
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 toggle public static HibernateDaoFactory
47    getInstance()
48    {
49  20 return INSTANCE;
50    }
51   
52    //------------------------------------------------------------------------
53    /**
54    * {@inheritDoc}
55    */
 
56  5 toggle @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 toggle @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 toggle 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 toggle 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 toggle @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    }