Browse Source

DATAMONGO-1400 - Adapt to rename of Tuple to Pair in Spring Data Commons.

Related tickets: DATACMNS-818.
pull/346/merge
Oliver Gierke 10 years ago
parent
commit
f318185ad0
  1. 10
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/BulkOperations.java
  2. 20
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultBulkOperations.java
  3. 12
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DefaultBulkOperationsIntegrationTests.java

10
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/BulkOperations.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2015 the original author or authors. * Copyright 2015-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,7 @@ import java.util.List;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.util.Tuple; import org.springframework.data.util.Pair;
import com.mongodb.BulkWriteResult; import com.mongodb.BulkWriteResult;
@ -78,7 +78,7 @@ public interface BulkOperations {
* @param updates Update operations to perform. * @param updates Update operations to perform.
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}. * @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
*/ */
BulkOperations updateOne(List<Tuple<Query, Update>> updates); BulkOperations updateOne(List<Pair<Query, Update>> updates);
/** /**
* Add a single update to the bulk operation. For the update request, all matching documents are updated. * Add a single update to the bulk operation. For the update request, all matching documents are updated.
@ -96,7 +96,7 @@ public interface BulkOperations {
* @return The bulk operation. * @return The bulk operation.
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}. * @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
*/ */
BulkOperations updateMulti(List<Tuple<Query, Update>> updates); BulkOperations updateMulti(List<Pair<Query, Update>> updates);
/** /**
* Add a single upsert to the bulk operation. An upsert is an update if the set of matching documents is not empty, * Add a single upsert to the bulk operation. An upsert is an update if the set of matching documents is not empty,
@ -117,7 +117,7 @@ public interface BulkOperations {
* @return The bulk operation. * @return The bulk operation.
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}. * @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
*/ */
BulkOperations upsert(List<Tuple<Query, Update>> updates); BulkOperations upsert(List<Pair<Query, Update>> updates);
/** /**
* Add a single remove operation to the bulk operation. * Add a single remove operation to the bulk operation.

20
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/DefaultBulkOperations.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2015 the original author or authors. * Copyright 2015-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@ import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.util.Tuple; import org.springframework.data.util.Pair;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import com.mongodb.BulkWriteException; import com.mongodb.BulkWriteException;
@ -148,7 +148,7 @@ class DefaultBulkOperations implements BulkOperations {
Assert.notNull(query, "Query must not be null!"); Assert.notNull(query, "Query must not be null!");
Assert.notNull(update, "Update must not be null!"); Assert.notNull(update, "Update must not be null!");
return updateOne(Arrays.asList(Tuple.of(query, update))); return updateOne(Arrays.asList(Pair.of(query, update)));
} }
/* /*
@ -156,11 +156,11 @@ class DefaultBulkOperations implements BulkOperations {
* @see org.springframework.data.mongodb.core.BulkOperations#updateOne(java.util.List) * @see org.springframework.data.mongodb.core.BulkOperations#updateOne(java.util.List)
*/ */
@Override @Override
public BulkOperations updateOne(List<Tuple<Query, Update>> updates) { public BulkOperations updateOne(List<Pair<Query, Update>> updates) {
Assert.notNull(updates, "Updates must not be null!"); Assert.notNull(updates, "Updates must not be null!");
for (Tuple<Query, Update> update : updates) { for (Pair<Query, Update> update : updates) {
update(update.getFirst(), update.getSecond(), false, false); update(update.getFirst(), update.getSecond(), false, false);
} }
@ -178,7 +178,7 @@ class DefaultBulkOperations implements BulkOperations {
Assert.notNull(query, "Query must not be null!"); Assert.notNull(query, "Query must not be null!");
Assert.notNull(update, "Update must not be null!"); Assert.notNull(update, "Update must not be null!");
return updateMulti(Arrays.asList(Tuple.of(query, update))); return updateMulti(Arrays.asList(Pair.of(query, update)));
} }
/* /*
@ -186,11 +186,11 @@ class DefaultBulkOperations implements BulkOperations {
* @see org.springframework.data.mongodb.core.BulkOperations#updateMulti(java.util.List) * @see org.springframework.data.mongodb.core.BulkOperations#updateMulti(java.util.List)
*/ */
@Override @Override
public BulkOperations updateMulti(List<Tuple<Query, Update>> updates) { public BulkOperations updateMulti(List<Pair<Query, Update>> updates) {
Assert.notNull(updates, "Updates must not be null!"); Assert.notNull(updates, "Updates must not be null!");
for (Tuple<Query, Update> update : updates) { for (Pair<Query, Update> update : updates) {
update(update.getFirst(), update.getSecond(), false, true); update(update.getFirst(), update.getSecond(), false, true);
} }
@ -211,9 +211,9 @@ class DefaultBulkOperations implements BulkOperations {
* @see org.springframework.data.mongodb.core.BulkOperations#upsert(java.util.List) * @see org.springframework.data.mongodb.core.BulkOperations#upsert(java.util.List)
*/ */
@Override @Override
public BulkOperations upsert(List<Tuple<Query, Update>> updates) { public BulkOperations upsert(List<Pair<Query, Update>> updates) {
for (Tuple<Query, Update> update : updates) { for (Pair<Query, Update> update : updates) {
upsert(update.getFirst(), update.getSecond()); upsert(update.getFirst(), update.getSecond());
} }

12
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/DefaultBulkOperationsIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2015 the original author or authors. * Copyright 2015-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.util.Tuple; import org.springframework.data.util.Pair;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -258,7 +258,7 @@ public class DefaultBulkOperationsIntegrationTests {
public void mixedBulkOrderedWithList() { public void mixedBulkOrderedWithList() {
List<BaseDoc> inserts = Arrays.asList(newDoc("1", "v1"), newDoc("2", "v2"), newDoc("3", "v2")); List<BaseDoc> inserts = Arrays.asList(newDoc("1", "v1"), newDoc("2", "v2"), newDoc("3", "v2"));
List<Tuple<Query, Update>> updates = Arrays.asList(Tuple.of(where("value", "v2"), set("value", "v3"))); List<Pair<Query, Update>> updates = Arrays.asList(Pair.of(where("value", "v2"), set("value", "v3")));
List<Query> removes = Arrays.asList(where("_id", "1")); List<Query> removes = Arrays.asList(where("_id", "1"));
BulkWriteResult result = createBulkOps(BulkMode.ORDERED).insert(inserts).updateMulti(updates).remove(removes) BulkWriteResult result = createBulkOps(BulkMode.ORDERED).insert(inserts).updateMulti(updates).remove(removes)
@ -276,9 +276,9 @@ public class DefaultBulkOperationsIntegrationTests {
insertSomeDocuments(); insertSomeDocuments();
List<Tuple<Query, Update>> updates = new ArrayList<Tuple<Query, Update>>(); List<Pair<Query, Update>> updates = new ArrayList<Pair<Query, Update>>();
updates.add(Tuple.of(where("value", "value1"), set("value", "value3"))); updates.add(Pair.of(where("value", "value1"), set("value", "value3")));
updates.add(Tuple.of(where("value", "value2"), set("value", "value4"))); updates.add(Pair.of(where("value", "value2"), set("value", "value4")));
int modifiedCount = multi ? bulkOps.updateMulti(updates).execute().getModifiedCount() int modifiedCount = multi ? bulkOps.updateMulti(updates).execute().getModifiedCount()
: bulkOps.updateOne(updates).execute().getModifiedCount(); : bulkOps.updateOne(updates).execute().getModifiedCount();

Loading…
Cancel
Save