Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
24   128   4   12
0   53   0.17   2
2     2  
1    
 
  Example       Line # 42 24 0% 4 0 100% 1.0
 
  (1)
 
1    //----------------------------------------------------------------------
2   
3    //PerfectJPattern: "Design patterns are good but components are better!"
4    //Example.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    //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20    //MA 02110-1301, USA.
21   
22    //----------------------------------------------------------------------
23    package org.perfectjpattern.jee.integration.dao.jpa;
24   
25    import java.text.*;
26    import java.util.*;
27   
28    import org.perfectjpattern.example.datamodel.*;
29    import org.perfectjpattern.example.datamodel.visitor.*;
30    import org.perfectjpattern.jee.api.business.servicelocator.*;
31    import org.perfectjpattern.jee.business.servicelocator.*;
32    import org.slf4j.*;
33   
34    /**
35    * Startup Main for the JPA Generic Dao example code
36    *
37    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
38    * @version $ $Date: Dec 5, 2008 2:04:37 AM $
39    */
40    //CHECKSTYLE:OFF
41    public final
 
42    class Example
43    // CHECKSTYLE:ON
44    {
45    //------------------------------------------------------------------------
46    // public
47    //------------------------------------------------------------------------
 
48  1 toggle public static void
49    main(String[] anArguments)
50    throws ParseException
51    {
52    // tweaking OpenEJB logging
53  1 System.setProperty("log4j.category.OpenEJB", "debug");
54   
55    //---------------------------------------------------------------
56    // use ServiceLocator to load the Local IGenericDao EJB
57    //---------------------------------------------------------------
58  1 IServiceLocator myServiceLocator = ServiceLocator.getInstance();
59  1 IMovieBaseDao myMovieBaseDao = myServiceLocator.locate(
60    "IMovieBaseDaoLocal");
61   
62    //---------------------------------------------------------------
63    // call IBaseDao methods
64    //---------------------------------------------------------------
65  1 myMovieBaseDao.create(new Movie("Fresa y chocolate",
66    "Tomas Gutierrez Alea", 1994));
67  1 myMovieBaseDao.create(new Movie("Vita e bella, La", "Roberto Benigni",
68    1997));
69  1 myMovieBaseDao.create(new Movie("Taken", "Pierre Morel", 2008));
70   
71    //---------------------------------------------------------------
72    // clear cache: demonstrates accessing whatever Session lies behind
73    //---------------------------------------------------------------
74  1 myMovieBaseDao.getSession().clear();
75   
76    //---------------------------------------------------------------
77    // find all Movies
78    //---------------------------------------------------------------
79  1 StringBuilder myBuilder = new StringBuilder();
80  1 List<Movie> myMovies = myMovieBaseDao.findAll();
81  1 ToStringVisitor myVisitor = new ToStringVisitor();
82  1 for (Movie myMovie : myMovies)
83    {
84  3 myVisitor.visit(myMovie);
85  3 String myResult = myVisitor.getResult();
86  3 myBuilder.append(myResult);
87    }
88   
89    //---------------------------------------------------------------
90    // use ServiceLocator to load the Local IGenericDao EJB
91    //---------------------------------------------------------------
92  1 IMovieGenericDao myMovieGenericDao = myServiceLocator.locate(
93    "IMovieGenericDaoLocal");
94   
95    //---------------------------------------------------------------
96    // find all Movies produced in 2008
97    //---------------------------------------------------------------
98  1 int myYear = 2008;
99  1 myMovies = myMovieGenericDao.findByYear(myYear);
100  1 for (Movie myMovie : myMovies)
101    {
102  1 myVisitor.visit(myMovie);
103  1 String myResult = myVisitor.getResult();
104  1 myBuilder.append(myResult);
105    }
106   
107  1 theLogger.debug(myBuilder.toString());
108   
109  1 myServiceLocator.shutdown();
110    }
111   
112    //------------------------------------------------------------------------
113    // protected
114    //------------------------------------------------------------------------
 
115  1 toggle protected static void
116    setLogger(Logger aLogger)
117    {
118  1 theLogger = aLogger;
119    }
120   
121    //------------------------------------------------------------------------
122    // members
123    //------------------------------------------------------------------------
124    /**
125    * Provides logging facilities for this class
126    */
127    private static Logger theLogger = LoggerFactory.getLogger(Example.class);
128    }