List of usage examples for org.hibernate SQLQuery list
List<R> list();
From source file:com.abiquo.server.core.infrastructure.RackDAO.java
License:Open Source License
/** * Obtains the racks (prefiltered by target datacenter and virtualdatacenter) with minimal VLANS * // and with vms deployed//w ww . j a v a2 s. c o m */ public List<Integer> getRackIdByMinVLANCount(final int idDatacenter) { SQLQuery query = getSession().createSQLQuery(SQL_RACK_IDS_BY_MIN_VLAN_COUNT); query.setInteger("idDatacenter", idDatacenter); return query.list(); }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * SQL (=?)/*ww w . j a v a 2 s . co m*/ * * @param sql * SQL * @param param * ? * @return ??object */ @SuppressWarnings("unchecked") public List findList(String sql, Object... param) { SQLQuery query = getSession().createSQLQuery(sql); if (param != null && param.length > 0) { for (int i = 0; i < param.length; i++) { query.setParameter(i, param[i]); } } return query.list(); }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * SQL (=:property)/*from w ww. ja v a 2s.co m*/ * * @param sql * SQL * @param values * ? * @return ??object */ @SuppressWarnings("unchecked") public List findListByProperty(String sql, final Map<String, Object> values) { SQLQuery query = getSession().createSQLQuery(sql); if (values != null && values.size() > 0) { query.setProperties(values); } return query.list(); }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ?SQL//from w ww.jav a 2 s. c o m * * @param pageSize * ??,0? * @param pageNo * ??1? * @param sql * SQL * @param param * ? * @return ??object */ @SuppressWarnings("unchecked") public List findList(int pageSize, int pageNo, String sql, Object... param) { if (pageSize <= 0 || pageNo <= 0) { // ? return findList(sql, param); } SQLQuery query = getSession().createSQLQuery(sql); query.setFirstResult(((pageNo - 1) * pageSize)); query.setMaxResults(pageSize); if (param != null && param.length > 0) { for (int i = 0; i < param.length; i++) { query.setParameter(i, param[i]); } } return query.list(); }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * SQL//from w w w . j a v a 2s.c o m * * @param pageSize * ??,0? * @param pageNo * ??1? * @param sql * SQL * @param clazz * ?list * @param param * ? * @return */ @SuppressWarnings("unchecked") public List findList(int pageSize, int pageNo, String sql, Class clazz, Object... param) { if (pageSize <= 0 || pageNo <= 0) { // ? return findList(sql, clazz, param); } SQLQuery query = getSession().createSQLQuery(sql).addEntity(clazz); query.setFirstResult(((pageNo - 1) * pageSize)); query.setMaxResults(pageSize); if (param != null && param.length > 0) { for (int i = 0; i < param.length; i++) { query.setParameter(i, param[i]); } } return query.list(); }
From source file:com.algoTrader.entity.marketData.TickDaoBase.java
/** * {@inheritDoc}/*www . j a v a2 s.c om*/ */ @Override @SuppressWarnings("unchecked") public Object findLastTickForSecurityAndMaxDate(final int transform, final String queryString, final int securityId, final Date maxDate) { try { SQLQuery queryObject = super.getSession(false).createSQLQuery(queryString); queryObject.addEntity(TickImpl.class); queryObject.setParameter("securityId", new Integer(securityId)); queryObject.setParameter("maxDate", maxDate); Set results = new LinkedHashSet(queryObject.list()); Object result = null; if (results.size() > 1) { throw new InvalidDataAccessResourceUsageException( "More than one instance of 'com.algoTrader.entity.marketData.Tick" + "' was found when executing query --> '" + queryString + "'"); } else if (results.size() == 1) { result = results.iterator().next(); } if (transform != TRANSFORM_NONE) { result = transformEntity(transform, (Tick) result); } return result; } catch (HibernateException ex) { throw super.convertHibernateAccessException(ex); } }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public <T> List<T> findByNativeQueryTransformer(final Class<T> transformerClass, final String queryString, final int firstResult, final int maxResults, final Map values) { final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() { @Override//from w w w . jav a 2 s .c o m public Object doInHibernate(Session session) throws HibernateException { final SQLQuery query = session.createSQLQuery(queryString); query.setResultTransformer(Transformers.aliasToBean(transformerClass)); setPagination(query, firstResult, maxResults); setNamedParameters(values, query); return query.list(); } }); traceResults(list); return list; }
From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java
License:Open Source License
@Override public <T> List<T> findByNativeQueryTransformerWithListParametersSupport(final Class<T> transformerClass, final String sqlQueryString, final Map values, final int firstResult, final int maxResults) { @SuppressWarnings("unchecked") final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() { @Override/*from w w w . ja v a2s. c o m*/ public Object doInHibernate(Session session) throws HibernateException { final SQLQuery query = session.createSQLQuery(sqlQueryString); query.setResultTransformer(Transformers.aliasToBean(transformerClass)); setPagination(query, firstResult, maxResults); setNamedParametersWithListSupport(values, query); return query.list(); } }); traceResults(list); return list; }
From source file:com.bitranger.parknshop.buyer.dao.CustomerFavouriteItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CustomerFavouriteItem> findByCustomerId(final Integer psCustomerId, final FetchOption option) { try {//from w w w . jav a2 s . c o m return getHibernateTemplate().executeFind(new HibernateCallback<List<CustomerFavouriteItem>>() { @Override public List<CustomerFavouriteItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session .createSQLQuery("select * from customer_favourite_item as C where C.id_customer = ?" + " order by C.time_created " + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc") + " limit ? offset ?"); query.setInteger(0, psCustomerId); query.setInteger(1, option.limit); query.setInteger(2, option.offset); query.addEntity(CustomerFavouriteItem.class); return query.list(); } }); } catch (RuntimeException e) { log.error("get failed", e); throw e; } }
From source file:com.bitranger.parknshop.buyer.dao.impl.CartCustomerItemDAO.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w ww. j a v a 2s. co m public List<CartCustomerItem> findByCustomerId(final Integer psCustomerId, final FetchOption option) { log.debug("getting CartCustomerItem instance with psCustomerId: " + psCustomerId); try { return getHibernateTemplate().executeFind(new HibernateCallback<List<CartCustomerItem>>() { @Override public List<CartCustomerItem> doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session .createSQLQuery("select * from cart_customer_item as C where C.id_customer = ?" + " order by C.time_created " + (option.sortOption == SortOption.ASCENDING ? "asc" : "desc") + " limit ? offset ?"); query.setInteger(0, psCustomerId); query.setInteger(1, option.limit); query.setInteger(2, option.offset); query.addEntity(CartCustomerItem.class); return query.list(); } }); } catch (RuntimeException e) { log.error("get failed", e); throw e; } }