List of usage examples for org.springframework.data.mongodb.core.query Query skip
long skip
To view the source code for org.springframework.data.mongodb.core.query Query skip.
Click Source Link
From source file:com.epam.ta.reportportal.database.dao.LogRepositoryCustomImpl.java
@Override public List<Log> findByTestItemRef(String itemRef, int limit, boolean isLoadBinaryData) { if (itemRef == null || limit <= 0) { return new ArrayList<>(); }// www . j a v a2s . co m Query query = query(where(ITEM_REFERENCE).is(itemRef)).with(SORT_DESC_LOG_TIME); if (!isLoadBinaryData) { query.fields().exclude(BINARY_CONTENT); } long count = mongoTemplate.count(query, Log.class); long max = Math.max(0, count - limit); if (max > 0) { query.skip((int) max); } return mongoTemplate.find(query, Log.class); }
From source file:net.cit.tetrad.resource.MainResource.java
private PersonJson setPersonJson(int sEcho, CommonDto dto, int pageNumber, int nPerPage) { Query query = setGroupCode(dto); int cnt = (int) monadService.getCount(query, COLL_DASHBOARD); List<Object> resultList = monadService.getListWithStrCollName(query.skip(pageNumber).limit(nPerPage), Map.class, COLL_DASHBOARD); PersonJson result = new PersonJson(); result.setsEcho(sEcho);/*w w w . j a v a2s. c o m*/ result.setiTotalRecords(cnt); result.setiTotalDisplayRecords(cnt); result.setAaData(getDashBoardData(resultList)); return result; }
From source file:net.cit.tetrad.resource.MainResource.java
/** * //from w w w .ja v a2 s . co m * @param request * @param response * @throws Exception */ @RequestMapping("/alarmList.do") public void alarmList(HttpServletRequest request, HttpServletResponse response) throws Exception { log.debug("start - alarmList()"); PersonJson result = new PersonJson(); Class<?> classname = Alarm.class; Query query = new Query(); CommonDto dto = new CommonDto(); try { dto.setAlarm(Integer.parseInt(request.getParameter("alarm"))); query = setAlarmSort(dto); int cnt = (int) monadService.getCount(query, classname); List<Object> resultList = monadService.getList(query.skip(0).limit(5), classname); result.setsEcho(Integer.parseInt(request.getParameter("sEcho"))); result.setiTotalRecords(cnt); result.setiTotalDisplayRecords(cnt); result.setAaData(resultList); JSONObject jsonObject = JSONObject.fromObject(result); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); Writer writer = response.getWriter(); writer.write(jsonObject.toString()); log.debug(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } log.debug("end - alarmList()"); }
From source file:com.seajas.search.profiler.service.repository.RepositoryService.java
/** * Process a paged list of all resources within the repository. * /* w w w .j ava 2s .c om*/ * @param collection * @param sourceId * @param taxonomyMatch * @param url * @param startDate * @param endDate * @param parameters * @param rangeStart * @param rangeEnd * @param processor * @return boolean */ public boolean processResources(final String collection, final Integer sourceId, final String taxonomyMatch, final String url, final Date startDate, final Date endDate, final Map<String, String> parameters, final Integer rangeStart, final Integer rangeEnd, final RepositoryProcessor processor) { Query query = createQuery(true, collection, sourceId, taxonomyMatch, startDate, endDate, url, parameters); query.fields().include("_id"); query.fields().include("currentState"); query.fields().include("element.hostname"); // Determine the total number of document this affects final AtomicLong currentResult = new AtomicLong(0L); // Then skip to it and get going query.skip(rangeStart); if (rangeEnd != null) query.limit(rangeEnd - rangeStart); if (logger.isInfoEnabled()) logger.info(String.format("Processing ranges %d to %s of (unknown) results through the given processor", rangeStart, rangeEnd != null ? rangeEnd.toString() : "end")); mongoTemplate.executeQuery(query, defaultCollection, new DocumentCallbackHandler() { @Override public void processDocument(final DBObject dbObject) throws MongoException, DataAccessException { CompositeState currentState = CompositeState.valueOf((String) dbObject.get("currentState")); if (!EnumSet.of(CompositeState.Content, CompositeState.CompletedDocument, CompositeState.InitialDocument).contains(currentState)) { if (logger.isDebugEnabled()) { ObjectId id = (ObjectId) dbObject.get("_id"); logger.debug("Skipping over element with ID '" + id + "' and current state '" + currentState + "'"); } return; } ObjectId id = (ObjectId) dbObject.get("_id"); String hostname = (String) ((BasicDBObject) dbObject.get("element")).get("hostname"); if (logger.isInfoEnabled()) logger.info("Processing re-indexing entry " + currentResult.getAndIncrement() + " / (unknown) with ID '" + id + "' and hostname '" + hostname + "'"); processor.process(id, hostname); } }); return true; }
From source file:com.ewcms.common.query.mongo.EasyQueryImpl.java
@Override public ResultPage<T> findPage(Pagination page) { Query query = Query.query(criteria); long count = operations.count(query, entityClass); setSort(query, page.getSort());//from w w w . j a v a 2s. com query.skip(page.getOffset()); query.limit(page.getSize()); List<T> list = operations.find(query, entityClass); return new ResultPageImpl<T>(page, count, list); }
From source file:com.seajas.search.profiler.service.repository.RepositoryService.java
/** * Retrieve a paged list of all resources within the repository. * * @param collection//from w ww .j ava 2 s . c o m * @param sourceId * @param taxonomyMatch * @param startDate * @param endDate * @param pagerStart * @param pagerResults * @param parameters * @return RepositoryResult */ public RepositoryResult findResources(final String collection, final Integer sourceId, final String taxonomyMatch, final Date startDate, final Date endDate, final Integer pagerStart, final Integer pagerResults, final Map<String, String> parameters) { Query query = createQuery(false, collection, sourceId, taxonomyMatch, startDate, endDate, null, parameters); query.with(new Sort(Sort.Direction.DESC, "originalContent.dateSubmitted")); if (logger.isInfoEnabled()) logger.info("About to count the number of results - which can potentially take a while - query = " + query.toString()); // First perform a count Long totalResults = mongoTemplate.count(query, defaultCollection); if (logger.isInfoEnabled()) logger.info("Counted " + totalResults + " result(s) to be retrieved from the storage back-end"); // Then add paging parameters to the query query.skip(pagerStart); query.limit(pagerResults); // And build up the result List<RepositoryResource> results = new ArrayList<RepositoryResource>(pagerResults); List<CompositeEntry> entries = mongoTemplate.find(query, CompositeEntry.class, defaultCollection); for (CompositeEntry entry : entries) results.add(new RepositoryResource(entry.getOriginalContent().getUri().toString(), entry.getSource().getCollection(), entry.getSource().getId(), entry.getOriginalContent().getHostname(), entry.getOriginalContent().getDateSubmitted(), entry.getId().toString())); return new RepositoryResult(pagerStart, pagerResults, totalResults, results); }
From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogService.java
@Override public int removeSuccessfullyTransferredMessages() { int limit = 1000; int skip = 0; int page = 0; int totalRemoved = 0; Query query = new Query(); query.addCriteria(Criteria.where("stateTimeStamp").lt(new Date(System.currentTimeMillis() - 2000)) .orOperator(Criteria.where("state").is("SENT"), Criteria.where("state").is("RECEIVED").and("label.transferType").is("SYNCH"), Criteria.where("state").is("FETCHED"))); // query.with(new Sort(Sort.Direction.DESC, "stateTimeStamp")); Boolean moreEntries = false;/* ww w . j ava2s . co m*/ do { query.limit(limit); query.skip(skip); List<ShsMessageEntry> entries = mongoTemplate.find(query, ShsMessageEntry.class); log.debug("found {} entries", entries.size()); if (entries.size() > 0 && entries.size() < limit) { //all entries found totalRemoved += iterateAndRemove(entries); moreEntries = false; } else if (entries.size() > 0 && entries.size() == limit) { totalRemoved += iterateAndRemove(entries); page++; skip = page * limit; moreEntries = true; } else { moreEntries = false; } } while (moreEntries && totalRemoved > 0); log.debug("Removed {} transferred messages", totalRemoved); return totalRemoved; }
From source file:net.cit.tetrad.resource.SubResource.java
@RequestMapping("/subAlarmList.do") public void subAlarmList(HttpServletRequest request, HttpServletResponse response, CommonDto dto) throws Exception { log.debug("start - subAlarmList()"); //iDisplayStart iDisplayLength datatable? ?? int pageNumber = Integer.parseInt(Utility.isNullNumber(request.getParameter("iDisplayStart"))); int nPerPage = Integer.parseInt(Utility.isNullNumber(request.getParameter("iDisplayLength"))); int sEcho = Integer.parseInt(Utility.isNullNumber(request.getParameter(REQ_SECHO))); log.debug("pageNumber=" + pageNumber + ", nPerPage=" + nPerPage); Enumeration parameter = request.getParameterNames(); log.debug(parameter.toString());/* ww w . j a va2 s .c om*/ while (parameter.hasMoreElements()) { String pName = (String) parameter.nextElement(); String pValue = request.getParameter(pName); log.debug(pName + " = " + pValue); } try { Class<?> classname = Alarm.class; Query query = new Query(); query = setAlarmSearch(dto);// ? ? + int cnt = (int) monadService.getCount(query, classname); List<Object> resultList = monadService.getList(query.skip(pageNumber).limit(nPerPage), classname); PersonJson result = setPersonJson(cnt, sEcho, pageNumber, nPerPage, resultList); JSONObject jsonObject = JSONObject.fromObject(result); Writer writer = setResponse(response).getWriter(); writer.write(jsonObject.toString()); log.debug(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } log.debug("end - subAlarmList()"); }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
@Override public ResponseDo getAuthHistory(String userId, String token, int limit, int ignore) throws ApiException { checker.checkUserInfo(userId, token); Criteria criteria = Criteria.where("applyUserId").is(userId); Query query = Query.query(criteria); query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "authTime"))); query.skip(ignore).limit(limit); List<AuthenticationHistory> authenticationHistoryList = authenticationHistoryDao.find(query); // //??? // HashSet<String> applicationIds = new HashSet<>(); // for (AuthenticationHistory history : authenticationHistoryList) { // applicationIds.add(history.getApplicationId()); // }//from w ww . j a v a2 s .c o m // List<AuthApplication> authApplications = authApplicationDao.findByIds((String[])applicationIds.toArray()); //?? HashSet<String> authUserIds = new HashSet<>(); for (AuthenticationHistory item : authenticationHistoryList) { authUserIds.add(item.getAuthId()); } List<User> userList = userDao.findByIds(authUserIds); Map<String, User> userMap = new HashMap<>(userList.size(), 1); for (User user : userList) { userMap.put(user.getUserId(), user); } //?? //? ?? ? ?? authUserId ? for (AuthenticationHistory history : authenticationHistoryList) { history.setAuthUser(userMap.get(history.getAuthId())); } // JSONArray jsonArr = new JSONArray(); // for (AuthenticationHistory history : authenticationHistoryList) { // JSONObject jsonObject = JSONObject.fromObject(history); // jsonObject.put("authUser", getUserFromList(userList, history.getAuthId())); // } return ResponseDo.buildSuccessResponse(authenticationHistoryList); }
From source file:com.gongpingjia.carplay.service.impl.UserServiceImpl.java
/** * ????/*from ww w.ja v a 2 s . com*/ * * @param viewUserId * @param userId * @param limit * @param ignore * @return * @throws ApiException */ @Override public ResponseDo getUserActivityList(String viewUserId, String userId, int limit, int ignore) throws ApiException { User viewUser = userDao.findById(viewUserId); User nowUser = userDao.findById(userId); if (null == viewUser) { LOG.error("the view user not exist userId is:{}", viewUserId); throw new ApiException("?"); } // if (viewUserId.equals(userId)) { LOG.warn("view self:viewUserId:{} userId:{}", viewUserId, userId); } // ??? Criteria criteria = new Criteria(); criteria.and("userId").is(viewUserId); criteria.and("deleteFlag").is(false); Query query = Query.query(criteria); query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "createTime"))); query.skip(ignore).limit(limit); List<Activity> activityList = activityDao.find(query); if (null == activityList || activityList.isEmpty()) { return ResponseDo.buildSuccessResponse("[]"); } //? activityIds applyUserId(userId) ? appointment List<String> activityIds = new ArrayList<>(activityList.size()); for (Activity activity : activityList) { activityIds.add(activity.getActivityId()); } Criteria appointCriteria = new Criteria(); appointCriteria.and("applyUserId").is(userId); appointCriteria.and("activityId").in(activityIds); appointCriteria.and("activityCategory").is(Constants.ActivityCatalog.COMMON); List<Appointment> appointmentList = appointmentDao.find(Query.query(appointCriteria)); if (null == appointmentList) { appointmentList = new ArrayList<>(); } //AppointmentList ?Appointment applyUserId=userId invitedUserId=viewUserId // activityId ? AppointmentList Appointment Map<String, Appointment> activityIdToAppointmentMap = new HashMap<>(appointmentList.size()); for (Appointment appointment : appointmentList) { activityIdToAppointmentMap.put(appointment.getActivityId(), appointment); } Map<String, Object> resultMap = new HashMap<>(); // // resultMap.put("cover", userDao.getCover(viewUser.getUserId())); // resultMap.put("distance", DistanceUtil.getDistance(viewUser.getLandmark(), nowUser.getLandmark())); //??+? ArrayList<Map<String, Object>> activityInfoList = new ArrayList<>(activityList.size()); for (Activity activity : activityList) { Map<String, Object> itemMap = new HashMap<>(); itemMap.put("activityId", activity.getActivityId()); itemMap.put("establish", activity.getEstablish()); itemMap.put("estabPoint", activity.getEstabPoint()); itemMap.put("type", activity.getType()); itemMap.put("pay", activity.getPay()); itemMap.put("transfer", activity.isTransfer()); itemMap.put("destination", activity.getDestination()); itemMap.put("destPoint", activity.getDestPoint()); itemMap.put("createTime", activity.getCreateTime()); itemMap.put("distance", DistanceUtil.getDistance(nowUser.getLandmark(), activity.getEstabPoint())); //? ? 0 1 3 ??? 4 ? int applyStatus = Constants.AppointmentStatus.INITIAL; Appointment appointment = activityIdToAppointmentMap.get(activity.getActivityId()); if (null != appointment) { applyStatus = appointment.getStatus(); } itemMap.put("status", applyStatus); itemMap.put("cover", userDao.getCover(activity.getCover(), viewUser.getUserId())); activityInfoList.add(itemMap); } resultMap.put("activities", activityInfoList); return ResponseDo.buildSuccessResponse(resultMap); }