Compare commits
25 Commits
issue/4491
...
3.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8930091b33 | ||
|
|
b1d750efed | ||
|
|
7a19593f02 | ||
|
|
9021445ccd | ||
|
|
db92c37502 | ||
|
|
99e5e2596e | ||
|
|
d0bf0e2e62 | ||
|
|
28efb3afbe | ||
|
|
99eb849c93 | ||
|
|
d33aa682e5 | ||
|
|
f6db089f6f | ||
|
|
13ae5e17bb | ||
|
|
ee203bf22a | ||
|
|
990696ba11 | ||
|
|
4bc2f108fe | ||
|
|
5064ba5b24 | ||
|
|
1179ded140 | ||
|
|
e12700c00b | ||
|
|
0507adab20 | ||
|
|
375ddf8afb | ||
|
|
283cf06dc1 | ||
|
|
10a8456581 | ||
|
|
e751a43cdf | ||
|
|
c987ba5f83 | ||
|
|
950bae0306 |
34
Jenkinsfile
vendored
34
Jenkinsfile
vendored
@@ -3,7 +3,7 @@ pipeline {
|
|||||||
|
|
||||||
triggers {
|
triggers {
|
||||||
pollSCM 'H/10 * * * *'
|
pollSCM 'H/10 * * * *'
|
||||||
upstream(upstreamProjects: "spring-data-commons/master", threshold: hudson.model.Result.SUCCESS)
|
upstream(upstreamProjects: "spring-data-commons/2.5.x", threshold: hudson.model.Result.SUCCESS)
|
||||||
}
|
}
|
||||||
|
|
||||||
options {
|
options {
|
||||||
@@ -68,7 +68,7 @@ pipeline {
|
|||||||
stage("test: baseline (jdk8)") {
|
stage("test: baseline (jdk8)") {
|
||||||
when {
|
when {
|
||||||
anyOf {
|
anyOf {
|
||||||
branch 'master'
|
branch '3.2.x'
|
||||||
not { triggeredBy 'UpstreamCause' }
|
not { triggeredBy 'UpstreamCause' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +76,9 @@ pipeline {
|
|||||||
label 'data'
|
label 'data'
|
||||||
}
|
}
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
@@ -85,7 +88,7 @@ pipeline {
|
|||||||
sh 'sleep 10'
|
sh 'sleep 10'
|
||||||
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
sh 'sleep 15'
|
sh 'sleep 15'
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +98,7 @@ pipeline {
|
|||||||
stage("Test other configurations") {
|
stage("Test other configurations") {
|
||||||
when {
|
when {
|
||||||
allOf {
|
allOf {
|
||||||
branch 'master'
|
branch '3.2.x'
|
||||||
not { triggeredBy 'UpstreamCause' }
|
not { triggeredBy 'UpstreamCause' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +108,9 @@ pipeline {
|
|||||||
label 'data'
|
label 'data'
|
||||||
}
|
}
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
@@ -114,7 +120,7 @@ pipeline {
|
|||||||
sh 'sleep 10'
|
sh 'sleep 10'
|
||||||
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
sh 'sleep 15'
|
sh 'sleep 15'
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,6 +132,9 @@ pipeline {
|
|||||||
label 'data'
|
label 'data'
|
||||||
}
|
}
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
@@ -135,7 +144,7 @@ pipeline {
|
|||||||
sh 'sleep 10'
|
sh 'sleep 10'
|
||||||
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
sh 'sleep 15'
|
sh 'sleep 15'
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +156,9 @@ pipeline {
|
|||||||
label 'data'
|
label 'data'
|
||||||
}
|
}
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
@@ -156,7 +168,7 @@ pipeline {
|
|||||||
sh 'sleep 10'
|
sh 'sleep 10'
|
||||||
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
sh 'sleep 15'
|
sh 'sleep 15'
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pjava11 clean dependency:list test -Duser.name=jenkins -Dsort -U -B'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,7 +180,7 @@ pipeline {
|
|||||||
stage('Release to artifactory') {
|
stage('Release to artifactory') {
|
||||||
when {
|
when {
|
||||||
anyOf {
|
anyOf {
|
||||||
branch 'master'
|
branch '3.2.x'
|
||||||
not { triggeredBy 'UpstreamCause' }
|
not { triggeredBy 'UpstreamCause' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,7 +197,7 @@ pipeline {
|
|||||||
script {
|
script {
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,artifactory ' +
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pci,artifactory ' +
|
||||||
'-Dartifactory.server=https://repo.spring.io ' +
|
'-Dartifactory.server=https://repo.spring.io ' +
|
||||||
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
||||||
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
||||||
@@ -201,7 +213,7 @@ pipeline {
|
|||||||
|
|
||||||
stage('Publish documentation') {
|
stage('Publish documentation') {
|
||||||
when {
|
when {
|
||||||
branch 'master'
|
branch '3.2.x'
|
||||||
}
|
}
|
||||||
agent {
|
agent {
|
||||||
label 'data'
|
label 'data'
|
||||||
@@ -216,7 +228,7 @@ pipeline {
|
|||||||
script {
|
script {
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,distribute ' +
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pci,distribute ' +
|
||||||
'-Dartifactory.server=https://repo.spring.io ' +
|
'-Dartifactory.server=https://repo.spring.io ' +
|
||||||
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
||||||
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
||||||
|
|||||||
202
LICENSE.txt
Normal file
202
LICENSE.txt
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
https://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
11
pom.xml
11
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.2</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>Spring Data MongoDB</name>
|
<name>Spring Data MongoDB</name>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data.build</groupId>
|
<groupId>org.springframework.data.build</groupId>
|
||||||
<artifactId>spring-data-parent</artifactId>
|
<artifactId>spring-data-parent</artifactId>
|
||||||
<version>2.5.0</version>
|
<version>2.5.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.type>multi</project.type>
|
<project.type>multi</project.type>
|
||||||
<dist.id>spring-data-mongodb</dist.id>
|
<dist.id>spring-data-mongodb</dist.id>
|
||||||
<springdata.commons>2.5.0</springdata.commons>
|
<springdata.commons>2.5.2</springdata.commons>
|
||||||
<mongo>4.2.3</mongo>
|
<mongo>4.2.3</mongo>
|
||||||
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
|
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
|
||||||
<jmh.version>1.19</jmh.version>
|
<jmh.version>1.19</jmh.version>
|
||||||
@@ -158,11 +158,6 @@
|
|||||||
<id>spring-libs-milestone</id>
|
<id>spring-libs-milestone</id>
|
||||||
<url>https://repo.spring.io/libs-milestone</url>
|
<url>https://repo.spring.io/libs-milestone</url>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
<pluginRepository>
|
|
||||||
<id>bintray-plugins</id>
|
|
||||||
<name>bintray-plugins</name>
|
|
||||||
<url>https://jcenter.bintray.com</url>
|
|
||||||
</pluginRepository>
|
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
29
settings.xml
Normal file
29
settings.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
|
||||||
|
https://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||||
|
|
||||||
|
<servers>
|
||||||
|
<server>
|
||||||
|
<id>spring-plugins-release</id>
|
||||||
|
<username>${env.ARTIFACTORY_USR}</username>
|
||||||
|
<password>${env.ARTIFACTORY_PSW}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>spring-libs-snapshot</id>
|
||||||
|
<username>${env.ARTIFACTORY_USR}</username>
|
||||||
|
<password>${env.ARTIFACTORY_PSW}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>spring-libs-milestone</id>
|
||||||
|
<username>${env.ARTIFACTORY_USR}</username>
|
||||||
|
<password>${env.ARTIFACTORY_PSW}</password>
|
||||||
|
</server>
|
||||||
|
<server>
|
||||||
|
<id>spring-libs-release</id>
|
||||||
|
<username>${env.ARTIFACTORY_USR}</username>
|
||||||
|
<password>${env.ARTIFACTORY_PSW}</password>
|
||||||
|
</server>
|
||||||
|
</servers>
|
||||||
|
|
||||||
|
</settings>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.2</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.2</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.2</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
this::getWriteTarget);
|
this::getWriteTarget);
|
||||||
this.idMapper = new QueryMapper(this);
|
this.idMapper = new QueryMapper(this);
|
||||||
|
|
||||||
|
|
||||||
this.spELContext = new SpELContext(DocumentPropertyAccessor.INSTANCE);
|
this.spELContext = new SpELContext(DocumentPropertyAccessor.INSTANCE);
|
||||||
this.dbRefProxyHandler = new DefaultDbRefProxyHandler(spELContext, mappingContext,
|
this.dbRefProxyHandler = new DefaultDbRefProxyHandler(spELContext, mappingContext,
|
||||||
(prop, bson, evaluator, path) -> {
|
(prop, bson, evaluator, path) -> {
|
||||||
@@ -161,8 +160,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
Assert.notNull(path, "ObjectPath must not be null");
|
Assert.notNull(path, "ObjectPath must not be null");
|
||||||
|
|
||||||
return new ConversionContext(path, this::readDocument, this::readCollectionOrArray, this::readMap, this::readDBRef,
|
return new ConversionContext(conversions, path, this::readDocument, this::readCollectionOrArray, this::readMap,
|
||||||
this::getPotentiallyConvertedSimpleRead);
|
this::readDBRef, this::getPotentiallyConvertedSimpleRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -376,8 +375,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <S> S populateProperties(ConversionContext context, MongoPersistentEntity<S> entity,
|
private <S> S populateProperties(ConversionContext context, MongoPersistentEntity<S> entity,
|
||||||
DocumentAccessor documentAccessor,
|
DocumentAccessor documentAccessor, SpELExpressionEvaluator evaluator, S instance) {
|
||||||
SpELExpressionEvaluator evaluator, S instance) {
|
|
||||||
|
|
||||||
PersistentPropertyAccessor<S> accessor = new ConvertingPropertyAccessor<>(entity.getPropertyAccessor(instance),
|
PersistentPropertyAccessor<S> accessor = new ConvertingPropertyAccessor<>(entity.getPropertyAccessor(instance),
|
||||||
conversionService);
|
conversionService);
|
||||||
@@ -423,8 +421,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Object readIdValue(ConversionContext context, SpELExpressionEvaluator evaluator,
|
private Object readIdValue(ConversionContext context, SpELExpressionEvaluator evaluator,
|
||||||
MongoPersistentProperty idProperty,
|
MongoPersistentProperty idProperty, Object rawId) {
|
||||||
Object rawId) {
|
|
||||||
|
|
||||||
String expression = idProperty.getSpelExpression();
|
String expression = idProperty.getSpelExpression();
|
||||||
Object resolvedValue = expression != null ? evaluator.evaluate(expression) : rawId;
|
Object resolvedValue = expression != null ? evaluator.evaluate(expression) : rawId;
|
||||||
@@ -434,8 +431,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
private void readProperties(ConversionContext context, MongoPersistentEntity<?> entity,
|
private void readProperties(ConversionContext context, MongoPersistentEntity<?> entity,
|
||||||
PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor,
|
PersistentPropertyAccessor<?> accessor, DocumentAccessor documentAccessor,
|
||||||
MongoDbPropertyValueProvider valueProvider,
|
MongoDbPropertyValueProvider valueProvider, SpELExpressionEvaluator evaluator) {
|
||||||
SpELExpressionEvaluator evaluator) {
|
|
||||||
|
|
||||||
DbRefResolverCallback callback = null;
|
DbRefResolverCallback callback = null;
|
||||||
|
|
||||||
@@ -505,8 +501,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Object readUnwrapped(ConversionContext context, DocumentAccessor documentAccessor,
|
private Object readUnwrapped(ConversionContext context, DocumentAccessor documentAccessor,
|
||||||
MongoPersistentProperty prop,
|
MongoPersistentProperty prop, MongoPersistentEntity<?> unwrappedEntity) {
|
||||||
MongoPersistentEntity<?> unwrappedEntity) {
|
|
||||||
|
|
||||||
if (prop.findAnnotation(Unwrapped.class).onEmpty().equals(OnEmpty.USE_EMPTY)) {
|
if (prop.findAnnotation(Unwrapped.class).onEmpty().equals(OnEmpty.USE_EMPTY)) {
|
||||||
return read(context, unwrappedEntity, (Document) documentAccessor.getDocument());
|
return read(context, unwrappedEntity, (Document) documentAccessor.getDocument());
|
||||||
@@ -1206,7 +1201,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
map.put(key, context.convert(value, valueType));
|
map.put(key, value == null ? value : context.convert(value, valueType));
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
@@ -1447,8 +1442,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
T target = null;
|
T target = null;
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
|
|
||||||
maybeEmitEvent(
|
maybeEmitEvent(new AfterLoadEvent<>(document, (Class<T>) type.getType(), collectionName));
|
||||||
new AfterLoadEvent<>(document, (Class<T>) type.getType(), collectionName));
|
|
||||||
target = (T) readDocument(context, document, type);
|
target = (T) readDocument(context, document, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1541,9 +1535,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private <T extends Object> T doConvert(Object value, Class<? extends T> target, @Nullable Class<? extends T> fallback) {
|
private <T extends Object> T doConvert(Object value, Class<? extends T> target,
|
||||||
|
@Nullable Class<? extends T> fallback) {
|
||||||
|
|
||||||
if(conversionService.canConvert(value.getClass(), target) || fallback == null) {
|
if (conversionService.canConvert(value.getClass(), target) || fallback == null) {
|
||||||
return conversionService.convert(value, target);
|
return conversionService.convert(value, target);
|
||||||
}
|
}
|
||||||
return conversionService.convert(value, fallback);
|
return conversionService.convert(value, fallback);
|
||||||
@@ -1853,6 +1848,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
*/
|
*/
|
||||||
protected static class ConversionContext {
|
protected static class ConversionContext {
|
||||||
|
|
||||||
|
private final org.springframework.data.convert.CustomConversions conversions;
|
||||||
private final ObjectPath path;
|
private final ObjectPath path;
|
||||||
private final ContainerValueConverter<Bson> documentConverter;
|
private final ContainerValueConverter<Bson> documentConverter;
|
||||||
private final ContainerValueConverter<Collection<?>> collectionConverter;
|
private final ContainerValueConverter<Collection<?>> collectionConverter;
|
||||||
@@ -1860,10 +1856,12 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
private final ContainerValueConverter<DBRef> dbRefConverter;
|
private final ContainerValueConverter<DBRef> dbRefConverter;
|
||||||
private final ValueConverter<Object> elementConverter;
|
private final ValueConverter<Object> elementConverter;
|
||||||
|
|
||||||
ConversionContext(ObjectPath path, ContainerValueConverter<Bson> documentConverter,
|
ConversionContext(org.springframework.data.convert.CustomConversions customConversions, ObjectPath path,
|
||||||
ContainerValueConverter<Collection<?>> collectionConverter, ContainerValueConverter<Bson> mapConverter,
|
ContainerValueConverter<Bson> documentConverter, ContainerValueConverter<Collection<?>> collectionConverter,
|
||||||
ContainerValueConverter<DBRef> dbRefConverter, ValueConverter<Object> elementConverter) {
|
ContainerValueConverter<Bson> mapConverter, ContainerValueConverter<DBRef> dbRefConverter,
|
||||||
|
ValueConverter<Object> elementConverter) {
|
||||||
|
|
||||||
|
this.conversions = customConversions;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.documentConverter = documentConverter;
|
this.documentConverter = documentConverter;
|
||||||
this.collectionConverter = collectionConverter;
|
this.collectionConverter = collectionConverter;
|
||||||
@@ -1884,6 +1882,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
Assert.notNull(typeHint, "TypeInformation must not be null");
|
Assert.notNull(typeHint, "TypeInformation must not be null");
|
||||||
|
|
||||||
|
if (conversions.hasCustomReadTarget(source.getClass(), typeHint.getType())) {
|
||||||
|
return (S) elementConverter.convert(source, typeHint);
|
||||||
|
}
|
||||||
|
|
||||||
if (source instanceof Collection) {
|
if (source instanceof Collection) {
|
||||||
|
|
||||||
Class<?> rawType = typeHint.getType();
|
Class<?> rawType = typeHint.getType();
|
||||||
@@ -1929,8 +1931,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
Assert.notNull(currentPath, "ObjectPath must not be null");
|
Assert.notNull(currentPath, "ObjectPath must not be null");
|
||||||
|
|
||||||
return new ConversionContext(currentPath, documentConverter, collectionConverter, mapConverter, dbRefConverter,
|
return new ConversionContext(conversions, currentPath, documentConverter, collectionConverter, mapConverter,
|
||||||
elementConverter);
|
dbRefConverter, elementConverter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectPath getPath() {
|
public ObjectPath getPath() {
|
||||||
|
|||||||
@@ -19,11 +19,14 @@ import java.util.*;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bson.BsonValue;
|
import org.bson.BsonValue;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.conversions.Bson;
|
import org.bson.conversions.Bson;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.data.domain.Example;
|
import org.springframework.data.domain.Example;
|
||||||
@@ -68,6 +71,8 @@ import com.mongodb.DBRef;
|
|||||||
*/
|
*/
|
||||||
public class QueryMapper {
|
public class QueryMapper {
|
||||||
|
|
||||||
|
protected static final Logger LOGGER = LoggerFactory.getLogger(QueryMapper.class);
|
||||||
|
|
||||||
private static final List<String> DEFAULT_ID_NAMES = Arrays.asList("id", "_id");
|
private static final List<String> DEFAULT_ID_NAMES = Arrays.asList("id", "_id");
|
||||||
private static final Document META_TEXT_SCORE = new Document("$meta", "textScore");
|
private static final Document META_TEXT_SCORE = new Document("$meta", "textScore");
|
||||||
static final ClassTypeInformation<?> NESTED_DOCUMENT = ClassTypeInformation.from(NestedDocument.class);
|
static final ClassTypeInformation<?> NESTED_DOCUMENT = ClassTypeInformation.from(NestedDocument.class);
|
||||||
@@ -189,19 +194,7 @@ public class QueryMapper {
|
|||||||
return new Document();
|
return new Document();
|
||||||
}
|
}
|
||||||
|
|
||||||
sortObject = filterUnwrappedObjects(sortObject, entity);
|
Document mappedSort = mapFieldsToPropertyNames(sortObject, entity);
|
||||||
|
|
||||||
Document mappedSort = new Document();
|
|
||||||
for (Map.Entry<String, Object> entry : BsonUtils.asMap(sortObject).entrySet()) {
|
|
||||||
|
|
||||||
Field field = createPropertyField(entity, entry.getKey(), mappingContext);
|
|
||||||
if (field.getProperty() != null && field.getProperty().isUnwrapped()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mappedSort.put(field.getMappedKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
mapMetaAttributes(mappedSort, entity, MetaMapping.WHEN_PRESENT);
|
mapMetaAttributes(mappedSort, entity, MetaMapping.WHEN_PRESENT);
|
||||||
return mappedSort;
|
return mappedSort;
|
||||||
}
|
}
|
||||||
@@ -219,13 +212,30 @@ public class QueryMapper {
|
|||||||
|
|
||||||
Assert.notNull(fieldsObject, "FieldsObject must not be null!");
|
Assert.notNull(fieldsObject, "FieldsObject must not be null!");
|
||||||
|
|
||||||
fieldsObject = filterUnwrappedObjects(fieldsObject, entity);
|
Document mappedFields = mapFieldsToPropertyNames(fieldsObject, entity);
|
||||||
|
|
||||||
Document mappedFields = getMappedObject(fieldsObject, entity);
|
|
||||||
mapMetaAttributes(mappedFields, entity, MetaMapping.FORCE);
|
mapMetaAttributes(mappedFields, entity, MetaMapping.FORCE);
|
||||||
return mappedFields;
|
return mappedFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Document mapFieldsToPropertyNames(Document fields, @Nullable MongoPersistentEntity<?> entity) {
|
||||||
|
|
||||||
|
if (fields.isEmpty()) {
|
||||||
|
return new Document();
|
||||||
|
|
||||||
|
}
|
||||||
|
Document target = new Document();
|
||||||
|
for (Map.Entry<String, Object> entry : BsonUtils.asMap(filterUnwrappedObjects(fields, entity)).entrySet()) {
|
||||||
|
|
||||||
|
Field field = createPropertyField(entity, entry.getKey(), mappingContext);
|
||||||
|
if (field.getProperty() != null && field.getProperty().isUnwrapped()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.put(field.getMappedKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
private void mapMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity, MetaMapping metaMapping) {
|
private void mapMetaAttributes(Document source, @Nullable MongoPersistentEntity<?> entity, MetaMapping metaMapping) {
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
@@ -444,6 +454,10 @@ public class QueryMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isNestedKeyword(value)) {
|
if (isNestedKeyword(value)) {
|
||||||
return getMappedKeyword(new Keyword((Bson) value), documentField.getPropertyEntity());
|
return getMappedKeyword(new Keyword((Bson) value), documentField.getPropertyEntity());
|
||||||
}
|
}
|
||||||
@@ -706,7 +720,7 @@ public class QueryMapper {
|
|||||||
* @param candidate
|
* @param candidate
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected boolean isNestedKeyword(Object candidate) {
|
protected boolean isNestedKeyword(@Nullable Object candidate) {
|
||||||
|
|
||||||
if (!(candidate instanceof Document)) {
|
if (!(candidate instanceof Document)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -751,12 +765,13 @@ public class QueryMapper {
|
|||||||
* converted one by one.
|
* converted one by one.
|
||||||
*
|
*
|
||||||
* @param documentField the field and its meta data
|
* @param documentField the field and its meta data
|
||||||
* @param value the actual value
|
* @param value the actual value. Can be {@literal null}.
|
||||||
* @return the potentially converted target value.
|
* @return the potentially converted target value.
|
||||||
*/
|
*/
|
||||||
private Object applyFieldTargetTypeHintToValue(Field documentField, Object value) {
|
@Nullable
|
||||||
|
private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Object value) {
|
||||||
|
|
||||||
if (documentField.getProperty() == null || !documentField.getProperty().hasExplicitWriteTarget()) {
|
if (value == null || documentField.getProperty() == null || !documentField.getProperty().hasExplicitWriteTarget()) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,7 +802,6 @@ public class QueryMapper {
|
|||||||
*/
|
*/
|
||||||
static class Keyword {
|
static class Keyword {
|
||||||
|
|
||||||
private static final String N_OR_PATTERN = "\\$.*or";
|
|
||||||
private static final Set<String> NON_DBREF_CONVERTING_KEYWORDS = new HashSet<>(
|
private static final Set<String> NON_DBREF_CONVERTING_KEYWORDS = new HashSet<>(
|
||||||
Arrays.asList("$", "$size", "$slice", "$gt", "$lt"));
|
Arrays.asList("$", "$size", "$slice", "$gt", "$lt"));
|
||||||
|
|
||||||
@@ -818,7 +832,7 @@ public class QueryMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOrOrNor() {
|
public boolean isOrOrNor() {
|
||||||
return key.matches(N_OR_PATTERN);
|
return key.equalsIgnoreCase("$or") || key.equalsIgnoreCase("$nor");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1169,8 +1183,8 @@ public class QueryMapper {
|
|||||||
removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression));
|
removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression));
|
||||||
|
|
||||||
if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
|
if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
|
||||||
return mappingContext
|
return mappingContext.getPersistentPropertyPath(
|
||||||
.getPersistentPropertyPath(PropertyPath.from(Pattern.quote(sourceProperty.getName()), entity.getTypeInformation()));
|
PropertyPath.from(Pattern.quote(sourceProperty.getName()), entity.getTypeInformation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyPath path = forName(rawPath);
|
PropertyPath path = forName(rawPath);
|
||||||
@@ -1178,29 +1192,47 @@ public class QueryMapper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
PersistentPropertyPath<MongoPersistentProperty> propertyPath = tryToResolvePersistentPropertyPath(path);
|
||||||
|
|
||||||
PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(path);
|
if (propertyPath == null) {
|
||||||
|
|
||||||
Iterator<MongoPersistentProperty> iterator = propertyPath.iterator();
|
if (QueryMapper.LOGGER.isInfoEnabled()) {
|
||||||
boolean associationDetected = false;
|
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
String types = StringUtils.collectionToDelimitedString(
|
||||||
|
path.stream().map(it -> it.getType().getSimpleName()).collect(Collectors.toList()), " -> ");
|
||||||
|
QueryMapper.LOGGER.info(
|
||||||
|
"Could not map '{}'. Maybe a fragment in '{}' is considered a simple type. Mapper continues with {}.",
|
||||||
|
path, types, pathExpression);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
MongoPersistentProperty property = iterator.next();
|
Iterator<MongoPersistentProperty> iterator = propertyPath.iterator();
|
||||||
|
boolean associationDetected = false;
|
||||||
|
|
||||||
if (property.isAssociation()) {
|
while (iterator.hasNext()) {
|
||||||
associationDetected = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (associationDetected && !property.isIdProperty()) {
|
MongoPersistentProperty property = iterator.next();
|
||||||
throw new MappingException(String.format(INVALID_ASSOCIATION_REFERENCE, pathExpression));
|
|
||||||
}
|
if (property.isAssociation()) {
|
||||||
|
associationDetected = true;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return propertyPath;
|
if (associationDetected && !property.isIdProperty()) {
|
||||||
} catch (InvalidPersistentPropertyPath e) {
|
throw new MappingException(String.format(INVALID_ASSOCIATION_REFERENCE, pathExpression));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return propertyPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private PersistentPropertyPath<MongoPersistentProperty> tryToResolvePersistentPropertyPath(PropertyPath path) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
return mappingContext.getPersistentPropertyPath(path);
|
||||||
|
} catch (MappingException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
package org.springframework.data.mongodb.core.geo;
|
package org.springframework.data.mongodb.core.geo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface definition for structures defined in <a href="https://geojson.org/>GeoJSON</a> format.
|
* Interface definition for structures defined in <a href="https://geojson.org/">GeoJSON</a> format.
|
||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @since 1.7
|
* @since 1.7
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import org.springframework.data.repository.core.RepositoryInformation;
|
|||||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||||
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments;
|
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments;
|
||||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||||
import org.springframework.data.repository.core.support.RepositoryFragment;
|
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||||
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
|
||||||
@@ -92,8 +91,21 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
|
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
|
||||||
|
return getRepositoryFragments(metadata, operations);
|
||||||
|
}
|
||||||
|
|
||||||
RepositoryFragments fragments = RepositoryFragments.empty();
|
/**
|
||||||
|
* Creates {@link RepositoryFragments} based on {@link RepositoryMetadata} to add Mongo-specific extensions. Typically
|
||||||
|
* adds a {@link QuerydslMongoPredicateExecutor} if the repository interface uses Querydsl.
|
||||||
|
* <p>
|
||||||
|
* Can be overridden by subclasses to customize {@link RepositoryFragments}.
|
||||||
|
*
|
||||||
|
* @param metadata repository metadata.
|
||||||
|
* @param operations the MongoDB operations manager.
|
||||||
|
* @return
|
||||||
|
* @since 3.2.1
|
||||||
|
*/
|
||||||
|
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata, MongoOperations operations) {
|
||||||
|
|
||||||
boolean isQueryDslRepository = QUERY_DSL_PRESENT
|
boolean isQueryDslRepository = QUERY_DSL_PRESENT
|
||||||
&& QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
|
&& QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
|
||||||
@@ -105,14 +117,11 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
|||||||
"Cannot combine Querydsl and reactive repository support in a single interface");
|
"Cannot combine Querydsl and reactive repository support in a single interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType(),
|
return RepositoryFragments
|
||||||
metadata);
|
.just(new QuerydslMongoPredicateExecutor<>(getEntityInformation(metadata.getDomainType()), operations));
|
||||||
|
|
||||||
fragments = fragments.append(RepositoryFragment.implemented(
|
|
||||||
getTargetRepositoryViaReflection(QuerydslMongoPredicateExecutor.class, entityInformation, operations)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fragments;
|
return RepositoryFragments.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.bson.types.Code;
|
import org.bson.types.Code;
|
||||||
import org.bson.types.Decimal128;
|
import org.bson.types.Decimal128;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
@@ -42,6 +41,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.beans.ConversionNotSupportedException;
|
import org.springframework.beans.ConversionNotSupportedException;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -81,6 +81,8 @@ import org.springframework.data.mongodb.core.mapping.TextScore;
|
|||||||
import org.springframework.data.mongodb.core.mapping.Unwrapped;
|
import org.springframework.data.mongodb.core.mapping.Unwrapped;
|
||||||
import org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback;
|
import org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback;
|
||||||
import org.springframework.data.util.ClassTypeInformation;
|
import org.springframework.data.util.ClassTypeInformation;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
import com.mongodb.BasicDBList;
|
import com.mongodb.BasicDBList;
|
||||||
@@ -527,7 +529,7 @@ class MappingMongoConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertsObjectsIfNecessary() {
|
void convertsObjectsIfNecessary() {
|
||||||
|
|
||||||
ObjectId id = new ObjectId();
|
ObjectId id = new ObjectId();
|
||||||
assertThat(converter.convertToMongoType(id)).isEqualTo(id);
|
assertThat(converter.convertToMongoType(id)).isEqualTo(id);
|
||||||
@@ -2111,21 +2113,21 @@ class MappingMongoConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2479
|
@Test // DATAMONGO-2479
|
||||||
public void entityCallbacksAreNotSetByDefault() {
|
void entityCallbacksAreNotSetByDefault() {
|
||||||
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNull();
|
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2479
|
@Test // DATAMONGO-2479
|
||||||
public void entityCallbacksShouldBeInitiatedOnSettingApplicationContext() {
|
void entityCallbacksShouldBeInitiatedOnSettingApplicationContext() {
|
||||||
|
|
||||||
ApplicationContext ctx = new StaticApplicationContext();
|
ApplicationContext ctx = new StaticApplicationContext();
|
||||||
converter.setApplicationContext(ctx);
|
converter.setApplicationContext(ctx);
|
||||||
|
|
||||||
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNotNull();
|
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2479
|
@Test // DATAMONGO-2479
|
||||||
public void setterForEntityCallbackOverridesContextInitializedOnes() {
|
void setterForEntityCallbackOverridesContextInitializedOnes() {
|
||||||
|
|
||||||
ApplicationContext ctx = new StaticApplicationContext();
|
ApplicationContext ctx = new StaticApplicationContext();
|
||||||
converter.setApplicationContext(ctx);
|
converter.setApplicationContext(ctx);
|
||||||
@@ -2133,11 +2135,11 @@ class MappingMongoConverterUnitTests {
|
|||||||
EntityCallbacks callbacks = EntityCallbacks.create();
|
EntityCallbacks callbacks = EntityCallbacks.create();
|
||||||
converter.setEntityCallbacks(callbacks);
|
converter.setEntityCallbacks(callbacks);
|
||||||
|
|
||||||
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
|
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2479
|
@Test // DATAMONGO-2479
|
||||||
public void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
|
void setterForApplicationContextShouldNotOverrideAlreadySetEntityCallbacks() {
|
||||||
|
|
||||||
EntityCallbacks callbacks = EntityCallbacks.create();
|
EntityCallbacks callbacks = EntityCallbacks.create();
|
||||||
ApplicationContext ctx = new StaticApplicationContext();
|
ApplicationContext ctx = new StaticApplicationContext();
|
||||||
@@ -2145,11 +2147,11 @@ class MappingMongoConverterUnitTests {
|
|||||||
converter.setEntityCallbacks(callbacks);
|
converter.setEntityCallbacks(callbacks);
|
||||||
converter.setApplicationContext(ctx);
|
converter.setApplicationContext(ctx);
|
||||||
|
|
||||||
Assertions.assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
|
assertThat(ReflectionTestUtils.getField(converter, "entityCallbacks")).isSameAs(callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2479
|
@Test // DATAMONGO-2479
|
||||||
public void resolveDBRefMapValueShouldInvokeCallbacks() {
|
void resolveDBRefMapValueShouldInvokeCallbacks() {
|
||||||
|
|
||||||
AfterConvertCallback<Person> afterConvertCallback = spy(new ReturningAfterConvertCallback());
|
AfterConvertCallback<Person> afterConvertCallback = spy(new ReturningAfterConvertCallback());
|
||||||
converter.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
converter.setEntityCallbacks(EntityCallbacks.create(afterConvertCallback));
|
||||||
@@ -2166,7 +2168,7 @@ class MappingMongoConverterUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAMONGO-2300
|
@Test // DATAMONGO-2300
|
||||||
public void readAndConvertDBRefNestedByMapCorrectly() {
|
void readAndConvertDBRefNestedByMapCorrectly() {
|
||||||
|
|
||||||
org.bson.Document cluster = new org.bson.Document("_id", 100L);
|
org.bson.Document cluster = new org.bson.Document("_id", 100L);
|
||||||
DBRef dbRef = new DBRef("clusters", 100L);
|
DBRef dbRef = new DBRef("clusters", 100L);
|
||||||
@@ -2428,6 +2430,96 @@ class MappingMongoConverterUnitTests {
|
|||||||
verify(subTypeOfGenericTypeConverter).convert(eq(source));
|
verify(subTypeOfGenericTypeConverter).convert(eq(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test // GH-3660
|
||||||
|
void usesCustomConverterForMapTypesOnWrite() {
|
||||||
|
|
||||||
|
converter = new MappingMongoConverter(resolver, mappingContext);
|
||||||
|
converter.setCustomConversions(MongoCustomConversions.create(it -> {
|
||||||
|
it.registerConverter(new TypeImplementingMapToDocumentConverter());
|
||||||
|
}));
|
||||||
|
converter.afterPropertiesSet();
|
||||||
|
|
||||||
|
TypeImplementingMap source = new TypeImplementingMap("one", 2);
|
||||||
|
org.bson.Document target = new org.bson.Document();
|
||||||
|
|
||||||
|
converter.write(source, target);
|
||||||
|
|
||||||
|
assertThat(target).containsEntry("1st", "one").containsEntry("2nd", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3660
|
||||||
|
void usesCustomConverterForTypesImplementingMapOnWrite() {
|
||||||
|
|
||||||
|
converter = new MappingMongoConverter(resolver, mappingContext);
|
||||||
|
converter.setCustomConversions(MongoCustomConversions.create(it -> {
|
||||||
|
it.registerConverter(new TypeImplementingMapToDocumentConverter());
|
||||||
|
}));
|
||||||
|
converter.afterPropertiesSet();
|
||||||
|
|
||||||
|
TypeImplementingMap source = new TypeImplementingMap("one", 2);
|
||||||
|
org.bson.Document target = new org.bson.Document();
|
||||||
|
|
||||||
|
converter.write(source, target);
|
||||||
|
|
||||||
|
assertThat(target).containsEntry("1st", "one").containsEntry("2nd", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3660
|
||||||
|
void usesCustomConverterForTypesImplementingMapOnRead() {
|
||||||
|
|
||||||
|
converter = new MappingMongoConverter(resolver, mappingContext);
|
||||||
|
converter.setCustomConversions(MongoCustomConversions.create(it -> {
|
||||||
|
it.registerConverter(new DocumentToTypeImplementingMapConverter());
|
||||||
|
}));
|
||||||
|
converter.afterPropertiesSet();
|
||||||
|
|
||||||
|
org.bson.Document source = new org.bson.Document("1st", "one")
|
||||||
|
.append("2nd", 2)
|
||||||
|
.append("_class", TypeImplementingMap.class.getName());
|
||||||
|
|
||||||
|
TypeImplementingMap target = converter.read(TypeImplementingMap.class, source);
|
||||||
|
|
||||||
|
assertThat(target).isEqualTo(new TypeImplementingMap("one", 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3660
|
||||||
|
void usesCustomConverterForPropertiesUsingTypesThatImplementMapOnWrite() {
|
||||||
|
|
||||||
|
converter = new MappingMongoConverter(resolver, mappingContext);
|
||||||
|
converter.setCustomConversions(MongoCustomConversions.create(it -> {
|
||||||
|
it.registerConverter(new TypeImplementingMapToDocumentConverter());
|
||||||
|
}));
|
||||||
|
converter.afterPropertiesSet();
|
||||||
|
|
||||||
|
TypeWrappingTypeImplementingMap source = new TypeWrappingTypeImplementingMap();
|
||||||
|
source.typeImplementingMap = new TypeImplementingMap("one", 2);
|
||||||
|
org.bson.Document target = new org.bson.Document();
|
||||||
|
|
||||||
|
converter.write(source, target);
|
||||||
|
|
||||||
|
assertThat(target).containsEntry("typeImplementingMap", new org.bson.Document("1st", "one").append("2nd", 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3660
|
||||||
|
void usesCustomConverterForPropertiesUsingTypesImplementingMapOnRead() {
|
||||||
|
|
||||||
|
converter = new MappingMongoConverter(resolver, mappingContext);
|
||||||
|
converter.setCustomConversions(MongoCustomConversions.create(it -> {
|
||||||
|
it.registerConverter(new DocumentToTypeImplementingMapConverter());
|
||||||
|
}));
|
||||||
|
converter.afterPropertiesSet();
|
||||||
|
|
||||||
|
org.bson.Document source = new org.bson.Document("typeImplementingMap",
|
||||||
|
new org.bson.Document("1st", "one")
|
||||||
|
.append("2nd", 2))
|
||||||
|
.append("_class", TypeWrappingTypeImplementingMap.class.getName());
|
||||||
|
|
||||||
|
TypeWrappingTypeImplementingMap target = converter.read(TypeWrappingTypeImplementingMap.class, source);
|
||||||
|
|
||||||
|
assertThat(target.typeImplementingMap).isEqualTo(new TypeImplementingMap("one", 2));
|
||||||
|
}
|
||||||
|
|
||||||
static class GenericType<T> {
|
static class GenericType<T> {
|
||||||
T content;
|
T content;
|
||||||
}
|
}
|
||||||
@@ -2971,4 +3063,106 @@ class MappingMongoConverterUnitTests {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WritingConverter
|
||||||
|
static class TypeImplementingMapToDocumentConverter implements Converter<TypeImplementingMap, org.bson.Document> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public org.bson.Document convert(TypeImplementingMap source) {
|
||||||
|
return new org.bson.Document("1st", source.val1).append("2nd", source.val2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReadingConverter
|
||||||
|
static class DocumentToTypeImplementingMapConverter implements Converter<org.bson.Document, TypeImplementingMap> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public TypeImplementingMap convert(org.bson.Document source) {
|
||||||
|
return new TypeImplementingMap(source.getString("1st"), source.getInteger("2nd"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TypeWrappingTypeImplementingMap {
|
||||||
|
|
||||||
|
String id;
|
||||||
|
TypeImplementingMap typeImplementingMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EqualsAndHashCode
|
||||||
|
static class TypeImplementingMap implements Map<String,String> {
|
||||||
|
|
||||||
|
String val1;
|
||||||
|
int val2;
|
||||||
|
|
||||||
|
TypeImplementingMap(String val1, int val2) {
|
||||||
|
this.val1 = val1;
|
||||||
|
this.val2 = val2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(Object key) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(Object value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get(Object key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String put(String key, String value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String remove(Object key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putAll(@NonNull Map<? extends String, ? extends String> m) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Set<String> keySet() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Collection<String> values() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Set<Entry<String, String>> entrySet() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,13 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
|
import org.springframework.data.convert.WritingConverter;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.domain.Sort.Direction;
|
import org.springframework.data.domain.Sort.Direction;
|
||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
@@ -50,6 +55,7 @@ import org.springframework.data.mongodb.core.mapping.DBRef;
|
|||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
import org.springframework.data.mongodb.core.mapping.Field;
|
import org.springframework.data.mongodb.core.mapping.Field;
|
||||||
import org.springframework.data.mongodb.core.mapping.FieldType;
|
import org.springframework.data.mongodb.core.mapping.FieldType;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.MongoId;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||||
import org.springframework.data.mongodb.core.mapping.TextScore;
|
import org.springframework.data.mongodb.core.mapping.TextScore;
|
||||||
@@ -73,6 +79,7 @@ import com.mongodb.client.model.Filters;
|
|||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
public class QueryMapperUnitTests {
|
public class QueryMapperUnitTests {
|
||||||
|
|
||||||
private QueryMapper mapper;
|
private QueryMapper mapper;
|
||||||
@@ -1257,6 +1264,52 @@ public class QueryMapperUnitTests {
|
|||||||
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.renamed", new org.bson.Document("$exists", true)));
|
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.renamed", new org.bson.Document("$exists", true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-3633
|
||||||
|
void mapsNullValueForFieldWithCustomTargetType() {
|
||||||
|
|
||||||
|
Query query = query(where("stringAsOid").is(null));
|
||||||
|
|
||||||
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(),
|
||||||
|
context.getPersistentEntity(NonIdFieldWithObjectIdTargetType.class));
|
||||||
|
|
||||||
|
assertThat(document).isEqualTo(new org.bson.Document("stringAsOid", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3635
|
||||||
|
void $floorKeywordDoesNotMatch$or$norPattern() {
|
||||||
|
|
||||||
|
Query query = new BasicQuery(" { $expr: { $gt: [ \"$spent\" , { $floor : \"$budget\" } ] } }");
|
||||||
|
assertThatNoException()
|
||||||
|
.isThrownBy(() -> mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3659
|
||||||
|
void allowsUsingFieldPathsForPropertiesHavingCustomConversionRegistered() {
|
||||||
|
|
||||||
|
Query query = query(where("address.street").is("1007 Mountain Drive"));
|
||||||
|
|
||||||
|
MongoCustomConversions mongoCustomConversions = new MongoCustomConversions(Collections.singletonList(new MyAddressToDocumentConverter()));
|
||||||
|
|
||||||
|
this.context = new MongoMappingContext();
|
||||||
|
this.context.setSimpleTypeHolder(mongoCustomConversions.getSimpleTypeHolder());
|
||||||
|
this.context.afterPropertiesSet();
|
||||||
|
|
||||||
|
this.converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, context);
|
||||||
|
this.converter.setCustomConversions(mongoCustomConversions);
|
||||||
|
this.converter.afterPropertiesSet();
|
||||||
|
|
||||||
|
this.mapper = new QueryMapper(converter);
|
||||||
|
|
||||||
|
assertThat(mapper.getMappedSort(query.getQueryObject(), context.getPersistentEntity(Customer.class))).isEqualTo(new org.bson.Document("address.street", "1007 Mountain Drive"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // GH-3668
|
||||||
|
void mapStringIdFieldProjection() {
|
||||||
|
|
||||||
|
org.bson.Document mappedFields = mapper.getMappedFields(new org.bson.Document("id", 1), context.getPersistentEntity(WithStringId.class));
|
||||||
|
assertThat(mappedFields).containsEntry("_id", 1);
|
||||||
|
}
|
||||||
|
|
||||||
class WithDeepArrayNesting {
|
class WithDeepArrayNesting {
|
||||||
|
|
||||||
List<WithNestedArray> level0;
|
List<WithNestedArray> level0;
|
||||||
@@ -1320,6 +1373,12 @@ public class QueryMapperUnitTests {
|
|||||||
@Id private String foo;
|
@Id private String foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WithStringId {
|
||||||
|
|
||||||
|
@MongoId String id;
|
||||||
|
String name;
|
||||||
|
}
|
||||||
|
|
||||||
class BigIntegerId {
|
class BigIntegerId {
|
||||||
|
|
||||||
@Id private BigInteger id;
|
@Id private BigInteger id;
|
||||||
@@ -1396,18 +1455,18 @@ public class QueryMapperUnitTests {
|
|||||||
@Field("geoJsonPointWithNameViaFieldAnnotation") GeoJsonPoint namedGeoJsonPoint;
|
@Field("geoJsonPointWithNameViaFieldAnnotation") GeoJsonPoint namedGeoJsonPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class SimpeEntityWithoutId {
|
static class SimpleEntityWithoutId {
|
||||||
|
|
||||||
String stringProperty;
|
String stringProperty;
|
||||||
Integer integerProperty;
|
Integer integerProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class EntityWithComplexValueTypeMap {
|
static class EntityWithComplexValueTypeMap {
|
||||||
Map<Integer, SimpeEntityWithoutId> map;
|
Map<Integer, SimpleEntityWithoutId> map;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class EntityWithComplexValueTypeList {
|
static class EntityWithComplexValueTypeList {
|
||||||
List<SimpeEntityWithoutId> list;
|
List<SimpleEntityWithoutId> list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class WithExplicitTargetTypes {
|
static class WithExplicitTargetTypes {
|
||||||
@@ -1487,4 +1546,28 @@ public class QueryMapperUnitTests {
|
|||||||
@Field("renamed")
|
@Field("renamed")
|
||||||
String renamed_fieldname_with_underscores;
|
String renamed_fieldname_with_underscores;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Document
|
||||||
|
static class Customer {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private ObjectId id;
|
||||||
|
private String name;
|
||||||
|
private MyAddress address;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyAddress {
|
||||||
|
private String street;
|
||||||
|
}
|
||||||
|
|
||||||
|
@WritingConverter
|
||||||
|
public static class MyAddressToDocumentConverter implements Converter<MyAddress, org.bson.Document> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.bson.Document convert(MyAddress address) {
|
||||||
|
org.bson.Document doc = new org.bson.Document();
|
||||||
|
doc.put("street", address.street);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ import org.springframework.data.mongodb.core.MongoOperations;
|
|||||||
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||||
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
|
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
|
||||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
import org.springframework.data.mongodb.repository.Person.Sex;
|
import org.springframework.data.mongodb.repository.Person.Sex;
|
||||||
import org.springframework.data.mongodb.repository.SampleEvaluationContextExtension.SampleSecurityContextHolder;
|
import org.springframework.data.mongodb.repository.SampleEvaluationContextExtension.SampleSecurityContextHolder;
|
||||||
import org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion;
|
import org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion;
|
||||||
@@ -1422,4 +1424,14 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
|||||||
Person target = repository.findWithAggregationInProjection(alicia.getId());
|
Person target = repository.findWithAggregationInProjection(alicia.getId());
|
||||||
assertThat(target.getFirstname()).isEqualTo(alicia.getFirstname().toUpperCase());
|
assertThat(target.getFirstname()).isEqualTo(alicia.getFirstname().toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-3633
|
||||||
|
void annotatedQueryWithNullEqualityCheckShouldWork() {
|
||||||
|
|
||||||
|
operations.updateFirst(Query.query(Criteria.where("id").is(dave.getId())), Update.update("age", null), Person.class);
|
||||||
|
|
||||||
|
Person byQueryWithNullEqualityCheck = repository.findByQueryWithNullEqualityCheck();
|
||||||
|
assertThat(byQueryWithNullEqualityCheck.getId()).isEqualTo(dave.getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -410,4 +410,7 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
|
|||||||
List<Person> findByUnwrappedUserUsername(String username);
|
List<Person> findByUnwrappedUserUsername(String username);
|
||||||
|
|
||||||
List<Person> findByUnwrappedUser(User user);
|
List<Person> findByUnwrappedUser(User user);
|
||||||
|
|
||||||
|
@Query("{ 'age' : null }")
|
||||||
|
Person findByQueryWithNullEqualityCheck();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ public class MongoTestTemplateConfiguration {
|
|||||||
mappingContext = new MongoMappingContext();
|
mappingContext = new MongoMappingContext();
|
||||||
mappingContext.setInitialEntitySet(mappingContextConfigurer.initialEntitySet());
|
mappingContext.setInitialEntitySet(mappingContextConfigurer.initialEntitySet());
|
||||||
mappingContext.setAutoIndexCreation(mappingContextConfigurer.autocreateIndex);
|
mappingContext.setAutoIndexCreation(mappingContextConfigurer.autocreateIndex);
|
||||||
|
if(mongoConverterConfigurer.customConversions != null) {
|
||||||
|
mappingContext.setSimpleTypeHolder(mongoConverterConfigurer.customConversions.getSimpleTypeHolder());
|
||||||
|
}
|
||||||
mappingContext.afterPropertiesSet();
|
mappingContext.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -383,6 +383,13 @@ class ParameterBindingJsonReaderUnitTests {
|
|||||||
.parse("{ 'stores.location' : { $geoWithin: { $centerSphere: [ [ 1.948516, 48.799029 ] , 0.004 ] } } }"));
|
.parse("{ 'stores.location' : { $geoWithin: { $centerSphere: [ [ 1.948516, 48.799029 ] , 0.004 ] } } }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-3633
|
||||||
|
void parsesNullValue() {
|
||||||
|
|
||||||
|
Document target = parse("{ 'parent' : null }");
|
||||||
|
assertThat(target).isEqualTo(new Document("parent", null));
|
||||||
|
}
|
||||||
|
|
||||||
private static Document parse(String json, Object... args) {
|
private static Document parse(String json, Object... args) {
|
||||||
|
|
||||||
ParameterBindingJsonReader reader = new ParameterBindingJsonReader(json, args);
|
ParameterBindingJsonReader reader = new ParameterBindingJsonReader(json, args);
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ public class AppConfig {
|
|||||||
----
|
----
|
||||||
====
|
====
|
||||||
|
|
||||||
To access the `com.mongodb.client.MongoClient` object created by the `MongoClientFactoryBean` in other `@Configuration` classes or your own classes, use a `private @Autowired Mongo mongo;` field.
|
To access the `com.mongodb.client.MongoClient` object created by the `MongoClientFactoryBean` in other `@Configuration` classes or your own classes, use a `private @Autowired MongoClient mongoClient;` field.
|
||||||
|
|
||||||
[[mongo.mongo-xml-config]]
|
[[mongo.mongo-xml-config]]
|
||||||
=== Registering a Mongo Instance by Using XML-based Metadata
|
=== Registering a Mongo Instance by Using XML-based Metadata
|
||||||
@@ -2444,9 +2444,8 @@ A `TypedAggregation`, just like an `Aggregation`, holds the instructions of the
|
|||||||
At runtime, field references get checked against the given input type, considering potential `@Field` annotations.
|
At runtime, field references get checked against the given input type, considering potential `@Field` annotations.
|
||||||
[NOTE]
|
[NOTE]
|
||||||
====
|
====
|
||||||
Changed in 3.2 referencing none-xistent properties does no longer raise errors. To restore the previous behaviour use the `strictMapping` option of `AggregationOptions`.
|
Changed in 3.2 referencing non-existent properties does no longer raise errors. To restore the previous behaviour use the `strictMapping` option of `AggregationOptions`.
|
||||||
====
|
====
|
||||||
+
|
|
||||||
* `AggregationDefinition`
|
* `AggregationDefinition`
|
||||||
+
|
+
|
||||||
An `AggregationDefinition` represents a MongoDB aggregation pipeline operation and describes the processing that should be performed in this aggregation step. Although you could manually create an `AggregationDefinition`, we recommend using the static factory methods provided by the `Aggregate` class to construct an `AggregateOperation`.
|
An `AggregationDefinition` represents a MongoDB aggregation pipeline operation and describes the processing that should be performed in this aggregation step. Although you could manually create an `AggregationDefinition`, we recommend using the static factory methods provided by the `Aggregate` class to construct an `AggregateOperation`.
|
||||||
|
|||||||
@@ -1,6 +1,36 @@
|
|||||||
Spring Data MongoDB Changelog
|
Spring Data MongoDB Changelog
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
Changes in version 3.2.2 (2021-06-22)
|
||||||
|
-------------------------------------
|
||||||
|
* #3677 - Add missing double quote to GeoJson.java JSDoc header.
|
||||||
|
* #3668 - Projection on the _id field returns wrong result when using `@MongoId` (MongoDB 4.4).
|
||||||
|
* #3666 - Documentation references outdated `Mongo` client.
|
||||||
|
* #3660 - MappingMongoConverter problem: ConversionContext#convert does not try to use custom converters first.
|
||||||
|
* #3659 - [3.2.1] Indexing Class with Custom Converter -> Couldn't find PersistentEntity for property private [...].
|
||||||
|
* #3635 - $floor isOrOrNor() return true.
|
||||||
|
* #3633 - NPE in QueryMapper when use Query with `null` as value.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.10 (2021-06-22)
|
||||||
|
--------------------------------------
|
||||||
|
* #3677 - Add missing double quote to GeoJson.java JSDoc header.
|
||||||
|
* #3666 - Documentation references outdated `Mongo` client.
|
||||||
|
* #3659 - [3.2.1] Indexing Class with Custom Converter -> Couldn't find PersistentEntity for property private [...].
|
||||||
|
* #3635 - $floor isOrOrNor() return true.
|
||||||
|
* #3633 - NPE in QueryMapper when use Query with `null` as value.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.2.1 (2021-05-14)
|
||||||
|
-------------------------------------
|
||||||
|
* #3638 - Introduce template method for easier customization of fragments.
|
||||||
|
* #3632 - Fix bullet points in aggregations framework asciidoc.
|
||||||
|
|
||||||
|
|
||||||
|
Changes in version 3.1.9 (2021-05-14)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
|
||||||
Changes in version 3.2.0 (2021-04-14)
|
Changes in version 3.2.0 (2021-04-14)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
* #3623 - `@Aggregation` repository query method causes `NullPointerException` when the result is empty.
|
* #3623 - `@Aggregation` repository query method causes `NullPointerException` when the result is empty.
|
||||||
@@ -3427,6 +3457,10 @@ Repository
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Spring Data MongoDB 3.2 GA (2021.0.0)
|
Spring Data MongoDB 3.2.2 (2021.0.2)
|
||||||
Copyright (c) [2010-2019] Pivotal Software, Inc.
|
Copyright (c) [2010-2019] Pivotal Software, Inc.
|
||||||
|
|
||||||
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
This product is licensed to you under the Apache License, Version 2.0 (the "License").
|
||||||
@@ -26,4 +26,6 @@ conditions of the subcomponent's license, as noted in the LICENSE file.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user