KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > dao > SystemConfigurationDAO


1 /*
2  * $Id: SystemConfigurationDAO.java,v 1.7 2005/01/17 21:36:09 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.dao;
27
28 import net.sf.hibernate.HibernateException;
29 import net.sf.hibernate.Session;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 import com.j2biz.blogunity.exception.BlogunityException;
35 import com.j2biz.blogunity.i18n.I18N;
36 import com.j2biz.blogunity.i18n.I18NStatusFactory;
37 import com.j2biz.blogunity.pojo.SystemConfiguration;
38 import com.j2biz.blogunity.util.HibernateUtil;
39
40 /**
41  * @author michelson
42  * @version $$
43  * @since 0.1
44  *
45  *
46  */

47 public class SystemConfigurationDAO extends AbstractDAO {
48
49     /**
50      * Logger for this class
51      */

52     private static final Log log = LogFactory.getLog(SystemConfigurationDAO.class);
53
54     /**
55      *
56      */

57     public SystemConfigurationDAO() {
58         super();
59     }
60
61     public SystemConfiguration getSystemConfiguration() throws BlogunityException {
62
63         Session session = HibernateUtil.getSession();
64         SystemConfiguration config = null;
65         try {
66             config = (SystemConfiguration) session.load(SystemConfiguration.class, new Long JavaDoc(1));
67         } catch (HibernateException ex) {
68
69             log.error("getSystemConfiguration()", ex);
70             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.SYSCONFIG_NOT_FOUND,
71                     ex));
72
73         }
74
75         return config;
76     }
77
78     public void updateSystemConfiguration(SystemConfiguration config) throws BlogunityException {
79
80         Session session = HibernateUtil.getSession();
81         try {
82
83             session.update(config);
84
85         } catch (HibernateException ex) {
86
87             log.error("setSystemConfiguration(SystemConfiguration)", ex);
88             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.SYSCONFIG_UPDATE, ex));
89         }
90
91     }
92
93     public void setSystemConfiguration(SystemConfiguration config) throws BlogunityException {
94
95         Session session = HibernateUtil.getSession();
96         SystemConfiguration configOld = null;
97         try {
98
99             try {
100                 configOld = getSystemConfiguration();
101             } catch (BlogunityException e) {
102                 configOld = null;
103             }
104
105             if (configOld == null) {
106                 session.save(config);
107             } else {
108                 configOld.setAllowNewUsers(config.getAllowNewUsers());
109                 configOld.setDataDir(config.getDataDir());
110                 configOld.setTempDir(config.getTempDir());
111                 // configOld.setRenderEngineClass(config.getRenderEngineClass());
112
configOld.setValidateNewUsers(config.getValidateNewUsers());
113                 configOld.setVelocityProperties(config.getVelocityProperties());
114                 session.save(configOld);
115             }
116
117         } catch (HibernateException ex) {
118
119             log.error("setSystemConfiguration(SystemConfiguration)", ex);
120             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.SYSCONFIG_UPDATE, ex));
121
122         }
123
124     }
125
126 }
Popular Tags