Example usage for org.springframework.data.domain Example of

List of usage examples for org.springframework.data.domain Example of

Introduction

In this page you can find the example usage for org.springframework.data.domain Example of.

Prototype

static <T> Example<T> of(T probe, ExampleMatcher matcher) 

Source Link

Document

Create a new Example using the given ExampleMatcher .

Usage

From source file:example.springdata.jpa.querybyexample.UserRepositoryIntegrationTests.java

/**
 * @see #153/*from   w  ww. j  a v a2 s . c  o m*/
 */
@Test
public void configuringMatchersUsingLambdas() {

    Example<User> example = Example.of(new User("Walter", "WHITE", null), matching().//
            withIgnorePaths("age").//
            withMatcher("firstname", matcher -> matcher.startsWith()).//
            withMatcher("lastname", matcher -> matcher.ignoreCase()));

    assertThat(repository.findAll(example), hasItems(flynn, walter));
}

From source file:example.springdata.mongodb.querybyexample.MongoOperationsIntegrationTests.java

/**
 * @see #153// ww  w.j a v  a2s.c om
 */
@Test
public void matchStartingStringsIgnoreCase() {

    Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching(). //
            withIgnorePaths("age").//
            withMatcher("firstname", startsWith()).//
            withMatcher("lastname", ignoreCase()));

    assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
}

From source file:example.UserRepositoryIntegrationTests.java

@Test
public void configuringMatchersUsingLambdas() {

    Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching().//
            withIgnorePaths("age").//
            withMatcher("firstname", matcher -> matcher.startsWith()).//
            withMatcher("lastname", matcher -> matcher.ignoreCase()));

    assertThat(repository.findAll(example), hasItems(flynn, walter));
}

From source file:example.MongoOperationsIntegrationTests.java

@Test
public void configuringMatchersUsingLambdas() {

    Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching().//
            withIgnorePaths("age"). //
            withMatcher("firstname", matcher -> matcher.startsWith()). //
            withMatcher("lastname", matcher -> matcher.ignoreCase()));

    assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
}

From source file:example.springdata.mongodb.querybyexample.UserRepositoryIntegrationTests.java

/**
 * @see #153//from w  w w.  ja  v a  2s  .  c o  m
 */
@Test
public void configuringMatchersUsingLambdas() {

    Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching().//
            withIgnorePaths("age").//
            withMatcher("firstname", matcher -> matcher.startsWith()).//
            withMatcher("lastname", matcher -> matcher.ignoreCase()));

    assertThat(repository.findAll(example), hasItems(flynn, walter));
}

From source file:example.springdata.jpa.querybyexample.UserRepositoryIntegrationTests.java

/**
 * @see #153/*from  ww  w. ja v a 2s . c  om*/
 */
@Test
public void valueTransformer() {

    Example<User> example = Example.of(new User(null, "White", 99), matching(). //
            withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));

    assertThat(repository.findAll(example), hasItems(walter));
}

From source file:example.UserRepositoryIntegrationTests.java

@Test
public void valueTransformer() {

    Example<Person> example = Example.of(new Person(null, "White", 99), matching(). //
            withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));

    assertThat(repository.findAll(example), hasItems(walter));
}

From source file:example.springdata.mongodb.querybyexample.MongoOperationsIntegrationTests.java

/**
 * @see #153/*from  ww  w  .j  a v a2 s  .  c  o  m*/
 */
@Test
public void configuringMatchersUsingLambdas() {

    Example<Person> example = Example.of(new Person("Walter", "WHITE", null), matching().//
            withIgnorePaths("age"). //
            withMatcher("firstname", matcher -> matcher.startsWith()). //
            withMatcher("lastname", matcher -> matcher.ignoreCase()));

    assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
}

From source file:example.MongoOperationsIntegrationTests.java

@Test
public void valueTransformer() {

    Example<Person> example = Example.of(new Person(null, "White", 99), matching(). //
            withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));

    assertThat(operations.find(query(byExample(example)), Person.class), hasItems(walter));
}

From source file:example.springdata.mongodb.querybyexample.UserRepositoryIntegrationTests.java

/**
 * @see #153/*from   w w w .  j  a v a  2 s.  c  o m*/
 */
@Test
public void valueTransformer() {

    Example<Person> example = Example.of(new Person(null, "White", 99), matching(). //
            withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));

    assertThat(repository.findAll(example), hasItems(walter));
}