1 package org.itracker.persistence.dao;
2
3 import org.hibernate.HibernateException;
4 import org.hibernate.Query;
5 import org.itracker.model.Language;
6
7 import java.util.List;
8
9
10
11
12 public class LanguageDAOImpl extends BaseHibernateDAOImpl<Language>
13 implements LanguageDAO {
14
15 public Language findById(Integer id) {
16 Language language;
17
18 try {
19 language = (Language) getSession().get(Language.class, id);
20 } catch (HibernateException ex) {
21 throw convertHibernateAccessException(ex);
22 }
23 return language;
24 }
25
26 public Language findByKeyAndLocale(String key, String locale) {
27 Language language;
28
29 try {
30 Query query = getSession().getNamedQuery(
31 "LanguagesByKeyAndLocaleQuery");
32 query.setString("key", key);
33 query.setString("locale", locale);
34 language = (Language) query.uniqueResult();
35 } catch (HibernateException ex) {
36 throw convertHibernateAccessException(ex);
37 }
38
39 if (language == null) {
40 throw new NoSuchEntityException("No language item for "
41 + key + " " + locale);
42 }
43 return language;
44 }
45
46 @SuppressWarnings("unchecked")
47 public List<Language> findByKey(String key) {
48 List<Language> languages;
49
50 try {
51 Query query = getSession().getNamedQuery("LanguagesByKeyQuery");
52 query.setString("key", key);
53 languages = query.list();
54 } catch (HibernateException ex) {
55 throw convertHibernateAccessException(ex);
56 }
57 return languages;
58 }
59
60 @SuppressWarnings("unchecked")
61 public List<Language> findByLocale(String locale) {
62 List<Language> languages;
63
64 try {
65 Query query = getSession().getNamedQuery("LanguagesByLocaleQuery");
66 query.setString("locale", locale);
67 languages = query.list();
68 } catch (HibernateException ex) {
69 throw convertHibernateAccessException(ex);
70 }
71 return languages;
72 }
73
74 }