KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > providers > persistence > GroupPersistenceProvider


1 /*
2  * Copyright (C) 2002 Erik Swenson - erik@oreports.com
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.providers.persistence;
21
22 import java.util.List JavaDoc;
23
24 import org.apache.log4j.Logger;
25 import org.efs.openreports.objects.Report;
26 import org.efs.openreports.objects.ReportGroup;
27 import org.efs.openreports.providers.HibernateProvider;
28 import org.efs.openreports.providers.ProviderException;
29 import org.efs.openreports.util.LocalStrings;
30 import org.hibernate.HibernateException;
31 import org.hibernate.Session;
32
33 public class GroupPersistenceProvider
34 {
35     protected static Logger log =
36         Logger.getLogger(GroupPersistenceProvider.class.getName());
37
38     public GroupPersistenceProvider() throws ProviderException
39     {
40         super();
41
42         log.info("GroupPersistenceProvider Created.");
43     }
44
45     public ReportGroup getReportGroup(Integer JavaDoc id) throws ProviderException
46     {
47         return (ReportGroup) HibernateProvider.load(ReportGroup.class, id);
48     }
49
50     public List JavaDoc getReportGroups() throws ProviderException
51     {
52         String JavaDoc fromClause =
53             "from org.efs.openreports.objects.ReportGroup reportGroup order by reportGroup.name ";
54         
55         return HibernateProvider.query(fromClause);
56     }
57     
58     public List JavaDoc getGroupsForReport(Report report) throws ProviderException
59     {
60         try
61         {
62             Session session = HibernateProvider.openSession();
63             
64             try
65             {
66                 List JavaDoc list = session.createQuery(
67                         "from org.efs.openreports.objects.ReportGroup as reportGroup "
68                                 + "where ? in elements(reportGroup.reports)").setEntity(0, report).list();
69
70                 if (list.size() == 0) return null;
71
72                 return list;
73             }
74             catch (HibernateException he)
75             {
76                 throw he;
77             }
78             finally
79             {
80                 session.close();
81             }
82         }
83         catch (HibernateException he)
84         {
85             throw new ProviderException(he);
86         }
87     }
88
89     public ReportGroup insertReportGroup(ReportGroup reportGroup)
90         throws ProviderException
91     {
92         return (ReportGroup) HibernateProvider.save(reportGroup);
93     }
94
95     public void updateReportGroup(ReportGroup reportGroup)
96         throws ProviderException
97     {
98         HibernateProvider.update(reportGroup);
99     }
100
101     public void deleteReportGroup(ReportGroup reportGroup)
102         throws ProviderException
103     {
104         try
105         {
106             HibernateProvider.delete(reportGroup);
107         }
108         catch (ConstraintException ce)
109         {
110             throw new ProviderException(LocalStrings.getString(LocalStrings.ERROR_GROUP_DELETION));
111         }
112     }
113 }
Popular Tags