Permalink
Browse files

DATAMONGO-620 - Updating versioned object uses explicit collection name.

We're now handing the collection name given to doSaveVersioned(…) to the update method.
  • Loading branch information...
olivergierke committed Feb 26, 2013
1 parent f337900 commit 6139e83d8d85ad2f423685fa6613afd1701ecbdf
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2012 the original author or authors.
+ * Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -792,7 +792,7 @@ public void save(Object objectToSave, String collectionName) {
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbObject));
Update update = Update.fromDBObject(dbObject, ID_FIELD);
- updateFirst(query, update, objectToSave.getClass());
+ doUpdate(collectionName, query, update, objectToSave.getClass(), false, false);
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbObject));
}
}
@@ -941,7 +941,7 @@ public WriteResult doInCollection(DBCollection collection) throws MongoException
if (entity != null && entity.hasVersionProperty() && !multi) {
if (writeResult.getN() == 0) {
throw new OptimisticLockingFailureException("Optimistic lock exception on saving entity: "
- + updateObj.toMap().toString());
+ + updateObj.toMap().toString() + " to collection " + collectionName);
}
}
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2012 the original author or authors.
+ * Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -146,6 +146,7 @@ protected void cleanDb() {
template.dropCollection(Sample.class);
template.dropCollection(MyPerson.class);
template.dropCollection("collection");
+ template.dropCollection("personX");
}
@Test
@@ -949,6 +950,7 @@ public void testFindOneWithSort() {
}
@Test
+ @SuppressWarnings("deprecation")
public void testUsingReadPreference() throws Exception {
this.template.execute("readPref", new CollectionCallback<Object>() {
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
@@ -1467,6 +1469,22 @@ public void queryCantBeNull() {
assertThat(template.find(null, PersonWithIdPropertyOfTypeObjectId.class), is(result));
}
+ /**
+ * @see DATAMONGO-620
+ */
+ @Test
+ public void versionsObjectIntoDedicatedCollection() {
+
+ PersonWithVersionPropertyOfTypeInteger person = new PersonWithVersionPropertyOfTypeInteger();
+ person.firstName = "Dave";
+
+ template.save(person, "personX");
+ assertThat(person.version, is(0));
+
+ template.save(person, "personX");
+ assertThat(person.version, is(1));
+ }
+
static class MyId {
String first;
@@ -15,7 +15,7 @@
*/
package org.springframework.data.mongodb.core;
-import org.springframework.data.mongodb.core.mapping.Version;
+import org.springframework.data.annotation.Version;
public class PersonWithVersionPropertyOfTypeInteger {

0 comments on commit 6139e83

Please sign in to comment.