Example usage for org.springframework.data.mongodb.core PersonWithIdPropertyOfTypeString setAge

List of usage examples for org.springframework.data.mongodb.core PersonWithIdPropertyOfTypeString setAge

Introduction

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

Prototype

public void setAge(int age) 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.PersonExample.java

public void doWork() {
    mongoOps.dropCollection("personexample");

    PersonWithIdPropertyOfTypeString p = new PersonWithIdPropertyOfTypeString();
    p.setFirstName("Sven");
    p.setAge(22);

    mongoOps.save(p);//from  w w  w. j a va 2s. c  o  m

    PersonWithIdPropertyOfTypeString p2 = new PersonWithIdPropertyOfTypeString();
    p2.setFirstName("Jon");
    p2.setAge(23);

    mongoOps.save(p2);

    log.debug("Saved: " + p);

    p = mongoOps.findById(p.getId(), PersonWithIdPropertyOfTypeString.class);

    log.debug("Found: " + p);

    // mongoOps.updateFirst(new Query(where("firstName").is("Sven")), new Update().set("age", 24));

    // mongoOps.updateFirst(new Query(where("firstName").is("Sven")), update("age", 24));

    p = mongoOps.findById(p.getId(), PersonWithIdPropertyOfTypeString.class);
    log.debug("Updated: " + p);

    List<PersonWithIdPropertyOfTypeString> folks = mongoOps.findAll(PersonWithIdPropertyOfTypeString.class);
    log.debug("Querying for all people...");
    for (PersonWithIdPropertyOfTypeString element : folks) {
        log.debug(element);
    }

    // mongoOps.remove( query(whereId().is(p.getId())), p.getClass());

    mongoOps.remove(p);

    List<PersonWithIdPropertyOfTypeString> people = mongoOps.findAll(PersonWithIdPropertyOfTypeString.class);

    // PersonWithIdPropertyOfTypeString p2 = mongoOps.findOne(query(whereId().is(p.getId())),
    // PersonWithIdPropertyOfTypeString.class);

    log.debug("Number of people = : " + people.size());

}

From source file:org.springframework.data.mongodb.core.PersonExample.java

public void doWork2() {
    mongoOps.dropCollection("personexample");

    PersonWithIdPropertyOfTypeString p = new PersonWithIdPropertyOfTypeString();
    p.setFirstName("Sven");
    p.setAge(22);

}