Example usage for org.hibernate SQLQuery setInteger

List of usage examples for org.hibernate SQLQuery setInteger

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setInteger.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(int position, int val) 

Source Link

Document

Bind a positional int-valued parameter.

Usage

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

/**
select IT.*, count(IT.count_purchase) as CT from ps_item as IT
where IT.id_category = ?/*from  ww  w .  j av  a  2 s. c  o m*/
order by CT desc
limit 0, ? 
 */
@SuppressWarnings("unchecked")
@Override
public List<PsItem> selectBestSellers(final int categoryID, final int limit) {

    return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

        @Override
        public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {

            SQLQuery query = session
                    .createSQLQuery(" select IT.*, count(IT.count_purchase) as CT from ps_item as IT "
                            + " where IT.id_category = ? " + " order by CT desc " + " limit 0, ? ");
            query.addEntity(PsItem.class);
            query.setInteger(0, categoryID);
            query.setInteger(1, limit);
            return query.list();
        }
    });
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w  w  w.j av a  2s .c o  m*/
public List<PsItem> findByPriceInCategory(final Integer psCategoryId, final Double priceMin,
        final Double priceMax, final FetchOption option) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {
            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery("select * from ps_item as P where P.id_category = ? "
                        + " and P.price > ? and P.price < ? " + "order by price "
                        + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?, ?");

                query.setInteger(0, psCategoryId).setDouble(1, priceMin).setDouble(2, priceMax)
                        .setInteger(3, option.offset).setInteger(4, option.limit);

                return query.addEntity(PsItem.class).list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByPriceInCategory failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w ww  .j ava 2 s.c  o  m*/
public List<PsItem> findByCountPurchaseInCategory(final Integer psCategoryId, final FetchOption op) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {
            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select * from ps_item as P where P.id_category = ? " + "order by count_purchase "
                                + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?, ?");

                query.setInteger(0, psCategoryId).setInteger(1, op.offset).setInteger(2, op.limit);
                query.addEntity(PsItem.class);

                return query.list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByCountPurchaseInCategory failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w  ww  . j  a va  2  s  .  c  om
public List<PsItem> findByCountFavouriteInCategory(final Integer psCategoryId, final FetchOption op) {

    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select * from ps_item as P where P.id_category = ? " + "order by count_favourite "
                                + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + " limit ?, ?");

                query.setInteger(0, psCategoryId).setInteger(1, op.offset).setInteger(2, op.limit);
                query.addEntity(PsItem.class);

                return query.list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByCountFavouriteInCategory failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  ww  w  .ja  v  a 2  s. c  o m
public List<PsItem> findByVoteInCategory(final Integer psCategoryId, final FetchOption op) {

    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session
                        .createSQLQuery("select * from ps_item as P where P.id_category = ? " + "order by vote "
                                + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?, ?");

                query.setInteger(0, psCategoryId).setInteger(1, op.offset).setInteger(2, op.limit);
                query.addEntity(PsItem.class);

                return query.list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByVoteInCategory failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww w.  jav  a2s  . c o m*/
public List<PsItem> findByPriceInTag(final Integer psTagId, final Double priceMin, final Double priceMax,
        final FetchOption op) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select P.* from ps_item as P where P.id in (select R.id_item from r_tag_item as R where R.id_tag = ? ) "
                                + " and P.price > ? and P.price < ? " + "order by price "
                                + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?,  ?");

                query.setInteger(0, psTagId).setDouble(1, priceMin).setDouble(2, priceMax)
                        .setInteger(3, op.offset).setInteger(4, op.limit);

                return query.addEntity(PsItem.class).list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByPriceInTag failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w  w . jav a  2  s .c o m
public List<PsItem> findByCountPurchaseInTag(final Integer psTagId, final FetchOption op) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select P.* from ps_item as P where P.id in (select R.id_item from r_tag_item as R where R.id_tag = ? ) "
                                + "order by count_purchase "
                                + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?, ?");

                query.setInteger(0, psTagId).setInteger(1, op.offset).setInteger(2, op.limit);

                return query.addEntity(PsItem.class).list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByCountPurchaseInTag failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from www  . ja  va 2s  . c o m*/
public List<PsItem> findByCountFavouriteInTag(final Integer psTagId, final FetchOption op) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select P.* from ps_item as P where P.id in (select R.id_item from r_tag_item as R where R.id_tag = ? ) "
                                + "order by count_favourite "
                                + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?, ?");

                query.setInteger(0, psTagId).setInteger(1, op.offset).setInteger(2, op.limit);

                return query.addEntity(PsItem.class).list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByCountFavouriteInTag failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from ww  w .ja va 2s  .  com*/
public List<PsItem> findByVoteInTag(final Integer psTagId, final FetchOption op) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select P.* from ps_item as P where P.id in (select R.id_item from r_tag_item as R where R.id_tag = ? ) "
                                + "order by vote " + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ")
                                + "limit ?, ?");

                query.setInteger(0, psTagId).setInteger(1, op.offset).setInteger(2, op.limit);

                return query.addEntity(PsItem.class).list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByVoteInTag failed", re);
        throw re;
    }
}

From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  ww  w . j  a va2s. com
public List<PsItem> findByOrderId(final Integer id) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() {

            @Override
            public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery(
                        "select P.* from ps_item as P where P.id in (select R.id_item from r_order_item as R where R.id_order = ? ) ");

                query.setInteger(0, id);
                query.addEntity(PsItem.class);
                return query.list();
            }
        });

    } catch (RuntimeException re) {
        log.error("find by findByOrderId failed", re);
        throw re;
    }

}