DATACMNS-1508 - Polishing.
Add findAllById, deleteAll to CoroutineCrudRepository. Keep CoroutineCrudRepository somewhat in sync with ReactiveCrudRepository by adding based methods for those accecpting Publisher. Also add some test. Update License Headers of Kotlin files and fix some warnings. Switch to kotlin-test-junit5. Original pull request: #415.
This commit is contained in:
committed by
Mark Paluch
parent
93c708379e
commit
769b0f6af5
@@ -40,13 +40,12 @@ import org.springframework.lang.Nullable;
|
||||
* errors.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.3
|
||||
* @see org.springframework.core.KotlinDetector#isKotlinReflectPresent()
|
||||
*/
|
||||
public final class KotlinReflectionUtils {
|
||||
|
||||
private static final int KOTLIN_KIND_CLASS = 1;
|
||||
|
||||
private KotlinReflectionUtils() {}
|
||||
|
||||
/**
|
||||
@@ -64,7 +63,7 @@ public final class KotlinReflectionUtils {
|
||||
return Arrays.stream(type.getDeclaredAnnotations()) //
|
||||
.filter(annotation -> annotation.annotationType().getName().equals("kotlin.Metadata")) //
|
||||
.map(annotation -> AnnotationUtils.getValue(annotation, "k")) //
|
||||
.anyMatch(it -> Integer.valueOf(KOTLIN_KIND_CLASS).equals(it));
|
||||
.anyMatch(it -> Integer.valueOf(KotlinClassHeaderKind.CLASS.id).equals(it));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,4 +201,15 @@ public final class KotlinReflectionUtils {
|
||||
Method javaMethod = ReflectJvmMapping.getJavaMethod(function);
|
||||
return javaMethod != null && javaMethod.equals(method);
|
||||
}
|
||||
|
||||
private enum KotlinClassHeaderKind {
|
||||
|
||||
CLASS(1), FILE(2), SYNTHETIC_CLASS(3), MULTI_FILE_CLASS_FACADE(4), MULTI_FILE_CLASS_PART(5);
|
||||
|
||||
int id;
|
||||
|
||||
KotlinClassHeaderKind(int val) {
|
||||
this.id = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2019 the original author or authors.
|
||||
* Copyright 2018-2020 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2020 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.
|
||||
@@ -24,6 +24,7 @@ import reactor.core.publisher.Mono
|
||||
* Interface for generic CRUD operations using Kotlin Coroutines on a repository for a specific type.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 2.3
|
||||
* @see Flow
|
||||
*/
|
||||
@@ -96,6 +97,18 @@ interface CoroutineCrudRepository<T, ID> : Repository<T, ID> {
|
||||
*/
|
||||
fun findAllById(ids: Iterable<ID>): Flow<T>
|
||||
|
||||
/**
|
||||
* Returns all instances of the type `T` with the given IDs.
|
||||
* If some or all ids are not found, no entities are returned for these IDs.
|
||||
* Note that the order of elements in the result is not guaranteed.
|
||||
*
|
||||
* @param ids must not be null nor contain any null values.
|
||||
* @return [Flow] emitting the found entities. The size can be equal or less than the number of given
|
||||
* ids.
|
||||
* @throws IllegalArgumentException in case the given [ids][Iterable] or one of its items is null.
|
||||
*/
|
||||
fun findAllById(ids: Flow<ID>): Flow<T>
|
||||
|
||||
/**
|
||||
* Returns the number of entities available.
|
||||
*
|
||||
@@ -128,6 +141,14 @@ interface CoroutineCrudRepository<T, ID> : Repository<T, ID> {
|
||||
*/
|
||||
suspend fun deleteAll(entities: Iterable<T>)
|
||||
|
||||
/**
|
||||
* Deletes all given entities.
|
||||
*
|
||||
* @param entityStream must not be null.
|
||||
* @throws IllegalArgumentException in case the given [entityStream][Flow] is null.
|
||||
*/
|
||||
fun <S : T> deleteAll(entityStream: Flow<S>)
|
||||
|
||||
/**
|
||||
* Deletes all entities managed by the repository.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2020 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.
|
||||
|
||||
Reference in New Issue
Block a user