File tree Expand file tree Collapse file tree 4 files changed +46
-10
lines changed
main/kotlin/org/springframework/data/mongodb/core/query
test/kotlin/org/springframework/data/mongodb/core/query Expand file tree Collapse file tree 4 files changed +46
-10
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import kotlin.reflect.KProperty1
20
20
21
21
/* *
22
22
* Abstraction of a property path consisting of [KProperty].
23
+ *
23
24
* @author Tjeu Kayim
24
25
* @author Mark Paluch
25
26
* @author Yoann de Martino
@@ -28,11 +29,7 @@ import kotlin.reflect.KProperty1
28
29
class KPropertyPath <T , U >(
29
30
internal val parent : KProperty <U >,
30
31
internal val child : KProperty1 <U , T >
31
- ) : KProperty<T> by child {
32
- override fun toString (): String {
33
- return asString(this )
34
- }
35
- }
32
+ ) : KProperty<T> by child
36
33
37
34
/* *
38
35
* Recursively construct field name for a nested property.
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 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.query
17
+
18
+ import kotlin.reflect.KProperty
19
+
20
+ /* *
21
+ * Extension for [KProperty] providing an `toPath` function to render a [KProperty] as property path.
22
+ *
23
+ * @author Mark Paluch
24
+ * @since 3.1
25
+ */
26
+ fun KProperty <* >.toPath (): String = asString(this )
Original file line number Diff line number Diff line change @@ -19,8 +19,11 @@ import org.assertj.core.api.Assertions.assertThat
19
19
import org.junit.Test
20
20
21
21
/* *
22
+ * Unit tests for [KPropertyPath] and its extensions.
23
+ *
22
24
* @author Tjeu Kayim
23
25
* @author Yoann de Martino
26
+ * @author Mark Paluch
24
27
*/
25
28
class KPropertyPathTests {
26
29
@@ -62,21 +65,30 @@ class KPropertyPathTests {
62
65
}
63
66
64
67
@Test
65
- fun `Convert nested KProperty to field name using toString() ` () {
68
+ fun `Convert simple KProperty to property path using toPath ` () {
66
69
67
- val property = ( Book ::author / Author ::name).toString( )
70
+ class AnotherEntity ( val entity : String )
68
71
69
- assertThat(property).isEqualTo(" author.name" )
72
+ val property = (AnotherEntity ::entity).toPath()
73
+
74
+ assertThat(property).isEqualTo(" entity" )
70
75
}
71
76
77
+ @Test
78
+ fun `Convert nested KProperty to field name using toPath()` () {
79
+
80
+ val property = (Book ::author / Author ::name).toPath()
81
+
82
+ assertThat(property).isEqualTo(" author.name" )
83
+ }
72
84
73
85
@Test
74
- fun `Convert triple nested KProperty to field name using toString() ` () {
86
+ fun `Convert triple nested KProperty to property path using toPath ` () {
75
87
76
88
class Entity (val book : Book )
77
89
class AnotherEntity (val entity : Entity )
78
90
79
- val property = (AnotherEntity ::entity / Entity ::book / Book ::author / Author ::name).toString ()
91
+ val property = (AnotherEntity ::entity / Entity ::book / Book ::author / Author ::name).toPath ()
80
92
81
93
assertThat(property).isEqualTo(" entity.book.author.name" )
82
94
}
Original file line number Diff line number Diff line change 7
7
* <<mongo.auditing,Reactive auditing>> enabled through `@EnableReactiveMongoAuditing`. `@EnableMongoAuditing` no longer registers `ReactiveAuditingEntityCallback`.
8
8
* Reactive SpEL support in `@Query` and `@Aggregation` query methods.
9
9
* Aggregation hints via `AggregationOptions.builder().hint(bson).build()`.
10
+ * Extension Function `KProperty.asPath()` to render property references into a property path representation.
10
11
11
12
[[new-features.3.0]]
12
13
== What's New in Spring Data MongoDB 3.0
You can’t perform that action at this time.
0 commit comments