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

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


   * @see DATAMONGO-862
   */
  @Test
  public void rendersUpdateAndPreservesKeyForPathsNotPointingToProperty() {

    Update update = new Update().set("listOfInterface.$.value", "expected-value");
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ParentClass.class));

    DBObject setClause = getAsDBObject(mappedObject, "$set");
    assertThat(setClause.containsField("listOfInterface.$.value"), is(true));
  }
View Full Code Here


   * @see DATAMONGO-863
   */
  @Test
  public void doesNotConvertRawDbObjects() {

    Update update = new Update();
    update.pull("options",
        new BasicDBObject("_id", new BasicDBObject("$in", converter.convertToMongoType(Arrays.asList(1L, 2L)))));

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

    DBObject setClause = getAsDBObject(mappedObject, "$pull");
    DBObject options = getAsDBObject(setClause, "options");
    DBObject idClause = getAsDBObject(options, "_id");
View Full Code Here

   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void testUpdateShouldApply$addToSetCorrectlyWhenUsedWith$each() {

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

    DBObject addToSet = getAsDBObject(mappedObject, "$addToSet");
    DBObject values = getAsDBObject(addToSet, "values");
    BasicDBList each = getAsDBList(values, "$each");
View Full Code Here

   * @see DATAMONG0-471
   */
  @Test
  public void testUpdateShouldRetainClassTypeInformationWhenUsing$addToSetWith$eachForCustomTypes() {

    Update update = new Update().addToSet("models").each(new ModelImpl(2014), new ModelImpl(1), new ModelImpl(28));
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ModelWrapper.class));

    DBObject addToSet = getAsDBObject(mappedObject, "$addToSet");

    DBObject values = getAsDBObject(addToSet, "models");
View Full Code Here

   * @see DATAMONGO-897
   */
  @Test
  public void updateOnDbrefPropertyOfInterfaceTypeWithoutExplicitGetterForIdShouldBeMappedCorrectly() {

    Update update = new Update().set("referencedDocument", new InterfaceDocumentDefinitionImpl("1", "Foo"));
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithReferenceToInterfaceImpl.class));

    DBObject $set = DBObjectTestUtils.getAsDBObject(mappedObject, "$set");
    Object model = $set.get("referencedDocument");

View Full Code Here

   * @see DATAMONGO-847
   */
  @Test
  public void updateMapperConvertsNestedQueryCorrectly() {

    Update update = new Update().pull("list", Query.query(Criteria.where("value").in("foo", "bar")));
    DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ParentClass.class));

    DBObject $pull = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$pull");
    DBObject list = DBObjectTestUtils.getAsDBObject($pull, "aliased");
    DBObject value = DBObjectTestUtils.getAsDBObject(list, "value");
View Full Code Here

   * @see DATAMONGO-847
   */
  @Test
  public void updateMapperConvertsPullWithNestedQuerfyOnDBRefCorrectly() {

    Update update = new Update().pull("dbRefAnnotatedList", Query.query(Criteria.where("id").is("1")));
    DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject $pull = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$pull");
    DBObject list = DBObjectTestUtils.getAsDBObject($pull, "dbRefAnnotatedList");

View Full Code Here

   * @see DATAMONGO-1077
   */
  @Test
  public void shouldNotRemovePositionalParameter() {

    Update update = new Update();
    update.unset("dbRefAnnotatedList.$");

    DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject $unset = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$unset");

    assertThat($unset, equalTo(new BasicDBObjectBuilder().add("dbRefAnnotatedList.$", 1).get()));
View Full Code Here

    Person person = new Person("Oliver2");
    person.setAge(25);
    mongoTemplate.insert(person);

    Query q = new Query(Criteria.where("BOGUS").gt(22));
    Update u = new Update().set("firstName", "Sven");
    mongoTemplate.updateFirst(q, u, Person.class);
  }
View Full Code Here

    thrown.expectMessage("array");
    thrown.expectMessage("firstName");
    thrown.expectMessage("failed");

    Query query = new Query(Criteria.where("firstName").is("Amol"));
    Update upd = new Update().push("age", 29);
    template.updateFirst(query, upd, Person.class);
  }
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.