List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(Class entityType);
From source file:com.bitranger.parknshop.common.dao.impl.PsCommentDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w. j av a 2 s . co m public List<PsComment> findByCustomerId(final Integer customerId, final FetchOption option) { log.debug("findByCustomerId: " + customerId); try { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsComment>>() { @Override public List<PsComment> doInHibernate(Session arg0) throws HibernateException, SQLException { SQLQuery query = arg0.createSQLQuery("select * from ps_comment where id_customer = ? " + "order by time_created " + (option.sortOption == SortOption.ASCENDING ? " asc " : " desc ") + "limit ?, ?"); query.setInteger(0, customerId); query.setInteger(1, option.offset); query.setInteger(2, option.limit); query.addEntity(PsComment.class); return query.list(); } }); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }
From source file:com.bitranger.parknshop.common.dao.impl.PsCommentDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//w w w.j av a 2 s. co m public List<PsComment> findByItemId(final Integer itemId, final FetchOption option) { log.debug("findByItemId: " + itemId); try { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsComment>>() { @Override public List<PsComment> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery("select * from ps_comment where id_item = ? " + " order by time_created " + (option.sortOption == SortOption.ASCENDING ? " asc " : " desc ") + "limit ?, ?"); query.setInteger(0, itemId); query.setInteger(1, option.offset); query.setInteger(2, option.limit); query.addEntity(PsComment.class); return query.list(); } }); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }
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. jav a2s. c om*/ order by IT.time_created desc limit 0, ? */ @SuppressWarnings("unchecked") @Override public List<PsItem> selectLatest(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 IT.time_created 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
/** select IT.*, count(IT.count_purchase) as CT from ps_item as IT where IT.id_category = ?// w w w .j a v 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 www.j a va 2 s .c om public List<PsItem> searchByKeyword(final String q) { return getHibernateTemplate().executeFind(new HibernateCallback<List<PsItem>>() { @Override public List<PsItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery(" SELECT IT.*, " + " MATCH (`name`, `introduction`) AGAINST (? IN NATURAL LANGUAGE MODE) AS relevance " + " FROM `ps_item` as IT " + " ORDER BY relevance DESC"); query.setString(0, q); query.addEntity(PsItem.class); return query.list(); } }); }
From source file:com.bitranger.parknshop.common.dao.impl.PsItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w ww. j a va 2s. com*/ 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// ww w . j a v a 2 s . c om 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/*from w w w .j av a 2s. co m*/ 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/*from w w w. ja v a 2 s .com*/ 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/* www. j a v a2 s . com*/ 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; } }