Skip to content

Commit

Permalink
upgrade versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zigzago committed Feb 12, 2022
1 parent 8b64d8c commit cf887db
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2016/2021 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.
*/

package org.litote.kmongo.issues

import org.bson.codecs.pojo.annotations.BsonId
import org.junit.Ignore
import org.junit.Test
import org.litote.kmongo.AllCategoriesKMongoBaseTest
import org.litote.kmongo.Id
import org.litote.kmongo.eq
import org.litote.kmongo.findOne
import org.litote.kmongo.newId
import kotlin.test.assertNotNull

data class Account(@BsonId val id: Id<Account>, val email: EmailAddress)

@JvmInline
value class EmailAddress(val value: String)


/**
*
*/
class Issue314ValueClass : AllCategoriesKMongoBaseTest<Account>() {

@Test
@Ignore
fun `test insert and load`() {
col.insertOne(Account(newId(), EmailAddress("a")))
val doc = col.findOne(Account::email eq EmailAddress("a"))
assertNotNull(doc)
}
}
17 changes: 15 additions & 2 deletions kmongo-core/src/main/kotlin/org/litote/kmongo/KMongo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import com.mongodb.MongoClientSettings
import com.mongodb.MongoClientSettings.getDefaultCodecRegistry
import com.mongodb.client.MongoClient
import com.mongodb.client.MongoClients
import org.bson.UuidRepresentation
import org.bson.codecs.configuration.CodecConfigurationException
import org.bson.codecs.configuration.CodecRegistry
import org.bson.internal.CodecRegistryHelper
import org.bson.internal.OverridableUuidRepresentationCodecRegistry
import org.litote.kmongo.service.ClassMappingType

/**
Expand Down Expand Up @@ -68,13 +70,24 @@ object KMongo {
fun createClient(settings: MongoClientSettings): MongoClient = MongoClients.create(
MongoClientSettings.builder(settings).codecRegistry(
configureRegistry(
CodecRegistryHelper.createRegistry(
createRegistry(
settings.codecRegistry, settings.uuidRepresentation
)
)
).build()
)

private fun createRegistry(codecRegistry: CodecRegistry, uuidRepresentation: UuidRepresentation): CodecRegistry =
if (uuidRepresentation !== UuidRepresentation.JAVA_LEGACY) {
OverridableUuidRepresentationCodecRegistry(codecRegistry, uuidRepresentation)
} else {
throw CodecConfigurationException(
"Changing the default UuidRepresentation requires a CodecRegistry that also "
+ "implements the CodecProvider interface"
)
}


internal fun configureRegistry(codecRegistry: CodecRegistry = getDefaultCodecRegistry()): CodecRegistry =
ClassMappingType.codecRegistry(codecRegistry)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2016/2021 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.
*/

package org.litote.kmongo.issues

import org.junit.Test
import org.litote.kmongo.and
import org.litote.kmongo.combine
import org.litote.kmongo.div
import org.litote.kmongo.eq
import org.litote.kmongo.exists
import org.litote.kmongo.json
import org.litote.kmongo.or
import org.litote.kmongo.setValue
import org.litote.kmongo.unset

/**
*
*/
class Issue316ReplaceNotNull {

class MyClass(val someId:String, val someOtherId: String, val nestedObject:NestedClass)
class NestedClass(val yetAnotherId: String)

@Test
fun `test insert and load`() {
val filter = and(
or(
MyClass::someId eq "someId",
MyClass::someOtherId eq "someOtherId",
MyClass::nestedObject / NestedClass::yetAnotherId eq "yetAnotherId"
),
MyClass::nestedObject exists true
)
println(filter.json)
}

class Data(val field1:Int, val field2:Int)

@Test
fun `test insert and load2`() {
val filter = combine(unset( Data::field1,), setValue(Data::field2 , 2))
println(filter.json)
}

}
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,33 @@

<properties>
<!-- dependencies -->
<kotlin.version>1.6.0</kotlin.version>
<mongo.version>4.4.0</mongo.version>
<mongo.base.version>4.4</mongo.base.version>
<coroutine.version>1.5.2</coroutine.version>
<kotlin.version>1.6.10</kotlin.version>
<mongo.version>4.5.0</mongo.version>
<mongo.base.version>4.5</mongo.base.version>
<coroutine.version>1.6.0</coroutine.version>
<rxjava.version>2.2.21</rxjava.version>
<rxkotlin.version>2.4.0</rxkotlin.version>
<reactor.version>2020.0.13</reactor.version>
<mongo.reactor.adapter.version>0.3.0</mongo.reactor.adapter.version>
<jackson.version>2.13.0</jackson.version>
<jackson-module.version>2.13.0</jackson-module.version>
<reactor.version>2020.0.15</reactor.version>
<mongo.reactor.adapter.version>0.3.2</mongo.reactor.adapter.version>
<jackson.version>2.13.1</jackson.version>
<jackson-module.version>2.13.1</jackson-module.version>
<bson4jackson.version>2.13.0</bson4jackson.version>
<kreflect.version>1.0.0</kreflect.version>
<jackson-module-loader.version>0.4.0</jackson-module-loader.version>
<kotlinx-serialization.version>1.3.1</kotlinx-serialization.version>
<kotlinx-serialization.version>1.3.2</kotlinx-serialization.version>
<kbson.version>0.4.4</kbson.version>

<!-- annotations processor -->
<kgenerator.version>0.4.0</kgenerator.version>
<kjackson-data.version>0.4.0</kjackson-data.version>
<kjackson-generator.version>0.4.0</kjackson-generator.version>
<kotlinx.metadata>0.3.0</kotlinx.metadata>
<kotlinx.metadata>0.4.1</kotlinx.metadata>

<!-- test dependencies -->
<flapdoodle.version>2.2.0</flapdoodle.version>
<sl4j.version>2.0.0-alpha5</sl4j.version>
<junit.version>4.13.2</junit.version>
<jmh.version>1.33</jmh.version>
<jmh.version>1.34</jmh.version>
<compiler-testing.version>0.19</compiler-testing.version>
<mockito.kotlin.version>2.2.0</mockito.kotlin.version>

Expand Down

0 comments on commit cf887db

Please sign in to comment.