Example usage for org.hibernate SQLQuery list

List of usage examples for org.hibernate SQLQuery list

Introduction

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

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

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 Short state) {
    log.debug("findByCustomerId: " + id);
    try {/*from  ww  w  .j av  a  2 s. co 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.status = ?");
                query.setInteger(0, id).setShort(1, state);
                query.addEntity(PsOrder.class);
                return query.list();

            }

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

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) {
    log.debug("findByCustomerId: " + id);
    try {/*from www . j a v a 2  s . co 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 = ? order by P.id desc");
                query.setInteger(0, id);
                query.addEntity(PsOrder.class);
                return query.list();

            }

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

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

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<PsOrder> findByShopId(final Integer id, final Date from, final Date to) {
    log.debug("find by shop_id: " + id);
    try {//from  w  w w .java  2  s.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_shop = ? 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 shop id failed", re);
        throw re;
    }
}

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

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<PsOrder> findByShopId(final Integer id) {
    log.debug("findByCustomerId: " + id);
    try {//  w  w w .j  a v a2 s  .co 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_shop = ?");
                query.setInteger(0, id);
                query.addEntity(PsOrder.class);
                return query.list();

            }

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

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

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<PsOrder> findByShopId(final Integer id, final Short state) {
    log.debug("findByCustomerId: " + id);
    try {//from  w ww  .j av  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_shop = ? and P.status = ?");
                query.setInteger(0, id).setShort(1, state);
                query.addEntity(PsOrder.class);
                return query.list();

            }

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

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

License:Open Source License

/**
         //from   w w  w  . j ava 2  s  .c  o m
select OD.* from ps_order as OD
 inner join ps_shop as SH on SH.id = OD.id_shop
where SH.id_seller = ?
        
         
 */

@Override
@SuppressWarnings("unchecked")
public List<PsOrder> findBySellerId(final Integer id) {
    return getHibernateTemplate().executeFind(new HibernateCallback<List<PsOrder>>() {

        @Override
        public List<PsOrder> doInHibernate(Session arg0) throws HibernateException, SQLException {

            SQLQuery query = arg0.createSQLQuery(" select OD.* from ps_order as OD "
                    + "         inner join ps_shop as SH on SH.id = OD.id_shop " + " where SH.id_seller = ?");
            query.addEntity(PsOrder.class);
            query.setInteger(0, id);
            return query.list();
        }
    });
}

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from ww  w  .j ava  2s  .c o  m*/
public List<PsRecipient> findByCustomId(final Integer id) {
    return getHibernateTemplate().executeFind(new HibernateCallback<List<PsRecipient>>() {

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

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

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*www. jav a  2  s  . co  m*/
public List<PsSeller> findAll(final FetchOption fetchOption) {
    log.debug("find all PsSeller");
    try {
        return getHibernateTemplate().executeFind(new HibernateCallback<List<PsSeller>>() {

            @Override
            public List<PsSeller> doInHibernate(Session arg0) throws HibernateException, SQLException {

                SQLQuery query = arg0.createSQLQuery("select * from ps_seller as P order by P.id "
                        + (fetchOption.sortOption == SortOption.ASCENDING ? "asc" : "desc"));

                query.addEntity(PsSeller.class);
                return query.list();
            }

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

}

From source file:com.bitranger.parknshop.seller.dao.PsNoticeSellerDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from w  w  w  . j ava 2  s . c  om*/
public List<PsNoticeSeller> getLatest(final int sellerID, final int n) {

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

        @Override
        public List<PsNoticeSeller> doInHibernate(Session arg0) throws HibernateException, SQLException {

            SQLQuery q = arg0.createSQLQuery(" select ps_notice_seller as NS "
                    + " where NS.is_valid = 1 and id_seller = ? " + " order by time_created desc limit ?");
            q.setInteger(0, sellerID);
            q.setInteger(1, n);
            q.addEntity(PsNoticeSeller.class);
            return q.list();
        }

    });
}

From source file:com.bitranger.parknshop.task.order.OrderPaid.java

License:Open Source License

@Override
public void run() {

    getHibernateTemplate().execute(new HibernateCallback<Void>() {

        @Override//w ww.  java2 s  .  c o m
        public Void doInHibernate(Session arg0) throws HibernateException, SQLException {

            SQLQuery query = arg0.createSQLQuery("");

            @SuppressWarnings("unchecked")
            List<PsOrder> orders = query.list();
            for (PsOrder psOrder : orders) {

                PsNoticeCustomer cnotice = new PsNoticeCustomer();
                cnotice.setPsCustomer(psOrder.getPsCustomer());
                cnotice.setMessage("Unpaied order cancled");
                save(cnotice);

                PsNoticeSeller nSeller = new PsNoticeSeller();
                nSeller.setPsSeller(psOrder.getPsShop().getPsSeller());
                nSeller.setMessage("Unpaied order cancled");
                psNoticeSellerDAO.save(nSeller);

                psOrderDAO.delete(psOrder);

            }
            return null;
        }
    });
}