Skip to content

Commit e91c54d

Browse files
committed
Add extension functions for BulkOperations methods converting kotlin.Pair to Spring Pair class.
1 parent ceac2b8 commit e91c54d

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2017-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mongodb.core
17+
18+
import org.springframework.data.mongodb.core.query.Query
19+
import org.springframework.data.mongodb.core.query.Update
20+
import org.springframework.data.mongodb.core.query.UpdateDefinition
21+
import org.springframework.data.util.Pair.of
22+
23+
/**
24+
* Extension for [BulkOperations.updateMulti] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
25+
*
26+
* @author 2tsumo-hitori
27+
*/
28+
fun BulkOperations.updateMulti(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations =
29+
updateMulti(kotlinPairs.toSpringPairs())
30+
31+
/**
32+
* Extension for [BulkOperations.upsert] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
33+
*
34+
* @author 2tsumo-hitori
35+
*/
36+
fun BulkOperations.upsert(kotlinPairs: List<Pair<Query, Update>>) : BulkOperations =
37+
upsert(kotlinPairs.toSpringPairs())
38+
39+
/**
40+
* Extension for [BulkOperations.updateOne] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
41+
*
42+
* @author 2tsumo-hitori
43+
*/
44+
fun BulkOperations.updateOne(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations =
45+
updateOne(kotlinPairs.toSpringPairs())
46+
47+
private fun <A : Query, B : UpdateDefinition> List<Pair<A, B>>.toSpringPairs(): List<org.springframework.data.util.Pair<A, B>> {
48+
49+
return map { (first, second) -> of(first, second) }
50+
}

0 commit comments

Comments
 (0)