Skip to content

DATAMONGO-2086 - Fix Fluent API Kotlin extension generics to allow projections #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAMONGO-2086-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAMONGO-2086-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-mongodb-cross-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAMONGO-2086-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAMONGO-2086-SNAPSHOT</version>
</dependency>

<!-- reactive -->
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAMONGO-2086-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAMONGO-2086-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,15 +37,14 @@ fun <T : Any> ExecutableFindOperation.query(entityClass: KClass<T>): ExecutableF
inline fun <reified T : Any> ExecutableFindOperation.query(): ExecutableFindOperation.ExecutableFind<T> =
query(T::class.java)


/**
* Extension for [ExecutableFindOperation.FindWithProjection. as] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @author Mark Paluch
* @since 2.0
*/
fun <T : Any> ExecutableFindOperation.FindWithProjection<T>.asType(resultType: KClass<T>): ExecutableFindOperation.FindWithQuery<T> =
fun <T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(resultType: KClass<T>): ExecutableFindOperation.FindWithQuery<T> =
`as`(resultType.java)

/**
Expand All @@ -55,7 +54,7 @@ fun <T : Any> ExecutableFindOperation.FindWithProjection<T>.asType(resultType: K
* @author Mark Paluch
* @since 2.0
*/
inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<T>.asType(): ExecutableFindOperation.FindWithQuery<T> =
inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<*>.asType(): ExecutableFindOperation.FindWithQuery<T> =
`as`(T::class.java)

/**
Expand All @@ -66,3 +65,12 @@ inline fun <reified T : Any> ExecutableFindOperation.FindWithProjection<T>.asTyp
*/
fun <T : Any> ExecutableFindOperation.DistinctWithProjection.asType(resultType: KClass<T>): ExecutableFindOperation.TerminatingDistinct<T> =
`as`(resultType.java);

/**
* Extension for [ExecutableFindOperation.DistinctWithProjection. as] leveraging reified type parameters.
*
* @author Christoph Strobl
* @since 2.1
*/
inline fun <reified T : Any> ExecutableFindOperation.DistinctWithProjection.asType(): ExecutableFindOperation.DistinctWithProjection =
`as`(T::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inline fun <reified T : Any> ExecutableMapReduceOperation.mapReduce(): Executabl
* @author Christoph Strobl
* @since 2.1
*/
fun <T : Any> ExecutableMapReduceOperation.MapReduceWithProjection<T>.asType(resultType: KClass<T>): ExecutableMapReduceOperation.MapReduceWithQuery<T> =
fun <T : Any> ExecutableMapReduceOperation.MapReduceWithProjection<*>.asType(resultType: KClass<T>): ExecutableMapReduceOperation.MapReduceWithQuery<T> =
`as`(resultType.java)

/**
Expand All @@ -50,5 +50,5 @@ fun <T : Any> ExecutableMapReduceOperation.MapReduceWithProjection<T>.asType(res
* @author Christoph Strobl
* @since 2.1
*/
inline fun <reified T : Any> ExecutableMapReduceOperation.MapReduceWithProjection<T>.asType(): ExecutableMapReduceOperation.MapReduceWithQuery<T> =
inline fun <reified T : Any> ExecutableMapReduceOperation.MapReduceWithProjection<*>.asType(): ExecutableMapReduceOperation.MapReduceWithQuery<T> =
`as`(T::class.java)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,7 @@ inline fun <reified T : Any> ReactiveFindOperation.query(): ReactiveFindOperatio
* @author Mark Paluch
* @since 2.0
*/
fun <T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(resultType: KClass<T>): ReactiveFindOperation.FindWithQuery<T> =
fun <T : Any> ReactiveFindOperation.FindWithProjection<*>.asType(resultType: KClass<T>): ReactiveFindOperation.FindWithQuery<T> =
`as`(resultType.java)

/**
Expand All @@ -50,7 +50,7 @@ fun <T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(resultType: KCl
* @author Mark Paluch
* @since 2.0
*/
inline fun <reified T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(): ReactiveFindOperation.FindWithQuery<T> =
inline fun <reified T : Any> ReactiveFindOperation.FindWithProjection<*>.asType(): ReactiveFindOperation.FindWithQuery<T> =
`as`(T::class.java)

/**
Expand All @@ -61,3 +61,12 @@ inline fun <reified T : Any> ReactiveFindOperation.FindWithProjection<T>.asType(
*/
fun <T : Any> ReactiveFindOperation.DistinctWithProjection.asType(resultType: KClass<T>): ReactiveFindOperation.TerminatingDistinct<T> =
`as`(resultType.java);

/**
* Extension for [ReactiveFindOperation.DistinctWithProjection. as] leveraging reified type parameters.
*
* @author Christoph Strobl
* @since 2.1
*/
inline fun <reified T : Any> ReactiveFindOperation.DistinctWithProjection.asType(): ReactiveFindOperation.DistinctWithProjection =
`as`(T::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ inline fun <reified T : Any> ReactiveMapReduceOperation.mapReduce(): ReactiveMap
* @author Christoph Strobl
* @since 2.1
*/
fun <T : Any> ReactiveMapReduceOperation.MapReduceWithProjection<T>.asType(resultType: KClass<T>): ReactiveMapReduceOperation.MapReduceWithQuery<T> =
fun <T : Any> ReactiveMapReduceOperation.MapReduceWithProjection<*>.asType(resultType: KClass<T>): ReactiveMapReduceOperation.MapReduceWithQuery<T> =
`as`(resultType.java)

/**
Expand All @@ -50,5 +50,5 @@ fun <T : Any> ReactiveMapReduceOperation.MapReduceWithProjection<T>.asType(resul
* @author Christoph Strobl
* @since 2.1
*/
inline fun <reified T : Any> ReactiveMapReduceOperation.MapReduceWithProjection<T>.asType(): ReactiveMapReduceOperation.MapReduceWithQuery<T> =
inline fun <reified T : Any> ReactiveMapReduceOperation.MapReduceWithProjection<*>.asType(): ReactiveMapReduceOperation.MapReduceWithQuery<T> =
`as`(T::class.java)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,24 +53,31 @@ class ExecutableFindOperationExtensionsTests {
verify(operation).query(First::class.java)
}

@Test // DATAMONGO-1689
@Test // DATAMONGO-1689, DATAMONGO-2086
fun `ExecutableFindOperation#FindOperationWithProjection#asType(KClass) extension should call its Java counterpart`() {

operationWithProjection.asType(First::class)
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType(User::class)
verify(operationWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-1689
@Test // DATAMONGO-1689, DATAMONGO-2086
fun `ExecutableFindOperation#FindOperationWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {

operationWithProjection.asType()
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType<User>()
verify(operationWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-1761
@Test // DATAMONGO-1761, DATAMONGO-2086
fun `ExecutableFindOperation#DistinctWithProjection#asType(KClass) extension should call its Java counterpart`() {

distinctWithProjection.asType(First::class)
verify(distinctWithProjection).`as`(First::class.java)
distinctWithProjection.asType(User::class)
verify(distinctWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-2086
fun `ExecutableFindOperation#DistinctWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {

distinctWithProjection.asType<User>()
verify(distinctWithProjection).`as`(User::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ class ExecutableMapReduceOperationExtensionsTests {
verify(operation).mapReduce(First::class.java)
}

@Test // DATAMONGO-1929
@Test // DATAMONGO-1929, DATAMONGO-2086
fun `ExecutableMapReduceOperation#MapReduceWithProjection#asType(KClass) extension should call its Java counterpart`() {

operationWithProjection.asType(First::class)
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType(User::class)
verify(operationWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-1929
@Test // DATAMONGO-1929, DATAMONGO-2086
fun `ExecutableMapReduceOperation#MapReduceWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {

operationWithProjection.asType()
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType<User>()
verify(operationWithProjection).`as`(User::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,24 +52,31 @@ class ReactiveFindOperationExtensionsTests {
verify(operation).query(First::class.java)
}

@Test // DATAMONGO-1719
@Test // DATAMONGO-1719, DATAMONGO-2086
fun `ReactiveFind#FindOperatorWithProjection#asType(KClass) extension should call its Java counterpart`() {

operationWithProjection.asType(First::class)
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType(User::class)
verify(operationWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-1719
@Test // DATAMONGO-1719, DATAMONGO-2086
fun `ReactiveFind#FindOperatorWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {

operationWithProjection.asType()
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType<User>()
verify(operationWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-1761
@Test // DATAMONGO-1761, DATAMONGO-2086
fun `ReactiveFind#DistinctWithProjection#asType(KClass) extension should call its Java counterpart`() {

distinctWithProjection.asType(First::class)
verify(distinctWithProjection).`as`(First::class.java)
distinctWithProjection.asType(User::class)
verify(distinctWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-2086
fun `ReactiveFind#DistinctWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {

distinctWithProjection.asType<User>()
verify(distinctWithProjection).`as`(User::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class ReactiveMapReduceOperationExtensionsTests {
@Test // DATAMONGO-1929
fun `ReactiveMapReduceOperation#MapReduceWithProjection#asType(KClass) extension should call its Java counterpart`() {

operationWithProjection.asType(First::class)
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType(User::class)
verify(operationWithProjection).`as`(User::class.java)
}

@Test // DATAMONGO-1929
fun `ReactiveMapReduceOperation#MapReduceWithProjection#asType() with reified type parameter extension should call its Java counterpart`() {

operationWithProjection.asType()
verify(operationWithProjection).`as`(First::class.java)
operationWithProjection.asType<User>()
verify(operationWithProjection).`as`(User::class.java)
}
}