├── .codebeatignore ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ └── maven-wrapper.properties ├── .travis.yml ├── LICENSE.txt ├── README.md ├── kmongo-annotation-processor ├── pom.xml ├── src │ ├── main │ │ ├── kotlin │ │ │ └── org │ │ │ │ └── litote │ │ │ │ └── kmongo │ │ │ │ └── KMongoAnnotationProcessor.kt │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── javax.annotation.processing.Processor │ └── test │ │ ├── kotlin │ │ └── org │ │ │ └── litote │ │ │ └── kmongo │ │ │ ├── InternalTest.kt │ │ │ ├── MockedClassMappingTypeService.kt │ │ │ ├── PathTest.kt │ │ │ ├── SerializationTest.kt │ │ │ ├── annotation │ │ │ └── ProcessorTest.kt │ │ │ ├── issue │ │ │ ├── Issue130ParentGeneric.kt │ │ │ └── Issue132ProjectionsAreNotAllowed.kt │ │ │ └── model │ │ │ ├── AnnotatedFileSample.kt │ │ │ ├── InternalDataClass.kt │ │ │ ├── NotAnnotatedData.kt │ │ │ ├── SimpleReferenced2Data.kt │ │ │ ├── SubData.kt │ │ │ ├── SubData2.kt │ │ │ ├── TestData.kt │ │ │ └── other │ │ │ └── SimpleReferencedData.kt │ │ └── resources │ │ └── META-INF │ │ └── services │ │ ├── javax.annotation.processing.Processor │ │ ├── org.litote.jackson.JacksonModuleServiceLoader │ │ └── org.litote.kmongo.service.ClassMappingTypeService └── target │ └── generated-sources │ └── kapt │ └── test │ └── org │ └── litote │ └── kmongo │ ├── issue │ ├── EmployeeAggregate1_.kt │ ├── Issue130ParentGeneric_.kt │ └── RecordCollectionImpl1_.kt │ └── model │ ├── InternalDataClass_.kt │ ├── InternalDataClass_Deserializer.kt │ ├── InternalDataClass_Serializer.kt │ ├── NotAnnotatedData_.kt │ ├── SimpleReferenced2Data_.kt │ ├── SimpleReferenced2Data_Deserializer.kt │ ├── SimpleReferenced2Data_Serializer.kt │ ├── SubData2_.kt │ ├── SubData_.kt │ ├── TestData_.kt │ ├── TestData_Deserializer.kt │ ├── TestData_Serializer.kt │ └── other │ └── SimpleReferencedData_.kt ├── kmongo-async-core-tests ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── reactivestreams │ ├── AggregateTest.kt │ ├── CommandTest.kt │ ├── CountTest.kt │ ├── DeleteTest.kt │ ├── DistinctTest.kt │ ├── FindOneAndModifyTest.kt │ ├── FindOneTest.kt │ ├── KMongoReactiveStreamsBaseTest.kt │ ├── ProjectionTest.kt │ ├── ReplaceTest.kt │ ├── UpdateTest.kt │ └── WatchTest.kt ├── kmongo-async-core ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── reactivestreams │ ├── MongoCollections.kt │ ├── MongoDatabases.kt │ └── Publishers.kt ├── kmongo-async-native └── pom.xml ├── kmongo-async-serialization └── pom.xml ├── kmongo-async-shared ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ └── org │ │ │ └── litote │ │ │ └── kmongo │ │ │ └── reactivestreams │ │ │ ├── DistinctPublishers.kt │ │ │ ├── FindPublishers.kt │ │ │ ├── KMongo.kt │ │ │ ├── MapReducePublishers.kt │ │ │ ├── MongoSharedCollections.kt │ │ │ ├── MongoSharedDatabases.kt │ │ │ └── service │ │ │ └── ReactiveStreamsMongoClientProviderService.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.litote.kmongo.service.MongoClientProviderService │ └── test │ ├── kotlin │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── MockedClassMappingType.kt │ │ └── reactivestreams │ │ └── MongoSharedDatabasesTest.kt │ └── resources │ └── META-INF │ └── services │ └── org.litote.kmongo.service.ClassMappingTypeService ├── kmongo-async └── pom.xml ├── kmongo-benchmark ├── README.md ├── common │ ├── pom.xml │ └── src │ │ └── main │ │ └── kotlin │ │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── Coordinate.kt │ │ ├── Friend.kt │ │ ├── FriendWithBuddies.kt │ │ ├── Gender.kt │ │ ├── KMongoBenchmark.kt │ │ └── util │ │ └── KMongoCodecBase.kt ├── data │ ├── Friend.json │ ├── FriendWithBuddies.json │ ├── FriendWithBuddiesAndCodec.json │ ├── FriendWithBuddiesData.json │ ├── jackson020618.json │ ├── jackson061219.json │ ├── jackson170119.json │ ├── native020618.json │ ├── native061219.json │ ├── native170119.json │ └── serialization061219.json ├── jackson │ ├── benchmark.sh │ ├── pom.xml │ └── src │ │ └── main │ │ └── kotlin │ │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── CodecRegistryBenchmark.kt │ │ └── FriendWithCustomDeserializer.kt ├── native │ ├── benchmark.sh │ ├── pom.xml │ └── src │ │ └── main │ │ └── kotlin │ │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── CodecRegistryBenchmark.kt │ │ └── FriendWithCustomCodec.kt ├── pom.xml └── serialization │ ├── benchmark.sh │ ├── pom.xml │ └── src │ └── main │ └── kotlin │ └── SerializationCodecRegistryBenchmark.kt ├── kmongo-core-tests ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ ├── AggregateTest.kt │ ├── AggregateTypedTest.kt │ ├── AllCategoriesKMongoBaseTest.kt │ ├── BigDecimalTest.kt │ ├── BinaryTest.kt │ ├── BsonIdTest.kt │ ├── BsonIdTypedTest.kt │ ├── BulkWriteTest.kt │ ├── BulkWriteTypedTest.kt │ ├── ChangeStreamTest.kt │ ├── CommandTest.kt │ ├── CountTest.kt │ ├── CountTypedTest.kt │ ├── DateTest.kt │ ├── DeleteTest.kt │ ├── DeleteTypedTest.kt │ ├── DistinctTest.kt │ ├── DistinctTypedTest.kt │ ├── FindOneAndModifyTest.kt │ ├── FindOneAndModifyTypedTest.kt │ ├── FindOneTest.kt │ ├── FindOneTypedTest.kt │ ├── IdTest.kt │ ├── IndexTest.kt │ ├── JsonExtensionTest.kt │ ├── KMongoBaseTest.kt │ ├── KTXDateTest.kt │ ├── KotlinClassesTest.kt │ ├── MapReduceTest.kt │ ├── PersistingNotNullTest.kt │ ├── ProjectionTest.kt │ ├── ReplaceTest.kt │ ├── ReplaceTypedTest.kt │ ├── SaveTest.kt │ ├── TimestampTest.kt │ ├── TypedOperationsTest.kt │ ├── UpdateTest.kt │ ├── UpdateTypedTest.kt │ ├── UpdateWithoutNullPropertiesTest.kt │ ├── UsageTest.kt │ ├── UsageTypedTest.kt │ ├── issues │ ├── Issue102ErrorWithNewProjectionSystem.kt │ ├── Issue103CantSerializeStringId.kt │ ├── Issue108ProjectionError.kt │ ├── Issue111MongoPoint.kt │ ├── Issue11BsonSerializerCanOnlyBeUsedWithBsonGenerator.kt │ ├── Issue128BsonIdNotRecognized.kt │ ├── Issue12EqToLocaleQueryCrash.kt │ ├── Issue157FilterForEnumValueFails.kt │ ├── Issue15SavingListOfBdRefNotWorkingCorrectly.kt │ ├── Issue16GetIdPropertyAndMap.kt │ ├── Issue18SavingDBRefContainingAnObjectIdBreaks.kt │ ├── Issue191PatternRegexpIssue.kt │ ├── Issue195BsonInvalidIdException.kt │ ├── Issue196SerializationOfMapWithEnumKeysFails.kt │ ├── Issue19updateOneByIdUpdateParameterInconsistent.kt │ ├── Issue1ExceptionWhenGeneratin_IdOfPrivateClass.kt │ ├── Issue20NeedAWayToBypassDocumentValidationOnSave.kt │ ├── Issue21SupportTransientToNotBeSaved.kt │ ├── Issue232FloatSerialization.kt │ ├── Issue245UuidRepresentation.kt │ ├── Issue254PathCaching.kt │ ├── Issue255LookupWithNestedObjects.kt │ ├── Issue257BsonFieldNotSerialized.kt │ ├── Issue258UpdateListOfReferences.kt │ ├── Issue272FindOneAndUpdate.kt │ ├── Issue30DBObjectInsertException.kt │ ├── Issue314ValueClass.kt │ ├── Issue34FindOneAndUpdateOrReplaceOrDeleteCouldReturnNull.kt │ ├── Issue383FilterId.kt │ ├── Issue384BehaviourEvaluate.kt │ ├── Issue3CrashOnEnumPropertyInAnnotationIntrospector.kt │ ├── Issue409RegexpOption.kt │ ├── Issue48UpdateOperatorInMap.kt │ ├── Issue49ShouldNotFilterInnerObjectIdOnUpdate.kt │ ├── Issue4FilterIdToExtendedJsonThrowKotlinException.kt │ ├── Issue70FailToAccessTheLastFieldInADataClass.kt │ ├── Issue94InconsistentIdGeneration.kt │ ├── Issue95NullDeserializedTo0.kt │ └── Issue96SetOfObjectIds.kt │ ├── other │ └── MongoIterableTest.kt │ └── session │ ├── AggregateWithSessionTest.kt │ ├── BulkWriteWithSessionTest.kt │ ├── ChangeStreamWithSessionTest.kt │ ├── CommandWithSessionTest.kt │ ├── CountWithSessionTest.kt │ ├── DeleteWithSessionTest.kt │ ├── FindOneAndModifyWithSessionTest.kt │ ├── ProjectionWithSessionTest.kt │ ├── ReplaceWithSessionTest.kt │ ├── SaveWithSessionTest.kt │ └── UpdateWithSessionTest.kt ├── kmongo-core ├── pom.xml └── src │ └── main │ ├── kotlin │ ├── kotlin │ │ ├── collections │ │ │ └── KMongoIterable.kt │ │ └── internal │ │ │ └── Annotations.kt │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── ChangeStreamIterables.kt │ │ ├── DistinctIterables.kt │ │ ├── FindIterables.kt │ │ ├── KMongo.kt │ │ ├── MapReduceIterables.kt │ │ ├── MongoCollections.kt │ │ ├── MongoCollectionsWithClientSession.kt │ │ ├── MongoDatabases.kt │ │ ├── MongoDatabasesWithClientSession.kt │ │ ├── MongoIterables.kt │ │ ├── SyncProperties.kt │ │ └── service │ │ └── SyncMongoClientProviderService.kt │ └── resources │ └── META-INF │ └── services │ └── org.litote.kmongo.service.MongoClientProviderService ├── kmongo-coroutine-core-tests ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── coroutine │ ├── CoroutineAggregatePublisherTest.kt │ ├── CoroutineDistinctPublisherTest.kt │ ├── CoroutineFindPublisherTest.kt │ ├── CoroutineListCollectionsPublisherTest.kt │ ├── CoroutineListIndexesPublisherTest.kt │ ├── CoroutineMapReducePublisherTest.kt │ ├── CoroutinePublisherTest.kt │ ├── CouroutineChangeStreamPublisherTest.kt │ ├── KMongoCoroutineBaseTest.kt │ ├── KMongoReactiveStreamsCoroutineBaseTest.kt │ ├── ReactiveStreamProjectionTest.kt │ ├── ReactiveStreamSaveTest.kt │ ├── ReactiveStreamsAggregateTest.kt │ ├── ReactiveStreamsBinaryTest.kt │ ├── ReactiveStreamsBulkWriteTest.kt │ ├── ReactiveStreamsCommandTest.kt │ ├── ReactiveStreamsCountTest.kt │ ├── ReactiveStreamsDeleteTest.kt │ ├── ReactiveStreamsDistinctTest.kt │ ├── ReactiveStreamsFindOneAndModifyTest.kt │ ├── ReactiveStreamsFindOneTest.kt │ ├── ReactiveStreamsIndexTest.kt │ ├── ReactiveStreamsInsertTest.kt │ ├── ReactiveStreamsReplaceTest.kt │ ├── ReactiveStreamsUpdateTest.kt │ ├── TestPublishers.kt │ └── issues │ ├── Issue118DeserializeNotConstructorParams.kt │ ├── Issue182CustomCodec.kt │ ├── Issue198NoValueReceivedViaOnNext.kt │ ├── Issue34FindOneAndUpdateOrReplaceOrDeleteCouldReturnNull.kt │ ├── Issue390SetToWithEnumSerialName.kt │ └── Issue69NullOrEmptyBsonDeleteManyCrash.kt ├── kmongo-coroutine-core ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── coroutine │ ├── CoroutineAggregatePublisher.kt │ ├── CoroutineChangeStreamPublisher.kt │ ├── CoroutineClient.kt │ ├── CoroutineClientSessions.kt │ ├── CoroutineCollection.kt │ ├── CoroutineDatabase.kt │ ├── CoroutineDistinctPublisher.kt │ ├── CoroutineFindPublisher.kt │ ├── CoroutineListCollectionsPublisher.kt │ ├── CoroutineListIndexesPublisher.kt │ ├── CoroutineMapReducePublisher.kt │ ├── CoroutinePublisher.kt │ └── Coroutines.kt ├── kmongo-coroutine-native └── pom.xml ├── kmongo-coroutine-serialization ├── pom.xml └── src │ └── test │ └── kotlin │ ├── Issue228WrappedObjectId.kt │ ├── Issue247SealedClassInsertMany.kt │ ├── Issue248ContainerWithSimplePolymorphism.kt │ ├── Issue248PolymorphismWithInstant.kt │ └── Issue248SimplePolymorphism.kt ├── kmongo-coroutine └── pom.xml ├── kmongo-coverage └── pom.xml ├── kmongo-data ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ ├── Data.kt │ └── DataRegistry.kt ├── kmongo-dokka └── pom.xml ├── kmongo-flapdoodle ├── pom.xml └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── EmbeddedMongo.kt │ │ ├── EmbeddedMongoLog.kt │ │ ├── KFlapdoodle.kt │ │ ├── KFlapdoodleConfiguration.kt │ │ ├── KFlapdoodleRule.kt │ │ ├── ReplicaSetEmbeddedMongo.kt │ │ ├── StandaloneEmbeddedMongo.kt │ │ ├── coroutine │ │ └── CoroutineFlapdoodleRule.kt │ │ ├── reactivestreams │ │ ├── KFlapdoodleReactiveStreams.kt │ │ ├── KFlapdoodleReactiveStreamsConfiguration.kt │ │ ├── ReactiveStreamsFlapdoodleRule.kt │ │ ├── ReactiveStreamsTestContext.kt │ │ └── SimpleSubscriber.kt │ │ ├── reactor │ │ └── ReactorFlapdoodleRule.kt │ │ └── rxjava2 │ │ └── RxFlapdoodleRule.kt │ └── test │ ├── kotlin │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── KFlapdoodleRuleTest.kt │ │ ├── StandaloneEmbeddedMongoTest.kt │ │ └── service │ │ └── SyncMongoClientProviderService.kt │ └── resources │ └── META-INF │ └── services │ └── org.litote.kmongo.service.MongoClientProviderService ├── kmongo-id-jackson ├── pom.xml └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── litote │ │ └── kmongo │ │ └── id │ │ └── jackson │ │ ├── IdJacksonModule.kt │ │ ├── IdKeyDeserializer.kt │ │ ├── IdKeySerializer.kt │ │ ├── IdToStringSerializer.kt │ │ └── StringToIdDeserializer.kt │ └── test │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── id │ └── jackson │ └── IdJsonTest.kt ├── kmongo-id-serialization ├── pom.xml └── src │ ├── main │ └── kotlin │ │ └── IdModule.kt │ └── test │ └── kotlin │ └── IdModuleTest.kt ├── kmongo-id ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ └── org │ │ │ └── litote │ │ │ └── kmongo │ │ │ ├── Id.kt │ │ │ ├── id │ │ │ ├── IdGenerator.kt │ │ │ ├── IdGeneratorProvider.kt │ │ │ ├── StringId.kt │ │ │ ├── UUIDStringIdGenerator.kt │ │ │ └── UUIDStringIdGeneratorProvider.kt │ │ │ └── ids.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.litote.kmongo.id.IdGeneratorProvider │ └── test │ └── kotlin │ └── IdTest.kt ├── kmongo-jackson-mapping ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ └── org │ │ │ └── litote │ │ │ └── kmongo │ │ │ ├── jackson │ │ │ ├── BsonModule.kt │ │ │ ├── ExtendedJsonModule.kt │ │ │ ├── FilterIdModule.kt │ │ │ ├── JacksonClassMappingTypeService.kt │ │ │ ├── JacksonCodec.kt │ │ │ ├── JacksonCodecProvider.kt │ │ │ ├── KMongoAnnotationIntrospector.kt │ │ │ ├── KMongoBsonFactory.kt │ │ │ ├── ObjectMapperFactory.kt │ │ │ └── StringDeserializationProblemHandler.kt │ │ │ └── util │ │ │ ├── KMongoConfiguration.kt │ │ │ └── MongoIdUtil.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.litote.kmongo.service.ClassMappingTypeService │ └── test │ ├── kotlin │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── jackson │ │ ├── Issue147OtherTypeSupportForBigDecimal.kt │ │ ├── JacksonClassMappingTypeServiceTest.kt │ │ ├── ObjectMapperFactoryTest.kt │ │ └── UUIDTest.kt │ │ └── util │ │ ├── JacksonModuleServiceLoaderTest.kt │ │ ├── KMongoConfigurationTest.kt │ │ ├── KMongoJacksonFeatureTest.kt │ │ └── MongoIdUtilTest.kt │ └── resources │ └── META-INF │ └── services │ └── org.litote.jackson.JacksonModuleServiceLoader ├── kmongo-kdoc ├── docs │ ├── about.md │ ├── assets │ │ └── images │ │ │ ├── benchmark1.png │ │ │ ├── benchmark2.png │ │ │ ├── benchmark3.png │ │ │ ├── benchmark4.png │ │ │ ├── favicon.ico │ │ │ ├── favicon.png │ │ │ └── kmongo.png │ ├── extensions-overview.md │ ├── index.md │ ├── mongo-shell-support.md │ ├── object-mapping.md │ ├── performance.md │ ├── quick-start.md │ └── typed-queries.md └── mkdocs.yml ├── kmongo-native-mapping ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ └── org │ │ │ ├── bson │ │ │ └── codecs │ │ │ │ └── pojo │ │ │ │ ├── ClassModelBuilder2.java │ │ │ │ ├── Convention2.java │ │ │ │ ├── ConventionAnnotationImpl2.java │ │ │ │ ├── ConventionDefaultsImpl2.java │ │ │ │ ├── EmptyObjectConvention.kt │ │ │ │ ├── EnumCodec.kt │ │ │ │ ├── JavaTimeCodecProvider.kt │ │ │ │ ├── KMongoAnnotationConvention.kt │ │ │ │ ├── KMongoConvention.kt │ │ │ │ ├── KMongoPojoCodec.kt │ │ │ │ ├── KMongoPojoCodecProvider.kt │ │ │ │ ├── KMongoPojoCodecService.kt │ │ │ │ ├── KeyObjectMapPropertyCodecProvider.kt │ │ │ │ ├── KotlinInstanceCreator.kt │ │ │ │ ├── KotlinInstanceCreatorFactory.kt │ │ │ │ ├── MissingKotlinParameterException.kt │ │ │ │ ├── PairPropertyCodecProvider.kt │ │ │ │ ├── PojoBuilderHelper2.java │ │ │ │ ├── PojoCodecProvider2.java │ │ │ │ ├── PropertyReflectionUtils2.java │ │ │ │ ├── TriplePropertyCodecProvider.kt │ │ │ │ └── UtilClassesCodecProvider.kt │ │ │ └── litote │ │ │ └── kmongo │ │ │ └── pojo │ │ │ └── PojoClassMappingTypeService.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.litote.kmongo.service.ClassMappingTypeService │ └── test │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── pojo │ └── PojoClassMappingTypeServiceTest.kt ├── kmongo-native ├── pom.xml └── src │ └── test │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── PojoAnnotationsTest.kt ├── kmongo-property ├── pom.xml └── src │ ├── main │ └── kotlin │ │ ├── kotlin │ │ └── internal │ │ │ └── Annotations.kt │ │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── Accumulators.kt │ │ ├── Aggregates.kt │ │ ├── Documents.kt │ │ ├── Filters.kt │ │ ├── Indexes.kt │ │ ├── Projections.kt │ │ ├── Properties.kt │ │ ├── SetTo.kt │ │ ├── Sorts.kt │ │ ├── UnsignedUpdates.kt │ │ ├── Updates.kt │ │ └── property │ │ └── KPropertyPath.kt │ └── test │ ├── kotlin │ └── org │ │ └── litote │ │ └── kmongo │ │ ├── AggregatesTest.kt │ │ ├── FiltersTest.kt │ │ ├── MockedClassMappingTypeService.kt │ │ ├── ProjectionTest.kt │ │ ├── Tests.kt │ │ ├── UnsignedUpdatesTest.kt │ │ ├── UpdatesTest.kt │ │ ├── issue │ │ └── Issue276SubclassTypedQueryTest.kt │ │ └── property │ │ └── KPropertyPathTest.kt │ └── resources │ └── META-INF │ └── services │ └── org.litote.kmongo.service.ClassMappingTypeService ├── kmongo-reactor-core-tests ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── reactor │ ├── AggregateTest.kt │ ├── BinaryTest.kt │ ├── CommandTest.kt │ ├── CountTest.kt │ ├── DeleteTest.kt │ ├── DistinctTest.kt │ ├── FindOneAndModifyTest.kt │ ├── FindOneTest.kt │ ├── InsertTest.kt │ ├── KMongoReactiveStreamsReactorBaseTest.kt │ ├── KMongoReactorBaseTest.kt │ ├── ReactiveStreamsAggregateTest.kt │ ├── ReactiveStreamsBinaryTest.kt │ ├── ReactiveStreamsCommandTest.kt │ ├── ReactiveStreamsCountTest.kt │ ├── ReactiveStreamsDeleteTest.kt │ ├── ReactiveStreamsDistinctTest.kt │ ├── ReactiveStreamsFindOneAndModifyTest.kt │ ├── ReactiveStreamsFindOneTest.kt │ ├── ReactiveStreamsReplaceTest.kt │ ├── ReactiveStreamsUpdateTest.kt │ ├── ReplaceTest.kt │ └── UpdateTest.kt ├── kmongo-reactor-core ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── reactor │ ├── Publishers.kt │ ├── ReactiveStreamsMongoCollections.kt │ ├── ReactiveStreamsMongoDatabases.kt │ ├── ReactorMongoCollections.kt │ ├── ReactorMongoDatabases.kt │ └── Reactors.kt ├── kmongo-reactor-native └── pom.xml ├── kmongo-reactor-serialization └── pom.xml ├── kmongo-reactor └── pom.xml ├── kmongo-rxjava2-core-tests ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── rxjava2 │ ├── AggregateTest.kt │ ├── BinaryTest.kt │ ├── CommandTest.kt │ ├── CountTest.kt │ ├── DeleteTest.kt │ ├── DistinctTest.kt │ ├── FindOneAndModifyTest.kt │ ├── FindOneTest.kt │ ├── KMongoReactiveStreamsRxBaseTest.kt │ ├── KMongoRxBaseTest.kt │ ├── ReactiveStreamsAggregateTest.kt │ ├── ReactiveStreamsBinaryTest.kt │ ├── ReactiveStreamsCommandTest.kt │ ├── ReactiveStreamsCountTest.kt │ ├── ReactiveStreamsDeleteTest.kt │ ├── ReactiveStreamsDistinctTest.kt │ ├── ReactiveStreamsFindOneAndModifyTest.kt │ ├── ReactiveStreamsFindOneTest.kt │ ├── ReactiveStreamsReplaceTest.kt │ ├── ReactiveStreamsUpdateTest.kt │ ├── ReplaceTest.kt │ └── UpdateTest.kt ├── kmongo-rxjava2-core ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ └── rxjava2 │ ├── Publishers.kt │ ├── ReactiveStreamsMongoCollections.kt │ ├── ReactiveStreamsMongoDatabases.kt │ └── RxJavas.kt ├── kmongo-rxjava2-native └── pom.xml ├── kmongo-rxjava2-serialization └── pom.xml ├── kmongo-rxjava2 └── pom.xml ├── kmongo-serialization-mapping ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ ├── IdController.kt │ │ ├── KMongoSerializationRepository.kt │ │ ├── Properties.kt │ │ ├── SerializationClassMappingTypeService.kt │ │ ├── SerializationCodec.kt │ │ ├── SerializationCodecRegistry.kt │ │ └── Serializers.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.litote.kmongo.service.ClassMappingTypeService │ └── test │ └── kotlin │ ├── ExternalSerializerTest.kt │ ├── SerializationClassMappingTypeServiceTest.kt │ ├── SerializationCodecTest.kt │ └── TemporalSerializerTest.kt ├── kmongo-serialization ├── pom.xml └── src │ └── test │ └── kotlin │ ├── Issue167TransientNotWorking.kt │ ├── Issue218ModuleId.kt │ ├── Issue229SealedClass.kt │ ├── Issue237CustomSerializer.kt │ ├── Issue247SealedClassInsertMany.kt │ ├── Issue248PolymorphismWithInstant.kt │ ├── Issue250SaveCreatesAnOtherCopy.kt │ ├── Issue268ObjectIdNotProperlyDeserialized.kt │ ├── Issue281Projection.kt │ ├── Issue287UUID.kt │ ├── Issue307MaximumSerializationDepth.kt │ ├── Issue310SealedInterfaceSerializer.kt │ ├── Issue328FieldIdQueryFilterSerialization.kt │ ├── Issue331EnumSerialName.kt │ ├── Issue343SetToWithEnumSerialName.kt │ ├── Issue354KotlinIdFieldIgnored.kt │ ├── Issue365UUIDSerializer.kt │ ├── Issue415SerialName.kt │ └── ObjectInPolymorphicNotWorking.kt ├── kmongo-shared-tests-java ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── litote │ └── kmongo │ └── issues │ ├── AbstractWithObjectId.java │ └── Foo.java ├── kmongo-shared-tests ├── pom.xml └── src │ └── main │ └── kotlin │ └── org │ └── litote │ └── kmongo │ ├── CoreCategory.kt │ ├── JacksonMappingCategory.kt │ ├── KMongoRootTest.kt │ ├── NativeMappingCategory.kt │ ├── SerializationMappingCategory.kt │ └── model │ ├── Coordinate.kt │ ├── ExposableFriend.kt │ ├── Friend.kt │ └── FriendContainer.kt ├── kmongo-shared ├── pom.xml └── src │ ├── main │ ├── kotlin │ │ └── org │ │ │ └── litote │ │ │ └── kmongo │ │ │ ├── MongoOperator.kt │ │ │ ├── MongoUtil.kt │ │ │ ├── SharedExtensions.kt │ │ │ ├── id │ │ │ ├── IdTransformer.kt │ │ │ ├── Ids.kt │ │ │ ├── MongoId.kt │ │ │ ├── MongoProperty.kt │ │ │ ├── ObjectIdGenerator.kt │ │ │ ├── ObjectIdGeneratorProvider.kt │ │ │ ├── ObjectIdToStringGenerator.kt │ │ │ └── WrappedObjectId.kt │ │ │ ├── service │ │ │ ├── ClassMappingType.kt │ │ │ ├── ClassMappingTypeService.kt │ │ │ ├── MongoClientProvider.kt │ │ │ └── MongoClientProviderService.kt │ │ │ └── util │ │ │ ├── CollectionNameFormatter.kt │ │ │ ├── KMongoUtil.kt │ │ │ ├── KotlinxDatetimeLoader.kt │ │ │ ├── ObjectMappingConfiguration.kt │ │ │ ├── PatternUtil.kt │ │ │ ├── SimpleExpression.kt │ │ │ ├── SimpleProjections.kt │ │ │ └── UpdateConfiguration.kt │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.litote.kmongo.id.IdGeneratorProvider │ └── test │ └── kotlin │ └── org │ └── litote │ └── kmongo │ ├── MongoOperatorTest.kt │ ├── service │ └── ClassMappingTypeServiceTest.kt │ └── util │ ├── CollectionNameFormatterTest.kt │ └── KMongoUtilTest.kt ├── kmongo ├── pom.xml └── src │ └── test │ └── kotlin │ └── org │ └── litote │ └── kmongo │ ├── MappingTest.kt │ ├── NullPropertyTest.kt │ └── issues │ ├── Issue135JsonIdentityInfo.kt │ ├── Issue136WriteObjectRef.kt │ ├── Issue247SealedClassInsertMany.kt │ ├── Issue268ObjectIdNotProperlyDeserialized.kt │ ├── Issue2IdNotGeneratedForSubclass.kt │ ├── Issue316ReplaceNotNull.kt │ ├── Issue35DateStoredAsTimestamp.kt │ ├── Issue371CustomEnum.kt │ ├── Issue374IsClosed.kt │ ├── Issue51ObjectNodeClassSerializedInArray.kt │ ├── Issue58PropertyIdHasDifferentDatatype.kt │ ├── Issue73BisIdNotDeserializedWhenUsingInterfaceAsCollectionClass.kt │ ├── Issue73IdNotDeserializedWhenUsingInterfaceAsCollectionClass.kt │ ├── Issue84EmbeddedDateWithInheritanceDeserializationFail.kt │ ├── Issue85ObjectIdIsNotProperlyDeserializedInAStringPropertyWhenPropertyIsInherited.kt │ └── TypedTest.kt ├── mvnw ├── mvnw.cmd └── pom.xml /.codebeatignore: -------------------------------------------------------------------------------- 1 | kmongo-core-tests/** 2 | kmongo-async-core-tests/** 3 | kmongo-coroutine-core-tests/** 4 | kmongo-rxjava2-core-tests/** 5 | kmongo-reactor-core-tests/** 6 | kmongo-shared-tests/** 7 | kmongo-benchmark/** 8 | kmongo-coverage/** 9 | kmongo-dokka/** 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | **/target/* 3 | !**/target/generated-sources 4 | *.iml 5 | kmongo-kdoc/site 6 | .gradle 7 | 8 | ############################## 9 | ## Maven 10 | ############################## 11 | pom.xml.tag 12 | pom.xml.releaseBackup 13 | pom.xml.versionsBackup 14 | pom.xml.next 15 | pom.xml.bak 16 | release.properties 17 | dependency-reduced-pom.xml 18 | buildNumber.properties 19 | .mvn/timing.properties 20 | .mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: ~> 1.0 3 | language: java 4 | dist: focal 5 | jdk: 6 | - openjdk18 7 | branches: 8 | only: 9 | - master 10 | script: 11 | - mvn verify -B -P \!dev,build 12 | cache: 13 | directories: 14 | - $HOME/.m2/repository 15 | after_success: 16 | - bash <(curl -s https://codecov.io/bash) -X fix 17 | install: true -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.KMongoAnnotationProcessor -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/InternalTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.junit.Test 20 | import org.litote.kmongo.model.InternalDataClass_ 21 | import kotlin.reflect.KVisibility 22 | import kotlin.test.assertEquals 23 | 24 | /** 25 | * 26 | */ 27 | class InternalTest { 28 | 29 | @Test 30 | fun checkInternal() { 31 | assertEquals(KVisibility.INTERNAL, InternalDataClass_::class.visibility) 32 | } 33 | } -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/issue/Issue130ParentGeneric.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issue 18 | 19 | import org.litote.kmongo.Data 20 | import java.io.Serializable 21 | 22 | interface IdentifiableOf { 23 | val _id: T 24 | } 25 | 26 | /** 27 | * 28 | */ 29 | @Data 30 | abstract class Issue130ParentGeneric() : IdentifiableOf { 31 | } -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/model/AnnotatedFileSample.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | //annotation not detected by processor 18 | @file:DataRegistry([SubData2::class, TestData::class]) 19 | 20 | package org.litote.kmongo.model 21 | 22 | import org.litote.kmongo.DataRegistry 23 | 24 | @DataRegistry([SubData2::class, TestData::class]) 25 | object Registry 26 | 27 | -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/model/InternalDataClass.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | import org.litote.kmongo.Data 20 | import org.litote.jackson.data.JacksonData 21 | 22 | /** 23 | * 24 | */ 25 | @Data(internal = true) 26 | @JacksonData(internal = true) 27 | class InternalDataClass(val l:Long) { 28 | } -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/model/NotAnnotatedData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | /** 20 | * 21 | */ 22 | open class NotAnnotatedData { 23 | 24 | var test: String? = null 25 | } -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/model/SimpleReferenced2Data.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | import org.litote.kmongo.Data 20 | import org.litote.jackson.data.JacksonData 21 | 22 | /** 23 | * 24 | */ 25 | @Data 26 | @JacksonData 27 | data class SimpleReferenced2Data(val price: Double = 0.0) { 28 | } -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/model/SubData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | import org.litote.kmongo.Data 20 | 21 | /** 22 | * 23 | */ 24 | @Data 25 | class SubData : TestData() { 26 | 27 | private val s: String? = null 28 | } -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/kotlin/org/litote/kmongo/model/SubData2.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | import org.litote.jackson.data.JacksonData 20 | 21 | /** 22 | * 23 | */ 24 | @JacksonData 25 | data class SubData2(val a1: Int = 0) : NotAnnotatedData() -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.jackson.generator.KJacksonGeneratorProcessor -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/resources/META-INF/services/org.litote.jackson.JacksonModuleServiceLoader: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.model.InternalDataClass_Serializer 18 | org.litote.kmongo.model.InternalDataClass_Deserializer 19 | org.litote.kmongo.model.TestData_Serializer 20 | org.litote.kmongo.model.TestData_Deserializer 21 | org.litote.kmongo.model.SimpleReferenced2Data_Serializer 22 | org.litote.kmongo.model.SimpleReferenced2Data_Deserializer -------------------------------------------------------------------------------- /kmongo-annotation-processor/src/test/resources/META-INF/services/org.litote.kmongo.service.ClassMappingTypeService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.MockedClassMappingTypeService -------------------------------------------------------------------------------- /kmongo-annotation-processor/target/generated-sources/kapt/test/org/litote/kmongo/issue/Issue130ParentGeneric_.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.issue 2 | 3 | import kotlin.String 4 | import kotlin.Suppress 5 | import kotlin.collections.Collection 6 | import kotlin.collections.Map 7 | import kotlin.reflect.KProperty1 8 | import org.litote.kmongo.property.KCollectionPropertyPath 9 | import org.litote.kmongo.property.KMapPropertyPath 10 | import org.litote.kmongo.property.KPropertyPath 11 | 12 | open class Issue130ParentGeneric_(previous: KPropertyPath?, property: KProperty1<*, 13 | Issue130ParentGeneric<*>?>) : KPropertyPath?>(previous,property) 14 | { 15 | companion object 16 | } 17 | 18 | open class Issue130ParentGeneric_Col(previous: KPropertyPath?, property: KProperty1<*, 19 | Collection>?>) : KCollectionPropertyPath?, Issue130ParentGeneric_>(previous,property) { 21 | @Suppress("UNCHECKED_CAST") 22 | override fun memberWithAdditionalPath(additionalPath: String): Issue130ParentGeneric_ = 23 | Issue130ParentGeneric_(this, customProperty(this, additionalPath))} 24 | 25 | open class Issue130ParentGeneric_Map(previous: KPropertyPath?, property: KProperty1<*, 26 | Map>?>) : KMapPropertyPath?, 27 | Issue130ParentGeneric_>(previous,property) { 28 | @Suppress("UNCHECKED_CAST") 29 | override fun memberWithAdditionalPath(additionalPath: String): Issue130ParentGeneric_ = 30 | Issue130ParentGeneric_(this, customProperty(this, additionalPath))} 31 | -------------------------------------------------------------------------------- /kmongo-annotation-processor/target/generated-sources/kapt/test/org/litote/kmongo/model/InternalDataClass_Serializer.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.model 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator 4 | import com.fasterxml.jackson.databind.SerializerProvider 5 | import com.fasterxml.jackson.databind.module.SimpleModule 6 | import com.fasterxml.jackson.databind.ser.std.StdSerializer 7 | import org.litote.jackson.JacksonModuleServiceLoader 8 | 9 | internal class InternalDataClass_Serializer : 10 | StdSerializer(InternalDataClass::class.java), JacksonModuleServiceLoader 11 | { 12 | override fun module() = SimpleModule().addSerializer(InternalDataClass::class.java, this) 13 | 14 | override fun serialize( 15 | value: InternalDataClass, 16 | gen: JsonGenerator, 17 | serializers: SerializerProvider 18 | ) { 19 | gen.writeStartObject() 20 | gen.writeFieldName("l") 21 | val _l_ = value.l 22 | gen.writeNumber(_l_) 23 | gen.writeEndObject() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /kmongo-annotation-processor/target/generated-sources/kapt/test/org/litote/kmongo/model/SimpleReferenced2Data_Serializer.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.model 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator 4 | import com.fasterxml.jackson.databind.SerializerProvider 5 | import com.fasterxml.jackson.databind.module.SimpleModule 6 | import com.fasterxml.jackson.databind.ser.std.StdSerializer 7 | import org.litote.jackson.JacksonModuleServiceLoader 8 | 9 | internal class SimpleReferenced2Data_Serializer : 10 | StdSerializer(SimpleReferenced2Data::class.java), 11 | JacksonModuleServiceLoader { 12 | override fun module() = SimpleModule().addSerializer(SimpleReferenced2Data::class.java, this) 13 | 14 | override fun serialize( 15 | value: SimpleReferenced2Data, 16 | gen: JsonGenerator, 17 | serializers: SerializerProvider 18 | ) { 19 | gen.writeStartObject() 20 | gen.writeFieldName("price") 21 | val _price_ = value.price 22 | gen.writeNumber(_price_) 23 | gen.writeEndObject() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /kmongo-annotation-processor/target/generated-sources/kapt/test/org/litote/kmongo/model/SubData2_.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.model 2 | 3 | import kotlin.Int 4 | import kotlin.String 5 | import kotlin.Suppress 6 | import kotlin.collections.Collection 7 | import kotlin.collections.Map 8 | import kotlin.reflect.KProperty1 9 | import org.litote.kmongo.property.KPropertyPath 10 | 11 | private val __A1: KProperty1 12 | get() = SubData2::a1 13 | class SubData2_(previous: KPropertyPath?, property: KProperty1<*, SubData2?>) : 14 | NotAnnotatedData_(previous,property) { 15 | val a1: KPropertyPath 16 | get() = KPropertyPath(this,__A1) 17 | 18 | companion object { 19 | val A1: KProperty1 20 | get() = __A1} 21 | } 22 | 23 | class SubData2_Col(previous: KPropertyPath?, property: KProperty1<*, 24 | Collection?>) : NotAnnotatedData_Col(previous,property) { 25 | val a1: KPropertyPath 26 | get() = KPropertyPath(this,__A1) 27 | 28 | @Suppress("UNCHECKED_CAST") 29 | override fun memberWithAdditionalPath(additionalPath: String): SubData2_ = SubData2_(this, 30 | customProperty(this, additionalPath))} 31 | 32 | class SubData2_Map(previous: KPropertyPath?, property: KProperty1<*, Map?>) 33 | : NotAnnotatedData_Map(previous,property) { 34 | val a1: KPropertyPath 35 | get() = KPropertyPath(this,__A1) 36 | 37 | @Suppress("UNCHECKED_CAST") 38 | override fun memberWithAdditionalPath(additionalPath: String): SubData2_ = SubData2_(this, 39 | customProperty(this, additionalPath))} 40 | -------------------------------------------------------------------------------- /kmongo-annotation-processor/target/generated-sources/kapt/test/org/litote/kmongo/model/SubData_.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.model 2 | 3 | import kotlin.String 4 | import kotlin.Suppress 5 | import kotlin.collections.Collection 6 | import kotlin.collections.Map 7 | import kotlin.reflect.KProperty1 8 | import org.litote.kmongo.property.KPropertyPath 9 | 10 | private val __S: KProperty1 11 | get() = org.litote.kreflect.findProperty("s") 12 | class SubData_(previous: KPropertyPath?, property: KProperty1<*, SubData?>) : 13 | TestData_(previous,property) { 14 | val s: KPropertyPath 15 | get() = KPropertyPath(this,__S) 16 | 17 | companion object { 18 | val S: KProperty1 19 | get() = __S} 20 | } 21 | 22 | class SubData_Col(previous: KPropertyPath?, property: KProperty1<*, Collection?>) 23 | : TestData_Col(previous,property) { 24 | val s: KPropertyPath 25 | get() = KPropertyPath(this,__S) 26 | 27 | @Suppress("UNCHECKED_CAST") 28 | override fun memberWithAdditionalPath(additionalPath: String): SubData_ = SubData_(this, 29 | customProperty(this, additionalPath))} 30 | 31 | class SubData_Map(previous: KPropertyPath?, property: KProperty1<*, Map?>) : 32 | TestData_Map(previous,property) { 33 | val s: KPropertyPath 34 | get() = KPropertyPath(this,__S) 35 | 36 | @Suppress("UNCHECKED_CAST") 37 | override fun memberWithAdditionalPath(additionalPath: String): SubData_ = SubData_(this, 38 | customProperty(this, additionalPath))} 39 | -------------------------------------------------------------------------------- /kmongo-async-core-tests/src/main/kotlin/org/litote/kmongo/reactivestreams/CommandTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.reactivestreams 17 | 18 | import org.bson.Document 19 | import org.junit.Test 20 | import org.litote.kmongo.model.Friend 21 | import kotlin.test.assertEquals 22 | 23 | /** 24 | * 25 | */ 26 | class CommandTest : KMongoReactiveStreamsBaseTest() { 27 | 28 | @Test 29 | fun canRunACommand() { 30 | database.runCommand("{ ping: 1 }").forEach { r, _ -> 31 | asyncTest { 32 | assertEquals(1.0, r!!.get("ok")) 33 | } 34 | } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /kmongo-async-core-tests/src/main/kotlin/org/litote/kmongo/reactivestreams/DistinctTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import org.junit.Test 20 | import org.litote.kmongo.model.Friend 21 | import kotlin.test.assertEquals 22 | import kotlin.test.assertTrue 23 | 24 | /** 25 | * 26 | */ 27 | class DistinctTest : KMongoReactiveStreamsBaseTest() { 28 | 29 | val wallStreetAvenue = "22 Wall Street Avenue" 30 | 31 | @Test 32 | fun distinctOnStringEntities() { 33 | col.insertMany( 34 | listOf( 35 | Friend("John", wallStreetAvenue), 36 | Friend("Smith", wallStreetAvenue), 37 | Friend("Peter", "24 Wall Street Avenue") 38 | ) 39 | ).forEach { _, _ -> 40 | col.distinct("address").listenList { r, _ -> 41 | asyncTest { 42 | assertEquals(2, r!!.size) 43 | assertTrue(r.contains(wallStreetAvenue) && r.contains("24 Wall Street Avenue")) 44 | } 45 | } 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /kmongo-async-core-tests/src/main/kotlin/org/litote/kmongo/reactivestreams/FindOneAndModifyTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import org.junit.Test 20 | import org.litote.kmongo.MongoOperator.set 21 | import org.litote.kmongo.model.Friend 22 | import kotlin.test.assertEquals 23 | 24 | /** 25 | * 26 | */ 27 | class FindOneAndModifyTest : KMongoReactiveStreamsBaseTest() { 28 | 29 | @Test 30 | fun canFindAndUpdateOne() { 31 | col.insertOne(Friend("John", "22 Wall Street Avenue")).forEach { _, _ -> 32 | col.findOneAndUpdate("{name:'John'}", "{$set: {address: 'A better place'}}").forEach { _, _ -> 33 | col.findOne("{name:'John'}").forEach { friend, _ -> 34 | asyncTest { 35 | assertEquals("John", friend!!.name) 36 | assertEquals("A better place", friend.address) 37 | } 38 | } 39 | } 40 | } 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /kmongo-async-core-tests/src/main/kotlin/org/litote/kmongo/reactivestreams/FindOneTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.reactivestreams 17 | 18 | import com.mongodb.client.model.Filters 19 | import org.junit.Test 20 | import org.litote.kmongo.model.Friend 21 | import kotlin.test.assertEquals 22 | 23 | /** 24 | * 25 | */ 26 | class FindOneTest : KMongoReactiveStreamsBaseTest() { 27 | 28 | @Test 29 | fun canFindOne() { 30 | col.insertOne(Friend("John", "22 Wall Street Avenue")) 31 | .forEach { _, _ -> 32 | col.findOne("{name:'John'}").forEach { friend, _ -> 33 | asyncTest { assertEquals("John", friend!!.name) } 34 | } 35 | } 36 | } 37 | 38 | @Test 39 | fun canFindOneBson() { 40 | col.insertOne(Friend("John", "22 Wall Street Avenue")) 41 | .forEach { _, _ -> 42 | col.findOne(Filters.eq("name", "John")).forEach { friend, _ -> 43 | asyncTest { assertEquals("John", friend!!.name) } 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /kmongo-async-core/pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 4.0.0 19 | 20 | 21 | org.litote.kmongo 22 | kmongo-root 23 | 5.2.2-SNAPSHOT 24 | 25 | 26 | kmongo-async-core 27 | KMongo async core 28 | Mongo asynchronous client core extensions 29 | 30 | 31 | 32 | org.litote.kmongo 33 | kmongo-async-shared 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /kmongo-async-shared/src/main/kotlin/org/litote/kmongo/reactivestreams/DistinctPublishers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import com.mongodb.reactivestreams.client.DistinctPublisher 20 | import org.litote.kmongo.util.KMongoUtil 21 | 22 | /** 23 | * Sets the query filter to apply to the query. 24 | * 25 | * @param filter the filter, which may be null 26 | * @return this 27 | */ 28 | fun DistinctPublisher.filter(filter: String): DistinctPublisher = filter(KMongoUtil.toBson(filter)) 29 | -------------------------------------------------------------------------------- /kmongo-async-shared/src/main/kotlin/org/litote/kmongo/reactivestreams/service/ReactiveStreamsMongoClientProviderService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams.service 18 | 19 | import com.mongodb.ConnectionString 20 | import com.mongodb.reactivestreams.client.MongoClient 21 | import org.litote.kmongo.reactivestreams.KMongo 22 | import org.litote.kmongo.service.MongoClientProviderService 23 | 24 | internal class ReactiveStreamsMongoClientProviderService : MongoClientProviderService { 25 | 26 | override fun createMongoClient(connectionString: ConnectionString): MongoClient { 27 | return KMongo.createClient(connectionString) 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /kmongo-async-shared/src/main/resources/META-INF/services/org.litote.kmongo.service.MongoClientProviderService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.reactivestreams.service.ReactiveStreamsMongoClientProviderService -------------------------------------------------------------------------------- /kmongo-async-shared/src/test/kotlin/org/litote/kmongo/MockedClassMappingType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.nhaarman.mockitokotlin2.mock 20 | import org.bson.BsonDocument 21 | import org.bson.codecs.configuration.CodecRegistry 22 | import org.litote.kmongo.service.ClassMappingTypeService 23 | import kotlin.reflect.KClass 24 | import kotlin.reflect.KProperty 25 | import kotlin.reflect.KProperty1 26 | 27 | class MockedClassMappingTypeService : ClassMappingTypeService { 28 | 29 | override fun priority(): Int { 30 | return 1000 31 | } 32 | 33 | override fun filterIdToBson(obj: Any, filterNullProperties: Boolean): BsonDocument = error("not implemented") 34 | 35 | override fun toExtendedJson(obj: Any?): String = error("not implemented") 36 | 37 | override fun findIdProperty(type: KClass<*>): KProperty1<*, *>? = error("not implemented") 38 | 39 | override fun getIdValue(idProperty: KProperty1, instance: T): R? = error("not implemented") 40 | 41 | override fun coreCodecRegistry(baseCodecRegistry: CodecRegistry): CodecRegistry = mock() 42 | 43 | override fun calculatePath(property: KProperty): String = property.name 44 | } -------------------------------------------------------------------------------- /kmongo-async-shared/src/test/kotlin/org/litote/kmongo/reactivestreams/MongoSharedDatabasesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import com.mongodb.reactivestreams.client.MongoDatabase 20 | import com.nhaarman.mockitokotlin2.any 21 | import com.nhaarman.mockitokotlin2.doReturn 22 | import com.nhaarman.mockitokotlin2.mock 23 | import com.nhaarman.mockitokotlin2.spy 24 | import com.nhaarman.mockitokotlin2.verify 25 | import org.junit.Test 26 | 27 | /** 28 | * 29 | */ 30 | class MongoSharedDatabasesTest { 31 | 32 | @Test 33 | fun `withKMongo calls withCodecRegistry`() { 34 | val database: MongoDatabase = spy { 35 | on { codecRegistry } doReturn mock() 36 | on { withCodecRegistry(any()) } doReturn mock() 37 | } 38 | database.withKMongo() 39 | 40 | verify(database).withCodecRegistry(any()) 41 | } 42 | } -------------------------------------------------------------------------------- /kmongo-async-shared/src/test/resources/META-INF/services/org.litote.kmongo.service.ClassMappingTypeService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.MockedClassMappingTypeService -------------------------------------------------------------------------------- /kmongo-benchmark/README.md: -------------------------------------------------------------------------------- 1 | To run the benchmark 2 | 3 | ```bash 4 | mvn clean package 5 | java -jar jackson/target/benchmarks.jar -wi 1 -i 1 -f 1 6 | java -jar native/target/benchmarks.jar -wi 1 -i 1 -f 1 7 | java -jar serialization/target/benchmarks.jar -wi 1 -i 1 -f 1 8 | ``` 9 | 10 | Build graphs with: https://nilskp.github.io/jmh-charts/ 11 | -------------------------------------------------------------------------------- /kmongo-benchmark/common/src/main/kotlin/org/litote/kmongo/Coordinate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlinx.serialization.Serializable 20 | 21 | /** 22 | * 23 | */ 24 | @Serializable 25 | data class Coordinate(val lat:Int, val lng:Int) -------------------------------------------------------------------------------- /kmongo-benchmark/common/src/main/kotlin/org/litote/kmongo/Friend.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import org.bson.codecs.pojo.annotations.BsonId 23 | import org.bson.types.ObjectId 24 | import org.litote.kmongo.id.MongoId 25 | 26 | /** 27 | * 28 | */ 29 | @Serializable 30 | data class Friend( 31 | @Contextual 32 | @SerialName("_id") 33 | @BsonId 34 | val id: ObjectId? = null, 35 | val name: String? = null, 36 | val address: String? = null, 37 | val coordinate: Coordinate? = null, 38 | val gender: Gender? = null 39 | ) -------------------------------------------------------------------------------- /kmongo-benchmark/common/src/main/kotlin/org/litote/kmongo/FriendWithBuddies.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import org.bson.codecs.pojo.annotations.BsonId 23 | import org.bson.types.ObjectId 24 | import org.litote.kmongo.id.MongoId 25 | 26 | /** 27 | * 28 | */ 29 | @Serializable 30 | data class FriendWithBuddies( 31 | @Contextual 32 | @SerialName("_id") 33 | @BsonId 34 | val id: ObjectId? = null, 35 | val name: String? = null, 36 | val address: String? = null, 37 | val coordinate: Coordinate? = null, 38 | val gender: Gender? = null, 39 | val buddies: List = emptyList() 40 | ) -------------------------------------------------------------------------------- /kmongo-benchmark/common/src/main/kotlin/org/litote/kmongo/Gender.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * 21 | */ 22 | enum class Gender { 23 | FEMALE 24 | } -------------------------------------------------------------------------------- /kmongo-benchmark/jackson/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (C) 2016/2022 Litote 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | java -jar target/benchmarks.jar -rf json -rff jackson.json -wi 3 -f 1 -------------------------------------------------------------------------------- /kmongo-benchmark/native/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (C) 2016/2022 Litote 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | java -jar target/benchmarks.jar -rf json -rff native.json -wi 3 -f 1 -------------------------------------------------------------------------------- /kmongo-benchmark/serialization/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (C) 2016/2022 Litote 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | java -jar target/benchmarks.jar -rf json -rff serialization.json -wi 3 -f 1 -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/AllCategoriesKMongoBaseTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion 20 | import org.junit.experimental.categories.Category 21 | 22 | /** 23 | * 24 | */ 25 | @Category(JacksonMappingCategory::class, NativeMappingCategory::class, SerializationMappingCategory::class) 26 | open class AllCategoriesKMongoBaseTest(mongoServerVersion: IFeatureAwareVersion = defaultMongoTestVersion) : 27 | KMongoBaseTest(mongoServerVersion) -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/CountTypedTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.junit.Test 20 | import org.litote.kmongo.model.Friend 21 | import kotlin.test.assertEquals 22 | 23 | /** 24 | * 25 | */ 26 | class CountTypedTest : AllCategoriesKMongoBaseTest() { 27 | 28 | fun newFriend(): Friend { 29 | return Friend("John", "22 Wall Street Avenue") 30 | } 31 | 32 | @Test 33 | fun canCountWithQueryProperty() { 34 | col.insertMany(listOf(newFriend(), newFriend())) 35 | var c = col.countDocuments(Friend::name exists true) 36 | assertEquals(2, c) 37 | c = col.countDocuments(Friend::name.exists()) 38 | assertEquals(2, c) 39 | } 40 | 41 | @Test 42 | fun canCountWithParametersProperty() { 43 | col.insertMany(listOf(newFriend(), Friend("Peter", "22 Wall Street Avenue"))) 44 | val c = col.countDocuments(Friend::name eq "Peter") 45 | assertEquals(1, c) 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/DeleteTypedTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.bson.types.ObjectId 20 | import org.junit.Test 21 | import org.litote.kmongo.model.Friend 22 | import kotlin.test.assertEquals 23 | 24 | /** 25 | * 26 | */ 27 | class DeleteTypedTest : AllCategoriesKMongoBaseTest() { 28 | 29 | @Test 30 | fun canDeleteASpecificDocumentWithProperty() { 31 | col.insertMany(listOf(Friend("John"), Friend("Peter"))) 32 | col.deleteOne(Friend::name eq "John") 33 | val list = col.find().toList() 34 | assertEquals(1, list.size) 35 | assertEquals("Peter", list.first().name) 36 | } 37 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/KotlinClassesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.Serializable 21 | import org.junit.Test 22 | import org.litote.kmongo.KotlinClassesTest.KotlinClasses 23 | import java.util.Locale 24 | import kotlin.test.assertEquals 25 | 26 | /** 27 | * 28 | */ 29 | class KotlinClassesTest : AllCategoriesKMongoBaseTest() { 30 | 31 | @Serializable 32 | data class KotlinClasses(var pair: Pair, var triple: Triple) 33 | 34 | @Test 35 | fun savedAndLoad() { 36 | val c = KotlinClasses(Pair("a", 1), Triple("b", 1.0, Locale.ENGLISH)) 37 | col.save(c) 38 | assertEquals(c, col.findOne()) 39 | } 40 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/TimestampTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.Serializable 21 | import org.bson.BsonTimestamp 22 | import org.junit.Test 23 | import org.litote.kmongo.TimestampTest.TimestampValue 24 | import kotlin.test.assertEquals 25 | 26 | /** 27 | * 28 | */ 29 | class TimestampTest : AllCategoriesKMongoBaseTest() { 30 | 31 | @Serializable 32 | data class TimestampValue(@Contextual val date: BsonTimestamp?) 33 | 34 | @Test 35 | fun testInsertAndLoad() { 36 | val value = TimestampValue(BsonTimestamp(1, 1)) 37 | col.insertOne(value) 38 | val loaded = col.findOne() 39 | assertEquals(value, loaded) 40 | } 41 | 42 | @Test 43 | fun testNullInsertAndLoad() { 44 | val value = TimestampValue(null) 45 | col.insertOne(value) 46 | val loaded = col.findOne() 47 | assertEquals(value, loaded) 48 | } 49 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue108ProjectionError.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.Serializable 21 | import org.junit.Test 22 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 23 | import org.litote.kmongo.Id 24 | import org.litote.kmongo.eq 25 | import org.litote.kmongo.issues.Issue108ProjectionError.Data 26 | import org.litote.kmongo.newId 27 | import org.litote.kmongo.projection 28 | import kotlin.test.assertEquals 29 | 30 | /** 31 | * 32 | */ 33 | class Issue108ProjectionError : AllCategoriesKMongoBaseTest() { 34 | 35 | @Serializable 36 | data class Data(@Contextual val _id: Id = newId(), @Contextual val nation: Nation) 37 | @Serializable 38 | data class Nation(val name: String) 39 | 40 | @Test 41 | fun `deserializing is ok`() { 42 | val data = Data(nation = Nation("b")) 43 | col.insertOne(data) 44 | mongoClient.startSession().use { 45 | assertEquals(Nation("b"), col.projection(it, Data::nation, Data::_id eq data._id).first()) 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue111MongoPoint.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import com.mongodb.client.model.geojson.Point 20 | import com.mongodb.client.model.geojson.Position 21 | import org.junit.Test 22 | import org.junit.experimental.categories.Category 23 | import org.litote.kmongo.KMongoBaseTest 24 | import org.litote.kmongo.NativeMappingCategory 25 | import org.litote.kmongo.findOne 26 | import org.litote.kmongo.issues.Issue111MongoPoint.Data 27 | import kotlin.test.assertEquals 28 | 29 | /** 30 | * 31 | */ 32 | class Issue111MongoPoint : KMongoBaseTest() { 33 | 34 | data class Data(val location: Point) 35 | 36 | @Category(NativeMappingCategory::class) 37 | @Test 38 | fun `deserializing is ok`() { 39 | val data = Data(Point(Position(20.0, 20.0))) 40 | col.insertOne(data) 41 | assertEquals(data, col.findOne()) 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue12EqToLocaleQueryCrash.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import com.mongodb.client.model.Filters 20 | import kotlinx.serialization.Contextual 21 | import kotlinx.serialization.Serializable 22 | import org.junit.Test 23 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 24 | import org.litote.kmongo.eq 25 | import org.litote.kmongo.findOne 26 | import org.litote.kmongo.issues.Issue12EqToLocaleQueryCrash.ClassWithLocalField 27 | import java.util.Locale 28 | import kotlin.test.assertEquals 29 | 30 | /** 31 | * 32 | */ 33 | class Issue12EqToLocaleQueryCrash : AllCategoriesKMongoBaseTest() { 34 | 35 | @Serializable 36 | data class ClassWithLocalField(@Contextual val locale: Locale) 37 | 38 | @Test 39 | fun testSerializeAndDeserializeLocale() { 40 | val l = ClassWithLocalField(Locale.ENGLISH) 41 | col.insertOne(l) 42 | val l2 = col.findOne(Filters.eq("locale", Locale.ENGLISH)) 43 | assertEquals(l, l2) 44 | val l3 = col.findOne(l::locale eq Locale.ENGLISH) 45 | assertEquals(l, l3) 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue157FilterForEnumValueFails.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Serializable 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.eq 23 | import org.litote.kmongo.issues.Issue157FilterForEnumValueFails.Data 24 | import kotlin.test.assertEquals 25 | 26 | /** 27 | * 28 | */ 29 | class Issue157FilterForEnumValueFails : AllCategoriesKMongoBaseTest() { 30 | 31 | @Serializable 32 | enum class Status { ACTIVE, INACTIVE } 33 | 34 | @Serializable 35 | data class Data(val status: Status) 36 | 37 | @Test 38 | fun `querying with enum is ok`() { 39 | val data = Data(Status.ACTIVE) 40 | col.insertOne(data) 41 | val count = col.countDocuments(Data::status eq Status.ACTIVE) 42 | assertEquals(1, count) 43 | } 44 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue16GetIdPropertyAndMap.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.bson.Document 20 | import org.bson.types.ObjectId 21 | import org.junit.Test 22 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 23 | import org.litote.kmongo.findOneById 24 | import org.litote.kmongo.model.Friend 25 | import org.litote.kmongo.save 26 | import kotlin.test.assertEquals 27 | 28 | /** 29 | * 30 | */ 31 | class Issue16GetIdPropertyAndMap : AllCategoriesKMongoBaseTest() { 32 | 33 | @Test 34 | fun testSerializeAndDeserializeDocumentWithId() { 35 | val id = ObjectId("58ed213ca00a936d64541a1d") 36 | val thing = Document("_id", id).append("name", "test this") 37 | database.getCollection("test").apply { 38 | save(thing) 39 | assertEquals(thing, findOneById(id)) 40 | save(thing) 41 | assertEquals(thing, findOneById(id)) 42 | } 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue20NeedAWayToBypassDocumentValidationOnSave.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.bson.Document 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.findOneById 23 | import org.litote.kmongo.model.Friend 24 | import org.litote.kmongo.save 25 | import org.litote.kmongo.withDocumentClass 26 | import kotlin.test.assertEquals 27 | 28 | /** 29 | * 30 | */ 31 | class Issue20NeedAWayToBypassDocumentValidationOnSave : AllCategoriesKMongoBaseTest() { 32 | 33 | @Test 34 | fun testSaveNullValue() { 35 | val c = col.withDocumentClass() 36 | c.save(Document(mapOf("_id" to 42, "payload" to Document(mapOf("v" to null))))) 37 | assertEquals(Document(mapOf("_id" to 42, "payload" to Document(mapOf("v" to null)))), c.findOneById(42)) 38 | } 39 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue21SupportTransientToNotBeSaved.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.Serializable 21 | import org.bson.Document 22 | import org.junit.Test 23 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 24 | import org.litote.kmongo.findOne 25 | import org.litote.kmongo.save 26 | import org.litote.kmongo.withDocumentClass 27 | import kotlin.test.assertFalse 28 | 29 | /** 30 | * 31 | */ 32 | class Issue21SupportTransientToNotBeSaved : 33 | AllCategoriesKMongoBaseTest() { 34 | 35 | @Serializable 36 | data class Activity( 37 | var activity: String, 38 | @Contextual 39 | var reference: Any? = null 40 | ) { 41 | @kotlinx.serialization.Transient 42 | @Transient 43 | var transactionId: Int = 0 44 | } 45 | 46 | @Test 47 | fun testSave() { 48 | col.save(Activity("a")) 49 | assertFalse(col.withDocumentClass().findOne()!!.contains("transactionId")) 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue232FloatSerialization.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Serializable 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.findOne 23 | import kotlin.test.assertEquals 24 | 25 | @Serializable 26 | data class FloatContainer(val float: Float, val double: Double) 27 | 28 | /** 29 | * 30 | */ 31 | class Issue232FloatSerialization : AllCategoriesKMongoBaseTest() { 32 | 33 | @Test 34 | fun `test insert and load`() { 35 | val e = FloatContainer(2.0F, 2.0) 36 | col.insertOne(e) 37 | assertEquals(e, col.findOne()) 38 | } 39 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue314ValueClass.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.bson.codecs.pojo.annotations.BsonId 20 | import org.junit.Ignore 21 | import org.junit.Test 22 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 23 | import org.litote.kmongo.Id 24 | import org.litote.kmongo.eq 25 | import org.litote.kmongo.findOne 26 | import org.litote.kmongo.newId 27 | import kotlin.test.assertNotNull 28 | 29 | data class Account(@BsonId val id: Id, val email: EmailAddress) 30 | 31 | @JvmInline 32 | value class EmailAddress(val value: String) 33 | 34 | 35 | /** 36 | * 37 | */ 38 | class Issue314ValueClass : AllCategoriesKMongoBaseTest() { 39 | 40 | @Test 41 | @Ignore 42 | fun `test insert and load`() { 43 | col.insertOne(Account(newId(), EmailAddress("a"))) 44 | val doc = col.findOne(Account::email eq EmailAddress("a")) 45 | assertNotNull(doc) 46 | } 47 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue34FindOneAndUpdateOrReplaceOrDeleteCouldReturnNull.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.junit.Test 20 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 21 | import org.litote.kmongo.MongoOperator.set 22 | import org.litote.kmongo.findOneAndDelete 23 | import org.litote.kmongo.findOneAndReplace 24 | import org.litote.kmongo.findOneAndUpdate 25 | import org.litote.kmongo.model.Friend 26 | import kotlin.test.assertNull 27 | 28 | /** 29 | * 30 | */ 31 | class Issue34FindOneAndUpdateOrReplaceOrDeleteCouldReturnNull : AllCategoriesKMongoBaseTest() { 32 | 33 | @Test 34 | fun findOneAndReplaceCouldReturnNull() { 35 | assertNull(col.findOneAndReplace("{}", Friend("test"))) 36 | } 37 | 38 | @Test 39 | fun findOneAndUpdateCouldReturnNull() { 40 | assertNull(col.findOneAndUpdate("{}", "{$set:{name:'John'}}")) 41 | } 42 | 43 | @Test 44 | fun findOneAndDeleteCouldReturnNull() { 45 | assertNull(col.findOneAndDelete("{}")) 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue383FilterId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.bson.codecs.pojo.annotations.BsonId 20 | import org.junit.Test 21 | import org.litote.kmongo.util.KMongoUtil 22 | import java.util.UUID 23 | import kotlin.test.assertFalse 24 | 25 | data class DocumentWithId( 26 | @BsonId val id: UUID, 27 | val name: String 28 | ) 29 | 30 | data class DocumentWithUnderscoreId( 31 | @BsonId val _id: UUID, 32 | val name: String 33 | ) 34 | 35 | /** 36 | * 37 | */ 38 | class Issue383FilterId() { 39 | 40 | @Test 41 | fun `filterIdToBson should filter id property`() { 42 | val id = UUID.randomUUID() 43 | val bson = KMongoUtil.filterIdToBson(DocumentWithId(id = id, name = "test"), false) 44 | assertFalse(bson.toBsonDocument().contains("_id")) 45 | } 46 | 47 | @Test 48 | fun `filterIdToBson should filter _id property`() { 49 | val id = UUID.randomUUID() 50 | val bson = KMongoUtil.filterIdToBson(DocumentWithUnderscoreId(_id = id, name = "test"), false) 51 | assertFalse(bson.toBsonDocument().contains("_id")) 52 | } 53 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue384BehaviourEvaluate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.junit.Test 20 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 21 | import org.litote.kmongo.evaluate 22 | import org.litote.kmongo.model.Friend 23 | 24 | /** 25 | * 26 | */ 27 | class Issue384BehaviourEvaluate : AllCategoriesKMongoBaseTest() { 28 | 29 | @Test 30 | fun `test insert and load`() { 31 | col.find().evaluate { 32 | println(count() == 0) // prints 'true' 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue3CrashOnEnumPropertyInAnnotationIntrospector.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Serializable 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.findOneById 23 | import kotlin.test.assertEquals 24 | 25 | enum class EnumWithBooleanProperty(val test: Boolean) { 26 | A(true), B(false) 27 | } 28 | 29 | @Serializable 30 | data class ClassWithEnumProperty(val _id: String? = null, val v: EnumWithBooleanProperty = EnumWithBooleanProperty.A) 31 | 32 | 33 | /** 34 | * [Crash on enum property in Annotation Introspector](https://github.com/Litote/kmongo/issues/3) 35 | */ 36 | class Issue3CrashOnEnumPropertyInAnnotationIntrospector : AllCategoriesKMongoBaseTest() { 37 | 38 | @Test 39 | fun testSerializeAndDeserialize() { 40 | val e = ClassWithEnumProperty() 41 | col.insertOne(e) 42 | val e2 = col.findOneById(e._id!!) 43 | assertEquals(e, e2) 44 | } 45 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue409RegexpOption.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.issues 2 | 3 | import org.junit.Test 4 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 5 | import org.litote.kmongo.countDocuments 6 | import org.litote.kmongo.json 7 | import org.litote.kmongo.model.Friend 8 | import org.litote.kmongo.regex 9 | import kotlin.test.assertEquals 10 | 11 | data class NewUser(val username: String) 12 | 13 | class Issue409RegexpOption : AllCategoriesKMongoBaseTest() { 14 | 15 | @Test 16 | fun `querying with regexoption is ok`() { 17 | col.insertOne(Friend("Joe")) 18 | 19 | assertEquals(1, col.countDocuments("{name:/J/}")) 20 | assertEquals(0, col.countDocuments("{name:/System#.*R/}")) 21 | 22 | val regex1 = "J".toRegex(setOf(RegexOption.IGNORE_CASE)) 23 | val regex2 = "System#.*R".toRegex(setOf(RegexOption.IGNORE_CASE)) 24 | 25 | assertEquals(1, col.countDocuments("{name:${regex1.json}}")) 26 | assertEquals(0, col.countDocuments("{name:${regex2.json}}")) 27 | 28 | assertEquals(1, col.countDocuments("{name:${regex1.toPattern().json}}")) 29 | assertEquals(0, col.countDocuments("{name:${regex2.toPattern().json}}")) 30 | 31 | assertEquals(1, col.countDocuments(Friend::name regex regex1)) 32 | assertEquals(0, col.countDocuments(Friend::name regex regex2)) 33 | 34 | val bson = (NewUser::username regex "^test$".toRegex(setOf(RegexOption.IGNORE_CASE))).toBsonDocument() 35 | 36 | assertEquals("{\"username\": {\"\$regularExpression\": {\"pattern\": \"^test\$\", \"options\": \"iu\"}}}", bson.toString()) 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue70FailToAccessTheLastFieldInADataClass.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Serializable 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.eq 23 | import org.litote.kmongo.findOne 24 | import org.litote.kmongo.issues.Issue70FailToAccessTheLastFieldInADataClass.Account 25 | import org.litote.kmongo.save 26 | import kotlin.test.assertEquals 27 | 28 | /** 29 | * 30 | */ 31 | class Issue70FailToAccessTheLastFieldInADataClass : AllCategoriesKMongoBaseTest() { 32 | 33 | @Serializable 34 | data class Account( 35 | var email: String, 36 | var subscriptionEnds: Long, 37 | val servers: MutableList = mutableListOf(), 38 | var isPatreon: Boolean 39 | ) 40 | 41 | @Test 42 | fun `findOne test successfully a boolean`() { 43 | val a = Account("test@test.org", 1, isPatreon = true) 44 | col.save(a) 45 | val result = col.findOne(Account::isPatreon eq true) 46 | assertEquals(a, result) 47 | } 48 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue94InconsistentIdGeneration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.Serializable 21 | import org.bson.Document 22 | import org.bson.types.ObjectId 23 | import org.junit.Test 24 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 25 | import org.litote.kmongo.Id 26 | import org.litote.kmongo.issues.Issue94InconsistentIdGeneration.Task 27 | import org.litote.kmongo.newId 28 | import org.litote.kmongo.withDocumentClass 29 | import kotlin.test.assertTrue 30 | 31 | /** 32 | * 33 | */ 34 | class Issue94InconsistentIdGeneration : AllCategoriesKMongoBaseTest() { 35 | 36 | @Serializable 37 | data class Task(@Contextual val _id: Id = newId()) 38 | 39 | @Test 40 | fun generateTwoTasks() { 41 | val t1 = Task() 42 | val t2 = Task() 43 | col.insertOne(t1) 44 | col.insertOne(t2) 45 | col.withDocumentClass().find().forEach { 46 | assertTrue { it.get("_id") is ObjectId } 47 | } 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/issues/Issue96SetOfObjectIds.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.junit.Test 20 | import org.junit.experimental.categories.Category 21 | import org.litote.kmongo.Id 22 | import org.litote.kmongo.JacksonMappingCategory 23 | import org.litote.kmongo.KMongoBaseTest 24 | import org.litote.kmongo.findOne 25 | import org.litote.kmongo.issues.Issue96SetOfObjectIds.Task 26 | import org.litote.kmongo.newId 27 | import org.litote.kmongo.withDocumentClass 28 | import kotlin.test.assertEquals 29 | 30 | /** 31 | * 32 | */ 33 | @Category(JacksonMappingCategory::class) 34 | class Issue96SetOfObjectIds : KMongoBaseTest() { 35 | 36 | data class Task(val ids: List>) 37 | data class TaskWithStringIds(val ids: List) 38 | 39 | @Test 40 | fun insertSetOfIds() { 41 | val task = Task(listOf(newId(), newId())) 42 | col.insertOne(task) 43 | assertEquals(task, col.findOne()) 44 | assertEquals>( 45 | task.ids.map { it.toString() }, 46 | col.withDocumentClass().findOne()!!.ids 47 | ) 48 | } 49 | } -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/session/CommandWithSessionTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.session 18 | 19 | import com.mongodb.client.ClientSession 20 | import org.bson.Document 21 | import org.junit.After 22 | import org.junit.Before 23 | import org.junit.Test 24 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 25 | import org.litote.kmongo.model.Friend 26 | import org.litote.kmongo.runCommand 27 | import kotlin.test.assertEquals 28 | 29 | /** 30 | * 31 | */ 32 | class CommandWithSessionTest : AllCategoriesKMongoBaseTest() { 33 | 34 | lateinit var session: ClientSession 35 | 36 | @Before 37 | fun setup() { 38 | session = mongoClient.startSession() 39 | } 40 | 41 | @After 42 | fun tearDown() { 43 | session.close() 44 | } 45 | 46 | @Test 47 | fun canRunACommand() { 48 | val r = database.runCommand(session,"{ ping: 1 }") 49 | assertEquals(1.0, r.get("ok")) 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /kmongo-core-tests/src/main/kotlin/org/litote/kmongo/session/CountWithSessionTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.session 18 | 19 | import com.mongodb.client.ClientSession 20 | import org.junit.After 21 | import org.junit.Before 22 | import org.junit.Test 23 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 24 | import org.litote.kmongo.MongoOperator 25 | import org.litote.kmongo.countDocuments 26 | import org.litote.kmongo.model.Friend 27 | import kotlin.test.assertEquals 28 | 29 | /** 30 | * 31 | */ 32 | class CountWithSessionTest : AllCategoriesKMongoBaseTest() { 33 | 34 | lateinit var session: ClientSession 35 | 36 | @Before 37 | fun setup() { 38 | session = mongoClient.startSession() 39 | } 40 | 41 | @After 42 | fun tearDown() { 43 | session.close() 44 | } 45 | 46 | fun newFriend(): Friend { 47 | return Friend("John", "22 Wall Street Avenue") 48 | } 49 | 50 | @Test 51 | fun canCountWithQuery() { 52 | col.insertMany(session, listOf(newFriend(), newFriend())) 53 | val c = col.countDocuments(session, "{name:{${MongoOperator.exists}:true}}") 54 | assertEquals(2, c) 55 | } 56 | } -------------------------------------------------------------------------------- /kmongo-core/pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 4.0.0 19 | 20 | 21 | org.litote.kmongo 22 | kmongo-root 23 | 5.2.2-SNAPSHOT 24 | 25 | 26 | kmongo-core 27 | KMongo sync core 28 | KMongo synchronous client core extensions 29 | 30 | 31 | 32 | org.mongodb 33 | mongodb-driver-sync 34 | 35 | 36 | org.litote.kmongo 37 | kmongo-property 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /kmongo-core/src/main/kotlin/kotlin/internal/Annotations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package kotlin.internal 18 | 19 | @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) 20 | @Retention(AnnotationRetention.BINARY) 21 | internal annotation class HidesMembers 22 | 23 | @Target(AnnotationTarget.TYPE) 24 | @Retention(AnnotationRetention.BINARY) 25 | internal annotation class NoInfer 26 | 27 | @Target(AnnotationTarget.TYPE_PARAMETER) 28 | @Retention(AnnotationRetention.BINARY) 29 | internal annotation class OnlyInputTypes 30 | 31 | @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) 32 | @Retention(AnnotationRetention.BINARY) 33 | internal annotation class InlineOnly -------------------------------------------------------------------------------- /kmongo-core/src/main/kotlin/org/litote/kmongo/DistinctIterables.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.client.DistinctIterable 20 | import org.litote.kmongo.util.KMongoUtil 21 | 22 | /** 23 | * Sets the query filter to apply to the query. 24 | * 25 | * @param filter the filter, which may be null 26 | * @return this 27 | */ 28 | fun DistinctIterable.filter(filter: String): DistinctIterable = filter(KMongoUtil.toBson(filter)) -------------------------------------------------------------------------------- /kmongo-core/src/main/kotlin/org/litote/kmongo/MapReduceIterables.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.client.MapReduceIterable 20 | import org.litote.kmongo.util.KMongoUtil 21 | 22 | /** 23 | * Sets the global variables that are accessible in the map, reduce and finalize functions. 24 | * 25 | * @param scope the global variables that are accessible in the map, reduce and finalize functions. 26 | * @return this 27 | */ 28 | fun MapReduceIterable.scope(scope: String): MapReduceIterable = scope(KMongoUtil.toBson(scope)) 29 | 30 | /** 31 | * Sets the sort criteria to apply to the query. 32 | * 33 | * @param sort the sort criteria, which may be null 34 | * @return this 35 | */ 36 | fun MapReduceIterable.sort(sort: String): MapReduceIterable = sort(KMongoUtil.toBson(sort)) 37 | 38 | /** 39 | * Sets the query filter to apply to the query. 40 | * 41 | * @param filter the filter to apply to the query 42 | * @return this 43 | */ 44 | fun MapReduceIterable.filter(filter: String): MapReduceIterable = filter(KMongoUtil.toBson(filter)) 45 | -------------------------------------------------------------------------------- /kmongo-core/src/main/kotlin/org/litote/kmongo/SyncProperties.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.client.MongoCollection 20 | import kotlin.reflect.KProperty1 21 | 22 | /** 23 | * Creates a $lookup pipeline stage for the specified filter (Typesafe version) 24 | * 25 | * @param from the collection in the same database to perform the join with. 26 | * @param localField specifies the field from the local collection to match values against. 27 | * @param foreignField specifies the field in the from collection to match values against. 28 | * @param newAs the name of the new array field to add to the input documents. 29 | * @return the $lookup pipeline stage 30 | * @mongodb.driver.manual reference/operator/aggregation/lookup/ $lookup 31 | */ 32 | fun lookup( 33 | from: MongoCollection, 34 | localField: KProperty1, 35 | foreignField: KProperty1, 36 | newAs: KProperty1 37 | ) = 38 | lookup(from.namespace.collectionName, localField.path(), foreignField.path(), newAs.path()) 39 | -------------------------------------------------------------------------------- /kmongo-core/src/main/kotlin/org/litote/kmongo/service/SyncMongoClientProviderService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.service 18 | 19 | import com.mongodb.ConnectionString 20 | import com.mongodb.client.MongoClient 21 | import org.litote.kmongo.KMongo 22 | 23 | /** 24 | * 25 | */ 26 | internal class SyncMongoClientProviderService : MongoClientProviderService { 27 | 28 | override fun createMongoClient(connectionString: ConnectionString): MongoClient { 29 | return KMongo.createClient(connectionString) 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /kmongo-core/src/main/resources/META-INF/services/org.litote.kmongo.service.MongoClientProviderService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.service.SyncMongoClientProviderService -------------------------------------------------------------------------------- /kmongo-coroutine-core-tests/src/main/kotlin/org/litote/kmongo/coroutine/CoroutinePublisherTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.coroutine 18 | 19 | import junit.framework.Assert.assertEquals 20 | import kotlinx.coroutines.flow.toList 21 | import kotlinx.coroutines.runBlocking 22 | import org.junit.Test 23 | import org.junit.experimental.categories.Category 24 | import org.litote.kmongo.CoreCategory 25 | import org.reactivestreams.Publisher 26 | 27 | @Category(CoreCategory::class) 28 | class CoroutinePublisherTest { 29 | 30 | private val publisher: Publisher = DoSinglePublisher(1) 31 | private val coroutine = publisher.coroutine 32 | 33 | @Test 34 | fun toList() { 35 | runBlocking { 36 | assertEquals(listOf(1), coroutine.toList()) 37 | } 38 | } 39 | 40 | @Test 41 | fun toFlow() { 42 | runBlocking { 43 | assertEquals(listOf(1), coroutine.toFlow().toList()) 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /kmongo-coroutine-core-tests/src/main/kotlin/org/litote/kmongo/coroutine/TestPublishers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.coroutine 18 | 19 | import org.reactivestreams.Publisher 20 | import org.reactivestreams.Subscriber 21 | import org.reactivestreams.Subscription 22 | import java.lang.RuntimeException 23 | 24 | class DoNothingPublisher : Publisher { 25 | 26 | override fun subscribe(s: Subscriber) { 27 | s.onComplete() 28 | } 29 | } 30 | 31 | class DoSinglePublisher(val t: T) : Publisher { 32 | 33 | override fun subscribe(s: Subscriber) { 34 | s.onSubscribe(object:Subscription { 35 | override fun cancel() { 36 | } 37 | 38 | override fun request(n: Long) { 39 | } 40 | }) 41 | s.onNext(t) 42 | s.onComplete() 43 | } 44 | 45 | } 46 | 47 | class ErrorPublisher(val t: Throwable = RuntimeException()) : Publisher { 48 | 49 | override fun subscribe(s: Subscriber) { 50 | s.onError(t) 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /kmongo-coroutine-core-tests/src/main/kotlin/org/litote/kmongo/coroutine/issues/Issue34FindOneAndUpdateOrReplaceOrDeleteCouldReturnNull.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.coroutine.issues 18 | 19 | import kotlinx.coroutines.runBlocking 20 | import org.junit.Test 21 | import org.litote.kmongo.MongoOperator.set 22 | import org.litote.kmongo.coroutine.KMongoReactiveStreamsCoroutineBaseTest 23 | import org.litote.kmongo.model.Friend 24 | import kotlin.test.assertNull 25 | 26 | /** 27 | * 28 | */ 29 | class Issue34FindOneAndUpdateOrReplaceOrDeleteCouldReturnNull : KMongoReactiveStreamsCoroutineBaseTest() { 30 | 31 | @Test 32 | fun findOneAndReplaceCouldReturnNull() = runBlocking { 33 | assertNull(col.findOneAndReplace("{}", Friend("test"))) 34 | } 35 | 36 | @Test 37 | fun findOneAndUpdateCouldReturnNull() = runBlocking { 38 | assertNull(col.findOneAndUpdate("{}", "{$set:{name:'John'}}")) 39 | } 40 | 41 | @Test 42 | fun findOneAndDeleteCouldReturnNull() = runBlocking { 43 | assertNull(col.findOneAndDelete("{}")) 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /kmongo-coroutine-core/src/main/kotlin/org/litote/kmongo/coroutine/CoroutineClientSessions.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.coroutine 18 | 19 | import com.mongodb.reactivestreams.client.ClientSession 20 | import kotlinx.coroutines.reactive.awaitFirstOrNull 21 | 22 | /** 23 | * Commit a transaction in the context of this session. A transaction can only be committed if one has first been started. 24 | */ 25 | suspend fun ClientSession.commitTransactionAndAwait() { 26 | commitTransaction().awaitFirstOrNull() 27 | } 28 | 29 | /** 30 | * Abort a transaction in the context of this session. A transaction can only be aborted if one has first been started. 31 | */ 32 | suspend fun ClientSession.abortTransactionAndAwait() { 33 | abortTransaction().awaitFirstOrNull() 34 | } 35 | -------------------------------------------------------------------------------- /kmongo-coroutine-core/src/main/kotlin/org/litote/kmongo/coroutine/Coroutines.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.coroutine 17 | 18 | import com.mongodb.internal.async.SingleResultCallback 19 | import kotlin.coroutines.resume 20 | import kotlin.coroutines.resumeWithException 21 | import kotlin.coroutines.suspendCoroutine 22 | 23 | 24 | /** 25 | * Coroutine wrapper for SingleResultCallback 26 | * 27 | * @param callback lambda that will be supplied to wrapped SingleResultCallback 28 | * @param the default target type of the collection to return 29 | */ 30 | suspend inline fun singleResult(crossinline callback: (SingleResultCallback) -> Unit): T? { 31 | return suspendCoroutine { continuation -> 32 | callback(SingleResultCallback { result: T?, throwable: Throwable? -> 33 | if (throwable != null) { 34 | continuation.resumeWithException(throwable) 35 | } else { 36 | continuation.resume(result) 37 | } 38 | }) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /kmongo-coroutine-serialization/src/test/kotlin/Issue228WrappedObjectId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.issues 17 | 18 | import kotlinx.coroutines.runBlocking 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import org.junit.Test 23 | import org.litote.kmongo.Id 24 | import org.litote.kmongo.coroutine.KMongoReactiveStreamsCoroutineBaseTest 25 | import org.litote.kmongo.newId 26 | import kotlin.test.assertEquals 27 | 28 | @Serializable 29 | data class Tag( 30 | @Contextual 31 | @SerialName("_id") val id: Id? = newId(), 32 | val displayName: String, 33 | val description: String? = null, 34 | val createdAt: Long = System.currentTimeMillis() 35 | ) 36 | 37 | /** 38 | * 39 | */ 40 | class Issue228WrappedObject : KMongoReactiveStreamsCoroutineBaseTest() { 41 | 42 | @Test 43 | fun testSaveAndLoad() = runBlocking { 44 | val tag = Tag(displayName = "foobar") 45 | col.insertOne(tag) 46 | assertEquals(tag, col.findOne()) 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /kmongo-data/pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 4.0.0 19 | 20 | 21 | org.litote.kmongo 22 | kmongo-root 23 | 5.2.2-SNAPSHOT 24 | 25 | 26 | kmongo-data 27 | KMongo data annotation 28 | KMongo annotation processor 29 | 30 | -------------------------------------------------------------------------------- /kmongo-data/src/main/kotlin/org/litote/kmongo/Data.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * Annotated classes will generate typed query helpers at compile time. 21 | * See [documentation](http://litote.org/kmongo/typed-queries/#kmongo-annotation-processor). 22 | */ 23 | @Target(AnnotationTarget.CLASS) 24 | @Retention(AnnotationRetention.SOURCE) 25 | @MustBeDocumented 26 | annotation class Data( 27 | /** 28 | * Set to internal visibility the generated classes. 29 | */ 30 | val internal: Boolean = false 31 | ) -------------------------------------------------------------------------------- /kmongo-data/src/main/kotlin/org/litote/kmongo/DataRegistry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlin.reflect.KClass 20 | 21 | /** 22 | * Give the same behaviour than @[Data] to the specified KClass array. 23 | * Useful if you can't annotate directly the target classes. 24 | */ 25 | @Target(AnnotationTarget.CLASS, AnnotationTarget.FILE) 26 | @Retention(AnnotationRetention.SOURCE) 27 | @MustBeDocumented 28 | annotation class DataRegistry( 29 | /** 30 | * List of data classes. 31 | */ 32 | val value: Array>, 33 | /** 34 | * Set to internal visibility the generated classes. 35 | */ 36 | val internal: Boolean = false 37 | ) -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/EmbeddedMongo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.ConnectionString 20 | import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion 21 | import org.bson.BsonDocument 22 | import org.bson.Document 23 | 24 | 25 | /** 26 | * Flapdoodle wrapper. 27 | */ 28 | internal class EmbeddedMongo(private val version: IFeatureAwareVersion) { 29 | 30 | private val standalone = System.getProperty("kmongo.flapdoodle.replicaset") != "true" 31 | 32 | fun connectionString(commandExecutor: (String, BsonDocument, (Document?, Throwable?) -> Unit) -> Unit): ConnectionString = 33 | if (standalone) { 34 | StandaloneEmbeddedMongo(version).connectionString(commandExecutor) 35 | } else { 36 | ReplicaSetEmbeddedMongo(version).connectionString(commandExecutor) 37 | } 38 | 39 | 40 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/EmbeddedMongoLog.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import de.flapdoodle.embed.mongo.transitions.ImmutableMongod 20 | import de.flapdoodle.embed.process.io.ProcessOutput 21 | import de.flapdoodle.embed.process.io.Processors 22 | import de.flapdoodle.reverse.transitions.Start 23 | 24 | fun ImmutableMongod.configLogs() = withProcessOutput( 25 | Start.to(ProcessOutput::class.java).initializedWith( 26 | if (System.getProperty("kmongo.flapdoddle.log") == "true") { 27 | ProcessOutput.builder().build() 28 | } else { 29 | ProcessOutput.builder() 30 | .output(Processors.silent()) 31 | .error(Processors.silent()) 32 | .commands(Processors.silent()) 33 | .build() 34 | } 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/KFlapdoodle.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.ConnectionString 20 | import com.mongodb.client.MongoClient 21 | import com.mongodb.client.MongoDatabase 22 | 23 | /** 24 | * Main KFlapoodle object - to access sync [mongoClient]. 25 | */ 26 | 27 | @Deprecated("use KFlapdoodleRule") 28 | object KFlapdoodle { 29 | 30 | private val configuration: KFlapdoodleConfiguration by lazy { KFlapdoodleConfiguration() } 31 | 32 | val mongoClient: MongoClient by lazy { configuration.mongoClient } 33 | 34 | val connectionString: ConnectionString by lazy { configuration.connectionString } 35 | 36 | fun newMongoClient(): MongoClient = configuration.newMongoClient() 37 | 38 | fun getDatabase(dbName: String = "test"): MongoDatabase = configuration.getDatabase(dbName) 39 | 40 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/reactivestreams/KFlapdoodleReactiveStreams.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import com.mongodb.reactivestreams.client.MongoClient 20 | /** 21 | * Async main KFlapoodle object - to access async [mongoClient]. 22 | */ 23 | @Deprecated("use ReactiveStreamsFlapdoodleRule") 24 | object KFlapdoodleReactiveStreams { 25 | 26 | private val configuration: KFlapdoodleReactiveStreamsConfiguration by lazy { KFlapdoodleReactiveStreamsConfiguration() } 27 | 28 | val mongoClient: MongoClient by lazy { configuration.mongoClient } 29 | 30 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/reactivestreams/KFlapdoodleReactiveStreamsConfiguration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import com.mongodb.ConnectionString 20 | import com.mongodb.reactivestreams.client.MongoClient 21 | import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion 22 | import org.litote.kmongo.EmbeddedMongo 23 | import org.litote.kmongo.defaultMongoTestVersion 24 | import org.litote.kmongo.service.MongoClientProvider 25 | 26 | /** 27 | * 28 | */ 29 | internal class KFlapdoodleReactiveStreamsConfiguration(version: IFeatureAwareVersion = defaultMongoTestVersion) { 30 | 31 | val mongoClient: MongoClient by lazy { 32 | MongoClientProvider.createMongoClient( 33 | EmbeddedMongo(version).connectionString { host, command, callback -> 34 | MongoClientProvider 35 | .createMongoClient(ConnectionString("mongodb://$host")) 36 | .getDatabase("admin") 37 | .runCommand(command) 38 | .subscribe(SimpleSubscriber { callback.invoke(null, it) }) 39 | } 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/reactivestreams/ReactiveStreamsTestContext.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import java.util.concurrent.CountDownLatch 20 | import java.util.concurrent.TimeUnit 21 | 22 | 23 | internal class ReactiveStreamsTestContext { 24 | 25 | private val lock = CountDownLatch(1) 26 | @Volatile 27 | var error: Throwable? = null 28 | 29 | fun test(testToRun: () -> Unit) { 30 | try { 31 | testToRun() 32 | } catch (t: Throwable) { 33 | error = t 34 | throw t 35 | } finally { 36 | lock.countDown() 37 | } 38 | } 39 | 40 | fun waitToComplete() { 41 | assert(lock.await(40, TimeUnit.SECONDS)) 42 | val err = error 43 | if (err != null) throw err 44 | } 45 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/main/kotlin/org/litote/kmongo/reactivestreams/SimpleSubscriber.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactivestreams 18 | 19 | import org.reactivestreams.Subscriber 20 | import org.reactivestreams.Subscription 21 | 22 | /** 23 | * 24 | */ 25 | internal class SimpleSubscriber(private val listener: (Throwable?) -> Unit = {}) : Subscriber { 26 | 27 | override fun onComplete() { 28 | listener(null) 29 | } 30 | 31 | override fun onSubscribe(s: Subscription) { 32 | s.request(Long.MAX_VALUE) 33 | } 34 | 35 | override fun onNext(t: T) { 36 | } 37 | 38 | override fun onError(t: Throwable) { 39 | listener(t) 40 | } 41 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/test/kotlin/org/litote/kmongo/KFlapdoodleRuleTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.client.model.Filters 20 | import org.junit.Rule 21 | import org.junit.Test 22 | import org.litote.kmongo.model.Friend 23 | import kotlin.test.assertEquals 24 | 25 | /** 26 | * 27 | */ 28 | class KFlapdoodleRuleTest : KMongoRootTest() { 29 | 30 | @Rule 31 | @JvmField 32 | val rule = KFlapdoodleRule.rule(true) 33 | 34 | @Test 35 | fun testRandomRule() { 36 | val friend = Friend("bob") 37 | rule.col.insertOne(friend) 38 | assertEquals(friend, rule.col.findOneAndDelete(Filters.eq("_id", friend._id))) 39 | } 40 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/test/kotlin/org/litote/kmongo/StandaloneEmbeddedMongoTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.mongodb.client.MongoClient 20 | import com.mongodb.client.model.Filters 21 | import org.junit.Test 22 | import org.litote.kmongo.model.Friend 23 | import org.litote.kmongo.service.MongoClientProvider 24 | import kotlin.test.assertEquals 25 | 26 | /** 27 | * 28 | */ 29 | class StandaloneEmbeddedMongoTest { 30 | 31 | @Test 32 | fun testStandalone() { 33 | val friend = Friend("bob") 34 | val mongoClient: MongoClient = MongoClientProvider.createMongoClient( 35 | StandaloneEmbeddedMongo(defaultMongoTestVersion).connectionString { _, _, _ -> } 36 | ) 37 | val col = mongoClient.getDatabase("test").getCollection("friend", Friend::class.java) 38 | col.insertOne(friend) 39 | assertEquals(friend, col.findOneAndDelete(Filters.eq("_id", friend._id!!))) 40 | } 41 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/test/kotlin/org/litote/kmongo/service/SyncMongoClientProviderService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.service 18 | 19 | import com.mongodb.ConnectionString 20 | import com.mongodb.MongoClientSettings 21 | import com.mongodb.client.MongoClient 22 | import com.mongodb.client.MongoClients 23 | import org.litote.kmongo.util.KMongoUtil 24 | 25 | /** 26 | * only used for test 27 | */ 28 | internal class SyncMongoClientProviderService : MongoClientProviderService { 29 | 30 | override fun createMongoClient(connectionString: ConnectionString): MongoClient { 31 | return MongoClients.create( 32 | MongoClientSettings 33 | .builder() 34 | .applyConnectionString(connectionString) 35 | .codecRegistry( 36 | ClassMappingType.codecRegistry(KMongoUtil.defaultCodecRegistry) 37 | ) 38 | .build() 39 | ) 40 | } 41 | } -------------------------------------------------------------------------------- /kmongo-flapdoodle/src/test/resources/META-INF/services/org.litote.kmongo.service.MongoClientProviderService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.service.SyncMongoClientProviderService -------------------------------------------------------------------------------- /kmongo-id-jackson/src/main/kotlin/org/litote/kmongo/id/jackson/IdJacksonModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id.jackson 18 | 19 | import com.fasterxml.jackson.databind.module.SimpleModule 20 | import org.litote.kmongo.Id 21 | import org.litote.kmongo.id.IdGenerator 22 | 23 | /** 24 | * Add support for serialization and deserialization of [Id] to or from json [String]. 25 | * The [IdGenerator] used must have a public constructor with only one String argument. 26 | * @param idGenerator if null [IdGenerator.defaultGenerator] is used 27 | */ 28 | class IdJacksonModule(idGenerator: IdGenerator? = null) : SimpleModule() { 29 | 30 | init { 31 | addSerializer(Id::class.java, IdToStringSerializer()) 32 | addDeserializer(Id::class.java, StringToIdDeserializer(idGenerator)) 33 | addKeySerializer(Id::class.java, IdKeySerializer()) 34 | addKeyDeserializer(Id::class.java, IdKeyDeserializer(idGenerator)) 35 | } 36 | } -------------------------------------------------------------------------------- /kmongo-id-jackson/src/main/kotlin/org/litote/kmongo/id/jackson/IdKeyDeserializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id.jackson 18 | 19 | import com.fasterxml.jackson.databind.DeserializationContext 20 | import com.fasterxml.jackson.databind.KeyDeserializer 21 | import org.litote.kmongo.Id 22 | import org.litote.kmongo.id.IdGenerator 23 | 24 | /** 25 | * Deserialize a [String] to an [Id] for a key. 26 | * @param idGenerator if null [IdGenerator.defaultGenerator] is used 27 | */ 28 | class IdKeyDeserializer(private val idGenerator: IdGenerator? = null) : KeyDeserializer() { 29 | 30 | override fun deserializeKey(key: String, ctxt: DeserializationContext): Any 31 | = StringToIdDeserializer.deserialize(idGenerator, key, ctxt) 32 | 33 | } -------------------------------------------------------------------------------- /kmongo-id-jackson/src/main/kotlin/org/litote/kmongo/id/jackson/IdKeySerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id.jackson 18 | 19 | import com.fasterxml.jackson.core.JsonGenerator 20 | import com.fasterxml.jackson.databind.JsonSerializer 21 | import com.fasterxml.jackson.databind.SerializerProvider 22 | import org.litote.kmongo.Id 23 | 24 | /** 25 | * Serialize an [Id] to a [String] for a [Map]. 26 | */ 27 | class IdKeySerializer : JsonSerializer>() { 28 | override fun serialize(value: Id<*>, gen: JsonGenerator, serializers: SerializerProvider) { 29 | gen.writeFieldName(value.toString()) 30 | } 31 | } -------------------------------------------------------------------------------- /kmongo-id-jackson/src/main/kotlin/org/litote/kmongo/id/jackson/IdToStringSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id.jackson 18 | 19 | import com.fasterxml.jackson.core.JsonGenerator 20 | import com.fasterxml.jackson.databind.JsonSerializer 21 | import com.fasterxml.jackson.databind.SerializerProvider 22 | import org.litote.kmongo.Id 23 | 24 | /** 25 | * Serialize an [Id] to a [String]. 26 | */ 27 | class IdToStringSerializer : JsonSerializer>() { 28 | override fun serialize(value: Id<*>, gen: JsonGenerator, serializers: SerializerProvider) { 29 | gen.writeString(value.toString()) 30 | } 31 | } -------------------------------------------------------------------------------- /kmongo-id-jackson/src/main/kotlin/org/litote/kmongo/id/jackson/StringToIdDeserializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id.jackson 18 | 19 | import com.fasterxml.jackson.core.JsonParser 20 | import com.fasterxml.jackson.databind.DeserializationContext 21 | import com.fasterxml.jackson.databind.JsonDeserializer 22 | import org.litote.kmongo.Id 23 | import org.litote.kmongo.id.IdGenerator 24 | 25 | /** 26 | * Deserialize a [String] to an [Id]. 27 | * @param idGenerator if null [IdGenerator.defaultGenerator] is used 28 | */ 29 | class StringToIdDeserializer(private val idGenerator: IdGenerator? = null) : JsonDeserializer>() { 30 | 31 | internal companion object { 32 | 33 | fun deserialize(idGenerator: IdGenerator? = null, s: String, ctxt: DeserializationContext): Id<*> 34 | = (idGenerator ?: IdGenerator.defaultGenerator).create(s) 35 | } 36 | 37 | 38 | override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Id<*> 39 | = deserialize(idGenerator, p.text, ctxt) 40 | 41 | } -------------------------------------------------------------------------------- /kmongo-id-jackson/src/test/kotlin/org/litote/kmongo/id/jackson/IdJsonTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id.jackson 18 | 19 | import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper 20 | import com.fasterxml.jackson.module.kotlin.readValue 21 | import org.junit.Test 22 | import org.litote.kmongo.Id 23 | import org.litote.kmongo.toId 24 | import kotlin.test.assertEquals 25 | 26 | /** 27 | * 28 | */ 29 | class IdJsonTest { 30 | 31 | data class Data( 32 | val id: Id = "id".toId(), 33 | val set: Set> = setOf(id), 34 | val map: Map, Boolean> = mapOf(id to true)) 35 | 36 | @Test 37 | fun testSerializationAndDeserialization() { 38 | val data = Data() 39 | val mapper = jacksonObjectMapper().registerModule(IdJacksonModule()) 40 | val json = mapper.writeValueAsString(data) 41 | assertEquals("{\"id\":\"id\",\"set\":[\"id\"],\"map\":{\"id\":true}}", json) 42 | assertEquals(data, mapper.readValue(json)) 43 | } 44 | } -------------------------------------------------------------------------------- /kmongo-id/pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 4.0.0 19 | 20 | 21 | org.litote.kmongo 22 | kmongo-root 23 | 5.2.2-SNAPSHOT 24 | 25 | 26 | kmongo-id 27 | Id interface 28 | Agnostic id interface - does not depend of the mongo java driver 29 | 30 | 31 | 32 | org.jetbrains.kotlin 33 | kotlin-reflect 34 | 35 | 36 | 37 | junit 38 | junit 39 | 40 | 41 | org.jetbrains.kotlin 42 | kotlin-test-junit 43 | 44 | 45 | -------------------------------------------------------------------------------- /kmongo-id/src/main/kotlin/org/litote/kmongo/Id.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * A unique document identifier. 21 | * 22 | * If the id type need to support json serialization and deserialization, 23 | * it must provide a toString() method and a constructor with a one String arg, 24 | * and consistent equals & hashCode methods. 25 | * 26 | * Please note that equals and hashCode methods of Id are "implementation dependant": 27 | * if classes A and B are two implementations of Id, instances of A are always not equals to 28 | * instances of B. 29 | * 30 | * @param T the owner of the id 31 | */ 32 | 33 | interface Id { 34 | 35 | /** 36 | * Cast Id to Id. 37 | */ 38 | @Suppress("UNCHECKED_CAST") 39 | fun cast(): Id = this as Id 40 | } -------------------------------------------------------------------------------- /kmongo-id/src/main/kotlin/org/litote/kmongo/id/IdGeneratorProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | /** 20 | * An [IdGeneratorProvider], declared as [java.util.ServiceLoader]. 21 | */ 22 | interface IdGeneratorProvider { 23 | 24 | /** 25 | * The priority of the [IdGeneratorProvider]. Greater is better. 26 | */ 27 | val priority: Int get() = 0 28 | 29 | /** 30 | * The provided generator. 31 | */ 32 | val generator: IdGenerator 33 | } -------------------------------------------------------------------------------- /kmongo-id/src/main/kotlin/org/litote/kmongo/id/StringId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.litote.kmongo.Id 20 | 21 | /** 22 | * A String id. 23 | */ 24 | data class StringId(val id: String) : Id { 25 | 26 | override fun toString(): String { 27 | return id 28 | } 29 | } -------------------------------------------------------------------------------- /kmongo-id/src/main/kotlin/org/litote/kmongo/id/UUIDStringIdGenerator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.litote.kmongo.Id 20 | import java.util.UUID 21 | import kotlin.reflect.KClass 22 | 23 | /** 24 | * Generator of [StringId] based on [UUID]. 25 | */ 26 | object UUIDStringIdGenerator : IdGenerator { 27 | 28 | override val idClass: KClass> = StringId::class 29 | 30 | override val wrappedIdClass: KClass = String::class 31 | 32 | override fun generateNewId(): Id = StringId(UUID.randomUUID().toString()) 33 | } -------------------------------------------------------------------------------- /kmongo-id/src/main/kotlin/org/litote/kmongo/id/UUIDStringIdGeneratorProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | /** 20 | * 21 | */ 22 | internal class UUIDStringIdGeneratorProvider : IdGeneratorProvider { 23 | 24 | override val generator: IdGenerator = UUIDStringIdGenerator 25 | 26 | } -------------------------------------------------------------------------------- /kmongo-id/src/main/kotlin/org/litote/kmongo/ids.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.litote.kmongo.id.IdGenerator 20 | import org.litote.kmongo.id.StringId 21 | 22 | /** 23 | * Generate a new [Id] with the [IdGenerator.defaultGenerator]. 24 | */ 25 | fun newId(): Id = IdGenerator.defaultGenerator.generateNewId() 26 | 27 | /** 28 | * Create a new [Id] from the current [String]. 29 | */ 30 | fun String.toId(): Id = StringId(this) 31 | -------------------------------------------------------------------------------- /kmongo-id/src/main/resources/META-INF/services/org.litote.kmongo.id.IdGeneratorProvider: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.id.UUIDStringIdGeneratorProvider -------------------------------------------------------------------------------- /kmongo-id/src/test/kotlin/IdTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | import org.junit.Test 18 | import org.litote.kmongo.Id 19 | import org.litote.kmongo.newId 20 | import kotlin.test.assertEquals 21 | 22 | /* 23 | * Copyright (C) 2016/2021 Litote 24 | * 25 | * Licensed under the Apache License, Version 2.0 (the "License"); 26 | * you may not use this file except in compliance with the License. 27 | * You may obtain a copy of the License at 28 | * 29 | * http://www.apache.org/licenses/LICENSE-2.0 30 | * 31 | * Unless required by applicable law or agreed to in writing, software 32 | * distributed under the License is distributed on an "AS IS" BASIS, 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 34 | * See the License for the specific language governing permissions and 35 | * limitations under the License. 36 | */ 37 | 38 | /** 39 | * 40 | */ 41 | class IdTest { 42 | 43 | @Test 44 | fun `cast works as expected`() { 45 | val id1: Id = newId() 46 | val id2: Id = id1.cast() 47 | assertEquals>(id1, id2) 48 | } 49 | } -------------------------------------------------------------------------------- /kmongo-jackson-mapping/src/main/kotlin/org/litote/kmongo/jackson/FilterIdModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.jackson 18 | 19 | import com.fasterxml.jackson.databind.introspect.Annotated 20 | import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector 21 | import com.fasterxml.jackson.databind.module.SimpleModule 22 | 23 | 24 | internal class FilterIdModule : SimpleModule() { 25 | 26 | object FilterIdIntrospector : NopAnnotationIntrospector() { 27 | 28 | override fun findFilterId(a: Annotated): Any? { 29 | return "_id" 30 | } 31 | } 32 | 33 | override fun setupModule(context: SetupContext) { 34 | super.setupModule(context) 35 | 36 | context.appendAnnotationIntrospector(FilterIdIntrospector) 37 | } 38 | } -------------------------------------------------------------------------------- /kmongo-jackson-mapping/src/main/kotlin/org/litote/kmongo/jackson/JacksonCodecProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.jackson 17 | 18 | import com.fasterxml.jackson.databind.ObjectMapper 19 | import org.bson.codecs.Codec 20 | import org.bson.codecs.configuration.CodecProvider 21 | import org.bson.codecs.configuration.CodecRegistry 22 | 23 | internal class JacksonCodecProvider( 24 | var bsonObjectMapper: ObjectMapper, 25 | var notBsonObjectMapper: ObjectMapper) : CodecProvider { 26 | 27 | override fun get(type: Class, registry: CodecRegistry): Codec { 28 | return JacksonCodec(bsonObjectMapper, notBsonObjectMapper, registry, type) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /kmongo-jackson-mapping/src/main/resources/META-INF/services/org.litote.kmongo.service.ClassMappingTypeService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.jackson.JacksonClassMappingTypeService -------------------------------------------------------------------------------- /kmongo-jackson-mapping/src/test/kotlin/org/litote/kmongo/jackson/JacksonClassMappingTypeServiceTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.jackson 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty 20 | import org.bson.codecs.pojo.annotations.BsonId 21 | import org.junit.Test 22 | import kotlin.test.assertEquals 23 | 24 | /** 25 | * 26 | */ 27 | class JacksonClassMappingTypeServiceTest { 28 | 29 | data class AnnotatedData(@JsonProperty("other") val property: String, @BsonId val key: String) 30 | 31 | @Test 32 | fun `getPath handles well @JsonProperty and @BsonId`() { 33 | val service = JacksonClassMappingTypeService() 34 | assertEquals( 35 | "other", 36 | service.getPath(AnnotatedData::property) 37 | ) 38 | assertEquals( 39 | "_id", 40 | service.getPath(AnnotatedData::key) 41 | ) 42 | } 43 | } -------------------------------------------------------------------------------- /kmongo-jackson-mapping/src/test/kotlin/org/litote/kmongo/util/JacksonModuleServiceLoaderTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.util 18 | 19 | import com.fasterxml.jackson.databind.Module 20 | import com.fasterxml.jackson.databind.module.SimpleModule 21 | import org.litote.jackson.JacksonModuleServiceLoader 22 | 23 | class TestModule : SimpleModule() 24 | 25 | /** 26 | * 27 | */ 28 | class JacksonModuleServiceLoaderTest : JacksonModuleServiceLoader { 29 | 30 | override fun module(): Module = TestModule() 31 | } -------------------------------------------------------------------------------- /kmongo-jackson-mapping/src/test/resources/META-INF/services/org.litote.jackson.JacksonModuleServiceLoader: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.util.JacksonModuleServiceLoaderTest -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/benchmark1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/benchmark1.png -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/benchmark2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/benchmark2.png -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/benchmark3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/benchmark3.png -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/benchmark4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/benchmark4.png -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/favicon.ico -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/favicon.png -------------------------------------------------------------------------------- /kmongo-kdoc/docs/assets/images/kmongo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Litote/kmongo/b2dc3094bbbb1dea718124322e9723b0d34debea/kmongo-kdoc/docs/assets/images/kmongo.png -------------------------------------------------------------------------------- /kmongo-kdoc/mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: 'KMongo' 2 | site_description: 'KMongo: a Kotlin toolkit for Mongo' 3 | site_author: 'litote.org' 4 | site_url: 'https://litote.org/kmongo/' 5 | repo_name: 'kmongo' 6 | repo_url: 'https://github.com/Litote/kmongo' 7 | edit_uri: '' 8 | nav: 9 | - Introduction: index.md 10 | - Quick Start: quick-start.md 11 | - Extensions Overview: extensions-overview.md 12 | - Object Mapping: object-mapping.md 13 | - Typed Queries: typed-queries.md 14 | - Mongo shell support: mongo-shell-support.md 15 | - Performance: performance.md 16 | - About: about.md 17 | theme: 18 | name: 'material' 19 | favicon: 'assets/images/favicon.png' 20 | logo: 'assets/images/favicon.png' 21 | markdown_extensions: 22 | - admonition 23 | - codehilite 24 | - toc: 25 | permalink: true 26 | copyright: 'Copyright © 2016/2022 Litote' 27 | -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/kotlin/org/bson/codecs/pojo/Convention2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.bson.codecs.pojo; 18 | 19 | /** 20 | * Copied from mongo driver 21 | */ 22 | interface Convention2 { 23 | void apply(ClassModelBuilder2 classModelBuilder); 24 | } 25 | -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/kotlin/org/bson/codecs/pojo/ConventionDefaultsImpl2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.bson.codecs.pojo; 18 | 19 | /** 20 | * Copied from mongo driver 21 | */ 22 | final class ConventionDefaultsImpl2 implements Convention2 { 23 | 24 | public void apply(final ClassModelBuilder2 classModelBuilder) { 25 | if (classModelBuilder.getDiscriminatorKey() == null) { 26 | classModelBuilder.discriminatorKey("_t"); 27 | } 28 | if (classModelBuilder.getDiscriminator() == null && classModelBuilder.getType() != null) { 29 | classModelBuilder.discriminator(classModelBuilder.getType().getName()); 30 | } 31 | 32 | for (final PropertyModelBuilder propertyModel : classModelBuilder.getPropertyModelBuilders()) { 33 | if (classModelBuilder.getIdPropertyName() == null) { 34 | String propertyName = propertyModel.getName(); 35 | if (propertyName.equals("_id") || propertyName.equals("id")) { 36 | classModelBuilder.idPropertyName(propertyName); 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/kotlin/org/bson/codecs/pojo/EmptyObjectConvention.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.bson.codecs.pojo 18 | 19 | /** 20 | * 21 | */ 22 | internal class EmptyObjectConvention : Convention2 { 23 | 24 | override fun apply(classModelBuilder: ClassModelBuilder2<*>) { 25 | //if there is no property, the pojo model is not usable. This is a mongo driver bug, but until they fix it... 26 | if (classModelBuilder.propertyModelBuilders.isEmpty()) { 27 | val name = "toString" 28 | val typeData = TypeData.builder(String::class.java).build() 29 | val propertyMetadata = PropertyMetadata(name, classModelBuilder.type.simpleName, typeData) 30 | 31 | classModelBuilder.addProperty( 32 | PropertyModel.builder() 33 | .propertyName(name) 34 | .readName(name) 35 | .typeData(typeData) 36 | .propertySerialization(PropertyModelSerializationImpl()) 37 | .propertyAccessor(PropertyAccessorImpl(propertyMetadata)) 38 | ) 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/kotlin/org/bson/codecs/pojo/EnumCodec.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.bson.codecs.pojo 18 | 19 | import org.bson.BsonReader 20 | import org.bson.BsonWriter 21 | import org.bson.codecs.Codec 22 | import org.bson.codecs.DecoderContext 23 | import org.bson.codecs.EncoderContext 24 | 25 | /** 26 | * 27 | */ 28 | internal class EnumCodec>(private val clazz: Class) : Codec { 29 | 30 | companion object { 31 | @Suppress("UPPER_BOUND_VIOLATED", "UNCHECKED_CAST") 32 | fun newCodec(clazz: Class) : EnumCodec<*> = EnumCodec(clazz as Class>) 33 | } 34 | 35 | override fun encode(writer: BsonWriter, value: T, encoderContext: EncoderContext) { 36 | writer.writeString(value.name) 37 | } 38 | 39 | override fun getEncoderClass(): Class { 40 | return clazz 41 | } 42 | 43 | override fun decode(reader: BsonReader, decoderContext: DecoderContext): T { 44 | return java.lang.Enum.valueOf(clazz, reader.readString()) as T 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/kotlin/org/bson/codecs/pojo/KotlinInstanceCreatorFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.bson.codecs.pojo 18 | 19 | import org.bson.codecs.pojo.KMongoConvention.Companion.getInstantiator 20 | import kotlin.reflect.KClass 21 | import kotlin.reflect.jvm.isAccessible 22 | 23 | /** 24 | * 25 | */ 26 | internal class KotlinInstanceCreatorFactory(val kClass: KClass) : InstanceCreatorFactory { 27 | 28 | private val instantiator = getInstantiator(kClass)?.apply { isAccessible = true } 29 | 30 | override fun create(): InstanceCreator { 31 | return KotlinInstanceCreator(kClass, instantiator ?: error("No instantiator found for $kClass")) 32 | } 33 | } -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/kotlin/org/bson/codecs/pojo/MissingKotlinParameterException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.bson.codecs.pojo 18 | 19 | /** 20 | * 21 | */ 22 | internal class MissingKotlinParameterException(message:String) : RuntimeException(message) { 23 | } -------------------------------------------------------------------------------- /kmongo-native-mapping/src/main/resources/META-INF/services/org.litote.kmongo.service.ClassMappingTypeService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.pojo.PojoClassMappingTypeService -------------------------------------------------------------------------------- /kmongo-native-mapping/src/test/kotlin/org/litote/kmongo/pojo/PojoClassMappingTypeServiceTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.pojo 18 | 19 | import org.bson.codecs.pojo.annotations.BsonId 20 | import org.bson.codecs.pojo.annotations.BsonProperty 21 | import org.junit.Test 22 | import kotlin.test.assertEquals 23 | 24 | /** 25 | * 26 | */ 27 | class PojoClassMappingTypeServiceTest { 28 | 29 | data class AnnotatedData(@BsonProperty("other") val property: String, @BsonId val key: String) 30 | 31 | @Test 32 | fun `getPath handles well @JsonProperty and @BsonId`() { 33 | val service = PojoClassMappingTypeService() 34 | assertEquals( 35 | "other", 36 | service.getPath(AnnotatedData::property) 37 | ) 38 | assertEquals( 39 | "_id", 40 | service.getPath(AnnotatedData::key) 41 | ) 42 | } 43 | } -------------------------------------------------------------------------------- /kmongo-property/src/main/kotlin/kotlin/internal/Annotations.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package kotlin.internal 18 | 19 | @Target(AnnotationTarget.TYPE_PARAMETER) 20 | @Retention(AnnotationRetention.BINARY) 21 | internal annotation class OnlyInputTypes -------------------------------------------------------------------------------- /kmongo-property/src/main/kotlin/org/litote/kmongo/Documents.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.bson.Document 20 | import kotlin.reflect.KProperty 21 | 22 | /** 23 | * Find the value for the specified path from the document. 24 | */ 25 | fun Document.findValue(property: KProperty): T? = findValue(property.path()) 26 | 27 | -------------------------------------------------------------------------------- /kmongo-property/src/main/kotlin/org/litote/kmongo/SetTo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import kotlin.reflect.KProperty 20 | 21 | /** 22 | * A property set to a new value used in update operations. 23 | */ 24 | data class SetTo(val property: KProperty, val value: T?) -------------------------------------------------------------------------------- /kmongo-property/src/test/kotlin/org/litote/kmongo/MockedClassMappingTypeService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.bson.BsonDocument 20 | import org.bson.codecs.configuration.CodecRegistry 21 | import org.litote.kmongo.service.ClassMappingTypeService 22 | import kotlin.reflect.KClass 23 | import kotlin.reflect.KProperty 24 | import kotlin.reflect.KProperty1 25 | 26 | /** 27 | * 28 | */ 29 | class MockedClassMappingTypeService : ClassMappingTypeService { 30 | 31 | override fun priority(): Int { 32 | return 1000 33 | } 34 | 35 | override fun filterIdToBson(obj: Any, filterNullProperties: Boolean): BsonDocument = error("not implemented") 36 | 37 | override fun toExtendedJson(obj: Any?): String = error("not implemented") 38 | 39 | override fun findIdProperty(type: KClass<*>): KProperty1<*, *> = error("not implemented") 40 | 41 | override fun getIdValue(idProperty: KProperty1, instance: T): R = error("not implemented") 42 | 43 | override fun coreCodecRegistry(baseCodecRegistry: CodecRegistry): CodecRegistry = error("not implemented") 44 | 45 | override fun calculatePath(property: KProperty): String = property.name 46 | } -------------------------------------------------------------------------------- /kmongo-property/src/test/kotlin/org/litote/kmongo/ProjectionTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.junit.Test 20 | import kotlin.test.assertEquals 21 | 22 | /** 23 | * 24 | */ 25 | class ProjectionTest { 26 | 27 | class ProjectionData(val s: String) 28 | 29 | @Test 30 | fun testProjectionWith() { 31 | assertEquals("\$s.a", ProjectionData::s.projectionWith("a")) 32 | } 33 | } -------------------------------------------------------------------------------- /kmongo-property/src/test/kotlin/org/litote/kmongo/Tests.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.bson.BsonDocument 20 | import org.bson.codecs.BsonValueCodecProvider 21 | import org.bson.codecs.DocumentCodecProvider 22 | import org.bson.codecs.IterableCodecProvider 23 | import org.bson.codecs.ValueCodecProvider 24 | import org.bson.codecs.configuration.CodecRegistries 25 | import org.bson.conversions.Bson 26 | 27 | private val DEFAULT_REGISTRY = 28 | CodecRegistries.fromProviders( 29 | listOf( 30 | ValueCodecProvider(), 31 | BsonValueCodecProvider(), 32 | DocumentCodecProvider(), 33 | IterableCodecProvider() 34 | ) 35 | ) 36 | 37 | val Bson.document: BsonDocument get() = toBsonDocument(BsonDocument::class.java, DEFAULT_REGISTRY) 38 | -------------------------------------------------------------------------------- /kmongo-property/src/test/kotlin/org/litote/kmongo/UpdatesTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.junit.Test 20 | 21 | /** 22 | * 23 | */ 24 | class UpdatesTest { 25 | 26 | class T(val s: List) 27 | 28 | @Test 29 | fun `addEachToSet works with Iterable sub interface`() { 30 | //check this compile 31 | T::s all setOf("test") 32 | } 33 | } -------------------------------------------------------------------------------- /kmongo-property/src/test/resources/META-INF/services/org.litote.kmongo.service.ClassMappingTypeService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.MockedClassMappingTypeService -------------------------------------------------------------------------------- /kmongo-reactor-core/src/main/kotlin/org/litote/kmongo/reactor/Publishers.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.reactor 18 | 19 | import org.reactivestreams.Publisher 20 | import reactor.kotlin.core.publisher.toFlux 21 | import reactor.kotlin.core.publisher.toMono 22 | 23 | /** 24 | * Subscribes to and awaits the termination of this [Publisher] instance in a blocking manner and rethrows any exception emitted. 25 | * 26 | * @throws RuntimeException wrapping an InterruptedException if the current thread is interrupted 27 | */ 28 | fun Publisher<*>.blockLast(): Any? = toFlux().blockLast() 29 | 30 | /** 31 | * Waits in a blocking fashion until the current Single signals a success value, null (which is returned) or an exception (which is propagated). 32 | * @return the success value or null 33 | */ 34 | fun Publisher.block(): T? = toMono().block() 35 | -------------------------------------------------------------------------------- /kmongo-serialization-mapping/src/main/kotlin/Properties.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.serialization 18 | 19 | import org.litote.kmongo.path 20 | import kotlin.reflect.KProperty 21 | import kotlin.reflect.KClass 22 | 23 | /** 24 | * Provides the path for subtype discriminator, in order to write this kind of filter: 25 | * 26 | * ```eq(subtypePath, B::class.subtypeQualifier)``` 27 | */ 28 | val subtypePath: String get() = configuration.classDiscriminator 29 | 30 | /** 31 | * Provides the path for subtype discriminator, in order to write this kind of filter: 32 | * 33 | * ```eq(A::myProperty.subtypePath, B::class.subtypeQualifier)``` 34 | */ 35 | val KProperty<*>.subtypePath: String get() = "${path()}.${configuration.classDiscriminator}" 36 | 37 | /** 38 | * Provides the value of subtype discriminator. 39 | */ 40 | val KClass<*>.subtypeQualifier: String get() = qualifiedName ?: error("no qualified name for class $this") -------------------------------------------------------------------------------- /kmongo-serialization-mapping/src/main/kotlin/SerializationCodecRegistry.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.serialization 18 | 19 | import com.github.jershell.kbson.Configuration 20 | import org.bson.codecs.Codec 21 | import org.bson.codecs.configuration.CodecRegistry 22 | 23 | /** 24 | * 25 | */ 26 | internal class SerializationCodecRegistry(private val configuration: Configuration) : CodecRegistry { 27 | 28 | override fun get(clazz: Class): Codec = SerializationCodec(clazz.kotlin, configuration) 29 | 30 | override fun get(clazz: Class, codecRegistry: CodecRegistry): Codec = get(clazz) 31 | } -------------------------------------------------------------------------------- /kmongo-serialization-mapping/src/main/resources/META-INF/services/org.litote.kmongo.service.ClassMappingTypeService: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.serialization.SerializationClassMappingTypeService -------------------------------------------------------------------------------- /kmongo-serialization/src/test/kotlin/Issue167TransientNotWorking.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.issues 17 | 18 | import kotlinx.serialization.Serializable 19 | import org.bson.Document 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.findOne 23 | import org.litote.kmongo.withDocumentClass 24 | import kotlin.test.assertEquals 25 | import kotlin.test.assertNull 26 | 27 | @Serializable 28 | data class ClassWithDelegatedProperty(val lastname: String, val firstname: String) { 29 | val fullName: String 30 | get() = "${lastname} ${firstname}" 31 | } 32 | 33 | /** 34 | * 35 | */ 36 | class Issue167TransientNotWorking : AllCategoriesKMongoBaseTest() { 37 | 38 | @Test 39 | fun canFindOne() { 40 | col.insertOne(ClassWithDelegatedProperty("John", "Doe")) 41 | val doc = col.withDocumentClass().findOne() 42 | assertEquals("John", doc?.getString("lastname")) 43 | assertEquals("Doe", doc?.getString("firstname")) 44 | assertNull(doc?.getString("fullName")) 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /kmongo-serialization/src/test/kotlin/Issue310SealedInterfaceSerializer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Serializable 20 | import org.junit.Ignore 21 | import org.junit.Test 22 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 23 | import org.litote.kmongo.findOne 24 | import kotlin.test.assertEquals 25 | 26 | @Serializable 27 | sealed interface Foo { 28 | @Serializable 29 | data class FooA(val x: Int) : Foo 30 | @Serializable 31 | data class FooB(val x: Double) : Foo 32 | @Serializable 33 | data class FooC(val z: String) : Foo 34 | } 35 | 36 | /** 37 | * 38 | */ 39 | class Issue310SealedInterfaceSerializer : AllCategoriesKMongoBaseTest() { 40 | 41 | @Ignore 42 | @Test 43 | fun insertAndLoad() { 44 | val fooA = Foo.FooA(1) 45 | col.insertOne(fooA) 46 | assertEquals(fooA, col.findOne()) 47 | } 48 | } -------------------------------------------------------------------------------- /kmongo-serialization/src/test/kotlin/Issue354KotlinIdFieldIgnored.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import kotlinx.serialization.Contextual 20 | import kotlinx.serialization.SerialName 21 | import kotlinx.serialization.Serializable 22 | import org.bson.Document 23 | import org.bson.types.ObjectId 24 | import org.junit.Test 25 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 26 | import org.litote.kmongo.findOne 27 | import org.litote.kmongo.withDocumentClass 28 | import kotlin.test.assertEquals 29 | import kotlin.test.assertNull 30 | 31 | @Serializable 32 | data class TestData(@SerialName("_id") @Contextual val id: ObjectId = ObjectId(), val value: String) 33 | 34 | /** 35 | * 36 | */ 37 | class Issue354KotlinIdFieldIgnored : AllCategoriesKMongoBaseTest() { 38 | 39 | @Test 40 | fun testSerialization() { 41 | val test = TestData(value = "Foo") 42 | 43 | col.insertOne(test) 44 | val test2 = col.findOne() 45 | 46 | assertEquals(test, test2) 47 | 48 | val doc = col.withDocumentClass().findOne() 49 | assertEquals(test.id, doc?.get("_id")) 50 | assertNull(doc?.get("id")) 51 | } 52 | } -------------------------------------------------------------------------------- /kmongo-serialization/src/test/kotlin/Issue415SerialName.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.issues 2 | 3 | import kotlinx.serialization.SerialName 4 | import kotlinx.serialization.Serializable 5 | import org.junit.Test 6 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 7 | import org.litote.kmongo.MongoOperator.set 8 | import org.litote.kmongo.model.Friend 9 | import org.litote.kmongo.pos 10 | import org.litote.kmongo.setValue 11 | import kotlin.test.assertEquals 12 | 13 | @Serializable 14 | data class BookEpisode( 15 | 16 | @SerialName("paragraphsZh") 17 | val baiduParagraphs: List?, 18 | val youdaoParagraphs: List? = null, 19 | ) 20 | 21 | class Issue415SerialName : AllCategoriesKMongoBaseTest() { 22 | 23 | @Test 24 | fun `test insert and load`() { 25 | assertEquals( 26 | "{\"$set\": {\"youdaoParagraphs.0\": \"test\"}}", 27 | setValue(BookEpisode::youdaoParagraphs.pos(0), "test").toBsonDocument().toString() 28 | ) 29 | assertEquals( 30 | "{\"$set\": {\"paragraphsZh.0\": \"test\"}}", 31 | setValue(BookEpisode::baiduParagraphs.pos(0), "test").toBsonDocument().toString() 32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /kmongo-shared-tests-java/src/main/java/org/litote/kmongo/issues/AbstractWithObjectId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues; 18 | 19 | import org.bson.codecs.pojo.annotations.BsonId; 20 | import org.bson.types.ObjectId; 21 | 22 | /** 23 | * 24 | */ 25 | public abstract class AbstractWithObjectId { 26 | 27 | @BsonId 28 | protected ObjectId id; 29 | 30 | public ObjectId getID() { 31 | return id; 32 | } 33 | 34 | public AbstractWithObjectId setID(final ObjectId id) { 35 | this.id = id; 36 | return this; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /kmongo-shared-tests-java/src/main/java/org/litote/kmongo/issues/Foo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues; 18 | 19 | /** 20 | * 21 | */ 22 | public class Foo extends AbstractWithObjectId { 23 | } 24 | -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/CoreCategory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * 21 | */ 22 | interface CoreCategory { 23 | } -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/JacksonMappingCategory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * 21 | */ 22 | interface JacksonMappingCategory { 23 | } -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/KMongoRootTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * 21 | */ 22 | abstract class KMongoRootTest -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/NativeMappingCategory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * 21 | */ 22 | interface NativeMappingCategory { 23 | } -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/SerializationMappingCategory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | /** 20 | * 21 | */ 22 | interface SerializationMappingCategory -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/model/Coordinate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.model 17 | 18 | import kotlinx.serialization.Serializable 19 | 20 | /** 21 | * 22 | */ 23 | @Serializable 24 | data class Coordinate(val lat: Int, val lng: Int) -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/model/ExposableFriend.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | import kotlinx.serialization.Serializable 20 | 21 | /** 22 | * 23 | */ 24 | @Serializable 25 | data class ExposableFriend(val _id: String, val name: String) -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/model/Friend.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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.litote.kmongo.model 17 | 18 | import kotlinx.serialization.Contextual 19 | import kotlinx.serialization.Serializable 20 | import org.bson.types.ObjectId 21 | import java.time.Instant 22 | 23 | /** 24 | * 25 | */ 26 | @Serializable 27 | data class Friend( 28 | var name: String?, 29 | val address: String?, 30 | @Contextual 31 | val _id: ObjectId? = null, 32 | val coordinate: Coordinate? = null, 33 | val tags: List = emptyList(), 34 | @Contextual 35 | val creationDate: Instant? = null 36 | ) { 37 | 38 | constructor(name: String) : this(name, null, null) 39 | 40 | constructor(name: String?, coordinate: Coordinate) : this(name, null, null, coordinate) 41 | 42 | constructor(_id: ObjectId, name: String) : this(name, null, _id) 43 | } -------------------------------------------------------------------------------- /kmongo-shared-tests/src/main/kotlin/org/litote/kmongo/model/FriendContainer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.model 18 | 19 | import kotlinx.serialization.Serializable 20 | 21 | /** 22 | * 23 | */ 24 | @Serializable 25 | data class FriendContainer(val friend: Friend) -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/MongoUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import org.bson.RawBsonDocument 20 | import org.bson.conversions.Bson 21 | import org.litote.kmongo.util.KMongoUtil 22 | 23 | /** 24 | * An immutable empty [Bson]. 25 | */ 26 | val EMPTY_BSON: Bson = RawBsonDocument.parse(KMongoUtil.EMPTY_JSON) 27 | -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/IdTransformer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.bson.types.ObjectId 20 | import org.litote.kmongo.Id 21 | 22 | /** 23 | * To manage id wrapped value. 24 | */ 25 | object IdTransformer { 26 | 27 | fun unwrapId(id: Id<*>): Any { 28 | return when (id) { 29 | is StringId -> id.id 30 | is WrappedObjectId -> id.id 31 | else -> error("unsupported id type $id") 32 | } 33 | } 34 | 35 | fun wrapId(id: Any): Id<*> { 36 | return when (id) { 37 | is String -> StringId(id) 38 | is ObjectId -> WrappedObjectId(id) 39 | else -> error("unsupported id type $id") 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/Ids.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.bson.types.ObjectId 20 | import org.litote.kmongo.Id 21 | 22 | /** 23 | * Create a new [Id] from the current [ObjectId]. 24 | */ 25 | fun ObjectId.toId(): Id = WrappedObjectId(this) -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/MongoId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | /** 20 | * Annotate mongo identifier property for kotlinx.serialization. 21 | */ 22 | @Deprecated("no longer required - use @SerialName(_id)") 23 | @Target(AnnotationTarget.PROPERTY) 24 | annotation class MongoId -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/MongoProperty.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | /** 20 | * Annotate mongo property name for kotlinx.serialization. 21 | */ 22 | @Deprecated("no longer required - use @SerialName(myPropertyName)") 23 | @Target(AnnotationTarget.PROPERTY) 24 | annotation class MongoProperty(val value: String) -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/ObjectIdGenerator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.bson.types.ObjectId 20 | import org.litote.kmongo.Id 21 | import kotlin.reflect.KClass 22 | 23 | /** 24 | * [ObjectId] generator. 25 | */ 26 | object ObjectIdGenerator : IdGenerator { 27 | 28 | /** 29 | * Generates a new WrappedObjectId. 30 | */ 31 | fun newObjectId(): WrappedObjectId = ObjectIdGenerator.generateNewId() 32 | 33 | override val idClass: KClass> = WrappedObjectId::class 34 | 35 | override val wrappedIdClass: KClass = ObjectId::class 36 | 37 | override fun generateNewId(): WrappedObjectId = WrappedObjectId(ObjectId()) 38 | 39 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/ObjectIdGeneratorProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | /** 20 | * 21 | */ 22 | internal class ObjectIdGeneratorProvider : IdGeneratorProvider { 23 | 24 | override val priority: Int = 1 25 | 26 | override val generator: IdGenerator = ObjectIdGenerator 27 | 28 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/ObjectIdToStringGenerator.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.bson.types.ObjectId 20 | import org.litote.kmongo.Id 21 | import kotlin.reflect.KClass 22 | 23 | /** 24 | * [ObjectId] based String generator. 25 | */ 26 | object ObjectIdToStringGenerator : IdGenerator { 27 | 28 | /** 29 | * Generates a new StringId. 30 | */ 31 | fun newStringId(): StringId = ObjectIdToStringGenerator.generateNewId() 32 | 33 | override val idClass: KClass> = StringId::class 34 | 35 | override val wrappedIdClass: KClass = String::class 36 | 37 | override fun generateNewId(): StringId = StringId(ObjectId().toHexString()) 38 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/id/WrappedObjectId.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.id 18 | 19 | import org.bson.types.ObjectId 20 | import org.litote.kmongo.Id 21 | 22 | /** 23 | * An [Id] containing a [ObjectId]. 24 | */ 25 | data class WrappedObjectId(val id: ObjectId) : Id { 26 | 27 | constructor(id: String) : this(ObjectId(id)) 28 | 29 | override fun toString(): String { 30 | return id.toString() 31 | } 32 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/service/MongoClientProvider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.service 18 | 19 | import com.mongodb.ConnectionString 20 | import java.io.Closeable 21 | import java.util.ServiceLoader 22 | 23 | /** 24 | * Provides a MongoClient class. Common interface for sync and async driver. 25 | * This object is mainly used for tests. 26 | */ 27 | object MongoClientProvider { 28 | 29 | /** 30 | * Create a new client with the given connection string. 31 | * 32 | * @param connectionString the settings 33 | * @return the client 34 | */ 35 | inline fun createMongoClient(connectionString: ConnectionString): T { 36 | return ServiceLoader 37 | .load(MongoClientProviderService::class.java) 38 | .map { it.createMongoClient(connectionString) } 39 | .filterIsInstance() 40 | .first() 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/service/MongoClientProviderService.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.service 18 | 19 | import com.mongodb.ConnectionString 20 | import java.io.Closeable 21 | 22 | /** 23 | * Provides a MongoClient class using [java.util.ServiceLoader]. 24 | */ 25 | interface MongoClientProviderService { 26 | 27 | /** 28 | * Create a new client with the given connection string. 29 | * 30 | * @param connectionString the settings 31 | * @return the client 32 | */ 33 | fun createMongoClient(connectionString: ConnectionString): T 34 | 35 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/util/KotlinxDatetimeLoader.kt: -------------------------------------------------------------------------------- 1 | package org.litote.kmongo.util 2 | 3 | object KotlinxDatetimeLoader { 4 | private var hasLoaded = false 5 | private var isExistInClassLoader = false 6 | 7 | /** 8 | * Call Class.forName multiple times can cause severe perf issue 9 | * if dependency kotlinx doesn't exist in project implement KMongo. 10 | * So we load it only on first time and return nothing if class not exist. 11 | */ 12 | fun loadKotlinxDateTime(loadSerializersAndDeserializers: () -> T, empty: () -> T): T { 13 | return try { 14 | if (!hasLoaded) { 15 | hasLoaded = true 16 | Class.forName("kotlinx.datetime.Instant") 17 | isExistInClassLoader = true 18 | } 19 | 20 | if (!isExistInClassLoader) { 21 | return empty() 22 | } 23 | 24 | loadSerializersAndDeserializers() 25 | } catch (e: ClassNotFoundException) { 26 | isExistInClassLoader = false 27 | empty() 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/kotlin/org/litote/kmongo/util/UpdateConfiguration.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.util 18 | 19 | /** 20 | * Default update operations configuration. 21 | */ 22 | object UpdateConfiguration { 23 | 24 | /** 25 | * If set to true, only not null properties are updated. 26 | * If set to false (default value), null properties are updated to null. 27 | */ 28 | @Volatile 29 | var updateOnlyNotNullProperties: Boolean = false 30 | } -------------------------------------------------------------------------------- /kmongo-shared/src/main/resources/META-INF/services/org.litote.kmongo.id.IdGeneratorProvider: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016/2022 Litote 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 | # http://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 | 17 | org.litote.kmongo.id.ObjectIdGeneratorProvider -------------------------------------------------------------------------------- /kmongo/src/test/kotlin/org/litote/kmongo/NullPropertyTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo 18 | 19 | import com.fasterxml.jackson.annotation.JsonInclude 20 | import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL 21 | import junit.framework.Assert.assertFalse 22 | import org.bson.Document 23 | import org.junit.Test 24 | import org.litote.kmongo.NullPropertyTest.Test1 25 | 26 | /** 27 | * 28 | */ 29 | class NullPropertyTest : AllCategoriesKMongoBaseTest() { 30 | 31 | data class Test1(@JsonInclude(NON_NULL) val nullableProperty: String? = null) 32 | 33 | 34 | @Test 35 | fun testFindAndUpdate() { 36 | col.insertOne(Test1()) 37 | assertFalse(col.withDocumentClass().findOne()!!.containsKey("nullableProperty")) 38 | } 39 | } -------------------------------------------------------------------------------- /kmongo/src/test/kotlin/org/litote/kmongo/issues/Issue371CustomEnum.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import com.fasterxml.jackson.annotation.JsonValue 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.eq 23 | import org.litote.kmongo.from 24 | import org.litote.kmongo.save 25 | import kotlin.test.assertEquals 26 | 27 | data class Stop(val type: StopType) 28 | 29 | enum class StopType(@JsonValue val value: Int) { 30 | STATION(1), 31 | // ... 32 | } 33 | 34 | /** 35 | * 36 | */ 37 | class Issue371CustomEnum : 38 | AllCategoriesKMongoBaseTest() { 39 | 40 | @Test 41 | fun `serialization and deserialization is ok`() { 42 | val s = Stop(StopType.STATION) 43 | col.save(s) 44 | val l = col.find(Stop::type from StopType.STATION.value).toList() 45 | assertEquals(listOf(s), l) 46 | } 47 | 48 | @Test 49 | fun `serialization and deserialization is really ok`() { 50 | val s = Stop(StopType.STATION) 51 | col.save(s) 52 | val l = col.find(Stop::type eq StopType.STATION).toList() 53 | assertEquals(listOf(s), l) 54 | } 55 | } -------------------------------------------------------------------------------- /kmongo/src/test/kotlin/org/litote/kmongo/issues/Issue58PropertyIdHasDifferentDatatype.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016/2022 Litote 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 | * http://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 | 17 | package org.litote.kmongo.issues 18 | 19 | import org.bson.types.ObjectId 20 | import org.junit.Test 21 | import org.litote.kmongo.AllCategoriesKMongoBaseTest 22 | import org.litote.kmongo.findOneById 23 | import org.litote.kmongo.save 24 | import kotlin.test.assertEquals 25 | 26 | /** 27 | * 28 | */ 29 | class Issue58PropertyIdHasDifferentDatatype : AllCategoriesKMongoBaseTest() { 30 | 31 | @Test 32 | fun testFindOneById() { 33 | val foo = Foo().apply { id = ObjectId() } 34 | col.save(foo) 35 | 36 | assertEquals(foo.id, col.findOneById(foo.id)?.id) 37 | } 38 | 39 | @Test 40 | fun testSaveObjectWithNullId() { 41 | val foo = Foo() 42 | col.save(foo) 43 | 44 | assertEquals(foo.id, col.findOneById(foo.id)?.id) 45 | } 46 | } --------------------------------------------------------------------------------