List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
From source file:com.hyzy.core.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?? /* w w w . j av a 2 s. c o m*/ * @author:lizhong * @param <T> * @param firstIndex * @param maxResult ?? 'maxResult''firstIndex''-1',?. * @param wheresql where??,???where,???param1 * :" o.username= :param1 and o.email= param2....." * @param params where????. * @param orderBy ?sql?orderby ?,map?key??,????(desc or asc) * @return */ @SuppressWarnings("unchecked") public QueryResult<T> getScrollData(int firstIndex, int maxResult, String wheresql, Object[] params, LinkedHashMap<String, String> orderBy) { String where = wheresql == null || "".equals(wheresql.trim()) ? "" : " where " + wheresql; String entityName = entityClass.getName(); String hql = "select o from " + entityName + " o " + where + buildOrderby(orderBy); Query query = getSession().createQuery(hql); setQueryParam(query, params); if (firstIndex != -1 && maxResult != -1) { query.setFirstResult(firstIndex).setMaxResults(maxResult); } QueryResult<T> qr = new QueryResult<T>(); qr.setResultList(query.list()); query = getSession() .createQuery("select count(" + getCountField(entityClass) + ") from " + entityName + " o " + where); setQueryParam(query, params); qr.setTotalRecord((Long) query.uniqueResult()); return qr; }
From source file:com.hyzy.core.orm.hibernate.HibernateDao.java
License:Apache License
protected Query setPageParameterToSqlQuery(final Query q, final Page<T> page) { Assert.isTrue(page.getPageSize() > 0, "Page Size must larger than zero"); //hibernatefirstResult??0 q.setFirstResult(page.getFirst() - 1); q.setMaxResults(page.getPageSize()); return q;/*from ww w .j a v a2 s .c o m*/ }
From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java
License:Open Source License
@Override public List<DverDetail> findAllRejectedDvers(final int start, final int end) throws DataAccessException { logger.info("Find All Rejected Dvers...."); List rejectedDvers = getHibernateTemplate().executeFind(new HibernateCallback<List<DverDetail>>() { @Override//www. j av a2s. c o m public List<DverDetail> doInHibernate(Session session) throws HibernateException, SQLException { org.hibernate.Query q = session.createQuery(FIND_REJECTED_DVERS); q.setFirstResult(start); q.setMaxResults(end); return q.list(); } }); return (!CollectionUtils.isEmpty(rejectedDvers)) ? rejectedDvers : new ArrayList<DverDetail>(); }
From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java
License:Open Source License
@Override public List<DverNotif> findAllFailNotifications(final int start, final int end) throws DataAccessException { List failNotifs = getHibernateTemplate().executeFind(new HibernateCallback<List<DverNotif>>() { @Override/* www.j a v a2 s .com*/ public List<DverNotif> doInHibernate(Session session) throws HibernateException, SQLException { logger.info("find All Failed Notifications ...."); org.hibernate.Query q = session.createQuery(FIND_FAIL_NOTIFICATIONS); q.setFirstResult(start); q.setMaxResults(end); return q.list(); } }); return (!CollectionUtils.isEmpty(failNotifs)) ? failNotifs : new ArrayList<DverNotif>(); }
From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java
License:Open Source License
@Override public List<DverDetail> filterRejectedDvers(Map<String, String> filtermap, int start, int end) throws DataAccessException { logger.info("filter Rejected DVER's By Scac Or Dot....."); Session session = SessionFactoryUtils.getSession(this.getSessionFactory(), true); String filterQuery = generateQuery(filtermap, Boolean.FALSE); logger.info("filter query for Rejected DVER's is :: " + filterQuery); Query filters = session.createQuery(filterQuery); filters.setFirstResult(start); filters.setMaxResults(end);//from w w w. ja va2 s. c om List result = filters.list(); session.close(); return result != null ? result : new ArrayList<DverDetail>(); }
From source file:com.iana.dver.dao.impl.DverUsersDaoImpl.java
License:Open Source License
@Override public List<DverUsers> findAllUsersByType(final Integer userTypeId, final Integer start, final Integer end, final String sortColumnIndex, final String sSortDirection) throws DataAccessException { List result = getHibernateTemplate().executeFind(new HibernateCallback<List<DverUsers>>() { @Override/*from w w w . j a va 2 s .c o m*/ public List<DverUsers> doInHibernate(Session session) throws HibernateException, SQLException { logger.info("find AllUsers By Type "); StringBuilder query = new StringBuilder( "FROM DverUsers DU WHERE DU.dverUserType.dverUserTypeId in (2,3) "); if (sortColumnIndex.equalsIgnoreCase("0")) { query.append("order by DU.companyName "); } else if (sortColumnIndex.equalsIgnoreCase("2")) { query.append("order by DU.fname "); } else if (sortColumnIndex.equalsIgnoreCase("3")) { query.append("order by DU.lname "); } query.append(sSortDirection); logger.info("All user listing query is :: " + query.toString()); Query q = session.createQuery(query.toString()); q.setFirstResult(start); q.setMaxResults(end); return q.list(); } }); return result != null ? result : new ArrayList<DverUsers>(); }
From source file:com.iana.dver.dao.impl.DverUsersDaoImpl.java
License:Open Source License
@Override public List<DverUsers> filterUserByScacOrDot(Integer userTypeId, Map<String, String> filtermap, Integer start, Integer end) throws DataAccessException { logger.info("filter User By Scac Or Dot....."); Session session = SessionFactoryUtils.getSession(this.getSessionFactory(), true); String filterQuery = generateQuery(userTypeId, filtermap, Boolean.FALSE); logger.info("user filter query is :: " + filterQuery); Query filters = session.createQuery(filterQuery); filters.setFirstResult(start); filters.setMaxResults(end);//from w w w. ja v a 2s . co m List result = filters.list(); session.close(); return result != null ? result : new ArrayList<DverUsers>(); }
From source file:com.ignou.aadhar.dao.hibernate.CityDaoHibernate.java
License:Open Source License
/************************************************************************ * THIS METHOD IS ONLY FOR REFERENCE. I WAS GOING FORWARD WITH THIS ONE * BUT WAS ABLE TO IMPLEMENT THE SAME WITH HIBERNATE CRITERIA. MIGHT * NEED THIS CODE SOME TIME LATER. HENCE NOT DELETED. * @param city//from www .j a va 2 s . c om * @param state * @param pageNumber * @param recordsPerPage * @param sortField * @param sortOrder * @return */ public List<Map<String, Object>> getCitiesHQL(String city, String state, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<Object[]> cities = null; /* Set the default sort field if not provided */ if (sortField == null || "".equals(sortField)) { sortField = "city"; } /* Set the default sort order if not provided */ if (sortOrder == null || "".equals(sortOrder)) { sortField = "asc"; } String searchString = ""; /* Add the city field search condition if provided */ if (city != null && !city.isEmpty()) { searchString += " AND city like '%" + city + "%' "; } /* Add the State field search condition if provided */ if (state != null && !state.isEmpty()) { searchString += " AND state.state like '%" + state + "%' "; } /* Create the Query now */ Query cityQuery = getSession().createQuery("SELECT c.id, c.city, c.state.state FROM city c " + "WHERE (1=1) " + searchString + "ORDER BY " + sortField + " " + sortOrder); /* Lets also count the total number of records matching the criteria */ int totalRecordCount = 0; /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { cities = cityQuery.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { cities = cityQuery.list(); } return null; }
From source file:com.impetus.client.rdbms.HibernateClient.java
License:Apache License
/** * Find.// w w w .j av a 2 s . co m * * @param query * the native fquery * @param parameterMap * the parameter map * @param maxResult * @param firstResult * @return the list */ public List findByQuery(String query, Map<Parameter, Object> parameterMap, int firstResult, int maxResult) { s = getStatelessSession(); Query q = s.createQuery(query); q.setFirstResult(firstResult); q.setMaxResults(maxResult); setParameters(parameterMap, q); return q.list(); }
From source file:com.impetus.client.rdbms.HibernateClient.java
License:Apache License
/** * Find.//from ww w. jav a2 s.c o m * * @param query * the native fquery * @param parameterMap * the parameter map * @param maxResult * @param firstResult * @return the list */ public int onExecuteUpdate(String query, Map<Parameter, Object> parameterMap, int firstResult, int maxResult) { s = getStatelessSession(); Query q = s.createQuery(query); q.setFirstResult(firstResult); q.setMaxResults(maxResult); setParameters(parameterMap, q); Transaction tx = onBegin(); int i = q.executeUpdate(); onCommit(tx); // tx.commit(); return i; }