6 package org
.spirit
.dao
.impl
;
8 import java
.util
.ArrayList
;
9 import java
.util
.Collection
;
10 import java
.util
.Iterator
;
11 import java
.util
.List
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.hibernate
.HibernateException
;
16 import org
.hibernate
.Query
;
17 import org
.hibernate
.Session
;
18 import org
.spirit
.bean
.impl
.BotListCityListing
;
19 import org
.spirit
.dao
.BotListCityListingDAO
;
20 import org
.springframework
.dao
.DataAccessException
;
21 import org
.springframework
.orm
.hibernate3
.HibernateCallback
;
22 import org
.springframework
.orm
.hibernate3
.support
.HibernateDaoSupport
;
25 * This is class is used by botverse.
27 * @author Berlin Brown
31 public class BotListCityListingDAOImpl
extends HibernateDaoSupport
32 implements BotListCityListingDAO
{
37 private static final long serialVersionUID
= 5404767492071334422L;
39 private Log log
= LogFactory
.getLog(getClass());
41 private final String DEFAULT_QUERY
= "from org.spirit.bean.impl.BotListCityListing city order by city.cityName";
43 * @see org.spirit.dao.BotListCityListingDAO#findWebFiles()
45 public Collection
findCityListings(final String query_str
) {
46 return getHibernateTemplate().executeFind(
47 new HibernateCallback() {
48 public Object
doInHibernate(Session session
) throws HibernateException
{
49 Query query
= session
.createQuery(query_str
);
50 // Set the maximum results
51 query
.setMaxResults(50);
52 List data
= query
.list();
53 for (Iterator it
= data
.iterator(); it
.hasNext(); ) {
54 BotListCityListing element
= (BotListCityListing
) it
.next();
55 List curdata
= element
.getListings();
64 public Collection
findCityListings() {
65 return findCityListings(DEFAULT_QUERY
);
69 * Find city listings by type.
73 public Collection
findCityListingsType(final String city_type
, final int page
, final int pageSize
) {
74 return getHibernateTemplate().executeFind(
75 new HibernateCallback() {
76 public Object
doInHibernate(Session session
) throws HibernateException
{
77 Query query
= session
.createQuery("from org.spirit.bean.impl.BotListCityListing city where city.cityCategory = :city_type order by city.stateAbbr, city.cityName");
78 query
.setString("city_type", city_type
);
79 // Set the maximum results
80 query
.setFirstResult(page
* pageSize
);
81 query
.setMaxResults(pageSize
);
82 List data
= query
.list();
83 for (Iterator it
= data
.iterator(); it
.hasNext(); ) {
84 BotListCityListing element
= (BotListCityListing
) it
.next();
85 List curdata
= element
.getListings();
95 * @see org.spirit.dao.BotListCityListingDAO#readCityListing(int)
97 public BotListCityListing
readCityListing(final int id
) throws DataAccessException
{
98 return (BotListCityListing
) getHibernateTemplate().execute(
99 new HibernateCallback() {
100 public Object
doInHibernate(Session session
) throws HibernateException
{
102 session
.createQuery("from org.spirit.bean.impl.BotListCityListing city where city.id = " + id
);
103 return query
.uniqueResult();
108 public long getCityPostCount(final int id
) {
109 ArrayList list
= (ArrayList
) getHibernateTemplate().find("select count(id) from org.spirit.bean.impl.BotListPostListing where cityId = " + id
);
113 if (list
.get(0) instanceof java
.lang
.Integer
) {
114 return ((Integer
) list
.get(0)).longValue();