List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public void doReSend(long start, long end, long now) { String hql = "from CargoMessage message where message.updateTime>? and message.updateTime<? and (message.type=? or message.type=?) order by message.updateTime desc"; if (end <= start) { return;//from ww w. j a v a 2 s . c om } if (end - start < Integer.MAX_VALUE) { end = start + (end - start) / 4 + RandomNumber.createRandomInt((int) (end - start) * 3 / 4); } Session session = null; List<CargoMessage> list = null; try { CargoMessageInterceptor inter = new CargoMessageInterceptor(end); session = sessionFactory.openSession(inter); Query query = session.createQuery(hql); query.setLong(0, start); query.setLong(1, end); query.setInteger(2, Constant.TYPE_NORMAL); query.setInteger(3, Constant.TYPE_XIWEI); query.setFirstResult(0); query.setMaxResults(20); list = query.list(); } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); session = null; } } if (list != null && !list.isEmpty()) { int i = RandomNumber.createRandomInt(list.size()); CargoMessage message = (CargoMessage) list.get(i); if (message.getType() == Constant.TYPE_ARTIFICIAL) { message.setType(Constant.TYPE_DELETE); update(message); } message.setMessageId(null); message.setUpdateTime(now); message.setModifyTime(now); message.setType(Constant.TYPE_ARTIFICIAL); // message.setUserId(0L); save(message); LogUtil.i(CargoMessage.class.getSimpleName(), "CargoMessage RESEND Success."); updateSubscribeProcess.processAddWithoutPush(message.getStart(), message.getEnd(), message.getEndFather(), message.getEndGrand(), Constant.MESSAGE_TYPE_CARGO, "", now); } else { LogUtil.i(CargoMessage.class.getSimpleName(), "CargoMessage RESEND Nothing."); } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Search Nearby cargoMessages by multiple trucklength * @param req//from ww w . j av a 2 s.c o m * @param endCity * @return */ private List<Object> getNearbyMultipleTruckLengthSearch(SearchCargoRequest req, City endCity) { // List<Object> list = new ArrayList<Object>(); Long today = TimeUtils.getStartOfDay(System.currentTimeMillis()); StringBuilder sb = new StringBuilder( String.format(Constant.NEARBY_CARGO_SEARCH_MULTIPLE_TRUCKLENGTH, today)); if (Double.valueOf(req.getTruckLength()) >= 0) { sb.append(" and find_in_set(").append(req.getTruckLength()).append(",message.truck_length_set)"); } if (req.getTruckType() >= 0) { sb.append(" and message.truck_type=").append(req.getTruckType()); } if (req.getWeightRange() > 0) { sb.append(" and message.cargo_weight_range=").append(req.getWeightRange()); } sb.append(" and city.id=").append(req.getStart()).append( " and (find_in_set(message.start, city.near_by) or find_in_set(message.start_father, city.near_by))") .append(" and (message.end=").append(endCity.getId()).append(" or message.end_father=") .append(endCity.getId()).append(" or message.end_grand=").append(endCity.getId()).append(" or 0=") .append(endCity.getId()).append(")"); sb.append(" and message.type>=? and message.type<4 order by message.update_time desc"); Long triggerTime = req.getAfter(); if (triggerTime.equals(Long.MAX_VALUE)) { triggerTime = System.currentTimeMillis(); } CargoMessageInterceptor inter = new CargoMessageInterceptor(); int count = req.getCount(); // for(int i = 0; i < Constant.SEARCH_TABLE_COUNT; i++) { Session session = null; try { // Long messageId, int type, // double weight, double capacity, int truckType, // String contact, String telephone, int start, int end, // String description, long updateTime, double truckLength, // String companyName, String companyAddress, String landlines, // String picture, int avatarAuthenticate, Long userId inter.setShardCriteria(triggerTime); session = sessionReadFactory.openSession(inter); Query query = session.createSQLQuery(sb.toString()).addScalar("messageId", StandardBasicTypes.LONG) .addScalar("type", StandardBasicTypes.INTEGER).addScalar("weight", StandardBasicTypes.DOUBLE) .addScalar("capacity", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("contact", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("start", StandardBasicTypes.INTEGER).addScalar("end", StandardBasicTypes.INTEGER) .addScalar("description", StandardBasicTypes.STRING) .addScalar("updateTime", StandardBasicTypes.LONG) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("companyName", StandardBasicTypes.STRING) .addScalar("companyAddress", StandardBasicTypes.STRING) .addScalar("landlines", StandardBasicTypes.STRING) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("avatarAuthenticate", StandardBasicTypes.INTEGER) .addScalar("userId", StandardBasicTypes.LONG) .addScalar("licenseAuthenticate", StandardBasicTypes.INTEGER) .addScalar("cargoType", StandardBasicTypes.INTEGER) .addScalar("score", StandardBasicTypes.DOUBLE) .addScalar("orderCount", StandardBasicTypes.INTEGER) .addScalar("charges", StandardBasicTypes.INTEGER) .addScalar("messageCount", StandardBasicTypes.LONG) .addScalar("truckLengthSet", StandardBasicTypes.STRING).setResultTransformer( Transformers.aliasToBean(com.consult.app.response.cargo.CargoMessageItem.class)); query.setLong(0, req.getBefore()); query.setLong(1, triggerTime); query.setInteger(2, Constant.TYPE_NORMAL); query.setFirstResult(0); query.setMaxResults(count); @SuppressWarnings("unchecked") List<Object> tmpList = query.list(); // if(tmpList != null && tmpList.size() > 0) { // list.addAll(tmpList); // if(tmpList.size() >= count) { // tx.commit(); // return list; // } // count -= tmpList.size(); //// min = metaList.get(metaList.size() - 1).getUpdateTime(); // } // if(inter.isFinishSearch(req.getBefore())) { // tx.commit(); // return list; // } // triggerTime = inter.getTriggerTime(); return tmpList; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } // } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
/** * Search Nearby cargoMessages//from w w w .j a v a 2 s .com * Deprecated! * @param req * @param endCity * @return */ private List<Object> getNearbyMessage(SearchCargoRequest req, City endCity) { // List<Object> list = new ArrayList<Object>(); StringBuilder sb = new StringBuilder(Constant.NEARBY_CARGO_SEARCH); if (req.getTruckLengthRange() > 0) { sb.append(" and message.truck_length_range=").append(req.getTruckLengthRange()); } if (req.getTruckType() >= 0) { sb.append(" and message.truck_type=").append(req.getTruckType()); } if (req.getWeightRange() > 0) { sb.append(" and message.cargo_weight_range=").append(req.getWeightRange()); } sb.append(" and city.id=").append(req.getStart()).append( " and (find_in_set(message.start, city.near_by) or find_in_set(message.start_father, city.near_by))") .append(" and (message.end=").append(endCity.getId()).append(" or message.end_father=") .append(endCity.getId()).append(" or message.end_grand=").append(endCity.getId()).append(" or 0=") .append(endCity.getId()).append(")"); sb.append(" and message.type>=? and message.type<4 order by message.update_time desc"); Long triggerTime = req.getAfter(); if (triggerTime.equals(Long.MAX_VALUE)) { triggerTime = System.currentTimeMillis(); } CargoMessageInterceptor inter = new CargoMessageInterceptor(); int count = req.getCount(); // for(int i = 0; i < Constant.SEARCH_TABLE_COUNT; i++) { Session session = null; try { // Long messageId, int type, // double weight, double capacity, int truckType, // String contact, String telephone, int start, int end, // String description, long updateTime, double truckLength, // String companyName, String companyAddress, String landlines, // String picture, int avatarAuthenticate, Long userId inter.setShardCriteria(triggerTime); session = sessionFactory.openSession(inter); Query query = session.createSQLQuery(sb.toString()).addScalar("messageId", StandardBasicTypes.LONG) .addScalar("type", StandardBasicTypes.INTEGER).addScalar("weight", StandardBasicTypes.DOUBLE) .addScalar("capacity", StandardBasicTypes.DOUBLE) .addScalar("truckType", StandardBasicTypes.INTEGER) .addScalar("contact", StandardBasicTypes.STRING) .addScalar("telephone", StandardBasicTypes.STRING) .addScalar("start", StandardBasicTypes.INTEGER).addScalar("end", StandardBasicTypes.INTEGER) .addScalar("description", StandardBasicTypes.STRING) .addScalar("updateTime", StandardBasicTypes.LONG) .addScalar("truckLength", StandardBasicTypes.DOUBLE) .addScalar("companyName", StandardBasicTypes.STRING) .addScalar("companyAddress", StandardBasicTypes.STRING) .addScalar("landlines", StandardBasicTypes.STRING) .addScalar("picture", StandardBasicTypes.STRING) .addScalar("avatarAuthenticate", StandardBasicTypes.INTEGER) .addScalar("userId", StandardBasicTypes.LONG) .addScalar("licenseAuthenticate", StandardBasicTypes.INTEGER) .addScalar("cargoType", StandardBasicTypes.INTEGER) .addScalar("score", StandardBasicTypes.DOUBLE) .addScalar("orderCount", StandardBasicTypes.INTEGER) .addScalar("charges", StandardBasicTypes.INTEGER) .addScalar("messageCount", StandardBasicTypes.LONG) .addScalar("truckLengthSet", StandardBasicTypes.STRING).setResultTransformer( Transformers.aliasToBean(com.consult.app.response.cargo.CargoMessageItem.class)); query.setLong(0, req.getBefore()); query.setLong(1, triggerTime); query.setInteger(2, Constant.TYPE_NORMAL); query.setFirstResult(0); query.setMaxResults(count); @SuppressWarnings("unchecked") List<Object> tmpList = query.list(); // if(tmpList != null && tmpList.size() > 0) { // list.addAll(tmpList); // if(tmpList.size() >= count) { // tx.commit(); // return list; // } // count -= tmpList.size(); //// min = metaList.get(metaList.size() - 1).getUpdateTime(); // } // if(inter.isFinishSearch(req.getBefore())) { // tx.commit(); // return list; // } // triggerTime = inter.getTriggerTime(); return tmpList; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } // } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public CargoMessage getFirstLineMessage(int start, int end, Long userId, Long updateTime) { String hql = "from CargoMessage message where message.updateTime>=? and message.userId=? and message.start=? and message.end=?"; Session session = null;/*from w w w . j a va2 s .c om*/ try { CargoMessageInterceptor inter = new CargoMessageInterceptor(updateTime); session = sessionFactory.openSession(inter); Query query = session.createQuery(hql); query.setLong(0, TimeUtils.getStartOfDay(updateTime)); query.setLong(1, userId); query.setInteger(2, start); query.setInteger(3, end); query.setFirstResult(0); query.setMaxResults(1); CargoMessage message = (CargoMessage) query.uniqueResult(); return message; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public List<Object> searchCargoByClerk(TelephoneRequest req) { Session session = null;/*w w w .jav a2s.c o m*/ long startOfDay = TimeUtils.getStartOfDay(System.currentTimeMillis()) + 1; try { CargoMessageInterceptor inter = new CargoMessageInterceptor(startOfDay + 1); session = sessionFactory.openSession(inter); String hql = "select new com.consult.app.response.admin.ClerkMessageItem(message) " + "from CargoMessage message " + "where message.telephone=? and message.updateTime>? and (message.type=1 or message.type=-1 or message.type=2 or message.type=-2)"; Query query = session.createQuery(hql); query.setString(0, req.getTelephone()); query.setLong(1, startOfDay); query.setFirstResult(0); query.setMaxResults(100); List<Object> list = query.list(); return list; } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); session = null; } } return null; }
From source file:com.consult.app.dao.impl.CargoMessageDaoImpl.java
@Override public List<Object> searchAllCargoByAdmin(TelephoneBeforeAfterCountRequest req) { Session session = null;/* w ww . ja v a2s . c o m*/ List<Object> list = null; // long startOfDay = TimeUtils.getStartOfDay(System.currentTimeMillis()) + 1; try { CargoMessageInterceptor interBefore = new CargoMessageInterceptor(req.getBefore()); int beforeIndex = interBefore.getTableIndex(); CargoMessageInterceptor interAfter = new CargoMessageInterceptor(req.getAfter()); int afterIndex = interAfter.getTableIndex(); if (beforeIndex != afterIndex) { LogUtil.i("searchAllCargoByAdmin", " beforeIndex != afterIndex "); return list; } session = sessionFactory.openSession(interBefore); String hql = "select new com.consult.app.response.admin.ClerkMessageItem(message) " + "from CargoMessage message " + "where message.telephone=? and message.createTime>? and message.createTime<? order by " + " message.createTime desc"; Query query = session.createQuery(hql); query.setString(0, String.valueOf(req.getTelephone())); query.setLong(1, req.getBefore()); query.setLong(2, req.getAfter()); query.setMaxResults(req.getCount()); list = query.list(); return list; } catch (Exception e) { e.printStackTrace(); } finally { if (session != null) { session.close(); session = null; } } return list; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getMessages(TypeBeforeAfterRequest req, int mode, long userId) { String condition = "", hql = ""; MessageInterceptor inter = null;// w ww . j a va 2 s . co m condition = " and message.updateTime>? and message.updateTime<=? order by message.updateTime desc"; if (req.getType() == Constant.MESSAGE_TYPE_CARGO) { hql = "select new com.consult.app.response.cargo.MyCargoMessageItem" + "(message.messageId, case when message.type>=1 and message.type<4 then 1 else 0 end, message.weight, message.capacity," + "message.truckType, message.contact, message.telephone, message.start, message.end," + "message.description, message.updateTime, message.truckLength, message.companyName, message.companyAddress, message.landlines," + "message.picture, message.avatarAuthenticate, message.userId, message.licenseAuthenticate, message.charges, message.cargoType, message.score, message.orderCount, message.messageCount, message.truckLengthSet) " + "from CargoMessage message where message.userId=? and message.type>=1 and message.type<=4 "; inter = new CargoMessageInterceptor(); } else if (req.getType() == Constant.MESSAGE_TYPE_FIXED) { // Noneed return null; } else if (req.getType() == Constant.MESSAGE_TYPE_TRUCK) { hql = "select new com.consult.app.response.truck.TruckMessageItem" + "(message.messageId, message.userId, message.start, message.end, message.travelType," + "profile.userName, message.telephone, message.transfer, " + "message.number, message.truckLength, message.truckLoad, message.truckType," + "case when message.type>=" + Constant.TYPE_NORMAL + " then 1 else 0 end, message.description, " + "message.updateTime, profile.picture, message.commonLines, user.avatarAuthenticate, user.numberAuthenticate) " + "from TruckMessage message, Profile profile, User user where user.userId=profile.userId and message.userId=user.userId and message.userId=? "; inter = new TruckMessageInterceptor(); } else { return null; } List<Object> list = new ArrayList<Object>(); Long triggerTime = req.getAfter(); if (triggerTime.equals(Long.MAX_VALUE)) { triggerTime = System.currentTimeMillis(); } int count = req.getCount(); // for(int i = 0; i < Constant.SEARCH_TABLE_COUNT; i++) { Session session = null; try { inter.setShardCriteria(triggerTime); session = sessionFactory.openSession(inter); Query query = session.createQuery(hql + condition); query.setLong(0, userId); query.setLong(1, req.getBefore()); query.setLong(2, req.getAfter()); query.setFirstResult(0); query.setMaxResults(count); @SuppressWarnings("unchecked") List<Object> tmpList = query.list(); if (tmpList != null && tmpList.size() > 0) { list.addAll(tmpList); if (tmpList.size() >= count) { return list; } count -= tmpList.size(); // min = metaList.get(metaList.size() - 1).getUpdateTime(); } if (inter.isFinishSearch(req.getBefore())) { return list; } triggerTime = inter.getTriggerTime(); } catch (Exception e) { e.printStackTrace(); return null; } finally { if (session != null) { session.close(); session = null; } } // } return list; }
From source file:com.consult.app.dao.impl.UserDaoImpl.java
@Override public List<Object> getLongUnloginUserToken(int appType, Long startId, int count, Long threshTime) { try {/* w w w .ja va2s .c om*/ // String content, Integer pushType, String token, // Integer notificationType, int badgeCount String hql = "select new com.consult.app.push.modal.PushQueueItem('" + Constant.LONG_UNLOGIN_MSG_CONTENT + "', user.loginFrom, user.token, " + PushUtil.NOTIFICATION_TYPE_BROADCAST + ", 0) " + "from User user, Profile profile, Token token " + "where user.userId=token.userId and user.token=token.token and user.userId=profile.userId 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> getTodayLoginUsers(IdTypeBeforeAfterRequest req) { String hql = ""; try {//w ww.j av a2 s .c om if (req.getId().intValue() <= Constant.CITY_ALL) { hql = "select new com.consult.app.response.admin.LastLoginItem(profile.userName, user.telephone, user.lastLogin) " + "from User user, Profile profile " + "where user.userId=profile.userId and user.lastLogin>? and user.lastLogin<? "; if (req.getType() == Constant.USER_TYPE_TRUCKER) { hql = hql + " and profile.userType=?"; } else { hql = hql + " and profile.userType<>?"; } hql = hql + " order by user.lastLogin desc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); // query.setLong(0, TimeUtils.getStartOfDay(System.currentTimeMillis())); query.setLong(0, req.getBefore()); query.setLong(1, req.getAfter()); query.setInteger(2, Constant.USER_TYPE_TRUCKER); query.setFirstResult(0); query.setMaxResults(req.getCount()); return query.list(); } else { hql = "select new com.consult.app.response.admin.LastLoginItem(profile.userName, user.telephone, user.lastLogin) " + "from User user, Profile profile " + "where user.userId=profile.userId and user.lastLogin>? and user.lastLogin<? "; if (req.getType() == Constant.USER_TYPE_TRUCKER) { hql = hql + " and profile.userType=?"; } else { hql = hql + " and profile.userType<>?"; } hql = hql + " and user.city=? order by user.lastLogin desc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, req.getBefore()); query.setLong(1, req.getAfter()); query.setInteger(2, Constant.USER_TYPE_TRUCKER); query.setInteger(3, req.getId().intValue()); 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> getPreAuthenticateUsers(CountTypeRequest req) { String hql = ""; List<Object> list1 = null, list2 = null; String cond = ""; if (req.getType() == 1) { cond = " and profile.userType=1 "; } else if (req.getType() > 1) { cond = " and profile.userType>1 "; }//from w ww .j ava 2 s .c o m try { //String userId, int type, String field1, // String field2, Long updateTime, int userType hql = "select new com.consult.app.response.admin.AuthenticateUserItem(" + "user.userId, 1, cer.idCard, profile.picture, profile.companyName, profile.companyAddress, user.updateTime, profile.userType, user.telephone, cer.idNumber) " + "from User user, Profile profile, Certificate cer " + "where user.userId=profile.userId and user.certificateId=cer.userId " + "and user.avatarAuthenticate=? and user.isAuthenticate=? " + cond + " order by user.updateTime asc"; Query query = sessionFactory.getCurrentSession().createQuery(hql); query.setLong(0, Constant.USER_AUTHENTICATE_WAIT); query.setLong(1, Constant.USER_AUTHENTICATE_SUCCESS); query.setFirstResult(0); query.setMaxResults(req.getCount()); return query.list(); } catch (Exception e) { e.printStackTrace(); return null; } // try { // //String userId, int type, String field1, //// String field2, Long updateTime, int userType // hql = "select new com.consult.app.response.admin.AuthenticateUserItem(" + // "user.userId, 2, profile.drivingLicense, profile.number, profile.companyName, profile.companyAddress, user.updateTime, profile.userType, user.telephone, '') " + // "from User user, Profile profile " + // "where user.userId=profile.userId " + // "and user.numberAuthenticate=? order by user.updateTime asc"; // Query query = sessionFactory.getCurrentSession().createQuery(hql); // query.setLong(0, Constant.USER_AUTHENTICATE_WAIT); // query.setFirstResult(0); // query.setMaxResults(req.getCount()); // list2 = query.list(); // } catch (Exception e) { // e.printStackTrace(); // return null; // } // return Cookie.mergeSort(new ArrayList(list1), new ArrayList(list2), 20, Cookie.ORDER_ASC); }