From fbf080af871d0c57d9f17743ed58e83e20de0a05 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Mon, 19 Feb 2024 23:03:08 +0530 Subject: [PATCH 01/13] Squashed commit of the following: commit 75d82226f89bc022af2e2ba52fea5fcc52144a57 Author: Anindya Chatterjee Date: Mon Feb 19 23:02:09 2024 +0530 update workflow commit 69bd68aad973f1f046d5421273bdbe33888ab0b5 Author: Anindya Chatterjee Date: Mon Feb 19 22:55:20 2024 +0530 Update CHANGELOG.md commit 7b7f014afad979f9e74f840953009c4e9598f0ed Author: Anindya Chatterjee Date: Mon Feb 19 21:29:38 2024 +0530 Release 4.2.1 commit 9ec33075b7cf1ba13fdc80e6dca9d7c6276eafed Merge: 77c8d4c2 78130924 Author: Anindya Chatterjee Date: Mon Feb 19 21:13:25 2024 +0530 Merge branch 'develop' into release commit 78130924c94c8f4396938981bbc637aee2f45b91 Merge: 20a10eeb 029d5cfc Author: Anindya Chatterjee Date: Fri Feb 16 21:33:52 2024 +0530 Merge branch 'main' into develop commit 20a10eeb4e9580c3c6d9a86e6a31285adc64973a Author: Anindya Chatterjee <696662+anidotnet@users.noreply.github.com> Date: Fri Jan 19 10:02:04 2024 +0530 Publish 4.2.1 SNAPSHOT for 8-Jan (#898) * merged to main (#890) * Update CHANGELOG.md * Update release.yml * Update release.yml * Update CHANGELOG.md * Update pom.xml * Update pom.xml (#891) * Update README.md * Bump uk.co.jemos.podam:podam from 8.0.0.RELEASE to 8.0.1.RELEASE (#893) Bumps [uk.co.jemos.podam:podam](https://github.com/mtedone/podam) from 8.0.0.RELEASE to 8.0.1.RELEASE. - [Release notes](https://github.com/mtedone/podam/releases) - [Commits](https://github.com/mtedone/podam/compare/8.0.0.RELEASE...8.0.1.RELEASE) --- updated-dependencies: - dependency-name: uk.co.jemos.podam:podam dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump joda-time:joda-time from 2.12.5 to 2.12.6 (#894) Bumps [joda-time:joda-time](https://github.com/JodaOrg/joda-time) from 2.12.5 to 2.12.6. - [Release notes](https://github.com/JodaOrg/joda-time/releases) - [Changelog](https://github.com/JodaOrg/joda-time/blob/main/RELEASE-NOTES.txt) - [Commits](https://github.com/JodaOrg/joda-time/compare/v2.12.5...v2.12.6) --- updated-dependencies: - dependency-name: joda-time:joda-time dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.3 to 3.2.5 (#896) Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.3 to 3.2.5. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.3...surefire-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.slf4j:slf4j-api from 2.0.10 to 2.0.11 (#895) Bumps org.slf4j:slf4j-api from 2.0.10 to 2.0.11. --- updated-dependencies: - dependency-name: org.slf4j:slf4j-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.mockito:mockito-core from 5.8.0 to 5.9.0 (#897) Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.8.0 to 5.9.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.8.0...v5.9.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> commit 3bc6918dbfc69163f4a744496fe44729a69ad285 Merge: d981831d 87793b1f Author: Anindya Chatterjee Date: Sat Jan 6 17:40:17 2024 +0530 Merge branch 'main' into develop commit 77c8d4c21ff242c670bf48489bdf7968dc428f3c Merge: 94334252 86ab638e Author: Anindya Chatterjee Date: Sat Jan 6 16:40:42 2024 +0530 Merge branch 'main' into release commit 94334252b43a95705d58991370609e1514811289 Merge: 54ce9c27 00c8448a Author: Anindya Chatterjee Date: Sat Jan 6 16:00:31 2024 +0530 Merge branch 'main' into release commit 54ce9c27239faf89d6fdcb67584cca0442029a06 Merge: 753dac24 52381dfa Author: Anindya Chatterjee Date: Fri Jan 5 22:41:24 2024 +0530 Merge branch 'main' into release commit 753dac2414da3d92f799ebb09763c42b647f615f Merge: 246875ee 40dfd18f Author: Anindya Chatterjee Date: Fri Jan 5 22:35:10 2024 +0530 Merge branch 'main' into release commit 246875eec0003c31935293fd49e7420f0a69699c Merge: f33d56b5 1bd1074b Author: Anindya Chatterjee Date: Fri Jan 5 22:05:53 2024 +0530 Merge branch 'main' into release commit f33d56b506a2334243a4173a3c80c475f573c22d Merge: 3431fe16 7d3ccf7d Author: Anindya Chatterjee Date: Fri Jan 5 21:55:03 2024 +0530 Merge branch 'main' into release commit 3431fe169705e0b71b3ec566e93400ce6dc8832c Merge: 3293c3fd 77cfe1b1 Author: Anindya Chatterjee Date: Fri Jan 5 21:27:48 2024 +0530 Merge branch 'main' into release commit 3293c3fde1373bb3295d3bb00a7db05d43e7905e Merge: 741b1fc8 ce445627 Author: Anindya Chatterjee Date: Fri Jan 5 13:25:48 2024 +0530 Merge branch 'main' into release commit 741b1fc8f6a45f2d98cb7fe776c689236de8afce Merge: 82635050 53b256dc Author: Anindya Chatterjee Date: Fri Jan 5 11:56:38 2024 +0530 Merge branch 'main' into release commit 82635050de6bcbce39bbdc4093c38c3ae4c80675 Merge: 04249886 ffcf79fc Author: Anindya Chatterjee Date: Fri Jan 5 11:02:11 2024 +0530 Merge branch 'main' into release commit 04249886ed6c18e05906712646aadb788503b83d Merge: f9a8f490 0e5a0cbc Author: Anindya Chatterjee Date: Fri Jan 5 10:49:15 2024 +0530 Merge branch 'main' into release commit f9a8f490d264efcd10f899d765ece9894c43426b Author: Anindya Chatterjee <696662+anidotnet@users.noreply.github.com> Date: Fri Jan 5 01:05:15 2024 +0530 Update pom.xml commit e19ddb89e1314c4a9b2f647fd748b54eb2877ccc Merge: 1968b782 5acb37ef Author: Anindya Chatterjee Date: Thu Jan 4 23:22:42 2024 +0530 Merge branch 'main' into release commit 1968b7826dc1860440a2402f3b483ef74e10dc5e Author: Anindya Chatterjee Date: Thu Jan 4 22:28:21 2024 +0530 Update CHANGELOG.md commit 23ddb14d8c3f34cb1df100268bf5f4a75c9e1fff Author: Anindya Chatterjee Date: Thu Jan 4 22:24:08 2024 +0530 Update release.yml commit 2b33c6db04ba015514474d9bf1263de4afb28480 Author: Anindya Chatterjee Date: Thu Jan 4 22:19:01 2024 +0530 Update release.yml commit 457007a690300a458840ac4d88366bf61ddbd534 Merge: 539f49d8 1f004b57 Author: Anindya Chatterjee Date: Thu Jan 4 22:15:53 2024 +0530 Merge branch 'main' into release commit 539f49d8c8cb6469f5ba2696711406479894b795 Merge: 7f4c1398 d6db0823 Author: Anindya Chatterjee Date: Thu Jan 4 22:08:34 2024 +0530 Merge branch 'main' into release commit 7f4c13983cee21f8c35a41d289243a94323d5905 Author: Anindya Chatterjee Date: Thu Jan 4 21:16:20 2024 +0530 Update CHANGELOG.md commit d981831dc1cd884a81efe576d404af2574b11ab0 Merge: bd705845 0990ae12 Author: Anindya Chatterjee Date: Tue Jan 2 11:05:47 2024 +0530 Merge branch 'main' into develop commit bd7058457f5d89835116ef3157380faa911e8084 Merge: 6a4673b9 6a247539 Author: Anindya Chatterjee Date: Sun Oct 1 22:19:50 2023 +0530 Merge branch 'main' into develop commit 6a4673b9a6146ac90a2ee59390a6b623f4b56f22 Author: Anindya Chatterjee <696662+anidotnet@users.noreply.github.com> Date: Sun Oct 1 13:49:07 2023 +0000 Update pom.xml --- .github/workflows/release.yml | 2 ++ .github/workflows/snapshot.yml | 2 ++ CHANGELOG.md | 9 +++++++++ nitrite-bom/pom.xml | 2 +- nitrite-jackson-mapper/pom.xml | 2 +- nitrite-mvstore-adapter/pom.xml | 2 +- nitrite-rocksdb-adapter/pom.xml | 2 +- nitrite-spatial/pom.xml | 2 +- nitrite-support/pom.xml | 2 +- nitrite/pom.xml | 2 +- pom.xml | 2 +- potassium-nitrite/pom.xml | 2 +- 12 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 272ebba5..edb94a0e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,6 +23,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + ref: release - uses: fregante/setup-git-user@v2 - name: Set up JDK 11 uses: actions/setup-java@v4 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 2299bf00..2e4bab89 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -23,6 +23,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + ref: develop - uses: fregante/setup-git-user@v2 - name: Set up JDK 11 uses: actions/setup-java@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2df34372..fd042275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## Release 4.2.1 - Feb 19, 2024 + +### Issue Fixes + +- Fix for #901 +- Fix for #902 +- Version upgrade for several dependencies + ## Release 4.2.0 - Jan 6, 2024 ### New Changes @@ -206,3 +214,4 @@ ## First Release - Apr 25, 2017 - Initial release + diff --git a/nitrite-bom/pom.xml b/nitrite-bom/pom.xml index 99255161..8ec54c47 100644 --- a/nitrite-bom/pom.xml +++ b/nitrite-bom/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite-bom diff --git a/nitrite-jackson-mapper/pom.xml b/nitrite-jackson-mapper/pom.xml index 0753b301..7c5f4197 100644 --- a/nitrite-jackson-mapper/pom.xml +++ b/nitrite-jackson-mapper/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite-jackson-mapper diff --git a/nitrite-mvstore-adapter/pom.xml b/nitrite-mvstore-adapter/pom.xml index b3d43b47..22c318b2 100644 --- a/nitrite-mvstore-adapter/pom.xml +++ b/nitrite-mvstore-adapter/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite-mvstore-adapter diff --git a/nitrite-rocksdb-adapter/pom.xml b/nitrite-rocksdb-adapter/pom.xml index ad0bfd45..677fb35b 100644 --- a/nitrite-rocksdb-adapter/pom.xml +++ b/nitrite-rocksdb-adapter/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite-rocksdb-adapter diff --git a/nitrite-spatial/pom.xml b/nitrite-spatial/pom.xml index 5094d4da..fd58610d 100644 --- a/nitrite-spatial/pom.xml +++ b/nitrite-spatial/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite-spatial diff --git a/nitrite-support/pom.xml b/nitrite-support/pom.xml index 130e4224..26e5b8ee 100644 --- a/nitrite-support/pom.xml +++ b/nitrite-support/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite-support diff --git a/nitrite/pom.xml b/nitrite/pom.xml index 2dbdd71c..1c7fb5bc 100644 --- a/nitrite/pom.xml +++ b/nitrite/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 nitrite diff --git a/pom.xml b/pom.xml index 28743671..209e0f2d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 pom Nitrite Database diff --git a/potassium-nitrite/pom.xml b/potassium-nitrite/pom.xml index 0df7d902..1bddada6 100644 --- a/potassium-nitrite/pom.xml +++ b/potassium-nitrite/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1-SNAPSHOT + 4.2.1 potassium-nitrite From e79b7d1543c6f3e725ced0cc1175ffccd55118c5 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Mon, 19 Feb 2024 23:15:28 +0530 Subject: [PATCH 02/13] Version bumped to 4.2.2-SNAPSHOT --- nitrite-bom/pom.xml | 2 +- nitrite-jackson-mapper/pom.xml | 2 +- nitrite-mvstore-adapter/pom.xml | 2 +- nitrite-rocksdb-adapter/pom.xml | 2 +- nitrite-spatial/pom.xml | 2 +- nitrite-support/pom.xml | 2 +- nitrite/pom.xml | 2 +- pom.xml | 2 +- potassium-nitrite/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nitrite-bom/pom.xml b/nitrite-bom/pom.xml index 8ec54c47..c3e28959 100644 --- a/nitrite-bom/pom.xml +++ b/nitrite-bom/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite-bom diff --git a/nitrite-jackson-mapper/pom.xml b/nitrite-jackson-mapper/pom.xml index 7c5f4197..df293eb8 100644 --- a/nitrite-jackson-mapper/pom.xml +++ b/nitrite-jackson-mapper/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite-jackson-mapper diff --git a/nitrite-mvstore-adapter/pom.xml b/nitrite-mvstore-adapter/pom.xml index 22c318b2..910a6956 100644 --- a/nitrite-mvstore-adapter/pom.xml +++ b/nitrite-mvstore-adapter/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite-mvstore-adapter diff --git a/nitrite-rocksdb-adapter/pom.xml b/nitrite-rocksdb-adapter/pom.xml index 677fb35b..aa194a07 100644 --- a/nitrite-rocksdb-adapter/pom.xml +++ b/nitrite-rocksdb-adapter/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite-rocksdb-adapter diff --git a/nitrite-spatial/pom.xml b/nitrite-spatial/pom.xml index fd58610d..e18183f9 100644 --- a/nitrite-spatial/pom.xml +++ b/nitrite-spatial/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite-spatial diff --git a/nitrite-support/pom.xml b/nitrite-support/pom.xml index 26e5b8ee..1b391494 100644 --- a/nitrite-support/pom.xml +++ b/nitrite-support/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite-support diff --git a/nitrite/pom.xml b/nitrite/pom.xml index 1c7fb5bc..3ce14ef9 100644 --- a/nitrite/pom.xml +++ b/nitrite/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT nitrite diff --git a/pom.xml b/pom.xml index 209e0f2d..7e91c4b9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT pom Nitrite Database diff --git a/potassium-nitrite/pom.xml b/potassium-nitrite/pom.xml index 1bddada6..72068dd1 100644 --- a/potassium-nitrite/pom.xml +++ b/potassium-nitrite/pom.xml @@ -4,7 +4,7 @@ org.dizitart nitrite-java - 4.2.1 + 4.2.2-SNAPSHOT potassium-nitrite From 677cbaedd1b435c39c9174d95865718082d3a544 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:08:55 +0530 Subject: [PATCH 03/13] Bump org.jetbrains.kotlinx:kotlinx-serialization-json (#907) Bumps [org.jetbrains.kotlinx:kotlinx-serialization-json](https://github.com/Kotlin/kotlinx.serialization) from 1.6.2 to 1.6.3. - [Release notes](https://github.com/Kotlin/kotlinx.serialization/releases) - [Changelog](https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md) - [Commits](https://github.com/Kotlin/kotlinx.serialization/compare/v1.6.2...v1.6.3) --- updated-dependencies: - dependency-name: org.jetbrains.kotlinx:kotlinx-serialization-json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7e91c4b9..0a4c74f5 100644 --- a/pom.xml +++ b/pom.xml @@ -61,7 +61,7 @@ 1.16.1 2.15.1 1.9.22 - 1.6.2 + 1.6.3 1.18.30 1.18.20.0 4.13.2 From b09ac64ae57f4cd8e7d9adfce2231f1f3ebc7d1b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:09:05 +0530 Subject: [PATCH 04/13] Bump com.google.errorprone:error_prone_core from 2.24.1 to 2.25.0 (#908) Bumps [com.google.errorprone:error_prone_core](https://github.com/google/error-prone) from 2.24.1 to 2.25.0. - [Release notes](https://github.com/google/error-prone/releases) - [Commits](https://github.com/google/error-prone/compare/v2.24.1...v2.25.0) --- updated-dependencies: - dependency-name: com.google.errorprone:error_prone_core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0a4c74f5..60ba1eeb 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ 33.0.0-jre 1.6.8 - 2.24.1 + 2.25.0 0.8.11 3.2.5 3.12.1 From 338ab6950928a6ff5e16691abdef7c7d7013d546 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 22 Feb 2024 07:40:53 +0530 Subject: [PATCH 05/13] Bump log4j.version from 2.22.1 to 2.23.0 (#910) Bumps `log4j.version` from 2.22.1 to 2.23.0. Updates `org.apache.logging.log4j:log4j-api` from 2.22.1 to 2.23.0 Updates `org.apache.logging.log4j:log4j-slf4j2-impl` from 2.22.1 to 2.23.0 Updates `org.apache.logging.log4j:log4j-core` from 2.22.1 to 2.23.0 --- updated-dependencies: - dependency-name: org.apache.logging.log4j:log4j-api dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.logging.log4j:log4j-slf4j2-impl dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.logging.log4j:log4j-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 60ba1eeb..c6c27a60 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ 4.13.2 5.10.0 8.0.1.RELEASE - 2.22.1 + 2.23.0 4.2.0 2.12.7 2.0.3 From 5ae2040b7af039871d1464be6d8060d70f6e18d6 Mon Sep 17 00:00:00 2001 From: Anton Zhdanov Date: Mon, 26 Feb 2024 06:58:10 +0200 Subject: [PATCH 06/13] #911 kotlinx.serialization DocumentDecoder List element index fix (#913) --- .../dizitart/kno2/serialization/DocumentDecoder.kt | 3 ++- .../kno2/KotlinXSerializationMapperTest.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt index 05572534..63b458b9 100644 --- a/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt +++ b/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/serialization/DocumentDecoder.kt @@ -119,13 +119,14 @@ internal class DocumentDecoder(private val document: Document, descriptor: Seria @OptIn(ExperimentalSerializationApi::class) private class ListDecoder(private val list: ArrayDeque) : AbstractDecoder() { private var elementIndex = 0 + private val initialSize = list.size override val serializersModule: SerializersModule = EmptySerializersModule() override fun decodeValue(): Any = list.removeFirst() override fun decodeElementIndex(descriptor: SerialDescriptor): Int { - if (list.isEmpty() || elementIndex == descriptor.elementsCount) return CompositeDecoder.DECODE_DONE + if (list.isEmpty() || elementIndex == initialSize) return CompositeDecoder.DECODE_DONE return elementIndex++ } diff --git a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt index 1c284a19..57c8b367 100644 --- a/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt +++ b/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/KotlinXSerializationMapperTest.kt @@ -124,6 +124,20 @@ class KotlinXSerializationMapperTest { emptyList(), emptyArray(), ), + TestData( + TestData.SomePolymorphType.SomeTypeB("someValue"), + emptyMap(), + emptyMap(), + TestData.InnerObject(""), + "", + TestData.SomeValueClass("someString"), + 1, + 1.0, + "test", + TestData.SomeEnum.SomeValue, + emptyList(), + emptyArray(), + ), ), valueClass = TestData.SomeValueClass("someString"), someArray = arrayOf("someArrayData"), From be816a1969b99ba13b22e9e92499a2bbfff99bd5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Feb 2024 23:09:54 +0530 Subject: [PATCH 07/13] Bump org.rocksdb:rocksdbjni from 8.10.0 to 8.10.2 (#914) Bumps [org.rocksdb:rocksdbjni](https://github.com/facebook/rocksdb) from 8.10.0 to 8.10.2. - [Release notes](https://github.com/facebook/rocksdb/releases) - [Changelog](https://github.com/facebook/rocksdb/blob/v8.10.2/HISTORY.md) - [Commits](https://github.com/facebook/rocksdb/compare/v8.10.0...v8.10.2) --- updated-dependencies: - dependency-name: org.rocksdb:rocksdbjni dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6c27a60..4e95e6a5 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ 2.0.12 1.9.3 2.2.224 - 8.10.0 + 8.10.2 5.5.0 1.19.0 1.16.1 From b09e6633e5bfe11d396c07562c2783509ab349a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 09:34:38 +0530 Subject: [PATCH 08/13] Bump org.rocksdb:rocksdbjni from 8.10.2 to 8.11.3 (#919) Bumps [org.rocksdb:rocksdbjni](https://github.com/facebook/rocksdb) from 8.10.2 to 8.11.3. - [Release notes](https://github.com/facebook/rocksdb/releases) - [Changelog](https://github.com/facebook/rocksdb/blob/v8.11.3/HISTORY.md) - [Commits](https://github.com/facebook/rocksdb/compare/v8.10.2...v8.11.3) --- updated-dependencies: - dependency-name: org.rocksdb:rocksdbjni dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4e95e6a5..05c612e3 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ 2.0.12 1.9.3 2.2.224 - 8.10.2 + 8.11.3 5.5.0 1.19.0 1.16.1 From 4caad0c8672e5c66a8ded6c7103256668bb7c51b Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee <696662+anidotnet@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:34:46 +0530 Subject: [PATCH 09/13] Fixes #916 (#918) * Fixes #916 * changelog updated --- CHANGELOG.md | 8 ++++ .../dizitart/no2/integration/NitriteTest.java | 41 +++++++++++++++++++ .../no2/mvstore/compat/v1/UpgradeUtil.java | 8 ++-- .../compat/v1/mvstore/fs/FilePathDisk.java | 3 +- .../java/org/dizitart/no2/NitriteTest.java | 32 +++++++++++---- .../dizitart/no2/integration/TestUtil.java | 15 +++++++ .../no2/spatial/SpatialIndexNegativeTest.java | 3 +- .../collection/operation/IndexOperations.java | 10 ++++- .../org/dizitart/no2/filters/TextFilter.java | 11 ++--- .../org/dizitart/no2/index/TextIndex.java | 2 +- .../no2/repository/AnnotationScanner.java | 8 +--- .../repository/DefaultObjectRepository.java | 3 +- .../repository/EntityDecoratorScanner.java | 8 +--- .../no2/repository/RepositoryOperations.java | 14 +++++-- .../DefaultTransactionalRepository.java | 2 +- 15 files changed, 125 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd042275..e9519b02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## Release 4.2.2 + +### Issue Fixes + +- Fix for #916 +- Fix for #911 +- Version upgrade for several dependencies + ## Release 4.2.1 - Feb 19, 2024 ### Issue Fixes diff --git a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/NitriteTest.java index 2f86eafd..01043be8 100644 --- a/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/NitriteTest.java +++ b/nitrite-jackson-mapper/src/test/java/org/dizitart/no2/integration/NitriteTest.java @@ -24,6 +24,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.mapper.JacksonMapperModule; +import org.dizitart.no2.exceptions.IndexingException; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexOptions; @@ -241,6 +242,24 @@ public void testGetCollectionInvalidName() { db.getCollection(META_MAP_NAME); } + @Test(expected = IndexingException.class) + public void testUniqueAndTextIndex() { + try (final Nitrite nitrite = Nitrite.builder() + .loadModule(new JacksonMapperModule()) + .openOrCreate()) { + nitrite.getRepository(EntityUniqueFullText.class); + } + } + + @Test(expected = IndexingException.class) + public void testNoUniqueAndTextIndex() { + try (final Nitrite nitrite = Nitrite.builder() + .loadModule(new JacksonMapperModule()) + .openOrCreate()) { + nitrite.getRepository(EntityNoUniqueFullText.class); + } + } + @Data @NoArgsConstructor @@ -263,4 +282,26 @@ public enum Status { public static class EmptyClass { } + + @Indices({ + @Index(fields = "value", type = IndexType.FULL_TEXT), + @Index(fields = "value") + }) + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class EntityUniqueFullText { + private String value; + } + + @Indices({ + @Index(fields = "value", type = IndexType.FULL_TEXT), + @Index(fields = "value", type = IndexType.NON_UNIQUE) + }) + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class EntityNoUniqueFullText { + private String value; + } } diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java index 80d887e3..5099915a 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/UpgradeUtil.java @@ -38,8 +38,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.CopyOnWriteArrayList; -import static org.dizitart.no2.common.Constants.INDEX_PREFIX; -import static org.dizitart.no2.common.Constants.STORE_INFO; +import static org.dizitart.no2.common.Constants.*; import static org.dizitart.no2.common.util.ObjectUtils.convertToObjectArray; import static org.dizitart.no2.common.util.StringUtils.isNullOrEmpty; @@ -91,9 +90,12 @@ private static void copyData(MVMap oldMap, org.h2.mvstore.MVMap newMap) { if (key instanceof Compat.NitriteId) { newKey = nitriteId((Compat.NitriteId) key); + } else if (oldMap.getName().contains(INDEX_META_PREFIX)) { + // index meta map, wrap with Field + newKey = key == null ? Fields.withNames() : Fields.withNames((String) key); } else if (oldMap.getName().contains(INDEX_PREFIX)) { // index map, wrap with DBValue - newKey = newKey == null ? DBNull.getInstance() : new DBValue((Comparable) newKey); + newKey = key == null ? DBNull.getInstance() : new DBValue((Comparable) key); } Object newValue = migrateValue(entry.getValue()); diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/fs/FilePathDisk.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/fs/FilePathDisk.java index 3e434182..3b34b008 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/fs/FilePathDisk.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/fs/FilePathDisk.java @@ -305,14 +305,13 @@ public InputStream newInputStream() throws IOException { } static void freeMemoryAndFinalize() { - IOUtils.trace("freeMemoryAndFinalize", (String)null, (Object)null); + IOUtils.trace("freeMemoryAndFinalize", null, null); Runtime var0 = Runtime.getRuntime(); long var1 = var0.freeMemory(); for(int var3 = 0; var3 < 16; ++var3) { var0.gc(); long var4 = var0.freeMemory(); - var0.runFinalization(); if (var4 == var1) { break; } diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java index 888552d7..8fe84ef0 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/NitriteTest.java @@ -63,6 +63,7 @@ import static org.dizitart.no2.collection.Document.createDocument; import static org.dizitart.no2.common.Constants.INTERNAL_NAME_SEPARATOR; import static org.dizitart.no2.common.Constants.META_MAP_NAME; +import static org.dizitart.no2.common.util.Iterables.listOf; import static org.dizitart.no2.filters.Filter.ALL; import static org.dizitart.no2.filters.Filter.and; import static org.dizitart.no2.filters.FluentFilter.where; @@ -186,22 +187,27 @@ public void testReopen() throws ParseException { NitriteCollection testCollection = db.getCollection("test"); assertNotNull(testCollection); long prevSize = testCollection.find().size(); + ObjectRepository repository = db.getRepository(Receipt.class); + assertNotNull(repository); + long prevRepoSize = repository.size(); db.close(); - db = null; - db = TestUtil.createDb(fileName, "test-user", "test-password"); - + db = TestUtil.createDb(fileName, "test-user", "test-password", listOf(new Receipt.Converter())); assertNotNull(db); testCollection = db.getCollection("test"); assertNotNull(testCollection); long sizeNow = testCollection.find().size(); assertEquals(prevSize, sizeNow); + repository = db.getRepository(Receipt.class); + assertNotNull(repository); + long repoSizeNow = repository.size(); + assertEquals(prevRepoSize, repoSizeNow); db.close(); db = null; - db = TestUtil.createDb(fileName, "test-user", "test-password"); + db = TestUtil.createDb(fileName, "test-user", "test-password", listOf(new Receipt.Converter())); testCollection = db.getCollection("test"); testCollection.insert(createDocument("firstName", "fn12") @@ -209,15 +215,25 @@ public void testReopen() throws ParseException { .put("birthDay", simpleDateFormat.parse("2010-07-01T16:02:48.440Z")) .put("data", new byte[]{10, 20, 30}) .put("body", "a quick brown fox jump over the lazy dog")); + repository = db.getRepository(Receipt.class); + Receipt r = new Receipt(); + r.status = Receipt.Status.COMPLETED; + r.clientRef = "10"; + r.synced = false; + repository.insert(r); db.close(); db = null; - db = TestUtil.createDb(fileName, "test-user", "test-password"); + db = TestUtil.createDb(fileName, "test-user", "test-password", listOf(new Receipt.Converter())); testCollection = db.getCollection("test"); assertNotNull(testCollection); sizeNow = testCollection.find().size(); assertEquals(prevSize + 1, sizeNow); + repository = db.getRepository(Receipt.class); + assertNotNull(repository); + repoSizeNow = repository.size(); + assertEquals(prevRepoSize + 1, repoSizeNow); } @Test @@ -491,9 +507,7 @@ public void testReadCompatibility() throws IOException { Files.copy(stream, Paths.get(System.getProperty("java.io.tmpdir") + File.separator + "old.db")); String oldDbFile = System.getProperty("java.io.tmpdir") + File.separator + "old.db"; - Nitrite db = TestUtil.createDb(oldDbFile, "test-user", "test-password"); - SimpleNitriteMapper documentMapper = (SimpleNitriteMapper) db.getConfig().nitriteMapper(); - documentMapper.registerEntityConverter(new Receipt.Converter()); + Nitrite db = TestUtil.createDb(oldDbFile, "test-user", "test-password", listOf(new Receipt.Converter())); NitriteCollection collection = db.getCollection("test"); @@ -517,6 +531,8 @@ public void testReadCompatibility() throws IOException { assertNotNull(repository.getAttributes()); db.close(); + + //TODO: CHeck reopen with repo. That should also fails too. } @Test diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java index f2f41101..0da8214d 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/TestUtil.java @@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; +import org.dizitart.no2.common.mapper.EntityConverter; import org.dizitart.no2.exceptions.ObjectMappingException; import org.dizitart.no2.mvstore.MVStoreModule; @@ -125,6 +126,20 @@ public static Nitrite createDb(String filePath, String user, String password) { .openOrCreate(user, password); } + public static Nitrite createDb(String filePath, String user, String password, + List> entityConverters) { + MVStoreModule storeModule = MVStoreModule.withConfig() + .filePath(filePath) + .compress(true) + .build(); + + return Nitrite.builder() + .loadModule(storeModule) + .loadModule(() -> new HashSet<>(entityConverters)) + .fieldSeparator(".") + .openOrCreate(user, password); + } + public static Document parse(String json) { try { ObjectMapper objectMapper = createObjectMapper(); diff --git a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialIndexNegativeTest.java b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialIndexNegativeTest.java index 313899fb..37dab2fe 100644 --- a/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialIndexNegativeTest.java +++ b/nitrite-spatial/src/test/java/org/dizitart/no2/spatial/SpatialIndexNegativeTest.java @@ -22,6 +22,7 @@ import org.dizitart.no2.exceptions.IndexingException; import org.dizitart.no2.filters.FluentFilter; import org.dizitart.no2.index.IndexOptions; +import org.dizitart.no2.index.IndexType; import org.dizitart.no2.repository.Cursor; import org.junit.Test; import org.locationtech.jts.geom.Geometry; @@ -55,7 +56,7 @@ public void testNoIndex() throws ParseException { @Test(expected = IndexingException.class) public void testIndexExists() { collection.createIndex(IndexOptions.indexOptions(SPATIAL_INDEX), "location"); - collection.createIndex(IndexOptions.indexOptions(SPATIAL_INDEX), "location"); + collection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "location"); } @Test(expected = FilterException.class) diff --git a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java index 3a6a6bc2..1e7edd2a 100644 --- a/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java +++ b/nitrite/src/main/java/org/dizitart/no2/collection/operation/IndexOperations.java @@ -61,8 +61,14 @@ void createIndex(Fields fields, String indexType) { // if no index create index indexDescriptor = indexManager.createIndexDescriptor(fields, indexType); } else { - // if index already there throw - throw new IndexingException("Index already exists on fields: " + fields); + // if index already there check if it is of same type, if not throw exception + if (!indexDescriptor.getIndexType().equals(indexType)) { + throw new IndexingException("Index already exists on fields: " + fields + + " with type " + indexDescriptor.getIndexType()); + } else { + // if index is of same type, return + return; + } } buildIndex(indexDescriptor, false); diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java index 8bec4d68..e1187501 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/TextFilter.java @@ -34,8 +34,8 @@ * @author Anindya Chatterjee * @since 1.0 */ +@Setter public class TextFilter extends StringFilter { - @Setter private TextTokenizer textTokenizer; /** @@ -100,12 +100,7 @@ private LinkedHashSet searchExactByIndex(NitriteMap> List nitriteIds = (List) indexMap.get(word); if (nitriteIds != null) { for (NitriteId id : nitriteIds) { - Integer score = scoreMap.get(id); - if (score == null) { - scoreMap.put(id, 1); - } else { - scoreMap.put(id, score + 1); - } + scoreMap.merge(id, 1, Integer::sum); } } } @@ -185,7 +180,7 @@ private LinkedHashSet searchContains(NitriteMap> inde private LinkedHashSet sortedIdsByScore(Map unsortedMap) { List> list = new LinkedList<>(unsortedMap.entrySet()); - Collections.sort(list, (e1, e2) -> (e2.getValue()).compareTo(e1.getValue())); + list.sort((e1, e2) -> (e2.getValue()).compareTo(e1.getValue())); LinkedHashSet result = new LinkedHashSet<>(); for (Map.Entry entry : list) { diff --git a/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java b/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java index bc343cd9..74fd575f 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/TextIndex.java @@ -152,7 +152,7 @@ public LinkedHashSet findNitriteIds(FindPlan findPlan) { textFilter.setTextTokenizer(textTokenizer); return textFilter.applyOnTextIndex(indexMap); } - throw new FilterException("Text index only supports a single TextFilter"); + throw new FilterException("TextFilter can only be applied on text index."); } private NitriteMap> findIndexMap() { diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/AnnotationScanner.java b/nitrite/src/main/java/org/dizitart/no2/repository/AnnotationScanner.java index 03f85f4e..ca2d78c6 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/AnnotationScanner.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/AnnotationScanner.java @@ -55,18 +55,14 @@ public AnnotationScanner(Class type, NitriteCollection collection, NitriteMap public void createIndices() { for (Index index : indices) { String[] fields = index.fields(); - if (!collection.hasIndex(fields)) { - collection.createIndex(indexOptions(index.type()), fields); - } + collection.createIndex(indexOptions(index.type()), fields); } } public void createIdIndex() { if (objectIdField != null) { String[] fieldNames = objectIdField.getEmbeddedFieldNames(); - if (!collection.hasIndex(fieldNames)) { - collection.createIndex(fieldNames); - } + collection.createIndex(fieldNames); } } diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java b/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java index 52456382..bbe46847 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/DefaultObjectRepository.java @@ -236,6 +236,7 @@ private void initialize() { } else { operations = new RepositoryOperations(type, collection, nitriteConfig); } - operations.createIndices(); + operations.scanIndexes(); + operations.createIndexes(); } } diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java b/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java index a9a071ab..426c2a2c 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/EntityDecoratorScanner.java @@ -68,18 +68,14 @@ public void readEntity() { public void createIndices() { for (EntityIndex index : indices) { String[] fields = index.getFieldNames().toArray(new String[0]); - if (!collection.hasIndex(fields)) { - collection.createIndex(indexOptions(index.getIndexType()), fields); - } + collection.createIndex(indexOptions(index.getIndexType()), fields); } } public void createIdIndex() { if (objectIdField != null) { String[] fieldNames = objectIdField.getEmbeddedFieldNames(); - if (!collection.hasIndex(fieldNames)) { - collection.createIndex(fieldNames); - } + collection.createIndex(fieldNames); } } diff --git a/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java b/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java index 254c86cb..49f22d6d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java +++ b/nitrite/src/main/java/org/dizitart/no2/repository/RepositoryOperations.java @@ -60,17 +60,23 @@ public RepositoryOperations(EntityDecorator entityDecorator, NitriteCollectio validateCollection(); } - public void createIndices() { + public void scanIndexes() { if (annotationScanner != null) { annotationScanner.performScan(); - annotationScanner.createIndices(); - annotationScanner.createIdIndex(); objectIdField = annotationScanner.getObjectIdField(); } else if (entityDecoratorScanner != null) { entityDecoratorScanner.readEntity(); + objectIdField = entityDecoratorScanner.getObjectIdField(); + } + } + + public void createIndexes() { + if (annotationScanner != null) { + annotationScanner.createIndices(); + annotationScanner.createIdIndex(); + } else if (entityDecoratorScanner != null) { entityDecoratorScanner.createIndices(); entityDecoratorScanner.createIdIndex(); - objectIdField = entityDecoratorScanner.getObjectIdField(); } } diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java b/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java index 52b27d54..f051c2b9 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java @@ -236,6 +236,6 @@ private void initialize() { } else { this.operations = new RepositoryOperations(type, backingCollection, nitriteConfig); } - this.operations.createIndices(); + this.operations.scanIndexes(); } } From 440f830a1487e9a29ab31879886fc8d1473b322f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 23:00:54 +0530 Subject: [PATCH 10/13] Bump org.mockito:mockito-core from 5.10.0 to 5.11.0 (#920) Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.10.0 to 5.11.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.10.0...v5.11.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 05c612e3..74741ba3 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ 1.18.30 1.18.20.0 4.13.2 - 5.10.0 + 5.11.0 8.0.1.RELEASE 2.23.0 4.2.0 From 32d7e02da1093036c81be05037e4ffc61dc574ed Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee <696662+anidotnet@users.noreply.github.com> Date: Mon, 4 Mar 2024 23:00:14 +0530 Subject: [PATCH 11/13] Fixes #917 (#921) --- CHANGELOG.md | 1 + .../dizitart/no2/mvstore/NitriteMVMap.java | 12 +- .../CollectionFindBySingleFieldIndexTest.java | 211 +++++++++++++++++- .../org/dizitart/no2/rocksdb/RocksDBMap.java | 26 +++ .../CollectionFindBySingleFieldIndexTest.java | 211 +++++++++++++++++- .../no2/filters/ComparableFilter.java | 2 - .../no2/filters/GreaterEqualFilter.java | 30 ++- .../no2/filters/GreaterThanFilter.java | 29 ++- .../no2/filters/LesserEqualFilter.java | 29 ++- .../no2/filters/LesserThanFilter.java | 29 ++- .../no2/filters/SortingAwareFilter.java | 24 ++ .../java/org/dizitart/no2/index/IndexMap.java | 92 ++++---- .../org/dizitart/no2/index/IndexScanner.java | 6 + .../org/dizitart/no2/store/NitriteMap.java | 14 ++ .../no2/store/memory/InMemoryMap.java | 12 + .../no2/transaction/TransactionalMap.java | 94 ++++---- .../dizitart/no2/integration/NitriteTest.java | 6 +- .../CollectionFindBySingleFieldIndexTest.java | 211 +++++++++++++++++- 18 files changed, 890 insertions(+), 149 deletions(-) create mode 100644 nitrite/src/main/java/org/dizitart/no2/filters/SortingAwareFilter.java diff --git a/CHANGELOG.md b/CHANGELOG.md index e9519b02..60ffe096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Issue Fixes +- Fix for #917 - Fix for #916 - Fix for #911 - Version upgrade for several dependencies diff --git a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVMap.java b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVMap.java index 23901cd2..7df7f6c6 100644 --- a/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVMap.java +++ b/nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/NitriteMVMap.java @@ -133,7 +133,7 @@ public Value putIfAbsent(Key key, Value value) { @Override public RecordStream> entries() { - return () -> new Iterator>() { + return () -> new Iterator<>() { final Iterator> entryIterator = mvMap.entrySet().iterator(); @Override @@ -154,6 +154,16 @@ public RecordStream> reversedEntries() { return () -> new ReverseIterator<>(mvMap); } + @Override + public Key firstKey() { + return mvMap.firstKey(); + } + + @Override + public Key lastKey() { + return mvMap.lastKey(); + } + @Override public Key higherKey(Key key) { return mvMap.higherKey(key); diff --git a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java index cbef67e2..0c00d480 100644 --- a/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java +++ b/nitrite-mvstore-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java @@ -38,8 +38,7 @@ import static org.dizitart.no2.filters.Filter.and; import static org.dizitart.no2.filters.Filter.or; import static org.dizitart.no2.filters.FluentFilter.where; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Anindya Chatterjee. @@ -420,4 +419,212 @@ public void testIssue45() { cursor = collection.find(where("notes").text("lazy")); assertEquals(cursor.size(), 3); } + + @Test + public void testSortByIndexDescendingLessThenEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingLessThenEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingLessThenEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingLessThenEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingGreaterThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingGreaterThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingGreaterThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingGreaterThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingGreaterThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingGreaterThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingGreaterThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingGreaterThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingLessThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingLessThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingLessThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingLessThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } } diff --git a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java index 55ebf109..47bbc282 100644 --- a/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java +++ b/nitrite-rocksdb-adapter/src/main/java/org/dizitart/no2/rocksdb/RocksDBMap.java @@ -224,6 +224,32 @@ public RecordStream> reversedEntries() { objectFormatter, getKeyType(), getValueType(), true)); } + @Override + @SuppressWarnings({"unchecked"}) + public K firstKey() { + try (RocksIterator iterator = rocksDB.newIterator(columnFamilyHandle)) { + iterator.seekToFirst(); + if (iterator.isValid()) { + byte[] key = iterator.key(); + return (K) objectFormatter.decodeKey(key, getKeyType()); + } + } + return null; + } + + @Override + @SuppressWarnings({"unchecked"}) + public K lastKey() { + try (RocksIterator iterator = rocksDB.newIterator(columnFamilyHandle)) { + iterator.seekToLast(); + if (iterator.isValid()) { + byte[] key = iterator.key(); + return (K) objectFormatter.decodeKey(key, getKeyType()); + } + } + return null; + } + @Override @SuppressWarnings({"unchecked", "rawtypes"}) public K higherKey(K k) { diff --git a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java index cbef67e2..0c00d480 100644 --- a/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java +++ b/nitrite-rocksdb-adapter/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java @@ -38,8 +38,7 @@ import static org.dizitart.no2.filters.Filter.and; import static org.dizitart.no2.filters.Filter.or; import static org.dizitart.no2.filters.FluentFilter.where; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Anindya Chatterjee. @@ -420,4 +419,212 @@ public void testIssue45() { cursor = collection.find(where("notes").text("lazy")); assertEquals(cursor.size(), 3); } + + @Test + public void testSortByIndexDescendingLessThenEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingLessThenEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingLessThenEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingLessThenEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingGreaterThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingGreaterThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingGreaterThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingGreaterThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingGreaterThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingGreaterThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingGreaterThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingGreaterThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingLessThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingLessThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingLessThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingLessThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } } diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java index 5e0f3704..da80c010 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/ComparableFilter.java @@ -16,12 +16,10 @@ package org.dizitart.no2.filters; -import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.index.IndexMap; import java.util.List; -import java.util.NavigableMap; /** * An abstract class representing a filter that compares fields. diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/GreaterEqualFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/GreaterEqualFilter.java index 93b5c4e2..3691cea7 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/GreaterEqualFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/GreaterEqualFilter.java @@ -19,6 +19,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.tuples.Pair; +import org.dizitart.no2.common.util.Comparables; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.index.IndexMap; @@ -31,7 +32,7 @@ /** * @author Anindya Chatterjee */ -class GreaterEqualFilter extends ComparableFilter { +class GreaterEqualFilter extends SortingAwareFilter { GreaterEqualFilter(String field, Comparable value) { super(field, value); } @@ -65,14 +66,25 @@ public List applyOnIndex(IndexMap indexMap) { // maintain the find sorting order List nitriteIds = new ArrayList<>(); - Comparable ceilingKey = indexMap.ceilingKey(comparable); - while (ceilingKey != null) { - // get the starting value, it can be a navigable-map (compound index) - // or list (single field index) - Object value = indexMap.get(ceilingKey); - processIndexValue(value, subMaps, nitriteIds); - - ceilingKey = indexMap.higherKey(ceilingKey); + if (isReverseScan()) { + // if reverse scan is required, then start from the last key + Comparable lastKey = indexMap.lastKey(); + while(lastKey != null && Comparables.compare(lastKey, comparable) >= 0) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(lastKey); + processIndexValue(value, subMaps, nitriteIds); + lastKey = indexMap.lowerKey(lastKey); + } + } else { + Comparable ceilingKey = indexMap.ceilingKey(comparable); + while (ceilingKey != null) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(ceilingKey); + processIndexValue(value, subMaps, nitriteIds); + ceilingKey = indexMap.higherKey(ceilingKey); + } } if (!subMaps.isEmpty()) { diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/GreaterThanFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/GreaterThanFilter.java index 089b3413..356d3458 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/GreaterThanFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/GreaterThanFilter.java @@ -19,6 +19,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.tuples.Pair; +import org.dizitart.no2.common.util.Comparables; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.index.IndexMap; @@ -31,7 +32,7 @@ /** * @author Anindya Chatterjee */ -class GreaterThanFilter extends ComparableFilter { +class GreaterThanFilter extends SortingAwareFilter { protected GreaterThanFilter(String field, Comparable value) { super(field, value); } @@ -64,14 +65,24 @@ public List applyOnIndex(IndexMap indexMap) { List, Object>> subMaps = new ArrayList<>(); List nitriteIds = new ArrayList<>(); - Comparable ceilingKey = indexMap.higherKey(comparable); - while (ceilingKey != null) { - // get the starting value, it can be a navigable-map (compound index) - // or list (single field index) - Object value = indexMap.get(ceilingKey); - processIndexValue(value, subMaps, nitriteIds); - - ceilingKey = indexMap.higherKey(ceilingKey); + if (isReverseScan()) { + Comparable lastKey = indexMap.lastKey(); + while (lastKey != null && Comparables.compare(lastKey, comparable) > 0) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(lastKey); + processIndexValue(value, subMaps, nitriteIds); + lastKey = indexMap.lowerKey(lastKey); + } + } else { + Comparable higherKey = indexMap.higherKey(comparable); + while (higherKey != null) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(higherKey); + processIndexValue(value, subMaps, nitriteIds); + higherKey = indexMap.higherKey(higherKey); + } } if (!subMaps.isEmpty()) { diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/LesserEqualFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/LesserEqualFilter.java index c248d629..40758fee 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/LesserEqualFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/LesserEqualFilter.java @@ -19,6 +19,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.tuples.Pair; +import org.dizitart.no2.common.util.Comparables; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.index.IndexMap; @@ -31,7 +32,7 @@ /** * @author Anindya Chatterjee */ -class LesserEqualFilter extends ComparableFilter { +class LesserEqualFilter extends SortingAwareFilter { LesserEqualFilter(String field, Comparable value) { super(field, value); } @@ -63,14 +64,24 @@ public List applyOnIndex(IndexMap indexMap) { List, Object>> subMap = new ArrayList<>(); List nitriteIds = new ArrayList<>(); - Comparable floorKey = indexMap.floorKey(comparable); - while (floorKey != null) { - // get the starting value, it can be a navigable-map (compound index) - // or list (single field index) - Object value = indexMap.get(floorKey); - processIndexValue(value, subMap, nitriteIds); - - floorKey = indexMap.lowerKey(floorKey); + if (isReverseScan()) { + Comparable floorKey = indexMap.floorKey(comparable); + while (floorKey != null) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(floorKey); + processIndexValue(value, subMap, nitriteIds); + floorKey = indexMap.lowerKey(floorKey); + } + } else { + Comparable firstKey = indexMap.firstKey(); + while (firstKey != null && Comparables.compare(firstKey, comparable) <= 0) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(firstKey); + processIndexValue(value, subMap, nitriteIds); + firstKey = indexMap.higherKey(firstKey); + } } if (!subMap.isEmpty()) { diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/LesserThanFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/LesserThanFilter.java index 93e35a83..66f8dc66 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/LesserThanFilter.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/LesserThanFilter.java @@ -19,6 +19,7 @@ import org.dizitart.no2.collection.Document; import org.dizitart.no2.collection.NitriteId; import org.dizitart.no2.common.tuples.Pair; +import org.dizitart.no2.common.util.Comparables; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.index.IndexMap; @@ -31,7 +32,7 @@ /** * @author Anindya Chatterjee */ -class LesserThanFilter extends ComparableFilter { +class LesserThanFilter extends SortingAwareFilter { LesserThanFilter(String field, Comparable value) { super(field, value); } @@ -63,14 +64,24 @@ public List applyOnIndex(IndexMap indexMap) { List, Object>> subMap = new ArrayList<>(); List nitriteIds = new ArrayList<>(); - Comparable floorKey = indexMap.lowerKey(comparable); - while (floorKey != null) { - // get the starting value, it can be a navigable-map (compound index) - // or list (single field index) - Object value = indexMap.get(floorKey); - processIndexValue(value, subMap, nitriteIds); - - floorKey = indexMap.lowerKey(floorKey); + if (isReverseScan()) { + Comparable lowerKey = indexMap.lowerKey(comparable); + while (lowerKey != null) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(lowerKey); + processIndexValue(value, subMap, nitriteIds); + lowerKey = indexMap.lowerKey(lowerKey); + } + } else { + Comparable firstKey = indexMap.firstKey(); + while (firstKey != null && Comparables.compare(firstKey, comparable) < 0) { + // get the starting value, it can be a navigable-map (compound index) + // or list (single field index) + Object value = indexMap.get(firstKey); + processIndexValue(value, subMap, nitriteIds); + firstKey = indexMap.higherKey(firstKey); + } } if (!subMap.isEmpty()) { diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/SortingAwareFilter.java b/nitrite/src/main/java/org/dizitart/no2/filters/SortingAwareFilter.java new file mode 100644 index 00000000..7404a30d --- /dev/null +++ b/nitrite/src/main/java/org/dizitart/no2/filters/SortingAwareFilter.java @@ -0,0 +1,24 @@ +package org.dizitart.no2.filters; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public abstract class SortingAwareFilter extends ComparableFilter { + + /** + * Indicates if the filter should scan the index in reverse order. + */ + private boolean reverseScan; + + /** + * Instantiates a new SortingAwareFilter. + * + * @param field the field + * @param value the value + */ + public SortingAwareFilter(String field, Object value) { + super(field, value); + } +} diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java index 6497768b..acb6b0df 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexMap.java @@ -59,6 +59,32 @@ public IndexMap(NavigableMap navigableMap) { this.navigableMap = navigableMap; } + public > T firstKey() { + DBValue dbKey; + if (nitriteMap != null) { + dbKey = nitriteMap.firstKey(); + } else if (navigableMap != null) { + dbKey = navigableMap.firstKey(); + } else { + return null; + } + + return dbKey == null || dbKey instanceof DBNull ? null : (T) dbKey.getValue(); + } + + public > T lastKey() { + DBValue dbKey; + if (nitriteMap != null) { + dbKey = nitriteMap.lastKey(); + } else if (navigableMap != null) { + dbKey = navigableMap.lastKey(); + } else { + return null; + } + + return dbKey == null || dbKey instanceof DBNull ? null : (T) dbKey.getValue(); + } + /** * Get the largest key that is smaller than the given key, or null if no * such key exists. @@ -69,18 +95,10 @@ public IndexMap(NavigableMap navigableMap) { */ public > T lowerKey(T key) { DBValue dbKey = key == null ? DBNull.getInstance() : new DBValue(key); - if (!reverseScan) { - if (nitriteMap != null) { - dbKey = nitriteMap.lowerKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.lowerKey(dbKey); - } - } else { - if (nitriteMap != null) { - dbKey = nitriteMap.higherKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.higherKey(dbKey); - } + if (nitriteMap != null) { + dbKey = nitriteMap.lowerKey(dbKey); + } else if (navigableMap != null) { + dbKey = navigableMap.lowerKey(dbKey); } return dbKey == null || dbKey instanceof DBNull ? null : (T) dbKey.getValue(); @@ -96,18 +114,10 @@ public > T lowerKey(T key) { */ public > T higherKey(T key) { DBValue dbKey = key == null ? DBNull.getInstance() : new DBValue(key); - if (!reverseScan) { - if (nitriteMap != null) { - dbKey = nitriteMap.higherKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.higherKey(dbKey); - } - } else { - if (nitriteMap != null) { - dbKey = nitriteMap.lowerKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.lowerKey(dbKey); - } + if (nitriteMap != null) { + dbKey = nitriteMap.higherKey(dbKey); + } else if (navigableMap != null) { + dbKey = navigableMap.higherKey(dbKey); } return dbKey == null || dbKey instanceof DBNull ? null : (T) dbKey.getValue(); @@ -122,18 +132,10 @@ public > T higherKey(T key) { */ public > T ceilingKey(T key) { DBValue dbKey = key == null ? DBNull.getInstance() : new DBValue(key); - if (!reverseScan) { - if (nitriteMap != null) { - dbKey = nitriteMap.ceilingKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.ceilingKey(dbKey); - } - } else { - if (nitriteMap != null) { - dbKey = nitriteMap.floorKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.floorKey(dbKey); - } + if (nitriteMap != null) { + dbKey = nitriteMap.ceilingKey(dbKey); + } else if (navigableMap != null) { + dbKey = navigableMap.ceilingKey(dbKey); } return dbKey == null || dbKey instanceof DBNull ? null : (T) dbKey.getValue(); @@ -148,18 +150,10 @@ public > T ceilingKey(T key) { */ public > T floorKey(T key) { DBValue dbKey = key == null ? DBNull.getInstance() : new DBValue(key); - if (!reverseScan) { - if (nitriteMap != null) { - dbKey = nitriteMap.floorKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.floorKey(dbKey); - } - } else { - if (nitriteMap != null) { - dbKey = nitriteMap.ceilingKey(dbKey); - } else if (navigableMap != null) { - dbKey = navigableMap.ceilingKey(dbKey); - } + if (nitriteMap != null) { + dbKey = nitriteMap.floorKey(dbKey); + } else if (navigableMap != null) { + dbKey = navigableMap.floorKey(dbKey); } return dbKey == null || dbKey instanceof DBNull ? null : (T) dbKey.getValue(); @@ -195,7 +189,7 @@ public Object get(Comparable comparable) { entryIterator = nitriteMap.reversedEntries().iterator(); } - return (Iterable, ?>>) () -> new Iterator, ?>>() { + return (Iterable, ?>>) () -> new Iterator<>() { @Override public boolean hasNext() { return entryIterator.hasNext(); diff --git a/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java b/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java index e036fb3c..f737490d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java +++ b/nitrite/src/main/java/org/dizitart/no2/index/IndexScanner.java @@ -21,6 +21,7 @@ import org.dizitart.no2.common.DBValue; import org.dizitart.no2.exceptions.FilterException; import org.dizitart.no2.filters.ComparableFilter; +import org.dizitart.no2.filters.SortingAwareFilter; import java.util.LinkedHashSet; import java.util.List; @@ -55,6 +56,11 @@ public LinkedHashSet doScan(List filters, Map scanResult = comparableFilter.applyOnIndex(indexMap); diff --git a/nitrite/src/main/java/org/dizitart/no2/store/NitriteMap.java b/nitrite/src/main/java/org/dizitart/no2/store/NitriteMap.java index f55a3127..07b26ce2 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/NitriteMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/NitriteMap.java @@ -118,6 +118,20 @@ public interface NitriteMap extends AttributesAware, AutoCloseable { */ Value putIfAbsent(Key key, Value value); + /** + * Get the first key in the map, or null if the map is empty. + * + * @return the result. + */ + Key firstKey(); + + /** + * Get the last key in the map, or null if the map is empty. + * + * @return the result. + */ + Key lastKey(); + /** * Get the lest key that is greater than the given key, or null if no * such key exists. diff --git a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java index 2394a1fc..40708663 100644 --- a/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/store/memory/InMemoryMap.java @@ -123,6 +123,18 @@ public RecordStream> reversedEntries() { return getStream(backingMap.descendingMap()); } + @Override + public Key firstKey() { + checkOpened(); + return backingMap.firstKey(); + } + + @Override + public Key lastKey() { + checkOpened(); + return backingMap.lastKey(); + } + @Override public Key higherKey(Key key) { checkOpened(); diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionalMap.java b/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionalMap.java index 577a4877..573031ab 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionalMap.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/TransactionalMap.java @@ -9,6 +9,7 @@ import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; import static org.dizitart.no2.common.util.ObjectUtils.deepCopy; @@ -82,7 +83,6 @@ public NitriteStore getStore() { @Override public void clear() { backingMap.clear(); -// primary.clear(); cleared = true; getStore().closeMap(mapName); } @@ -175,51 +175,50 @@ public RecordStream> reversedEntries() { } @Override - public K higherKey(K k) { + public K firstKey() { if (cleared) { return null; } - K primaryKey = primary.higherKey(k); - K backingKey = backingMap.higherKey(k); + K primaryKey = primary.firstKey(); + K backingKey = backingMap.firstKey(); - if (primaryKey == null) { - return backingKey; - } + return computeKey(primaryKey, backingKey, SortedSet::first); + } - if (backingKey == null) { - return primaryKey; + public K lastKey() { + if (cleared) { + return null; } - NavigableSet keySet = new TreeSet<>(); - keySet.add(backingKey); - keySet.add(primaryKey); + K primaryKey = primary.lastKey(); + K backingKey = backingMap.lastKey(); - return keySet.higher(k); + return computeKey(primaryKey, backingKey, SortedSet::last); } @Override - public K ceilingKey(K k) { + public K higherKey(K k) { if (cleared) { return null; } - K primaryKey = primary.ceilingKey(k); - K backingKey = backingMap.ceilingKey(k); + K primaryKey = primary.higherKey(k); + K backingKey = backingMap.higherKey(k); - if (primaryKey == null) { - return backingKey; - } + return computeKey(primaryKey, backingKey, keySet -> keySet.higher(k)); + } - if (backingKey == null) { - return primaryKey; + @Override + public K ceilingKey(K k) { + if (cleared) { + return null; } - NavigableSet keySet = new TreeSet<>(); - keySet.add(backingKey); - keySet.add(primaryKey); + K primaryKey = primary.ceilingKey(k); + K backingKey = backingMap.ceilingKey(k); - return keySet.ceiling(k); + return computeKey(primaryKey, backingKey, keySet -> keySet.ceiling(k)); } @Override @@ -231,19 +230,7 @@ public K lowerKey(K k) { K primaryKey = primary.lowerKey(k); K backingKey = backingMap.lowerKey(k); - if (primaryKey == null) { - return backingKey; - } - - if (backingKey == null) { - return primaryKey; - } - - NavigableSet keySet = new TreeSet<>(); - keySet.add(backingKey); - keySet.add(primaryKey); - - return keySet.lower(k); + return computeKey(primaryKey, backingKey, keySet -> keySet.lower(k)); } @Override @@ -255,19 +242,7 @@ public K floorKey(K k) { K primaryKey = primary.floorKey(k); K backingKey = backingMap.floorKey(k); - if (primaryKey == null) { - return backingKey; - } - - if (backingKey == null) { - return primaryKey; - } - - NavigableSet keySet = new TreeSet<>(); - keySet.add(backingKey); - keySet.add(primaryKey); - - return keySet.floor(k); + return computeKey(primaryKey, backingKey, keySet -> keySet.floor(k)); } @Override @@ -315,13 +290,28 @@ public boolean isClosed() { return closedFlag.get(); } + private K computeKey(K primaryKey, K backingKey, Function, K> computeFunction) { + if (primaryKey == null) { + return backingKey; + } + + if (backingKey == null) { + return primaryKey; + } + + NavigableSet keySet = new TreeSet<>(); + keySet.add(backingKey); + keySet.add(primaryKey); + return computeFunction.apply(keySet); + } + private RecordStream> getStream(RecordStream> primaryStream, RecordStream> backingStream) { if (cleared) { return RecordStream.empty(); } - return () -> new Iterator>() { + return () -> new Iterator<>() { private final Iterator> primaryIterator = primaryStream.iterator(); private final Iterator> iterator = backingStream.iterator(); private Pair nextPair; diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java index 938e65a1..143bc56b 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/NitriteTest.java @@ -23,14 +23,13 @@ import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.Nitrite; import org.dizitart.no2.collection.Document; -import org.dizitart.no2.collection.FindOptions; import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.collection.UpdateOptions; import org.dizitart.no2.common.SortOrder; import org.dizitart.no2.common.concurrent.ThreadPoolManager; import org.dizitart.no2.common.mapper.EntityConverter; -import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.common.mapper.NitriteMapper; +import org.dizitart.no2.common.mapper.SimpleNitriteMapper; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.ValidationException; import org.dizitart.no2.index.IndexOptions; @@ -57,6 +56,7 @@ import java.util.concurrent.ExecutorService; import static org.dizitart.no2.collection.Document.createDocument; +import static org.dizitart.no2.collection.FindOptions.orderBy; import static org.dizitart.no2.common.Constants.INTERNAL_NAME_SEPARATOR; import static org.dizitart.no2.common.Constants.META_MAP_NAME; import static org.dizitart.no2.filters.Filter.ALL; @@ -291,7 +291,7 @@ public void testIssue185() throws InterruptedException { for (int i = 0; i < 1000; ++i) { repository.find(where("status").eq(Receipt.Status.COMPLETED).not(), - FindOptions.orderBy("createdTimestamp", SortOrder.Descending)).toList(); + orderBy("createdTimestamp", SortOrder.Descending)).toList(); try { Thread.sleep(5); } catch (InterruptedException ignored) { diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java index cbef67e2..722df3d5 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/collection/CollectionFindBySingleFieldIndexTest.java @@ -38,8 +38,7 @@ import static org.dizitart.no2.filters.Filter.and; import static org.dizitart.no2.filters.Filter.or; import static org.dizitart.no2.filters.FluentFilter.where; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Anindya Chatterjee. @@ -420,4 +419,212 @@ public void testIssue45() { cursor = collection.find(where("notes").text("lazy")); assertEquals(cursor.size(), 3); } + + @Test + public void testSortByIndexDescendingLessThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingLessThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingLessThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingLessThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lte(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingGreaterThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingGreaterThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingGreaterThanEqual() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingGreaterThanEqual"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gte(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingGreaterThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingGreaterThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingGreaterThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingGreaterThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").gt(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexDescendingLessThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexDescendingLessThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Descending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Descending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } + + @Test + public void testSortByIndexAscendingLessThan() { + NitriteCollection nitriteCollection = db.getCollection("testSortByIndexAscendingLessThan"); + List integerList = Arrays.asList(1, 2, 3, 4, 5); + integerList.forEach(i -> { + Document doc = Document.createDocument(); + doc.put("name", i); + nitriteCollection.insert(doc); + }); + + DocumentCursor cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Ascending)); + + List docIter = cursor.toList(); + Integer[] nonIndexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + nitriteCollection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "name"); + + cursor = nitriteCollection.find(where("name").lt(3), + orderBy("name", SortOrder.Ascending)); + docIter = cursor.toList(); + Integer[] indexedResult = docIter.stream().map(d -> d.get("name", Integer.class)).toArray(Integer[]::new); + + assertArrayEquals(nonIndexedResult, indexedResult); + } } From 9584140b754e8b6caa9c7263c8c33b7b84fab0aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:46:06 +0530 Subject: [PATCH 12/13] Bump org.jetbrains.dokka:dokka-maven-plugin from 1.9.10 to 1.9.20 (#922) Bumps [org.jetbrains.dokka:dokka-maven-plugin](https://github.com/Kotlin/dokka) from 1.9.10 to 1.9.20. - [Release notes](https://github.com/Kotlin/dokka/releases) - [Commits](https://github.com/Kotlin/dokka/commits) --- updated-dependencies: - dependency-name: org.jetbrains.dokka:dokka-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74741ba3..1fcd88c3 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ 3.12.1 3.6.3 3.3.0 - 1.9.10 + 1.9.20 1.23 7.0_r2 1.6.13 From 7ce7e32c4be775977d7a23ddcf01be22647fcf66 Mon Sep 17 00:00:00 2001 From: Anindya Chatterjee Date: Tue, 5 Mar 2024 20:23:57 +0530 Subject: [PATCH 13/13] preparing release 4.2.2 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ffe096..d248a2f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## Release 4.2.2 +## Release 4.2.2 - Mar 5, 2024 ### Issue Fixes