KickJava   Java API By Example, From Geeks To Geeks.

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


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.ReportParameter;
26 import org.efs.openreports.providers.HibernateProvider;
27 import org.efs.openreports.providers.ProviderException;
28 import org.efs.openreports.util.LocalStrings;
29
30 import org.hibernate.*;
31
32 public class ParameterPersistenceProvider
33 {
34     protected static Logger log =
35         Logger.getLogger(ParameterPersistenceProvider.class.getName());
36
37     public ParameterPersistenceProvider() throws ProviderException
38     {
39         super();
40
41         log.info("ParameterPersistenceProvider Created.");
42     }
43
44     public ReportParameter getReportParameter(Integer JavaDoc id)
45         throws ProviderException
46     {
47         return (ReportParameter) HibernateProvider.load(ReportParameter.class, id);
48     }
49     
50     public ReportParameter getReportParameter(String JavaDoc name) throws ProviderException
51     {
52         try
53         {
54             Session session = HibernateProvider.openSession();
55             
56             try
57             {
58                 List JavaDoc list = session.createQuery(
59                         "from org.efs.openreports.objects.ReportParameter reportParameter "
60                                 + "where reportParameter.name = ?").setString(0, name)
61                         .list();
62                     
63                 if (list.size() == 0)
64                     return null;
65
66                 ReportParameter reportParameter = (ReportParameter) list.get(0);
67                 
68                 return reportParameter;
69             }
70             catch (HibernateException he)
71             {
72                 throw he;
73             }
74             finally
75             {
76                 session.close();
77             }
78         }
79         catch (HibernateException he)
80         {
81             throw new ProviderException(he);
82         }
83     }
84
85     public List JavaDoc getReportParameters() throws ProviderException
86     {
87         String JavaDoc fromClause =
88             "from org.efs.openreports.objects.ReportParameter reportParameter order by reportParameter.name ";
89         
90         return HibernateProvider.query(fromClause);
91     }
92
93     public ReportParameter insertReportParameter(ReportParameter reportParameter)
94         throws ProviderException
95     {
96         return (ReportParameter) HibernateProvider.save(reportParameter);
97     }
98
99     public void updateReportParameter(ReportParameter reportParameter)
100         throws ProviderException
101     {
102         HibernateProvider.update(reportParameter);
103     }
104
105     public void deleteReportParameter(ReportParameter reportParameter)
106         throws ProviderException
107     {
108         try
109         {
110             HibernateProvider.delete(reportParameter);
111         }
112         catch (ConstraintException ce)
113         {
114             throw new ProviderException(LocalStrings.getString(LocalStrings.ERROR_PARAMETER_DELETION));
115         }
116     }
117 }
Popular Tags