Skip to content

Commit 2ca879f

Browse files
committed
DATAMONGO-2138 - Polishing.
Rename NestedProperty to KPropertyPath to reflect the underlying concept in alignment with our own PropertyPath type. Rename nestedFieldName(…) method to asString(…) to align with Kotlin method terminology. Reformat. Slightly reword documentation. Add Type-safe Queries for Kotlin to What's New section. Original pull request: #622.
1 parent 8d969ef commit 2ca879f

File tree

7 files changed

+256
-205
lines changed

7 files changed

+256
-205
lines changed

Diff for: spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/CriteriaExtensions.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,36 @@ import kotlin.reflect.KProperty
2323
* @author Sebastien Deleuze
2424
* @since 2.0
2525
*/
26-
fun Criteria.isEqualTo(o: Any?) : Criteria = `is`(o)
26+
fun Criteria.isEqualTo(o: Any?): Criteria = `is`(o)
2727

2828
/**
2929
* Extension for [Criteria.in] providing an `inValues` alias since `in` is a reserved keyword in Kotlin.
3030
*
3131
* @author Sebastien Deleuze
3232
* @since 2.0
3333
*/
34-
fun <T: Any?> Criteria.inValues(c: Collection<T>) : Criteria = `in`(c)
34+
fun <T : Any?> Criteria.inValues(c: Collection<T>): Criteria = `in`(c)
3535

3636
/**
3737
* Extension for [Criteria.in] providing an `inValues` alias since `in` is a reserved keyword in Kotlin.
3838
*
3939
* @author Sebastien Deleuze
4040
* @since 2.0
4141
*/
42-
fun Criteria.inValues(vararg o: Any?) : Criteria = `in`(*o)
42+
fun Criteria.inValues(vararg o: Any?): Criteria = `in`(*o)
4343

4444
/**
4545
* Creates a Criteria using a KProperty as key.
46-
* Supports nested field names with [NestedProperty].
46+
* Supports nested field names with [KPropertyPath].
4747
* @author Tjeu Kayim
4848
* @since 2.2
4949
*/
50-
fun where(key: KProperty<*>): Criteria = Criteria.where(nestedFieldName(key))
50+
fun where(key: KProperty<*>): Criteria = Criteria.where(asString(key))
51+
5152
/**
5253
* Add new key to the criteria chain using a KProperty.
53-
* Supports nested field names with [NestedProperty].
54+
* Supports nested field names with [KPropertyPath].
5455
* @author Tjeu Kayim
5556
* @since 2.2
5657
*/
57-
infix fun Criteria.and(key: KProperty<*>): Criteria = and(nestedFieldName(key))
58+
infix fun Criteria.and(key: KProperty<*>): Criteria = and(asString(key))

Diff for: spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/NestedProperty.kt renamed to spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/KPropertyPath.kt

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ import kotlin.reflect.KProperty
1919
import kotlin.reflect.KProperty1
2020

2121
/**
22-
* Refer to a field in an embedded/nested document.
22+
* Abstraction of a property path consisting of [KProperty].
2323
* @author Tjeu Kayim
24+
* @author Mark Paluch
2425
* @since 2.2
2526
*/
26-
class NestedProperty<T, U>(
27-
internal val parent: KProperty<U>,
28-
internal val child: KProperty1<U, T>
27+
class KPropertyPath<T, U>(
28+
internal val parent: KProperty<U>,
29+
internal val child: KProperty1<U, T>
2930
) : KProperty<T> by child
3031

3132
/**
3233
* Recursively construct field name for a nested property.
3334
* @author Tjeu Kayim
3435
*/
35-
internal fun nestedFieldName(property: KProperty<*>): String {
36+
internal fun asString(property: KProperty<*>): String {
3637
return when (property) {
37-
is NestedProperty<*, *> ->
38-
"${nestedFieldName(property.parent)}.${property.child.name}"
38+
is KPropertyPath<*, *> ->
39+
"${asString(property.parent)}.${property.child.name}"
3940
else -> property.name
4041
}
4142
}
4243

4344
/**
44-
* Builds [NestedProperty] from Property References.
45+
* Builds [KPropertyPath] from Property References.
4546
* Refer to a field in an embedded/nested document.
4647
*
4748
* For example, referring to the field "book.author":
@@ -52,4 +53,4 @@ internal fun nestedFieldName(property: KProperty<*>): String {
5253
* @since 2.2
5354
*/
5455
operator fun <T, U> KProperty<T>.div(other: KProperty1<T, U>) =
55-
NestedProperty(this, other)
56+
KPropertyPath(this, other)

0 commit comments

Comments
 (0)