KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) 2005 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.hibernate.HibernateException;
25 import org.hibernate.Session;
26
27 import org.apache.log4j.Logger;
28 import org.efs.openreports.objects.ORProperty;
29 import org.efs.openreports.providers.HibernateProvider;
30 import org.efs.openreports.providers.ProviderException;
31
32 public class PropertiesPersistenceProvider
33 {
34     protected static Logger log = Logger
35             .getLogger(PropertiesPersistenceProvider.class.getName());
36
37     public PropertiesPersistenceProvider() throws ProviderException
38     {
39         super();
40
41         log.info("PropertiesPersistenceProvider Created.");
42     }
43
44     public ORProperty getProperty(String JavaDoc key) throws ProviderException
45     {
46         try
47         {
48             Session session = HibernateProvider.openSession();
49
50             try
51             {
52                 List JavaDoc list = session.createQuery(
53                         "from org.efs.openreports.objects.ORProperty as orProperty "
54                                 + "where orProperty.key = ?").setCacheable(true).setString(0, key).list();
55                     
56                 if (list.size() == 0)
57                     return null;
58
59                 ORProperty property = (ORProperty) list.get(0);
60
61                 return property;
62             }
63             catch (HibernateException he)
64             {
65                 throw he;
66             }
67             finally
68             {
69                 session.close();
70             }
71         }
72         catch (HibernateException he)
73         {
74             throw new ProviderException(he);
75         }
76     }
77
78     public ORProperty insertProperty(ORProperty property)
79             throws ProviderException
80     {
81         return (ORProperty) HibernateProvider.save(property);
82     }
83
84     public void updateProperty(ORProperty property) throws ProviderException
85     {
86         HibernateProvider.update(property);
87     }
88
89     public void deleteProperty(ORProperty property) throws ProviderException
90     {
91         try
92         {
93             HibernateProvider.delete(property);
94         }
95         catch (ConstraintException ce)
96         {
97             throw new ProviderException(ce.getMessage());
98         }
99     }
100
101 }
Popular Tags