Browse Source

Polishing.

Tweak documentation, add since tags. Reformat code, change space indents to tab indents.

See #4911
Original pull request: #4912
pull/4931/head
Mark Paluch 9 months ago
parent
commit
833601d847
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 12
      spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/BulkOperationsExtensions.kt
  2. 21
      spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/BulkOperationExtensionsTests.kt

12
spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/BulkOperationsExtensions.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2017-2025 the original author or authors. * Copyright 2025 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.
@ -21,30 +21,32 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition
import org.springframework.data.util.Pair.of import org.springframework.data.util.Pair.of
/** /**
* Extension for [BulkOperations.updateMulti] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair]. * Extension for [BulkOperations.updateMulti] that converts a list of [kotlin.Pair] to list of [org.springframework.data.util.Pair].
* *
* @author 2tsumo-hitori * @author 2tsumo-hitori
* @since 4.5
*/ */
fun BulkOperations.updateMulti(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations = fun BulkOperations.updateMulti(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations =
updateMulti(kotlinPairs.toSpringPairs()) updateMulti(kotlinPairs.toSpringPairs())
/** /**
* Extension for [BulkOperations.upsert] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair]. * Extension for [BulkOperations.upsert] that converts a list of [kotlin.Pair] to list of [org.springframework.data.util.Pair].
* *
* @author 2tsumo-hitori * @author 2tsumo-hitori
* @since 4.5
*/ */
fun BulkOperations.upsert(kotlinPairs: List<Pair<Query, Update>>) : BulkOperations = fun BulkOperations.upsert(kotlinPairs: List<Pair<Query, Update>>): BulkOperations =
upsert(kotlinPairs.toSpringPairs()) upsert(kotlinPairs.toSpringPairs())
/** /**
* Extension for [BulkOperations.updateOne] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair]. * Extension for [BulkOperations.updateOne] that converts a [kotlin.Pair] to [org.springframework.data.util.Pair].
* *
* @author 2tsumo-hitori * @author 2tsumo-hitori
* @since 4.5
*/ */
fun BulkOperations.updateOne(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations = fun BulkOperations.updateOne(kotlinPairs: List<Pair<Query, UpdateDefinition>>): BulkOperations =
updateOne(kotlinPairs.toSpringPairs()) updateOne(kotlinPairs.toSpringPairs())
private fun <A : Query, B : UpdateDefinition> List<Pair<A, B>>.toSpringPairs(): List<org.springframework.data.util.Pair<A, B>> { private fun <A : Query, B : UpdateDefinition> List<Pair<A, B>>.toSpringPairs(): List<org.springframework.data.util.Pair<A, B>> {
return map { (first, second) -> of(first, second) } return map { (first, second) -> of(first, second) }
} }

21
spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/BulkOperationExtensionsTests.kt

@ -1,5 +1,5 @@
/* /*
* Copyright 2017-2025 the original author or authors. * Copyright 2025 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.
@ -17,7 +17,7 @@ package org.springframework.data.mongodb.core
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import org.junit.Test import org.junit.jupiter.api.Test
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
@ -25,6 +25,7 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition
import org.springframework.data.util.Pair.of import org.springframework.data.util.Pair.of
/** /**
* Unit tests for BulkOperationExtensions.
* @author 2tsumo-hitori * @author 2tsumo-hitori
*/ */
class BulkOperationExtensionsTests { class BulkOperationExtensionsTests {
@ -32,8 +33,9 @@ class BulkOperationExtensionsTests {
private val bulkOperation = mockk<BulkOperations>(relaxed = true) private val bulkOperation = mockk<BulkOperations>(relaxed = true)
@Test // GH-4911 @Test // GH-4911
fun `BulkOperation#updateMulti#updates() using kotlin#Pair should call its Java counterpart`() { fun `BulkOperation#updateMulti using kotlin#Pair should call its Java counterpart`() {
val list : MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
val list: MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
list.add(where("value", "v2") to set("value", "v3")) list.add(where("value", "v2") to set("value", "v3"))
bulkOperation.updateMulti(list) bulkOperation.updateMulti(list)
@ -43,8 +45,9 @@ class BulkOperationExtensionsTests {
} }
@Test // GH-4911 @Test // GH-4911
fun `BulkOperation#upsert#updates() using kotlin#Pair should call its Java counterpart`() { fun `BulkOperation#upsert using kotlin#Pair should call its Java counterpart`() {
val list : MutableList<Pair<Query, Update>> = mutableListOf()
val list: MutableList<Pair<Query, Update>> = mutableListOf()
list.add(where("value", "v2") to set("value", "v3")) list.add(where("value", "v2") to set("value", "v3"))
bulkOperation.upsert(list) bulkOperation.upsert(list)
@ -54,8 +57,9 @@ class BulkOperationExtensionsTests {
} }
@Test // GH-4911 @Test // GH-4911
fun `BulkOperation#updateOne#updates() using kotlin#Pair should call its Java counterpart`() { fun `BulkOperation#updateOne using kotlin#Pair should call its Java counterpart`() {
val list : MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
val list: MutableList<Pair<Query, UpdateDefinition>> = mutableListOf()
list.add(where("value", "v2") to set("value", "v3")) list.add(where("value", "v2") to set("value", "v3"))
bulkOperation.updateOne(list) bulkOperation.updateOne(list)
@ -71,4 +75,5 @@ class BulkOperationExtensionsTests {
private fun set(field: String, value: String): Update { private fun set(field: String, value: String): Update {
return Update().set(field, value) return Update().set(field, value)
} }
} }
Loading…
Cancel
Save