01: /*
02: Mdarad-Toolobox is a collection of tools for Architected RAD
03: (Rapid Application Development) based on an MDA approach.
04: The toolbox contains frameworks and generators for many environments
05: (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
06: applications from a design Model
07: Copyright (C) 2004-2005 Elapse Technologies Inc.
08:
09: 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: package org.mdarad.framework.facade;
25:
26: import java.util.List;
27:
28: import org.dataisland.primitives.bean.LocalizationContext;
29: import org.dataisland.primitives.exception.LocalizationContextNotFoundException;
30: import org.dataisland.primitives.exception.LocalizationException;
31: import org.hibernate.HibernateException;
32: import org.hibernate.Session;
33: import org.hibernate.criterion.Expression;
34: import org.mdarad.framework.dao.DAOException;
35: import org.mdarad.framework.dao.HibernateDAO;
36:
37: /**
38: * Created by IntelliJ IDEA.
39: * User: voarsenault
40: * Date: Jun 8, 2004
41: * Time: 10:03:06 AM
42: * To change this template use File | Settings | File Templates.
43: */
44: public class LocalizationContextDAO extends HibernateDAO {
45: private static LocalizationContextDAO instance = null;
46:
47: private LocalizationContextDAO() {
48: }
49:
50: static public LocalizationContextDAO getInstance() {
51: if (instance == null)
52: 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(
62: String humanReadableKey) throws LocalizationException,
63: LocalizationContextNotFoundException {
64: if (humanReadableKey == null) {
65: throw new IllegalArgumentException(
66: "The LocalizationContext's human readable key cannot be null.");
67: }
68:
69: org.dataisland.primitives.bean.LocalizationContext lOutput = null;
70:
71: try {
72:
73: // Initialize the hibernate session
74: Session session = currentSession();
75:
76: try {
77: // Get persisted entity
78: List lResults = session.createCriteria(
79: LocalizationContext.class).add(
80: Expression.eq("humanReadableKey",
81: humanReadableKey)).list();
82: if (lResults.size() == 0)
83: throw new org.dataisland.primitives.exception.LocalizationContextNotFoundException(
84: "The requested localization context cannot be found.");
85: lOutput = (org.dataisland.primitives.bean.LocalizationContext) lResults
86: .get(0);
87: } catch (HibernateException he) {
88: throw new LocalizationException(he);
89: } finally {
90: // Close the hibernate session
91: closeSession();
92: }
93: } catch (DAOException bse) {
94: throw new LocalizationException(bse);
95: }
96: return lOutput;
97: }
98:
99: }
|