DATAMONGO-2155 - Polishing.
Reduce visibility of MappedUpdated to package-protected to avoid exposure. Rename UpdateDefinition.incVersion() to inc(). Reintroduce doUpdate() methods accepting Update and delegating to the new doUpdate() methods to preserve binary compatibility. Original pull request: #625.
This commit is contained in:
@@ -83,7 +83,7 @@ public class MappedDocument {
|
||||
return Filters.eq(ID_FIELD, document.get(ID_FIELD));
|
||||
}
|
||||
|
||||
public MappedUpdate updateWithoutId() {
|
||||
public UpdateDefinition updateWithoutId() {
|
||||
return new MappedUpdate(Update.fromDocument(document, ID_FIELD));
|
||||
}
|
||||
|
||||
@@ -92,9 +92,9 @@ public class MappedDocument {
|
||||
* mapped to the specific domain type.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 2.2
|
||||
* @since 2.1.4
|
||||
*/
|
||||
public class MappedUpdate implements UpdateDefinition {
|
||||
class MappedUpdate implements UpdateDefinition {
|
||||
|
||||
private final Update delegate;
|
||||
|
||||
@@ -122,11 +122,11 @@ public class MappedDocument {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.query.UpdateDefinition#incVersion(java.lang.String)
|
||||
* @see org.springframework.data.mongodb.core.query.UpdateDefinition#inc(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void incVersion(String version) {
|
||||
delegate.incVersion(version);
|
||||
public void inc(String version) {
|
||||
delegate.inc(version);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1386,7 +1386,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
MappedDocument mapped = source.toMappedDocument(mongoConverter);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<>(toSave, mapped.getDocument(), collectionName));
|
||||
MappedUpdate update = mapped.updateWithoutId();
|
||||
UpdateDefinition update = mapped.updateWithoutId();
|
||||
|
||||
UpdateResult result = doUpdate(collectionName, query, update, toSave.getClass(), false, false);
|
||||
|
||||
@@ -1556,7 +1556,12 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
return doUpdate(collectionName, query, update, entityClass, false, true);
|
||||
}
|
||||
|
||||
protected UpdateResult doUpdate(final String collectionName, final Query query, final UpdateDefinition update,
|
||||
protected UpdateResult doUpdate(final String collectionName, final Query query, final Update update,
|
||||
@Nullable final Class<?> entityClass, final boolean upsert, final boolean multi) {
|
||||
return doUpdate(collectionName, query, (UpdateDefinition) update, entityClass, upsert, multi);
|
||||
}
|
||||
|
||||
private UpdateResult doUpdate(final String collectionName, final Query query, final UpdateDefinition update,
|
||||
@Nullable final Class<?> entityClass, final boolean upsert, final boolean multi) {
|
||||
|
||||
Assert.notNull(collectionName, "CollectionName must not be null!");
|
||||
@@ -1622,7 +1627,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
if (persistentEntity != null && persistentEntity.hasVersionProperty()) {
|
||||
String versionFieldName = persistentEntity.getRequiredVersionProperty().getFieldName();
|
||||
if (!update.modifies(versionFieldName)) {
|
||||
update.incVersion(versionFieldName);
|
||||
update.inc(versionFieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1612,7 +1612,12 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return doUpdate(collectionName, query, update, entityClass, false, true);
|
||||
}
|
||||
|
||||
protected Mono<UpdateResult> doUpdate(String collectionName, Query query, @Nullable UpdateDefinition update,
|
||||
protected Mono<UpdateResult> doUpdate(String collectionName, Query query, @Nullable Update update,
|
||||
@Nullable Class<?> entityClass, boolean upsert, boolean multi) {
|
||||
return doUpdate(collectionName, query, (UpdateDefinition) update, entityClass, upsert, multi);
|
||||
}
|
||||
|
||||
private Mono<UpdateResult> doUpdate(String collectionName, Query query, @Nullable UpdateDefinition update,
|
||||
@Nullable Class<?> entityClass, boolean upsert, boolean multi) {
|
||||
|
||||
MongoPersistentEntity<?> entity = entityClass == null ? null : getPersistentEntity(entityClass);
|
||||
@@ -1675,7 +1680,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
if (persistentEntity != null && persistentEntity.hasVersionProperty()) {
|
||||
String versionFieldName = persistentEntity.getRequiredVersionProperty().getFieldName();
|
||||
if (!update.modifies(versionFieldName)) {
|
||||
update.incVersion(versionFieldName);
|
||||
update.inc(versionFieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,10 +157,10 @@ public class Update implements UpdateDefinition {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.query.UpdateDefinition#incVersion()
|
||||
* @see org.springframework.data.mongodb.core.query.UpdateDefinition#inc()
|
||||
*/
|
||||
@Override
|
||||
public void incVersion(String key) {
|
||||
public void inc(String key) {
|
||||
inc(key, 1L);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ import org.bson.Document;
|
||||
* Interface fixing must have operations for {@literal updates} as implemented via {@link Update}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 2.2
|
||||
* @author Mark Paluch
|
||||
* @since 2.1.4
|
||||
*/
|
||||
public interface UpdateDefinition {
|
||||
|
||||
@@ -47,9 +48,9 @@ public interface UpdateDefinition {
|
||||
boolean modifies(String key);
|
||||
|
||||
/**
|
||||
* Bump the version of a given {@literal key} by {@code 1}.
|
||||
* Increment the value of a given {@literal key} by {@code 1}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
*/
|
||||
void incVersion(String key);
|
||||
void inc(String key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user