KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > business > hibernate > HibernateConfigManagerImpl


1 /*
2  * Created on Jun 18, 2004
3  */

4 package org.roller.business.hibernate;
5
6 import net.sf.hibernate.Criteria;
7 import net.sf.hibernate.HibernateException;
8 import net.sf.hibernate.Session;
9
10 import org.roller.RollerException;
11 import org.roller.business.ConfigManagerImpl;
12 import org.roller.business.PersistenceStrategy;
13 import org.roller.pojos.RollerConfigData;
14
15 import java.util.List JavaDoc;
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18
19 /**
20  * @author David M Johnson
21  */

22 public class HibernateConfigManagerImpl extends ConfigManagerImpl
23 {
24     static final long serialVersionUID = -3674252864091781177L;
25     
26     private static Log mLogger =
27         LogFactory.getFactory().getInstance(HibernateConfigManagerImpl.class);
28     
29     /**
30      * @param strategy
31      * @param roller
32      */

33     public HibernateConfigManagerImpl(PersistenceStrategy strategy)
34     {
35         super(strategy);
36         mLogger.debug("Instantiating Config Manager");
37     }
38
39     /**
40      * Fetch all RollerConfigs and return the first one, if any.
41      * Note: there should only be one!
42      * @see org.roller.model.ConfigManager#getRollerConfig()
43      */

44     public RollerConfigData getRollerConfig() throws RollerException
45     {
46         mLogger.error("Someone is trying to use the old config!!\n"+
47                 "This configuration mechanism has been deprecated\n"+
48                 "You should see this message only once when you first upgrade\n"+
49                 "your installation to roller 1.2\n\n"+
50                 "If you continue to see this message please shoot us an email\n"+
51                 "at roller-development@lists.sourceforge.net with some output\n"+
52                 "from your log files.\n");
53         try
54         {
55             Session session = ((HibernateStrategy)mStrategy).getSession();
56             Criteria criteria = session.createCriteria(RollerConfigData.class);
57             criteria.setMaxResults(1);
58             List JavaDoc list = criteria.list();
59             return list.size()!=0 ? (RollerConfigData)list.get(0) : null;
60         }
61         catch (HibernateException e)
62         {
63             throw new RollerException(e);
64         }
65     }
66
67 }
68
Popular Tags