List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.ikon.module.db.DbDashboardModule.java
License:Open Source License
/** * Get mails from statement//from w w w .j av a2 s. c om */ @SuppressWarnings("unchecked") private ArrayList<DashboardMailResult> getUserMails(String user, String source, String qs) throws DatabaseException { log.debug("getUserMails({}, {}, {})", new Object[] { user, source, qs }); ArrayList<DashboardMailResult> al = new ArrayList<DashboardMailResult>(); org.hibernate.Session hSession = null; try { hSession = HibernateUtil.getSessionFactory().openSession(); org.hibernate.Query q = hSession.createQuery(qs); q.setString("user", user); q.setMaxResults(MAX_RESULTS); for (Iterator<Activity> it = q.list().iterator(); it.hasNext();) { Activity act = it.next(); try { NodeMail nMail = NodeMailDAO.getInstance().findByPk(act.getItem()); Mail mail = BaseMailModule.getProperties(user, nMail); DashboardMailResult vo = new DashboardMailResult(); vo.setMail(mail); vo.setDate(act.getDate()); vo.setVisited(false); al.add(vo); } catch (PathNotFoundException e) { // Do nothing } } } catch (HibernateException e) { throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(hSession); } log.debug("getUserMails: {}", al); return al; }
From source file:com.ikon.vernum.BranchVersionNumerationAdapter.java
License:Open Source License
@Override public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer) { String curVersionName = nDocVer.getName(); String nextVersionName = curVersionName; Query q = session.createQuery(qs); NodeDocumentVersion ndv = null;/* w w w .ja v a2s . c om*/ do { nextVersionName = buildVersionName(nextVersionName); q.setString("parent", nDoc.getUuid()); q.setString("name", nextVersionName); ndv = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); if (ndv != null) { nextVersionName = curVersionName + ".0"; } } while (ndv != null); return nextVersionName; }
From source file:com.ikon.vernum.MajorMinorReleaseVersionNumerationAdapter.java
License:Open Source License
@Override public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer) { String versionNumber = nDocVer.getName(); String ver[] = versionNumber.split("\\."); int major = Integer.parseInt(ver[0]); int minor = Integer.parseInt(ver[1]); int release = Integer.parseInt(ver[2]); Query q = session.createQuery(qs); NodeDocumentVersion ndv = null;//from www .j ava 2 s.co m do { release++; q.setString("parent", nDoc.getUuid()); q.setString("name", major + "." + minor + "." + release); ndv = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); } while (ndv != null); return major + "." + minor + "." + release; }
From source file:com.ikon.vernum.MajorMinorVersionNumerationAdapter.java
License:Open Source License
@Override public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer) { String versionNumber = nDocVer.getName(); String ver[] = versionNumber.split("\\."); int major = Integer.parseInt(ver[0]); int minor = Integer.parseInt(ver[1]); Query q = session.createQuery(qs); NodeDocumentVersion ndv = null;//from w w w . j av a 2 s .c o m do { minor++; q.setString("parent", nDoc.getUuid()); q.setString("name", major + "." + minor); ndv = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); } while (ndv != null); return major + "." + minor; }
From source file:com.ikon.vernum.PlainVersionNumerationAdapter.java
License:Open Source License
@Override public String getNextVersionNumber(Session session, NodeDocument nDoc, NodeDocumentVersion nDocVer) { String versionNumber = nDocVer.getName(); int nextVerNumber = Integer.parseInt(versionNumber); Query q = session.createQuery(qs); NodeDocumentVersion ndv = null;/*w w w . j av a 2s. c om*/ do { nextVerNumber++; q.setString("parent", nDoc.getUuid()); q.setString("name", String.valueOf(nextVerNumber)); ndv = (NodeDocumentVersion) q.setMaxResults(1).uniqueResult(); } while (ndv != null); return String.valueOf(nextVerNumber); }
From source file:com.impetus.client.rdbms.HibernateClient.java
License:Apache License
/** * Find./*from w w w . ja va 2 s .c om*/ * * @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.//w ww. j a va 2s .co 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; }
From source file:com.ineunet.knife.persist.dao.support.PaginationDaoSupport.java
License:Apache License
@Override public List<T> list(QueryParameters queryParameters, int start, int rows, String orderBy) { Map<String, Object> paramValues = new HashMap<String, Object>(); String jql = this.prepareQuery(queryParameters, paramValues); if (orderBy != null && orderBy.trim().length() != 0) jql += " order by o." + orderBy; Query query = this.createQuery(jql, paramValues); query.setFirstResult(start);/* www. java2 s.c om*/ query.setMaxResults(rows); @SuppressWarnings("unchecked") List<T> list = query.list(); return list; }
From source file:com.ineunet.knife.persist.dao.support.PaginationDaoSupport.java
License:Apache License
@Override public List<T> list(QueryParameters queryParameters) { QueryParamParser param = new QueryParamParser(queryParameters); int start = param.getStart(); String orderBy = param.getOrderBy(); int rows = param.getRows(); Map<String, Object> paramValues = new HashMap<String, Object>(); String jql = this.prepareQuery(queryParameters, paramValues); if (orderBy != null && orderBy.trim().length() != 0) jql += " order by o." + orderBy; Query query = this.createQuery(jql, paramValues); query.setFirstResult(start);// w w w . ja v a 2s . co m query.setMaxResults(rows); @SuppressWarnings("unchecked") List<T> list = query.list(); return list; }
From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java
@Override public List<EmpEliminationViewModel> getListEmpEliminationViewModelByParam( EmpEliminationSearchParameter searchParameter, int firstResult, int maxResults, Order order) { final StringBuilder query = new StringBuilder("SELECT empCareerHistory.id AS empCareerHistoryId,"); query.append(" bioData.id AS bioDataId,"); query.append(" careerTransition.id AS careerTransitionId,"); query.append(" jabatan.id AS lastJabatanId,"); query.append(" empCareerHistory.nik as nik,"); query.append(" jabatan.name AS jabatanName,"); query.append(" empCareerHistory.status AS empCareerHistoryStatus,"); query.append(" empCareerHistory.tglPenganngkatan AS terminationDate"); query.append(" FROM EmpCareerHistory empCareerHistory"); query.append(" INNER JOIN empCareerHistory.bioData bioData"); query.append(" INNER JOIN empCareerHistory.careerTransition careerTransition"); query.append(" INNER JOIN empCareerHistory.jabatan jabatan"); query.append(" INNER JOIN careerTransition.systemCareerConst systemCareerConst"); query.append(" WHERE systemCareerConst.isWork = 0 "); //filter by search param query.append(doSearchEmpEliminationViewModelByParam(searchParameter)); query.append("ORDER BY " + order); Query hbm = getCurrentSession().createQuery(query.toString()); hbm = this.setValueQueryEmpEliminationViewModelByParam(hbm, searchParameter); return hbm.setMaxResults(maxResults).setFirstResult(firstResult) .setResultTransformer(Transformers.aliasToBean(EmpEliminationViewModel.class)).list(); }