Search in sources :

Example 1 with QPerson

use of org.springframework.data.mongodb.repository.QPerson in project spring-data-mongodb by spring-projects.

the class QuerydslRepositorySupportTests method shouldAllowAny.

// DATAMONGO-1063
@Test
public void shouldAllowAny() {
    person.setSkills(Arrays.asList("vocalist", "songwriter", "guitarist"));
    operations.save(person);
    QPerson p = QPerson.person;
    SpringDataMongodbQuery<Person> query = repoSupport.from(p).where(p.skills.any().in("guitarist"));
    assertThat(query.fetchOne(), is(person));
}
Also used : QPerson(org.springframework.data.mongodb.repository.QPerson) Person(org.springframework.data.mongodb.repository.Person) QPerson(org.springframework.data.mongodb.repository.QPerson) Test(org.junit.Test)

Example 2 with QPerson

use of org.springframework.data.mongodb.repository.QPerson in project spring-data-mongodb by spring-projects.

the class QuerydslMongoPredicateExecutorIntegrationTests method setup.

@Before
public void setup() {
    MongoRepositoryFactory factory = new MongoRepositoryFactory(operations);
    MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
    repository = new QuerydslMongoPredicateExecutor<Person>(entityInformation, operations);
    operations.dropCollection(Person.class);
    dave = new Person("Dave", "Matthews", 42);
    oliver = new Person("Oliver August", "Matthews", 4);
    carter = new Person("Carter", "Beauford", 49);
    person = new QPerson("person");
    operations.insertAll(Arrays.asList(oliver, dave, carter));
}
Also used : QPerson(org.springframework.data.mongodb.repository.QPerson) Person(org.springframework.data.mongodb.repository.Person) QPerson(org.springframework.data.mongodb.repository.QPerson) Before(org.junit.Before)

Example 3 with QPerson

use of org.springframework.data.mongodb.repository.QPerson in project spring-data-mongodb by spring-projects.

the class QuerydslRepositorySupportTests method shouldAllowDbRefAgainstIdProperty.

// DATAMONGO-1394
@Test
public void shouldAllowDbRefAgainstIdProperty() {
    User bart = new User();
    bart.setUsername("bart@simpson.com");
    operations.save(bart);
    person.setCoworker(bart);
    operations.save(person);
    QPerson p = QPerson.person;
    SpringDataMongodbQuery<Person> queryUsingIdField = repoSupport.from(p).where(p.coworker.id.eq(bart.getId()));
    SpringDataMongodbQuery<Person> queryUsingRefObject = repoSupport.from(p).where(p.coworker.eq(bart));
    assertThat(queryUsingIdField.fetchOne(), equalTo(person));
    assertThat(queryUsingIdField.fetchOne(), equalTo(queryUsingRefObject.fetchOne()));
}
Also used : User(org.springframework.data.mongodb.repository.User) QPerson(org.springframework.data.mongodb.repository.QPerson) Person(org.springframework.data.mongodb.repository.Person) QPerson(org.springframework.data.mongodb.repository.QPerson) Test(org.junit.Test)

Example 4 with QPerson

use of org.springframework.data.mongodb.repository.QPerson in project spring-data-mongodb by spring-projects.

the class QuerydslRepositorySupportTests method providesMongoQuery.

@Test
public void providesMongoQuery() {
    QPerson p = QPerson.person;
    QuerydslRepositorySupport support = new QuerydslRepositorySupport(operations) {
    };
    SpringDataMongodbQuery<Person> query = support.from(p).where(p.lastname.eq("Matthews"));
    assertThat(query.fetchOne(), is(person));
}
Also used : QPerson(org.springframework.data.mongodb.repository.QPerson) Person(org.springframework.data.mongodb.repository.Person) QPerson(org.springframework.data.mongodb.repository.QPerson) Test(org.junit.Test)

Aggregations

Person (org.springframework.data.mongodb.repository.Person)4 QPerson (org.springframework.data.mongodb.repository.QPerson)4 Test (org.junit.Test)3 Before (org.junit.Before)1 User (org.springframework.data.mongodb.repository.User)1