List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getPreIdAuthenticateUsers(CountRequest req) { try {// ww w .ja v a 2 s .c om //String userId, int type, String field1, // String field2, Long updateTime, int userType String hql = "select new com.consult.app.response.admin.AuthenticateUserItem(" + "user.userId, 3, certificate.idNumber, certificate.realName, user.updateTime, profile.userType, user.telephone) " + "from User user, Certificate certificate, Profile profile " + "where user.userId=profile.userId and user.certificateId=certificate.userId " + "and user.isAuthenticate=? order by user.userId asc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, Constant.USER_AUTHENTICATE_WAIT); query.setFirstResult(0); query.setMaxResults(req.getCount()); return query.list(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getLongUnloginUserTelephone(int appType, Long startId, int count, Long threshTime) { try {//w ww. ja v a 2 s . co m // String content, Integer pushType, String token, // Integer notificationType, int badgeCount String hql = "select new com.consult.app.response.user.TelephoneItem(user.telephone) " + "from User user, Token token " + "where user.userId=token.userId and user.token=token.token and user.userId>? "; if (appType != Cookie.APP_TYPE_ALL) { hql = hql + " and user.loginFrom=? "; } hql = hql + " and profile.userType=? and user.lastLogin<? order by user.userId asc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); int i = 0; query.setLong(i, startId); if (appType != Cookie.APP_TYPE_ALL) { query.setInteger(++i, appType); } query.setInteger(++i, Constant.USER_TYPE_TRUCKER); query.setLong(++i, threshTime); query.setFirstResult(0); query.setMaxResults(count + 1); return query.list(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getReadyToCheckUser(Long startId, int count) { try {//from w ww . ja v a 2 s .c o m // String content, Integer pushType, String token, // Integer notificationType, int badgeCount String hql = "from User user " + "where user.userId>? and user.smsLocate=? order by user.userId asc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, startId); query.setInteger(1, Constant.SMS_LOCATE_READY_TO_CHECK); query.setFirstResult(0); query.setMaxResults(count + 1); return query.list(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
public List<Object> searchDriverList(SearchDriverRequest req) { /**//from w ww. j a v a 2 s . c om * */ long possitionTime = System.currentTimeMillis() - TimeUtils.DAY * 14; Query query = null; StringBuffer querysql = new StringBuffer(""); String truckLengthCondition = req.getTruckLength() <= 0d ? "" : "and p.truck_length=:truckLength"; String sqlTem = "(select u.user_id as userId,p.picture as picture,p.user_name as userName,u.telephone as telephone,p.truck_length as truckLength,p.truck_load as truckLoad,p.truck_type as truckType,p.number as number,u.is_authenticate as isAuthenticate,u.create_time as updateTime,p.order_count as orderCount,u.city as cityId,abs(u.city-:start) as sortFlag from users u, profiles p, %s sub, search_conditions sc where sub.user_id=u.user_id and u.user_id=p.user_id and p.user_type=1 and sub.search_id=sc.search_id and u.telephone>13000000000 " + truckLengthCondition + " and sub.push_subscribe=1 and u.push_subscribe=1 and u.type=1 and sub.type>0 and (sc.end=:end or sc.end=:endFather) and (sc.start=:start or sc.start=:startFather) and u.update_time>:before and u.update_time<:after and u.update_time>:possitionTime)"; for (int i = 0; i < Constant.SHARD_TABLE_SUBSCRIBE.length; i++) { if (i == 0) { querysql.append("select t.* from (" + String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all "); } else if (i == Constant.SHARD_TABLE_SUBSCRIBE.length - 1) { querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + ") t group by t.userId order by t.sortFlag asc,t.updateTime desc");//,t.orderCount desc } else { querysql.append(String.format(sqlTem, Constant.SHARD_TABLE_SUBSCRIBE[i]) + " union all "); } } query = sessionFactory.getCurrentSession().createSQLQuery(querysql.toString()) .addScalar("userId", StandardBasicTypes.LONG).addScalar("picture", StandardBasicTypes.STRING) .addScalar("userName", StandardBasicTypes.STRING).addScalar("telephone", StandardBasicTypes.STRING) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("truckLoad", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER).addScalar("number", StandardBasicTypes.STRING) .addScalar("isAuthenticate", StandardBasicTypes.INTEGER) .addScalar("updateTime", StandardBasicTypes.LONG) .addScalar("orderCount", StandardBasicTypes.INTEGER).addScalar("cityId", StandardBasicTypes.INTEGER) .setResultTransformer(Transformers.aliasToBean(com.consult.app.response.truck.DriverInfo.class)); if (req.getTruckLength() > 0) { query.setDouble("truckLength", req.getTruckLength()); } query.setInteger("end", req.getEnd()).setInteger("endFather", req.getEndFather()) .setInteger("start", req.getStart()).setInteger("startFather", req.getStartFather()) .setLong("before", req.getBefore()).setLong("after", req.getAfter()) .setLong("possitionTime", possitionTime); query.setMaxResults(req.getCount()); @SuppressWarnings("unchecked") List<Object> all = query.list(); return all; }
From source file:com.copyright.common.hibernate.HibernateDao.java
License:Apache License
/** * ?Query,./*from ww w . ja v a 2 s. co m*/ */ protected Query setPageParameterToQuery(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 source file:com.corendal.netapps.wiki.writedatabeans.AbstractArticle.java
License:Open Source License
@Override public void load() { /*//w w w .j a va 2 s . co m * set the record as "not found" */ this.setIsFound(false); /* * initialize the populate flag */ this.isRawBodyHTMLPopulated = false; this.isBodyTextPopulated = false; this.isBodyHTMLPopulated = false; /* * initialize the prepared statement and the result set */ PreparedStatement prepStmt = null; ResultSet rs = null; /* * get the JDBC data session */ HibernateDataSession ds = DataSessionSetGlobal.get() .getSharedHibernateDataSession(DataSessionTypeConstants.WIKI_SHARED); /* * get the primary key of the article */ PrimaryKey entityPk = PrimaryKeyUtil.getAlphanumericSingleKey(EntitiesDictionary.ARTICLES); PrimaryKey recordPk = this.getPrimaryKey(); /* * retrieve the article information from the database */ String selectStatement = "select content_version.version_num, " + "content_version.version_info_id, content_version.request_id, " + "content_version.friendly_address, " + "content.content_class_typ_id, content_version.id, " + "content.content_rule_typ_id, content_version.cmnt, content.enabled_flag " + "from " + ds.getTableNameWithDefaultSchema("content_version") + ", " + ds.getTableNameWithDefaultSchema("content") + " " + "where content_version.content_id = ? " + "and content.content_typ_id = ? " + "and content_version.current_flag = ? " + "and content.id = content_version.content_id "; // FIXME: hibernate select query try { /* * create the prepared statement */ prepStmt = ds.getReadConnection().prepareStatement(selectStatement); /* * associate the id and the article type */ prepStmt.setString(1, recordPk.toString()); prepStmt.setString(2, ContentTypesDictionary.ARTICLE); prepStmt.setString(3, "Y"); /* * execute the query */ rs = prepStmt.executeQuery(); /* * loop the results */ while (rs.next()) { this.setIsFound(true); this.versionNum = rs.getInt(1); this.versionInfoId = rs.getString(2); this.requestId = rs.getString(3); this.friendlyAddress = rs.getString(4); this.contentClassTypeId = rs.getString(5); this.versionId = rs.getString(6); this.contentRuleTypeId = rs.getString(7); this.comment = ds.getStringFromCharacterStream(rs, 8); this.enabledFlag = rs.getString(9); } } catch (Exception e) { /* * log the exception */ this.appendLoadTrace(e.getMessage()); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, recordPk); } finally { /* * close the recordset and the prepared statement */ CloseUtil.closeResultSet(rs); CloseUtil.closePreparedStatement(prepStmt); } /* * retrieve the parent information from the database */ if (this.getIsFound()) { /* * retrieve the parent information from the database */ try { /* * get the query */ Query query = ds.getReadNamedQuery(LOAD); /* * associate the query parameters */ query.setParameter("childContentId", recordPk.toString()); query.setParameter("mainFlag", "Y"); /* * only get one content map */ query.setMaxResults(1); /* * get content map mapping */ ContentMapMapping contentMapMapping = (ContentMapMapping) query.uniqueResult(); /* * store values from mapping */ if (contentMapMapping != null) { this.mainParentId = contentMapMapping.getParentContentId(); } } catch (Exception e) { /* * log the exception */ this.appendLoadTrace(e.getMessage()); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, recordPk); } } /* * retrieve the editor from the database */ if (this.getIsFound()) { PrimaryKey rolePk = PrimaryKeyUtil.getAlphanumericSingleKey(RolesDictionary.EDITOR); this.editorId = AccountRoleXrefFactory.getSingleAccountId(this, ds, entityPk, rolePk, recordPk); } /* * retrieve the associate editors from the database */ if (this.getIsFound()) { PrimaryKey rolePk = PrimaryKeyUtil.getAlphanumericSingleKey(RolesDictionary.EDITOR); this.associateEditorsId = GroupRoleXrefFactory.getSingleGroupId(this, ds, entityPk, rolePk, recordPk); } /* * retrieve the author information from the database */ if (this.getIsFound()) { selectStatement = "select account_role_xref.account_id " + "from " + ds.getTableNameWithDefaultSchema("account_role_xref") + ", " + ds.getTableNameWithDefaultSchema("content_version") + " " + "where content_version.version_num= ? " + "and content_version.content_id = ? " + "and account_role_xref.role_id = ? " + "and account_role_xref.entity_id = ? " + "and content_version.id=account_role_xref.record_id"; // FIXME: hibernate select query try { /* * create the prepared statement */ prepStmt = ds.getReadConnection().prepareStatement(selectStatement); /* * associate the id, the version number and the editor role */ prepStmt.setInt(1, this.versionNum); prepStmt.setString(2, recordPk.toString()); prepStmt.setString(3, RolesDictionary.AUTHOR); prepStmt.setString(4, EntitiesDictionary.ARTICLE_VERSIONS); /* * execute the query */ rs = prepStmt.executeQuery(); /* * loop the results */ this.authorId = null; while (rs.next()) { this.authorId = rs.getString(1); } } catch (Exception e) { /* * log the exception */ this.appendLoadTrace(e.getMessage()); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, recordPk); } finally { /* * close the recordset and the prepared statement */ CloseUtil.closeResultSet(rs); CloseUtil.closePreparedStatement(prepStmt); } } /* * load this write data bean */ if (this.getIsFound()) { super.load(entityPk, recordPk); } }
From source file:com.corendal.netapps.wiki.writedatabeans.AbstractArticle.java
License:Open Source License
/** * Populates the body of this article./*from w w w .j a va 2s . c o m*/ */ private void populateBodyHTML() { /* * indicate that the body has been populated */ this.isBodyHTMLPopulated = true; /* * get the JDBC data session */ HibernateDataSession ds = DataSessionSetGlobal.get() .getSharedHibernateDataSession(DataSessionTypeConstants.WIKI_SHARED); /* * get the primary key of the article */ PrimaryKey entityPk = PrimaryKeyUtil.getAlphanumericSingleKey(EntitiesDictionary.ARTICLES); PrimaryKey recordPk = this.getPrimaryKey(); /* * retrieve the body html information from the database */ if (this.getIsFound()) { try { /* * get the query */ Query query = ds.getReadNamedQuery(POPULATE_BODY_HTML); /* * associate the query parameters */ query.setParameter("contentVersionId", this.versionId); /* * only get one content body */ query.setMaxResults(1); /* * get content body mapping */ ContentBodyMapping contentBodyMapping = (ContentBodyMapping) query.uniqueResult(); this.bodyHTML = null; /* * store values from mapping */ if (contentBodyMapping != null) { this.bodyHTML = contentBodyMapping.getBodyHtml(); } } catch (Exception e) { /* * log the exception */ this.appendLoadTrace(e.getMessage()); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, recordPk); } } }
From source file:com.corendal.netapps.wiki.writedatabeans.AbstractArticle.java
License:Open Source License
/** * Populates the body of this article.//from www. ja v a 2s .com */ private void populateBodyText() { /* * indicate that the body has been populated */ this.isBodyTextPopulated = true; /* * get the JDBC data session */ HibernateDataSession ds = DataSessionSetGlobal.get() .getSharedHibernateDataSession(DataSessionTypeConstants.WIKI_SHARED); /* * get the primary key of the article */ PrimaryKey entityPk = PrimaryKeyUtil.getAlphanumericSingleKey(EntitiesDictionary.ARTICLES); PrimaryKey recordPk = this.getPrimaryKey(); /* * retrieve the body text information from the database */ if (this.getIsFound()) { try { /* * get the query */ Query query = ds.getReadNamedQuery(POPULATE_BODY_TEXT); /* * associate the query parameters */ query.setParameter("contentVersionId", this.versionId); /* * only get one content body */ query.setMaxResults(1); /* * get content body mapping */ ContentBodyMapping contentBodyMapping = (ContentBodyMapping) query.uniqueResult(); this.bodyText = null; /* * store values from mapping */ if (contentBodyMapping != null) { this.bodyText = contentBodyMapping.getBodyText(); } } catch (Exception e) { /* * log the exception */ this.appendLoadTrace(e.getMessage()); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, recordPk); } } }
From source file:com.corendal.netapps.wiki.writedatabeans.AbstractArticle.java
License:Open Source License
public PrimaryKey getFirstRequestPrimaryKey() { /*//from w ww . jav a 2 s. c o m * initialize the request id */ String firstRequestId = null; /* * get the JDBC data session */ HibernateDataSession ds = DataSessionSetGlobal.get() .getSharedHibernateDataSession(DataSessionTypeConstants.WIKI_SHARED); /* * get the primary key of the article */ PrimaryKey entityPk = PrimaryKeyUtil.getAlphanumericSingleKey(EntitiesDictionary.ARTICLES); PrimaryKey recordPk = this.getPrimaryKey(); try { /* * get the query */ Query query = ds.getReadNamedQuery(GET_FIRST_REQUEST_PRIMARY_KEY); /* * associate the query parameters */ query.setParameter("contentId", recordPk.toString()); query.setParameter("versionNumber", 1); /* * only get one version */ query.setMaxResults(1); /* * get content version mapping */ ContentVersionMapping contentVersionMapping = (ContentVersionMapping) query.uniqueResult(); /* * store values from mapping */ if (contentVersionMapping != null) { firstRequestId = contentVersionMapping.getRequestId(); } } catch (Exception e) { /* * log the exception */ this.appendLoadTrace(e.getMessage()); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, recordPk); } /* * return */ return PrimaryKeyUtil.getAlphanumericSingleKeyOrNull(firstRequestId); }
From source file:com.corendal.netapps.wiki.writedatabeans.AbstractArticle.java
License:Open Source License
/** * Returns a ranked list of all article primary keys that have been * accessed./*w w w . j a va 2 s. c o m*/ * * @param cnt * number of rows to return * * * @return a java.util.List object */ public static final List<PrimaryKey> findEnabledByRank(int cnt) { /* * initialize the result */ List<PrimaryKey> primaryKeys = new ArrayList<PrimaryKey>(); /* * initialize the prepared statement and the result set */ PreparedStatement prepStmt = null; ResultSet rs = null; /* * get the JDBC data session */ HibernateDataSession ds = DataSessionSetGlobal.get() .getSharedHibernateDataSession(DataSessionTypeConstants.WIKI_SHARED); /* * retrieve the content access period information from the database */ Date maxAccessDate = null; try { /* * get the query */ Query query = ds.getReadNamedQuery(FIND_ENABLED_BY_RANK_1); /* * only get one benefit */ query.setMaxResults(1); /* * get benefit mapping */ maxAccessDate = (Date) query.uniqueResult(); } catch (Exception e) { /* * log the exception */ PrimaryKey entityPk = PrimaryKeyUtil.getAlphanumericSingleKey(EntitiesDictionary.ARTICLES); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, null); } /* * retrieve the content information from the database */ if (maxAccessDate != null) { String selectStatement = "select content_id, access_rank, access_num " + "from " + ds.getTableNameWithDefaultSchema("content_access_period") + ", " + ds.getTableNameWithDefaultSchema("content") + " " + "where content_access_period.content_id = content.id " + "and content.content_typ_id = ? " + "and content_access_period.access_date = ? " + "order by access_date desc, access_rank "; // FIXME: hibernate select query try { /* * create the prepared statement */ prepStmt = ds.getReadConnection().prepareStatement(selectStatement); /* * associate the id */ prepStmt.setString(1, ContentTypesDictionary.ARTICLE); prepStmt.setDate(2, DateUtil.getDateToSQLDate(maxAccessDate)); /* * execute the query */ rs = prepStmt.executeQuery(); /* * loop the results */ int itemCount = 0; while ((rs.next()) && (itemCount < cnt)) { PrimaryKey pk = PrimaryKeyUtil.getAlphanumericSingleKey(rs.getString(1)); primaryKeys.add(pk); itemCount++; } } catch (Exception e) { /* * log the exception */ PrimaryKey entityPk = PrimaryKeyUtil.getAlphanumericSingleKey(EntitiesDictionary.ARTICLES); LoggerUtil.logError(ABSTRACT_CLASS_NAME, e, entityPk, null); } finally { /* * close the recordset and the prepared statement */ CloseUtil.closeResultSet(rs); CloseUtil.closePreparedStatement(prepStmt); } } /* * return all article primary keys */ return primaryKeys; }