From 0223eb80fcd3a0e4d30e568c638bd9b55b1473f0 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Mon, 23 Sep 2024 10:27:50 +0100 Subject: [PATCH 1/9] Helper methods and extensions to improve kotlin interop. (#1478) Adds a new package `org.mongodb.mongodb-driver-kotlin-extensions`. Its both, kotlin driver and bson kotlin implementation agnostic. Can be used with any combination of `bson-kotlin`, `bson-kotlinx`, `mongodb-driver-kotlin-sync` and `mongodb-driver-kotlin-coroutine`. Initial Filters extensions support, with both inflix and nested helpers eg: ``` import com.mongodb.kotlin.client.model.Filters.eq // infix Person::name.eq(person.name) // nested val bson = eq(Person::name, person.name) ``` Also adds path based support which works with vairous annotations on the data class: `@SerialName("_id")`, `@BsonId`, `@BsonProperty("_id")`: ``` (Restaurant::reviews / Review::score).path() == "reviews.rating" ``` JAVA-5308 JAVA-5484 --- THIRD-PARTY-NOTICES | 23 + config/spotbugs/exclude.xml | 6 + driver-kotlin-extensions/build.gradle.kts | 163 +++ .../mongodb/kotlin/client/model/Filters.kt | 1215 +++++++++++++++++ .../mongodb/kotlin/client/model/Properties.kt | 134 ++ .../kotlin/client/property/KPropertyPath.kt | 188 +++ .../kotlin/kotlin/internal/OnlyInputTypes.kt | 27 + .../kotlin/client/model/ExtensionsApiTest.kt | 63 + .../kotlin/client/model/FiltersTest.kt | 667 +++++++++ .../kotlin/client/model/KPropertiesTest.kt | 139 ++ settings.gradle | 1 + 11 files changed, 2626 insertions(+) create mode 100644 driver-kotlin-extensions/build.gradle.kts create mode 100644 driver-kotlin-extensions/src/main/kotlin/com/mongodb/kotlin/client/model/Filters.kt create mode 100644 driver-kotlin-extensions/src/main/kotlin/com/mongodb/kotlin/client/model/Properties.kt create mode 100644 driver-kotlin-extensions/src/main/kotlin/com/mongodb/kotlin/client/property/KPropertyPath.kt create mode 100644 driver-kotlin-extensions/src/main/kotlin/kotlin/internal/OnlyInputTypes.kt create mode 100644 driver-kotlin-extensions/src/test/kotlin/com/mongodb/kotlin/client/model/ExtensionsApiTest.kt create mode 100644 driver-kotlin-extensions/src/test/kotlin/com/mongodb/kotlin/client/model/FiltersTest.kt create mode 100644 driver-kotlin-extensions/src/test/kotlin/com/mongodb/kotlin/client/model/KPropertiesTest.kt diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index 7229bf7192..f881b10354 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -161,3 +161,26 @@ https://github.com/mongodb/mongo-java-driver. See the License for the specific language governing permissions and limitations under the License. +8) The following files (originally from https://github.com/Litote/kmongo): + + Filters.kt + Properties.kt + KPropertyPath.kt + FiltersTest.kt + KPropertiesTest.kt + + Copyright 2008-present MongoDB, Inc. + Copyright (C) 2016/2022 Litote + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index 488c797a6a..5983e0d9d0 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -223,6 +223,12 @@ + + + + + + + + + + + + + + + + + +