View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.domain.repository;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import javax.persistence.PersistenceException;
29  
30  import org.hibernate.Query;
31  import org.hibernate.Session;
32  import org.springframework.orm.hibernate3.HibernateCallback;
33  import org.springframework.stereotype.Repository;
34  
35  import com.gisgraphy.domain.geoloc.entity.AlternateName;
36  
37  /**
38   * A data access object for {@link AlternateName}
39   * 
40   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
41   */
42  @Repository
43  public class AlternateNameDao extends GenericDao<AlternateName, Long> implements
44  	IAlternateNameDao {
45  
46      /**
47       * Default constructor
48       */
49      public AlternateNameDao() {
50  	super(AlternateName.class);
51      }
52  
53      /*
54       * (non-Javadoc)
55       * 
56       * @see com.gisgraphy.domain.repository.IAlternateNameDao#getUsedLanguages()
57       */
58      @SuppressWarnings("unchecked")
59      public List<String> getUsedLanguagesCodes() {
60  	return (List<String>) this.getHibernateTemplate().execute(
61  		new HibernateCallback() {
62  
63  		    public Object doInHibernate(final Session session)
64  			    throws PersistenceException {
65  			final String queryString = "select distinct(a.language) from AlternateName a where a.language != null";
66  
67  			final Query qry = session.createQuery(queryString);
68  			qry.setCacheable(true);
69  
70  			List<String> result = (List<String>) qry.list();
71  			if (result == null) {
72  			    result = new ArrayList<String>();
73  			}
74  
75  			return result;
76  		    }
77  		});
78  
79      }
80  
81  }