Search in sources :

Example 11 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingContainingIncludingNull.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingContainingIncludingNull() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withStringMatcher(CONTAINING).withIncludeNullValues();
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname IS NULL OR firstname LIKE '%do%')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 12 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithFieldSpecificStringMatcherContains.

// GH-929
@Test
void queryByExampleWithFirstnameWithFieldSpecificStringMatcherContains() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withMatcher("firstname", contains());
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname LIKE '%do%')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 13 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingOnTheEndingIncludingNull.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingOnTheEndingIncludingNull() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withStringMatcher(ENDING).withIncludeNullValues();
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname IS NULL OR firstname LIKE '%do')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 14 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project spring-data-commons by spring-projects.

the class ExampleSpecificationAccessorUnitTests method exactMatcherUsesExactMatching.

// DATACMNS-953
@Test
public void exactMatcherUsesExactMatching() {
    ExampleMatcher matcher = // 
    ExampleMatcher.matching().withMatcher("firstname", exact());
    assertThat(new ExampleMatcherAccessor(matcher).getPropertySpecifier("firstname").getStringMatcher()).isEqualTo(StringMatcher.EXACT);
}
Also used : ExampleMatcher(org.springframework.data.domain.ExampleMatcher) ExampleMatcherAccessor(org.springframework.data.support.ExampleMatcherAccessor) Test(org.junit.Test)

Example 15 with ExampleMatcher

use of org.springframework.data.domain.ExampleMatcher in project mecaworks by KadarH.

the class ClasseServiceImpl method classeList.

/**
 * search with nom
 *
 * @param pageable page description
 * @param search   keyword
 * @return Page
 */
@Override
public Page<Classe> classeList(Pageable pageable, String search) {
    log.info("Service- ClasseServiceImpl Calling ClasseList with params :" + pageable + ", " + search);
    try {
        if (search.isEmpty()) {
            log.debug("fetching Classe page");
            return classeRepo.findAll(pageable);
        } else {
            log.debug("Searching by :" + search);
            // creating example
            Classe classe = new Classe();
            classe.setNom(search);
            // creating matcher
            ExampleMatcher matcher = ExampleMatcher.matchingAny().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING).withIgnoreCase().withIgnoreNullValues();
            Example<Classe> example = Example.of(classe, matcher);
            log.debug("getting search results");
            return classeRepo.findAll(example, pageable);
        }
    } catch (Exception e) {
        log.debug("Failed retrieving list of Classes");
        throw new OperationFailedException("Operation échouée", e);
    }
}
Also used : ExampleMatcher(org.springframework.data.domain.ExampleMatcher) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) Classe(me.kadarh.mecaworks.domain.others.Classe) ResourceNotFoundException(me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException) OperationFailedException(me.kadarh.mecaworks.service.exceptions.OperationFailedException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ExampleMatcher (org.springframework.data.domain.ExampleMatcher)33 Test (org.junit.jupiter.api.Test)20 Query (org.springframework.data.relational.core.query.Query)17 NoSuchElementException (java.util.NoSuchElementException)9 OperationFailedException (me.kadarh.mecaworks.service.exceptions.OperationFailedException)9 ResourceNotFoundException (me.kadarh.mecaworks.service.exceptions.ResourceNotFoundException)9 Objects (java.util.Objects)2 Classe (me.kadarh.mecaworks.domain.others.Classe)2 Marque (me.kadarh.mecaworks.domain.others.Marque)2 SousFamille (me.kadarh.mecaworks.domain.others.SousFamille)2 Assertions (org.assertj.core.api.Assertions)2 Test (org.junit.Test)2 Example (org.springframework.data.domain.Example)2 BaseEntity (com.google.cloud.datastore.BaseEntity)1 BaseKey (com.google.cloud.datastore.BaseKey)1 Cursor (com.google.cloud.datastore.Cursor)1 Datastore (com.google.cloud.datastore.Datastore)1 DatastoreReaderWriter (com.google.cloud.datastore.DatastoreReaderWriter)1 Entity (com.google.cloud.datastore.Entity)1 Builder (com.google.cloud.datastore.Entity.Builder)1