Example usage for org.springframework.data.mongodb.core.mapping Person getAddress

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

Introduction

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

Prototype

public T getAddress() 

Source Link

Usage

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

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testQueryUpdate() {
    Address addr = new Address();
    addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" });
    addr.setCity("Anytown");
    addr.setPostalCode(12345);//from   www  .  j  a va 2s.  c om
    addr.setCountry("USA");

    Person p = new Person(1111, "Query", "Update", 37, addr);
    template.insert(p);

    addr.setCity("New Town");
    template.updateFirst(query(where("ssn").is(1111)), update("address", addr), Person.class);

    Person p2 = template.findOne(query(where("ssn").is(1111)), Person.class);
    assertThat(p2.getAddress().getCity(), is("New Town"));
}

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

@Test
@SuppressWarnings("rawtypes")
public void testUpsert() {
    Address addr = new Address();
    addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" });
    addr.setCity("Anytown");
    addr.setPostalCode(12345);/*  w w  w .  j ava2s  .  c  om*/
    addr.setCountry("USA");

    Person p2 = template.findOne(query(where("ssn").is(1111)), Person.class);
    assertNull(p2);

    template.upsert(query(where("ssn").is(1111).and("firstName").is("Query").and("lastName").is("Update")),
            update("address", addr), Person.class);

    p2 = template.findOne(query(where("ssn").is(1111)), Person.class);
    assertThat(p2.getAddress().getCity(), is("Anytown"));

    template.dropCollection(Person.class);
    template.upsert(query(where("ssn").is(1111).and("firstName").is("Query").and("lastName").is("Update")),
            update("address", addr), "person");
    p2 = template.findOne(query(where("ssn").is(1111)), Person.class);
    assertThat(p2.getAddress().getCity(), is("Anytown"));

}