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

@SuppressWarnings("unchecked")
@Override/*from w  w  w  .ja va 2 s  .  c om*/
public List<PsItem> findBySeller(final Integer sellerId, final FetchOption fetchOption) {
    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_shop in (select S.id from ps_shop as S where S.id_seller = ? ) ");

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

    } catch (RuntimeException re) {
        log.error("find by findBySeller 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  v a 2  s  .c  o  m*/
public List<PsItem> findByShop(final Integer shopId, final FetchOption fetchOption) {
    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_shop = ? "
                        + "order by name " + (fetchOption.sortOption == SortOption.ASCENDING ? "asc" : "desc ")
                        + "limit ?, ?");

                query.setInteger(0, shopId).setInteger(1, fetchOption.offset).setInteger(2, fetchOption.limit);
                query.addEntity(PsItem.class);

                return query.list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByShop 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 .ja  v a 2s  .  com
public List<PsItem> findByCountPurchase(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 " + "order by count_purchase "
                        + (op.sortOption == SortOption.ASCENDING ? "asc" : "desc ") + "limit ?, ?");

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

                return query.list();
            }
        });
    } catch (RuntimeException re) {
        log.error("find by findByCountPurchase 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  . j a  v  a2 s  . co m
public List<PsItem> findByCountFavourite(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 " + " order by count_favourite "
                        + (op.sortOption == SortOption.ASCENDING ? " asc " : " desc ") + " limit ?, ?");

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

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

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

License:Open Source License

@Override
@SuppressWarnings({ "unchecked" })
public List<PsItemInfo> findByItemId(final java.lang.Integer id) {
    try {// w  w  w. ja  va  2  s  .  c  o  m
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItemInfo>>() {

            @Override
            public List<PsItemInfo> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery("select * from ps_item_info where id_item = ? ");

                query.setInteger(0, id);
                query.addEntity(PsItemInfo.class);

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

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w  ww .j  av  a 2s.  c o m
public List<PsRecipient> findByCustomId(final Integer id) {
    log.debug("findByCustomerId: " + id);
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsRecipient>>() {

            @Override
            public List<PsRecipient> doInHibernate(Session arg0) throws HibernateException, SQLException {
                SQLQuery query = arg0.createSQLQuery("select * from ps_recipient as P where P.id_customer = ?");
                query.setInteger(0, id);
                query.addEntity(PsRecipient.class);
                return query.list();

            }

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

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

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<PsTag> selectTopTags(final int category, final int limit) {

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

        @Override//from ww w. ja v  a  2 s . co m
        public List<PsTag> doInHibernate(Session session) throws HibernateException, SQLException {
            SQLQuery query = session.createSQLQuery(" select TG.*, sum(TG.id) as TG_C from ps_tag as TG "
                    + "      inner join r_tag_item as RTI on RTI.id_tag    = TG.id "
                    + "      inner join ps_item as IT on IT.id = RTI.id_item " + " where IT.id_category = ? "
                    + " group by TG.id " + " order by TG_C " + " limit 0, ? ");
            query.addEntity(PsTag.class);
            query.setInteger(0, category);
            query.setInteger(1, limit);
            return query.list();
        }
    });
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w  w w .  jav a 2s .  co  m
public List<ROrderItem> findByOrderId(final Integer id) {
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<ROrderItem>>() {
            @Override
            public List<ROrderItem> doInHibernate(Session session) throws HibernateException, SQLException {
                SQLQuery query = session.createSQLQuery("select * from r_order_item as R where R.id_order = ?");

                query.setInteger(0, id);

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

From source file:com.bitranger.parknshop.common.service.ads.ItemAdService.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w ww. j  a  va 2s.co m
public List<PsPromotItem> forItem(@Nullable final List<Integer> tags, final int category, final int limit,
        @Nullable PsCustomer customer) {
    if (customer != null) {
        return new CFilter().filter(tags, category, limit, customer.getId());
    }

    return psAdItemDAO.hibernate().executeFind(new HibernateCallback<List<PsPromotItem>>() {

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

            //            session.createSQLQuery(
            //            "update ps_ad_item as AD set AD.num_fetched = AD.num_fetched + 1"
            //            ).executeUpdate();
            StringBuilder b = new StringBuilder(512);
            b.append(" select * from ps_promot_item as PM "
                    + " inner join ps_ad_item as AD on AD.id_promot = PM.id "
                    + " inner join ps_item as IT on IT.id = PM.id_item "
                    + " inner join r_tag_item as RIT on RIT.id_item = IT.id " + " where IT.id_category = ? "
                    + " and AD.time_start < CURRENT_TIMESTAMP and CURRENT_TIMESTAMP < AD.time_end ");
            if (tags != null && tags.size() > 0) {
                b.append(" and RIT.id_tag in (");
                for (Integer i : tags) {
                    b.append(i).append(',');
                }
                b.setCharAt(b.length() - 1, ')');
            }

            b.append(" order by AD.weight desc " + " limit 0, 32 ");

            SQLQuery query = session.createSQLQuery(b.toString());
            query.setInteger(0, category);
            List<PsPromotItem> ls = query.addEntity(PsPromotItem.class).list();

            return randomReduce(ls, limit);
        }
    });
}

From source file:com.bitranger.parknshop.seller.dao.impl.PsOrderDAO.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<PsOrder> findByCustomerId(final Integer id, final Date from, final Date to) {
    log.debug("findByCustomerId: " + id);
    try {/*from  w  w w  .  j  a v  a  2s.  c o m*/
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsOrder>>() {

            @Override
            public List<PsOrder> doInHibernate(Session arg0) throws HibernateException, SQLException {
                SQLQuery query = arg0.createSQLQuery(
                        "select * from ps_order as P where P.id_customer = ? and P.time_created > ? "
                                + "+ and P.time_created < ?");
                query.setInteger(0, id).setDate(1, from).setDate(2, to);
                query.addEntity(PsOrder.class);
                return query.list();

            }

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