All pastes #352828 Raw Edit

Something

public text v1 · immutable
·published 2007-02-13 01:08 UTC
rendered paste body
package se.dinapengar.news.dao;

import se.dinapengar.news.model.DISE_Articles;
import se.dinapengar.news.model.DISE_Sections;

import java.util.Iterator;

import org.hibernate.Query;
// Author: joed

// Date  : Feb 7, 2007
public class SectionsDao extends AbstractDaoHibernate <DISE_Sections>{

         protected SectionsDao(DISE_Sections dise_Articles) { super(DISE_Sections.class); }

                public Iterator find(final QueryParam qp, DISE_Sections filter) {
                return buildFindQuery(qp, filter, false).iterate();

        }

         protected Query buildFindQuery(QueryParam qp, DISE_Sections filter, boolean count) {
                StringBuffer hql = new StringBuffer();
                if (count) {
                        hql.append("select count(*) ");
                }
                hql.append(" from DISE_Sections target where 1=1 ");
                if (filter.getId() != null) {
                        hql.append("and upper(target.section) like (:section)");
                }

                if (!count && qp != null && qp.hasSort()) {
                        hql.append("order by upper(target.").append(qp.getSort()).append(
                                        ") ").append((qp.isSortAsc()) ? " asc" : " desc");
                }

                Query query = (Query) getSession().createQuery(hql.toString());

                if (!count && qp != null) {
                        query.setFirstResult(qp.getFirst()).setMaxResults(qp.getCount());
                }

                return query;
        }

     public DISE_Sections load(long id) {
                return (DISE_Sections) getSession().get(DISE_Sections.class, new Long(id));
        }

           public int count(DISE_Sections filter) {
                return ((Integer) buildFindQuery(null, filter, true).uniqueResult())
                                .intValue();
        }



}