List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:com.luna.common.service.UserServiceTest.java
@Test public void testFindAllByPageableAndSortDesc() { int count = 15; User lastUser = null;// w w w . j av a 2s . com for (int i = 0; i < count; i++) { lastUser = userService.save(createUser()); } Sort sortDesc = new Sort(Sort.Direction.DESC, "id"); Pageable pageable = new PageRequest(0, 5, sortDesc); Page<User> userPage = userService.findAll(pageable); assertEquals(5, userPage.getNumberOfElements()); assertTrue(userPage.getContent().contains(lastUser)); assertTrue(userPage.getContent().get(0).getId() > userPage.getContent().get(1).getId()); }
From source file:org.apigw.authserver.svc.impl.CertifiedClientDetailsServiceImpl.java
@Override @Transactional(propagation = Propagation.SUPPORTS) public List<CertifiedClient> findAllClients() { return certifiedClientRepository.findAll(new Sort(Sort.Direction.ASC, "clientId")); }
From source file:io.omatic.event.service.EventMaintainanceService.java
/** * Maintenance method used to keep the number of {@link Event} records in the database * at a manageable level. //from w w w . ja v a 2 s . c o m * * Note that this method can be scheduled. To do so specify a value for the externalised * property eventomatic.maintenance.cronSchedule. The value must be in crontab format. For more information see * <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html">here</a> */ @Transactional @Scheduled(cron = "${eventomatic.maintenance.cronSchedule}") public void maintainPoll() { // Firstly delete any events that are older than they should be, this will stop historic data clogging up the system. 0 disable if (applicationConfiguration.getMaintenance().getMaxAge() < 0) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, applicationConfiguration.getMaintenance().getMaxAge().intValue()); Date maxAge = cal.getTime(); long countOldEvents = eventRepository.countByRecievedDateBefore(maxAge); log.info("Checking for mesages older than {} and found {}", maxAge, countOldEvents); if (countOldEvents > 0) { log.info("Deleting {} events from before {}", countOldEvents, maxAge); eventRepository.deleteByRecievedDateBefore(maxAge); log.info("Deletion complete"); } } else { log.info("Age based housekeeping disabled"); } // Secondly, if the max events has exceeded the specified limit then trim the database. 0 or -1 will disable. if (applicationConfiguration.getMaintenance().getEventLimit() > 0) { long countTotalEvents = eventRepository.count(); Long overrun = countTotalEvents - applicationConfiguration.getMaintenance().getEventLimit(); log.info("Checking for event count of greather than {} and found {}", applicationConfiguration.getMaintenance().getEventLimit(), countTotalEvents); if (overrun > 0) { Page<Event> events = eventRepository .findAll(new PageRequest(0, overrun.intValue(), new Sort(Direction.ASC, "recievedDate"))); eventRepository.deleteInBatch(events); log.info("Deleted {} of {} events.", overrun, countTotalEvents); } } else { log.info("Event limit based housekeeping disabled"); } }
From source file:com.epam.ta.reportportal.database.dao.LoadWithLineGraphCallbackTest.java
@Test public void testEmptyFieldsSet() { Filter filter = new Filter(Launch.class, Condition.CONTAINS, false, "launch", "name"); Sort sort = new Sort(Direction.ASC, "name"); StatisticsDocumentHandler callback = new StatisticsDocumentHandler(new ArrayList<>(), Lists.newArrayList("")); launchRepository.loadWithCallback(filter, sort, 5, new ArrayList<>(), callback, "launch"); Assert.assertNotNull(callback.getResult()); Assert.assertTrue(callback.getResult().isEmpty()); }
From source file:cn.org.once.cstack.service.impl.MessageServiceImpl.java
/** * Returns a Sort object which sorts persons in ascending order by using the * last name.//from w w w . j a v a 2 s . co m * * @return */ private Sort sortByLastNameAsc() { return new Sort(Sort.Direction.DESC, "date"); }
From source file:com.pkrete.locationservice.admin.solr.service.impl.OwnerIndexServiceImpl.java
/** * Returns all the OwnerDocuments sorted by name * * @return list of OwnerDocuments sorted by name *//*from w w w.j av a2s .c o m*/ @Override public List<OwnerDocument> find() { return this.repository.findByDocumentType(DocumentType.OWNER, new Sort(Sort.Direction.ASC, "name")); }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.impl.IAViewServiceImpl.java
public List<MongoInformationAssetView> findUntaggedDocumentsBySeriesMongo(String seriesIaid, Integer limit, Integer offset) {/* w w w .java 2 s.c o m*/ Query query = Query.query(Criteria.where("series").is(seriesIaid).and("categories").size(0)); query.limit(limit); query.skip(offset); query.with(new Sort(Sort.Direction.ASC, "_id")); return mongoTemplate.find(query, MongoInformationAssetView.class); }
From source file:org.springside.examples.quickstart.service.BulletinDataService.java
/***/ private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) { Sort sort = null;// w w w . ja v a 2s .c o m if ("auto".equals(sortType)) { sort = new Sort(Direction.DESC, "id"); } else if ("title".equals(sortType)) { sort = new Sort(Direction.ASC, "title"); } else { sort = new Sort(Direction.ASC, "announcementDate"); } return new PageRequest(pageNumber - 1, pagzSize, sort); }
From source file:example.springdata.jpa.projections.CustomerRepositoryIntegrationTest.java
@Test public void supportsProjectionInCombinationWithPagination() { Page<CustomerProjection> page = customers .findPagedProjectedBy(new PageRequest(0, 1, new Sort(Direction.ASC, "lastname"))); assertThat(page.getContent().get(0).getFirstname(), is("Carter")); }
From source file:demo.CustomerRepositoryIntegrationTest.java
/** * @since Step 4.2/*w ww .j a v a 2s. c o m*/ */ @Test public void browseThrouhgCustomersSortedByLastnameDesc() { Iterable<Customer> result = repository.findAll(new Sort(Direction.DESC, "lastname")); assertThat(result).asList().extracting("lastname").containsExactly("Steinbach", "Friedrich", "Daub"); }