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
2020
2121/* *
2222 * Abstraction of a property path consisting of [KProperty].
23+ *
2324 * @author Tjeu Kayim
2425 * @author Mark Paluch
2526 * @author Yoann de Martino
@@ -28,11 +29,7 @@ import kotlin.reflect.KProperty1
2829class KPropertyPath <T , U >(
2930 internal val parent : KProperty <U >,
3031 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
3633
3734/* *
3835 * 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
1919import org.junit.Test
2020
2121/* *
22+ * Unit tests for [KPropertyPath] and its extensions.
23+ *
2224 * @author Tjeu Kayim
2325 * @author Yoann de Martino
26+ * @author Mark Paluch
2427 */
2528class KPropertyPathTests {
2629
@@ -62,21 +65,30 @@ class KPropertyPathTests {
6265 }
6366
6467 @Test
65- fun `Convert nested KProperty to field name using toString() ` () {
68+ fun `Convert simple KProperty to property path using toPath ` () {
6669
67- val property = ( Book ::author / Author ::name).toString( )
70+ class AnotherEntity ( val entity : String )
6871
69- assertThat(property).isEqualTo(" author.name" )
72+ val property = (AnotherEntity ::entity).toPath()
73+
74+ assertThat(property).isEqualTo(" entity" )
7075 }
7176
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+ }
7284
7385 @Test
74- fun `Convert triple nested KProperty to field name using toString() ` () {
86+ fun `Convert triple nested KProperty to property path using toPath ` () {
7587
7688 class Entity (val book : Book )
7789 class AnotherEntity (val entity : Entity )
7890
79- val property = (AnotherEntity ::entity / Entity ::book / Book ::author / Author ::name).toString ()
91+ val property = (AnotherEntity ::entity / Entity ::book / Book ::author / Author ::name).toPath ()
8092
8193 assertThat(property).isEqualTo(" entity.book.author.name" )
8294 }
Original file line number Diff line number Diff line change 77* <<mongo.auditing,Reactive auditing>> enabled through `@EnableReactiveMongoAuditing`. `@EnableMongoAuditing` no longer registers `ReactiveAuditingEntityCallback`.
88* Reactive SpEL support in `@Query` and `@Aggregation` query methods.
99* Aggregation hints via `AggregationOptions.builder().hint(bson).build()`.
10+ * Extension Function `KProperty.asPath()` to render property references into a property path representation.
1011
1112[[new-features.3.0]]
1213== What's New in Spring Data MongoDB 3.0
You can’t perform that action at this time.
0 commit comments