Package org.springframework.data.mongodb.core.query

Examples of org.springframework.data.mongodb.core.query.Update


    mongoTemplate.insert(new Person("Dick", 22));
    mongoTemplate.insert(new Person("Harry", 23));

    Query queryObj = new Query(Criteria.where("name").is("Harry"));

    Update updateObj = new Update().inc("age", 1);

    // return's old person object
    p = mongoTemplate.findAndModify(queryObj, updateObj, Person.class);

    assertThat(p.getName(), is("Harry"));
View Full Code Here


   * @param bean
   */
  public void updateRecord(T bean) {
    Query query = new Query(Criteria.where(bean.getKeyName()).is(
        bean.getKeyValue()));
    Update update = new Update();

    Map<String, Object> map = bean.toMap();

    Iterator<String> iterator = map.keySet().iterator();

    while (iterator.hasNext()) {
      String key = iterator.next();
      update.set(key, map.get(key));
    }

    mongoTemplate.updateFirst(query, update, getBeanClass());
  }
View Full Code Here

   * @see DATAMONGO-721
   */
  @Test
  public void updateMapperRetainsTypeInformationForCollectionField() {

    Update update = new Update().push("list", new ConcreteChildClass("2", "BAR"));

    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ParentClass.class));

    DBObject push = getAsDBObject(mappedObject, "$push");
    DBObject list = getAsDBObject(push, "aliased");

View Full Code Here

   * @see DATAMONGO-807
   */
  @Test
  public void updateMapperShouldRetainTypeInformationForNestedEntities() {

    Update update = Update.update("model", new ModelImpl(1));
    UpdateMapper mapper = new UpdateMapper(converter);

    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ModelWrapper.class));

    DBObject set = getAsDBObject(mappedObject, "$set");
    DBObject modelDbObject = (DBObject) set.get("model");
    assertThat(modelDbObject.get("_class"), not(nullValue()));
View Full Code Here

   * @see DATAMONGO-807
   */
  @Test
  public void updateMapperShouldNotPersistTypeInformationForKnownSimpleTypes() {

    Update update = Update.update("model.value", 1);
    UpdateMapper mapper = new UpdateMapper(converter);

    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ModelWrapper.class));

    DBObject set = getAsDBObject(mappedObject, "$set");
    assertThat(set.get("_class"), nullValue());
  }
View Full Code Here

   * @see DATAMONGO-807
   */
  @Test
  public void updateMapperShouldNotPersistTypeInformationForNullValues() {

    Update update = Update.update("model", null);
    UpdateMapper mapper = new UpdateMapper(converter);

    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ModelWrapper.class));

    DBObject set = getAsDBObject(mappedObject, "$set");
    assertThat(set.get("_class"), nullValue());
  }
View Full Code Here

   * @see DATAMONGO-407
   */
  @Test
  public void updateMapperShouldRetainTypeInformationForNestedCollectionElements() {

    Update update = Update.update("list.$", new ConcreteChildClass("42", "bubu"));

    UpdateMapper mapper = new UpdateMapper(converter);
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ParentClass.class));

    DBObject set = getAsDBObject(mappedObject, "$set");
    DBObject modelDbObject = getAsDBObject(set, "aliased.$");
    assertThat(modelDbObject.get("_class"), is((Object) ConcreteChildClass.class.getName()));
View Full Code Here

   * @see DATAMONGO-407
   */
  @Test
  public void updateMapperShouldSupportNestedCollectionElementUpdates() {

    Update update = Update.update("list.$.value", "foo").set("list.$.otherValue", "bar");

    UpdateMapper mapper = new UpdateMapper(converter);
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ParentClass.class));

    DBObject set = getAsDBObject(mappedObject, "$set");
    assertThat(set.get("aliased.$.value"), is((Object) "foo"));
    assertThat(set.get("aliased.$.otherValue"), is((Object) "bar"));
View Full Code Here

   * @see DATAMONGO-407
   */
  @Test
  public void updateMapperShouldWriteTypeInformationForComplexNestedCollectionElementUpdates() {

    Update update = Update.update("list.$.value", "foo").set("list.$.someObject", new ConcreteChildClass("42", "bubu"));

    UpdateMapper mapper = new UpdateMapper(converter);
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ParentClass.class));

    DBObject dbo = getAsDBObject(mappedObject, "$set");
    assertThat(dbo.get("aliased.$.value"), is((Object) "foo"));

View Full Code Here

   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void updateMapperShouldConvertPushCorrectlyWhenCalledWithEachUsingSimpleTypes() {

    Update update = new Update().push("values").each("spring", "data", "mongodb");
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Model.class));

    DBObject push = getAsDBObject(mappedObject, "$push");
    DBObject values = getAsDBObject(push, "values");
    BasicDBList each = getAsDBList(values, "$each");

View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.query.Update

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.