List of usage examples for org.springframework.data.mongodb.core.mapping Address setLines
public void setLines(String[] lines)
From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testWriteEntity() { Address addr = new Address(); addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" }); addr.setCity("Anytown"); addr.setPostalCode(12345);/* w w w . j a va2s . c om*/ addr.setCountry("USA"); Account acct = new Account(); acct.setBalance(1000.00f); template.insert(acct, "account"); List<Account> accounts = new ArrayList<Account>(); accounts.add(acct); Person p = new Person(123456789, "John", "Doe", 37, addr); p.setAccounts(accounts); template.insert(p, "person"); Account newAcct = new Account(); newAcct.setBalance(10000.00f); template.insert(newAcct, "account"); accounts.add(newAcct); template.save(p, "person"); assertNotNull(p.getId()); List<Person> result = template.find(new Query(Criteria.where("ssn").is(123456789)), Person.class); assertThat(result.size(), is(1)); assertThat(result.get(0).getAddress().getCountry(), is("USA")); assertThat(result.get(0).getAccounts(), notNullValue()); }
From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testUniqueIndex() { Address addr = new Address(); addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" }); addr.setCity("Anytown"); addr.setPostalCode(12345);/*ww w . j a v a2s.c om*/ addr.setCountry("USA"); Person p1 = new Person(1234567890, "John", "Doe", 37, addr); Person p2 = new Person(1234567890, "Jane", "Doe", 38, addr); List<Person> persons = new ArrayList<Person>(); persons.add(p1); persons.add(p2); template.insert(persons, MongoCollectionUtils.getPreferredCollectionName(Person.class)); List<Person> result = template.find(new Query(Criteria.where("ssn").is(1234567890)), Person.class); assertThat(result.size(), is(1)); }
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 v a2 s . c o m*/ 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);//from www. j a va 2 s . 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")); }