KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import org.efs.openreports.objects.ReportDataSource;
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.Criteria;
31 import org.hibernate.HibernateException;
32 import org.hibernate.Session;
33 import org.hibernate.criterion.Expression;
34
35 public class DataSourcePersistenceProvider
36 {
37     protected static Logger log =
38         Logger.getLogger(DataSourcePersistenceProvider.class.getName());
39
40     public DataSourcePersistenceProvider() throws ProviderException
41     {
42         super();
43
44         log.info("DataSourcePersistenceProvider Created.");
45     }
46
47     public ReportDataSource getDataSource(Integer JavaDoc id) throws ProviderException
48     {
49         return (ReportDataSource) HibernateProvider.load(ReportDataSource.class, id);
50     }
51     
52     public ReportDataSource getDataSource(String JavaDoc name) throws ProviderException
53     {
54         Session session = null;
55         
56         try
57         {
58             session = HibernateProvider.openSession();
59             
60             Criteria criteria = session.createCriteria(ReportDataSource.class);
61             criteria.add(Expression.eq("name", name));
62             
63             return (ReportDataSource) criteria.uniqueResult();
64         }
65         catch (HibernateException he)
66         {
67             throw new ProviderException(he);
68         }
69         finally
70         {
71             HibernateProvider.closeSession(session);
72         }
73     }
74
75     public List JavaDoc getDataSources() throws ProviderException
76     {
77         String JavaDoc fromClause =
78             "from org.efs.openreports.objects.ReportDataSource reportDataSource order by reportDataSource.name ";
79         
80         return HibernateProvider.query(fromClause);
81     }
82
83     public ReportDataSource insertDataSource(ReportDataSource reportDataSource)
84         throws ProviderException
85     {
86         return (ReportDataSource) HibernateProvider.save(reportDataSource);
87     }
88
89     public void updateDataSource(ReportDataSource reportDataSource)
90         throws ProviderException
91     {
92         HibernateProvider.update(reportDataSource);
93     }
94
95     public void deleteDataSource(ReportDataSource reportDataSource)
96         throws ProviderException
97     {
98         try
99         {
100             HibernateProvider.delete(reportDataSource);
101         }
102         catch (ConstraintException ce)
103         {
104             throw new ProviderException(LocalStrings.getString(LocalStrings.ERROR_DATASOURCE_DELETION));
105         }
106     }
107 }
Popular Tags