Example usage for org.springframework.data.mongodb.core.mapping PersonWithObjectId PersonWithObjectId

List of usage examples for org.springframework.data.mongodb.core.mapping PersonWithObjectId PersonWithObjectId

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.mapping PersonWithObjectId PersonWithObjectId.

Prototype

public PersonWithObjectId(Integer ssn, String firstName, String lastName) 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java

@Test
public void testPersonPojo() throws Exception {

    LOGGER.info("about to create new personpojo");
    PersonWithObjectId p = new PersonWithObjectId(12345, "Person", "Pojo");
    LOGGER.info("about to insert");
    template.insert(p);/*  w  ww . ja  va2s  .c om*/
    LOGGER.info("done inserting");
    assertNotNull(p.getId());

    List<PersonWithObjectId> result = template.find(new Query(Criteria.where("ssn").is(12345)),
            PersonWithObjectId.class);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).getSsn(), is(12345));
}

From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java

@Test
public void testOrQuery() {
    PersonWithObjectId p1 = new PersonWithObjectId(1, "first", "");
    template.save(p1);/*from ww w.  ja v a 2 s. c  o m*/
    PersonWithObjectId p2 = new PersonWithObjectId(2, "second", "");
    template.save(p2);

    List<PersonWithObjectId> results = template.find(
            new Query(new Criteria().orOperator(where("ssn").is(1), where("ssn").is(2))),
            PersonWithObjectId.class);

    assertNotNull(results);
    assertThat(results.size(), is(2));
    assertThat(results.get(1).getSsn(), is(2));
}