KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > facade > LocalizationContextDAO


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23
24
25 package org.mdarad.framework.facade;
26
27 import java.util.List JavaDoc;
28
29 import org.dataisland.primitives.bean.LocalizationContext;
30 import org.dataisland.primitives.exception.LocalizationContextNotFoundException;
31 import org.dataisland.primitives.exception.LocalizationException;
32 import org.hibernate.HibernateException;
33 import org.hibernate.Session;
34 import org.hibernate.criterion.Expression;
35 import org.mdarad.framework.dao.DAOException;
36 import org.mdarad.framework.dao.HibernateDAO;
37
38 /**
39  * Created by IntelliJ IDEA.
40  * User: voarsenault
41  * Date: Jun 8, 2004
42  * Time: 10:03:06 AM
43  * To change this template use File | Settings | File Templates.
44  */

45 public class LocalizationContextDAO extends HibernateDAO {
46     private static LocalizationContextDAO instance = null;
47
48     private LocalizationContextDAO() {
49     }
50
51     static public LocalizationContextDAO getInstance() {
52         if (instance == null) instance = new LocalizationContextDAO();
53         return instance;
54     }
55
56     /**
57      * @param humanReadableKey
58      * @return
59      * @throws LocalizationException
60      */

61     public org.dataisland.primitives.bean.LocalizationContext fetchLocalizationContextByHumanReadableKey(String JavaDoc humanReadableKey) throws LocalizationException, LocalizationContextNotFoundException {
62         if (humanReadableKey == null) {
63             throw new IllegalArgumentException JavaDoc("The LocalizationContext's human readable key cannot be null.");
64         }
65
66         org.dataisland.primitives.bean.LocalizationContext lOutput = null;
67
68         try {
69
70             // Initialize the hibernate session
71
Session session = currentSession();
72
73             try {
74                 // Get persisted entity
75
List JavaDoc lResults = session.createCriteria(LocalizationContext.class)
76                                        .add(Expression.eq("humanReadableKey", humanReadableKey)).list();
77                 if (lResults.size() == 0) throw new org.dataisland.primitives.exception.LocalizationContextNotFoundException("The requested localization context cannot be found.");
78                 lOutput = (org.dataisland.primitives.bean.LocalizationContext) lResults.get(0);
79             } catch (HibernateException he) {
80                 throw new LocalizationException(he);
81             } finally {
82                 // Close the hibernate session
83
closeSession();
84             }
85         } catch (DAOException bse) {
86             throw new LocalizationException(bse);
87         }
88         return lOutput;
89     }
90
91 }
92
Popular Tags