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 javax.persistence.PersistenceException;
26  
27  import org.hibernate.Query;
28  import org.hibernate.Session;
29  import org.springframework.orm.hibernate3.HibernateCallback;
30  import org.springframework.stereotype.Repository;
31  
32  import com.gisgraphy.stats.StatsUsage;
33  import com.gisgraphy.stats.StatsUsageType;
34  
35  /**
36   * Dao for {@link StatsUsage}
37   * 
38   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
39   * 
40   */
41  @Repository
42  public class StatsUsageDao extends GenericDao<StatsUsage, Long> implements
43  	IStatsUsageDao {
44  
45      /**
46       * Default Constructor
47       */
48      public StatsUsageDao() {
49  	super(StatsUsage.class);
50      }
51  
52      /*
53       * (non-Javadoc)
54       * 
55       * @see com.gisgraphy.domain.repository.IStatUsageDao#getByUsageType(com.gisgraphy.stats.StatsUsageType)
56       */
57      public StatsUsage getByUsageType(final StatsUsageType statsUsageType) {
58  	return (StatsUsage) this.getHibernateTemplate().execute(
59  		new HibernateCallback() {
60  
61  		    public Object doInHibernate(final Session session)
62  			    throws PersistenceException {
63  			final String queryString = "from StatsUsage as s where s.statsUsageType = :statstype";
64  
65  			final Query qry = session.createQuery(queryString);
66  			qry.setParameter("statstype", statsUsageType);
67  			qry.setCacheable(true);
68  
69  			return (StatsUsage) qry.uniqueResult();
70  		    }
71  		});
72      }
73  
74  }