Search in sources :

Example 11 with PageRequest

use of org.springframework.data.domain.PageRequest in project ignite by apache.

the class IgniteSpringDataQueriesSelfTest method testSelectSeveralFields.

/** */
public void testSelectSeveralFields() {
    List<List> lists = repo.selectSeveralField("^[a-z]+$", new PageRequest(2, 6));
    assertEquals(6, lists.size());
    for (List list : lists) {
        assertEquals(2, list.size());
        assertTrue(list.get(0) instanceof Integer);
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) List(java.util.List)

Example 12 with PageRequest

use of org.springframework.data.domain.PageRequest in project ignite by apache.

the class IgniteSpringDataQueriesSelfTest method testPageable.

/** */
public void testPageable() {
    PageRequest pageable = new PageRequest(1, 5, Sort.Direction.DESC, "firstName");
    HashSet<String> firstNames = new HashSet<>();
    List<Person> pageable1 = repo.findByFirstNameRegex("^[a-z]+$", pageable);
    assertEquals(5, pageable1.size());
    for (Person person : pageable1) {
        firstNames.add(person.getFirstName());
        assertTrue(person.getFirstName().matches("^[a-z]+$"));
    }
    List<Person> pageable2 = repo.findByFirstNameRegex("^[a-z]+$", pageable.next());
    assertEquals(5, pageable2.size());
    for (Person person : pageable2) {
        firstNames.add(person.getFirstName());
        assertTrue(person.getFirstName().matches("^[a-z]+$"));
    }
    assertEquals(10, firstNames.size());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Person(org.apache.ignite.springdata.misc.Person) HashSet(java.util.HashSet)

Example 13 with PageRequest

use of org.springframework.data.domain.PageRequest in project ocvn by devgateway.

the class GenericOCDSController method textSearchQuery.

/**
     * Creates a mongodb query for searching based on text index, sorts the results by score
     *
     * @param request
     * @return
     */
protected Query textSearchQuery(final TextSearchRequest request) {
    PageRequest pageRequest = new PageRequest(request.getPageNumber(), request.getPageSize());
    Query query = null;
    if (request.getText() == null) {
        query = new Query();
    } else {
        query = TextQuery.queryText(new TextCriteria().matching(request.getText())).sortByScore();
    }
    query.with(pageRequest);
    return query;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) TextQuery(org.springframework.data.mongodb.core.query.TextQuery) Query(org.springframework.data.mongodb.core.query.Query) TextCriteria(org.springframework.data.mongodb.core.query.TextCriteria)

Example 14 with PageRequest

use of org.springframework.data.domain.PageRequest in project ocvn by devgateway.

the class SortableJpaRepositoryDataProvider method iterator.

/**
     * @see SortableDataProvider#iterator(long, long)
     */
@Override
public Iterator<? extends T> iterator(final long first, final long count) {
    int page = (int) ((double) first / WebConstants.PAGE_SIZE);
    Page<T> findAll = jpaRepository.findAll(filterState.getSpecification(), new PageRequest(page, WebConstants.PAGE_SIZE, translateSort()));
    return findAll.iterator();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest)

Example 15 with PageRequest

use of org.springframework.data.domain.PageRequest in project ocvn by devgateway.

the class AbstractOrganizationSearchController method organizationSearchTextByType.

protected List<Organization> organizationSearchTextByType(final TextSearchRequest request, Organization.OrganizationType type) {
    Query query = null;
    if (request.getText() == null) {
        query = new Query();
    } else {
        //this is for Full Text Search, in case we need this later, right now it's not very useful
        //query = TextQuery.queryText(new TextCriteria().matching(request.getText())).sortByScore();
        query = new Query().addCriteria(Criteria.where("name").regex(Pattern.compile(request.getText(), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)));
    }
    if (type != null) {
        query.addCriteria(Criteria.where("roles").is(type)).with(new PageRequest(request.getPageNumber(), request.getPageSize()));
    }
    List<Organization> orgs = mongoTemplate.find(query, Organization.class);
    return orgs;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Organization(org.devgateway.ocds.persistence.mongo.Organization) Query(org.springframework.data.mongodb.core.query.Query)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)28 Pageable (org.springframework.data.domain.Pageable)7 Sort (org.springframework.data.domain.Sort)7 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Person (org.apache.ignite.springdata.misc.Person)3 List (java.util.List)2 Cache (javax.cache.Cache)2 Release (org.devgateway.ocds.persistence.mongo.Release)2 Query (org.springframework.data.mongodb.core.query.Query)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Book (org.springside.examples.bootapi.domain.Book)2 City (sample.data.jpa.domain.City)2 City (sample.data.rest.domain.City)2 JsonView (com.fasterxml.jackson.annotation.JsonView)1 UserEntity (com.myspringboot.entity.UserEntity)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1