Compare commits
402 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b502a095f | ||
|
|
7552329598 | ||
|
|
fa4f8bfe9f | ||
|
|
58fde292d5 | ||
|
|
e71f8b34be | ||
|
|
152d84a200 | ||
|
|
ddf77d55ff | ||
|
|
2acf1bc5d4 | ||
|
|
26f230036a | ||
|
|
3ee696dab2 | ||
|
|
7ee12e9637 | ||
|
|
414d716c07 | ||
|
|
5f9e25cd8a | ||
|
|
caa2dd4e85 | ||
|
|
28fc1e4823 | ||
|
|
d62639d11c | ||
|
|
b13e47d8ac | ||
|
|
3743ca56df | ||
|
|
0f974130d1 | ||
|
|
020da42800 | ||
|
|
4307b4cd91 | ||
|
|
af874b635c | ||
|
|
017e01810d | ||
|
|
05b46779cb | ||
|
|
ba56d247c9 | ||
|
|
4484dac574 | ||
|
|
af4b1788fc | ||
|
|
af40f15a36 | ||
|
|
193b7de2d9 | ||
|
|
f5204e859f | ||
|
|
16818324d8 | ||
|
|
a9269c0086 | ||
|
|
d3624b9af4 | ||
|
|
3711ed5b50 | ||
|
|
c20feabada | ||
|
|
f93e40fdee | ||
|
|
dca508f3dc | ||
|
|
742448a281 | ||
|
|
1a4749e97c | ||
|
|
a3cbe829b2 | ||
|
|
4ca6f29666 | ||
|
|
df65644d59 | ||
|
|
05a169c858 | ||
|
|
e49119038d | ||
|
|
f2df84e8c4 | ||
|
|
1504fd0529 | ||
|
|
f63610c925 | ||
|
|
06eb52cf13 | ||
|
|
c9a4a8a370 | ||
|
|
8d17ddb92c | ||
|
|
0e96ef2d0c | ||
|
|
4d8b965176 | ||
|
|
37bb390447 | ||
|
|
5c79e1e4ef | ||
|
|
9b41d70f75 | ||
|
|
b2e52ab28f | ||
|
|
fed33444e9 | ||
|
|
a4ad37703f | ||
|
|
42e95e9600 | ||
|
|
ed894aa51a | ||
|
|
693ff04294 | ||
|
|
b018b31e20 | ||
|
|
bacb75d098 | ||
|
|
ec0fe6f994 | ||
|
|
d3d690b908 | ||
|
|
b98b5125f1 | ||
|
|
d68bd4b44a | ||
|
|
a73ae9a1a5 | ||
|
|
ac3c578e93 | ||
|
|
9872f8cb07 | ||
|
|
1b1ab2c495 | ||
|
|
6554274dde | ||
|
|
34f91acbfe | ||
|
|
8e7d508cfe | ||
|
|
04dd78cb36 | ||
|
|
52c554cfe1 | ||
|
|
c1bb8c4ba5 | ||
|
|
ed9a367bb8 | ||
|
|
b88ce46239 | ||
|
|
42ec94d321 | ||
|
|
53f35e185f | ||
|
|
e08bfd253c | ||
|
|
caaafa275d | ||
|
|
1f082abc7f | ||
|
|
df77fcc19d | ||
|
|
007b965673 | ||
|
|
1b9680cece | ||
|
|
13f1d21919 | ||
|
|
4c10bf30bc | ||
|
|
8f78d0e0d8 | ||
|
|
56115a263c | ||
|
|
66b809318a | ||
|
|
bfff60d915 | ||
|
|
051e973226 | ||
|
|
eb61629f10 | ||
|
|
85783e5354 | ||
|
|
433b012b91 | ||
|
|
8dca0049ca | ||
|
|
635f3b82be | ||
|
|
e69c7e1134 | ||
|
|
1f94e74b75 | ||
|
|
98858e0f5f | ||
|
|
90f311de51 | ||
|
|
7f7015fd86 | ||
|
|
ab9c5d73a0 | ||
|
|
13caa162db | ||
|
|
d5d620d777 | ||
|
|
21d50f2a72 | ||
|
|
4912d62be6 | ||
|
|
2bf6f226d6 | ||
|
|
1a6f7e371a | ||
|
|
2ef5d795ce | ||
|
|
e3d2f16202 | ||
|
|
c44232ff39 | ||
|
|
385e911708 | ||
|
|
171d8b2b1e | ||
|
|
7ac7eefad6 | ||
|
|
7a39e94e4b | ||
|
|
25733664b3 | ||
|
|
81da10f499 | ||
|
|
bde114ed19 | ||
|
|
a2403f58ec | ||
|
|
875b8eda9f | ||
|
|
fc0a021937 | ||
|
|
a6aa174ff5 | ||
|
|
8b36617752 | ||
|
|
56e8799c22 | ||
|
|
88e60070d6 | ||
|
|
6c7039580f | ||
|
|
fba003f215 | ||
|
|
1a3239554c | ||
|
|
37b541931d | ||
|
|
9038280f68 | ||
|
|
75935a2bdb | ||
|
|
d9ca3d7eb3 | ||
|
|
04e77ad5ab | ||
|
|
0ab39a17a7 | ||
|
|
49a6f13797 | ||
|
|
b0fd6f691b | ||
|
|
b5778772d9 | ||
|
|
0f55fb305d | ||
|
|
5ae7547465 | ||
|
|
cf4e04a30e | ||
|
|
89c1dc77d9 | ||
|
|
a2c842b59b | ||
|
|
0cd0be9478 | ||
|
|
f88d1de068 | ||
|
|
62bfde2b6b | ||
|
|
93a27f80a3 | ||
|
|
c2b0090ff1 | ||
|
|
0345abb5f8 | ||
|
|
35196e3129 | ||
|
|
37d99c4948 | ||
|
|
288e04b2d3 | ||
|
|
689c1480bd | ||
|
|
09fbe6060e | ||
|
|
d5cf3dfc22 | ||
|
|
0f987f44ef | ||
|
|
5df22233d8 | ||
|
|
9751c6bc8b | ||
|
|
7dc509953a | ||
|
|
2f4f1e524d | ||
|
|
26ddf9d59f | ||
|
|
96ff4e1d14 | ||
|
|
2af13c27a7 | ||
|
|
f4d2fc6231 | ||
|
|
3ab679bcc7 | ||
|
|
318d552797 | ||
|
|
8cfbd39c7e | ||
|
|
3a14af5485 | ||
|
|
00034d899a | ||
|
|
fba6d7d8be | ||
|
|
95c4707902 | ||
|
|
32f3e60c9f | ||
|
|
b57e571033 | ||
|
|
6604c507dd | ||
|
|
e1df28797a | ||
|
|
c6630aa279 | ||
|
|
bf921cdbd7 | ||
|
|
a1b4e6df59 | ||
|
|
4b3312998a | ||
|
|
c5501db577 | ||
|
|
936a0d35f7 | ||
|
|
5dd91d0b6d | ||
|
|
28510de6c8 | ||
|
|
4bbf4cd5cf | ||
|
|
90bd3f0f18 | ||
|
|
1e35116419 | ||
|
|
dd336f0ecb | ||
|
|
d020219ded | ||
|
|
0345eff69a | ||
|
|
55fee27fb6 | ||
|
|
ffba352e15 | ||
|
|
1118df5550 | ||
|
|
29f05af733 | ||
|
|
7bac739146 | ||
|
|
6366d3cec1 | ||
|
|
44913abd80 | ||
|
|
7a7f7c942d | ||
|
|
e9c9938016 | ||
|
|
c9da0a75ff | ||
|
|
581961e79a | ||
|
|
0e0d726457 | ||
|
|
7b5fea960f | ||
|
|
a04821ff90 | ||
|
|
a6bd41bcf2 | ||
|
|
6387eb9762 | ||
|
|
5fb4b036bb | ||
|
|
4f0dc04a81 | ||
|
|
ee59c6b774 | ||
|
|
b0b905ddb7 | ||
|
|
7f7be5e47d | ||
|
|
5a49aa6519 | ||
|
|
b68079c421 | ||
|
|
fde49f2a5a | ||
|
|
4d73d76b9f | ||
|
|
8f2c806403 | ||
|
|
d0eb76946e | ||
|
|
df43d7fcdb | ||
|
|
7b34a602ed | ||
|
|
c829387c82 | ||
|
|
a4e12a96c9 | ||
|
|
7e3f7bd861 | ||
|
|
46ab6b4c94 | ||
|
|
8029acb3fb | ||
|
|
96ffb0b7f4 | ||
|
|
7849b5333b | ||
|
|
fb45b4eb2a | ||
|
|
a6a84421b4 | ||
|
|
c4dcc7d0f5 | ||
|
|
c25a1a9e53 | ||
|
|
81c68955fe | ||
|
|
22ca597fca | ||
|
|
6259cd2c3b | ||
|
|
f153399c3b | ||
|
|
65508eb01b | ||
|
|
a7c25c8524 | ||
|
|
087f8f78b5 | ||
|
|
534ce2e5f5 | ||
|
|
0f4f745d3c | ||
|
|
ca802c7ca4 | ||
|
|
e9d14f41a5 | ||
|
|
3b6880edfd | ||
|
|
0b77906a83 | ||
|
|
993018feb1 | ||
|
|
dd15bbc5c1 | ||
|
|
f6c62d6e2f | ||
|
|
632c499cf1 | ||
|
|
2c9956723e | ||
|
|
d0c2c820d7 | ||
|
|
f69ddb6c61 | ||
|
|
073668b1d1 | ||
|
|
291d84591c | ||
|
|
46806a5606 | ||
|
|
85519eb84d | ||
|
|
f8ee9648da | ||
|
|
c7f9274480 | ||
|
|
0bc0fff24e | ||
|
|
c21b35973d | ||
|
|
44017485fc | ||
|
|
c56a13ad00 | ||
|
|
0a2ea88f3c | ||
|
|
80da9e21ed | ||
|
|
708466b323 | ||
|
|
2905315452 | ||
|
|
ecc9f3fd60 | ||
|
|
c83929c2a3 | ||
|
|
9abf098bdb | ||
|
|
f688cca400 | ||
|
|
f09c622b2f | ||
|
|
6049541d0a | ||
|
|
2a3f862703 | ||
|
|
8b97e932a2 | ||
|
|
5f29bee6c9 | ||
|
|
5b8037a0ad | ||
|
|
1a19e140ee | ||
|
|
83307c424f | ||
|
|
8394523645 | ||
|
|
62be436569 | ||
|
|
44e6f5fa3f | ||
|
|
f2fb05662f | ||
|
|
a1fbe31551 | ||
|
|
fca1a79f81 | ||
|
|
cbf87e6e49 | ||
|
|
af133c26d0 | ||
|
|
ab5b1f0140 | ||
|
|
3a5876537b | ||
|
|
48f51d0fb0 | ||
|
|
fb499f8c69 | ||
|
|
bcc2c94e03 | ||
|
|
284f547e99 | ||
|
|
d824f3b8b2 | ||
|
|
7b1a96f4a9 | ||
|
|
4f75fec5c5 | ||
|
|
61bd56dd74 | ||
|
|
b4222c5646 | ||
|
|
4a45928aee | ||
|
|
e2200eccf7 | ||
|
|
96c4901e7f | ||
|
|
1393f23f3b | ||
|
|
9bbe1f2a26 | ||
|
|
eacfe2b8f7 | ||
|
|
674f0cca2b | ||
|
|
da7b51a51e | ||
|
|
a1b5175299 | ||
|
|
56fff286aa | ||
|
|
60112b4d14 | ||
|
|
277b7a1c7c | ||
|
|
c5b892f03b | ||
|
|
dbf43941be | ||
|
|
1d98b77f3d | ||
|
|
cd4e4065ff | ||
|
|
9f4872de4f | ||
|
|
7abf69e575 | ||
|
|
588ed2b0e2 | ||
|
|
8a228f22cd | ||
|
|
d652b2bdb4 | ||
|
|
f7e527e45c | ||
|
|
aede7c9cad | ||
|
|
1a5de2e1db | ||
|
|
cc07a1bbb4 | ||
|
|
32cbae0e5f | ||
|
|
9eaf67148d | ||
|
|
ff60149166 | ||
|
|
f7a010827d | ||
|
|
1e8c4cec5b | ||
|
|
0e0b45597b | ||
|
|
b014fe4c7c | ||
|
|
ead7679f21 | ||
|
|
18cf94dc34 | ||
|
|
30d99445e2 | ||
|
|
839aecee84 | ||
|
|
c6592b01b0 | ||
|
|
48176a833c | ||
|
|
0facdcfa98 | ||
|
|
837a9885f2 | ||
|
|
6cc5bc627a | ||
|
|
84f7f433f7 | ||
|
|
7df9e932f7 | ||
|
|
5308e6c37f | ||
|
|
bc1c6c9a64 | ||
|
|
62006129ca | ||
|
|
5c2370399f | ||
|
|
3bffe402c0 | ||
|
|
6959c56df6 | ||
|
|
b5bc4320aa | ||
|
|
909c51d00a | ||
|
|
4a04e82e86 | ||
|
|
1370653c93 | ||
|
|
ebfcfb3834 | ||
|
|
77aafc597b | ||
|
|
a4503812bd | ||
|
|
8943e38944 | ||
|
|
c700a508d5 | ||
|
|
11a23becce | ||
|
|
ad2a3483be | ||
|
|
499f019798 | ||
|
|
d0e782687a | ||
|
|
928134c6e1 | ||
|
|
48034a348d | ||
|
|
565132c619 | ||
|
|
4a012d5654 | ||
|
|
ccb8ae08a6 | ||
|
|
8cc0609190 | ||
|
|
004e8ba0ea | ||
|
|
9093f8d8af | ||
|
|
801a3645a9 | ||
|
|
9ebe1439f1 | ||
|
|
26dc0c5c27 | ||
|
|
6e1d426a87 | ||
|
|
f549fd18b5 | ||
|
|
a3a547a706 | ||
|
|
0ff8171309 | ||
|
|
63dfb59a3f | ||
|
|
d33ee2ffac | ||
|
|
59388d99cc | ||
|
|
ee6048e289 | ||
|
|
9a062d53f3 | ||
|
|
a3c5b07eb7 | ||
|
|
40d30a230d | ||
|
|
10116f7c93 | ||
|
|
705203c898 | ||
|
|
8fb9d9e5f4 | ||
|
|
c23c5ae6c6 | ||
|
|
e67bacf66c | ||
|
|
617dbdac3f | ||
|
|
8ad4f4b71b | ||
|
|
9048ec83af | ||
|
|
b2e3e3fb8e | ||
|
|
e9a2b84af5 | ||
|
|
5b8be281fb | ||
|
|
66b318dabe | ||
|
|
b78569374a | ||
|
|
79921a7260 | ||
|
|
bcd8f242e5 | ||
|
|
73fab14b21 | ||
|
|
d4505880c7 | ||
|
|
a54b91392e | ||
|
|
5dc7e7c65f | ||
|
|
8802e2c36f | ||
|
|
d8189620d2 | ||
|
|
fd6411f0ed |
38
.travis.yml
38
.travis.yml
@@ -1,38 +0,0 @@
|
|||||||
language: java
|
|
||||||
|
|
||||||
jdk:
|
|
||||||
- oraclejdk8
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- mkdir -p downloads
|
|
||||||
- mkdir -p var/db var/log
|
|
||||||
- if [[ ! -d downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION} ]] ; then cd downloads && wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}.tgz && tar xzf mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}.tgz && cd ..; fi
|
|
||||||
- downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}/bin/mongod --version
|
|
||||||
- downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}/bin/mongod --dbpath var/db --replSet rs0 --fork --logpath var/log/mongod.log
|
|
||||||
- sleep 10
|
|
||||||
- |-
|
|
||||||
downloads/mongodb-linux-x86_64-ubuntu1604-${MONGO_VERSION}/bin/mongo --eval "rs.initiate({_id: 'rs0', members:[{_id: 0, host: '127.0.0.1:27017'}]});"
|
|
||||||
sleep 15
|
|
||||||
|
|
||||||
env:
|
|
||||||
matrix:
|
|
||||||
- MONGO_VERSION=4.1.10
|
|
||||||
- MONGO_VERSION=4.0.4
|
|
||||||
- MONGO_VERSION=3.6.12
|
|
||||||
- MONGO_VERSION=3.4.20
|
|
||||||
global:
|
|
||||||
- PROFILE=ci
|
|
||||||
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- oracle-java8-installer
|
|
||||||
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.m2
|
|
||||||
- downloads
|
|
||||||
|
|
||||||
script: "mvn clean dependency:list test -P${PROFILE} -Dsort"
|
|
||||||
193
Jenkinsfile
vendored
193
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.3.x", threshold: hudson.model.Result.SUCCESS)
|
||||||
}
|
}
|
||||||
|
|
||||||
options {
|
options {
|
||||||
@@ -30,16 +30,32 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Publish JDK 8 + MongoDB 4.1') {
|
stage('Publish JDK 8 + MongoDB 4.2') {
|
||||||
when {
|
when {
|
||||||
changeset "ci/openjdk8-mongodb-4.1/**"
|
changeset "ci/openjdk8-mongodb-4.2/**"
|
||||||
}
|
}
|
||||||
agent { label 'data' }
|
agent { label 'data' }
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def image = docker.build("springci/spring-data-openjdk8-with-mongodb-4.1", "ci/openjdk8-mongodb-4.1/")
|
def image = docker.build("springci/spring-data-openjdk8-with-mongodb-4.2.0", "ci/openjdk8-mongodb-4.2/")
|
||||||
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
|
image.push()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Publish JDK 14 + MongoDB 4.2') {
|
||||||
|
when {
|
||||||
|
changeset "ci/openjdk14-mongodb-4.2/**"
|
||||||
|
}
|
||||||
|
agent { label 'data' }
|
||||||
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def image = docker.build("springci/spring-data-openjdk14-with-mongodb-4.2.0", "ci/openjdk14-mongodb-4.2/")
|
||||||
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
image.push()
|
image.push()
|
||||||
}
|
}
|
||||||
@@ -49,57 +65,113 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("test: baseline") {
|
stage("test: baseline (jdk8)") {
|
||||||
when {
|
when {
|
||||||
anyOf {
|
anyOf {
|
||||||
branch 'master'
|
branch '3.0.x'
|
||||||
not { triggeredBy 'UpstreamCause' }
|
not { triggeredBy 'UpstreamCause' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
agent {
|
agent {
|
||||||
docker {
|
label 'data'
|
||||||
image 'springci/spring-data-openjdk8-with-mongodb-4.0:latest'
|
|
||||||
label 'data'
|
|
||||||
args '-v $HOME:/tmp/jenkins-home'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'rm -rf ?'
|
script {
|
||||||
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
sh 'mongod --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
docker.image('springci/spring-data-openjdk8-with-mongodb-4.2.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
sh 'sleep 10'
|
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
||||||
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
||||||
sh 'sleep 15'
|
sh 'sleep 10'
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw clean dependency:list test -Dsort -B'
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
|
sh 'sleep 15'
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("Test other configurations") {
|
stage("Test other configurations") {
|
||||||
when {
|
when {
|
||||||
anyOf {
|
anyOf {
|
||||||
branch 'master'
|
branch '3.0.x'
|
||||||
not { triggeredBy 'UpstreamCause' }
|
not { triggeredBy 'UpstreamCause' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parallel {
|
parallel {
|
||||||
stage("test: mongodb 4.1") {
|
stage("test: mongodb 4.0 (jdk8)") {
|
||||||
agent {
|
agent {
|
||||||
docker {
|
label 'data'
|
||||||
image 'springci/spring-data-openjdk8-with-mongodb-4.1:latest'
|
|
||||||
label 'data'
|
|
||||||
args '-v $HOME:/tmp/jenkins-home'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
options { timeout(time: 30, unit: 'MINUTES') }
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
steps {
|
steps {
|
||||||
sh 'rm -rf ?'
|
script {
|
||||||
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
sh 'mongod --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
docker.image('springci/spring-data-openjdk8-with-mongodb-4.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
sh 'sleep 10'
|
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
||||||
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
||||||
sh 'sleep 15'
|
sh 'sleep 10'
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw clean dependency:list test -Dsort -B'
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
|
sh 'sleep 15'
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("test: mongodb 4.2 (jdk8)") {
|
||||||
|
agent {
|
||||||
|
label 'data'
|
||||||
|
}
|
||||||
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
|
docker.image('springci/spring-data-openjdk8-with-mongodb-4.2.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
|
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
||||||
|
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
||||||
|
sh 'sleep 10'
|
||||||
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
|
sh 'sleep 15'
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage("test: baseline (jdk14)") {
|
||||||
|
agent {
|
||||||
|
label 'data'
|
||||||
|
}
|
||||||
|
options { timeout(time: 30, unit: 'MINUTES') }
|
||||||
|
environment {
|
||||||
|
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
|
docker.image('springci/spring-data-openjdk15-with-mongodb-4.2.0:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
|
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
||||||
|
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
||||||
|
sh 'sleep 10'
|
||||||
|
sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||||
|
sh 'sleep 15'
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,16 +180,12 @@ pipeline {
|
|||||||
stage('Release to artifactory') {
|
stage('Release to artifactory') {
|
||||||
when {
|
when {
|
||||||
anyOf {
|
anyOf {
|
||||||
branch 'master'
|
branch '3.0.x'
|
||||||
not { triggeredBy 'UpstreamCause' }
|
not { triggeredBy 'UpstreamCause' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
agent {
|
agent {
|
||||||
docker {
|
label 'data'
|
||||||
image 'adoptopenjdk/openjdk8:latest'
|
|
||||||
label 'data'
|
|
||||||
args '-v $HOME:/tmp/jenkins-home'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
options { timeout(time: 20, unit: 'MINUTES') }
|
options { timeout(time: 20, unit: 'MINUTES') }
|
||||||
|
|
||||||
@@ -126,28 +194,29 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
sh 'rm -rf ?'
|
script {
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,artifactory ' +
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
'-Dartifactory.server=https://repo.spring.io ' +
|
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pci,artifactory ' +
|
||||||
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
'-Dartifactory.server=https://repo.spring.io ' +
|
||||||
"-Dartifactory.staging-repository=libs-snapshot-local " +
|
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
||||||
"-Dartifactory.build-name=spring-data-mongodb " +
|
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
||||||
"-Dartifactory.build-number=${BUILD_NUMBER} " +
|
"-Dartifactory.staging-repository=libs-snapshot-local " +
|
||||||
'-Dmaven.test.skip=true clean deploy -B'
|
"-Dartifactory.build-name=spring-data-mongodb " +
|
||||||
|
"-Dartifactory.build-number=${BUILD_NUMBER} " +
|
||||||
|
'-Dmaven.test.skip=true clean deploy -U -B'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Publish documentation') {
|
stage('Publish documentation') {
|
||||||
when {
|
when {
|
||||||
branch 'master'
|
branch '3.0.x'
|
||||||
}
|
}
|
||||||
agent {
|
agent {
|
||||||
docker {
|
label 'data'
|
||||||
image 'adoptopenjdk/openjdk8:latest'
|
|
||||||
label 'data'
|
|
||||||
args '-v $HOME:/tmp/jenkins-home'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
options { timeout(time: 20, unit: 'MINUTES') }
|
options { timeout(time: 20, unit: 'MINUTES') }
|
||||||
|
|
||||||
@@ -156,12 +225,18 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pci,distribute ' +
|
script {
|
||||||
'-Dartifactory.server=https://repo.spring.io ' +
|
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
|
||||||
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
|
||||||
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pci,distribute ' +
|
||||||
"-Dartifactory.distribution-repository=temp-private-local " +
|
'-Dartifactory.server=https://repo.spring.io ' +
|
||||||
'-Dmaven.test.skip=true clean deploy -B'
|
"-Dartifactory.username=${ARTIFACTORY_USR} " +
|
||||||
|
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
|
||||||
|
"-Dartifactory.distribution-repository=temp-private-local " +
|
||||||
|
'-Dmaven.test.skip=true clean deploy -U -B'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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.
|
||||||
159
README.adoc
159
README.adoc
@@ -50,12 +50,7 @@ public class MyService {
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableMongoRepositories
|
@EnableMongoRepositories
|
||||||
class ApplicationConfig extends AbstractMongoConfiguration {
|
class ApplicationConfig extends AbstractMongoClientConfiguration {
|
||||||
|
|
||||||
@Override
|
|
||||||
public MongoClient mongoClient() {
|
|
||||||
return new MongoClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getDatabaseName() {
|
protected String getDatabaseName() {
|
||||||
@@ -94,6 +89,143 @@ If you'd rather like the latest snapshots of the upcoming major version, use our
|
|||||||
</repository>
|
</repository>
|
||||||
----
|
----
|
||||||
|
|
||||||
|
== Upgrading from 2.x
|
||||||
|
|
||||||
|
The 4.0 MongoDB Java Driver does no longer support certain features that have already been deprecated in one of the last minor versions.
|
||||||
|
Some of the changes affect the initial setup configuration as well as compile/runtime features. We summarized the most typical changes one might encounter.
|
||||||
|
|
||||||
|
=== XML Namespace
|
||||||
|
|
||||||
|
.Changed XML Namespace Elements and Attributes:
|
||||||
|
|===
|
||||||
|
Element / Attribute | 2.x | 3.x
|
||||||
|
|
||||||
|
| `<mongo:mongo-client />`
|
||||||
|
| Used to create a `com.mongodb.MongoClient`
|
||||||
|
| Now exposes a `com.mongodb.client.MongoClient`
|
||||||
|
|
||||||
|
| `<mongo:mongo-client replica-set="..." />`
|
||||||
|
| Was a comma delimited list of replica set members (host/port)
|
||||||
|
| Now defines the replica set name. +
|
||||||
|
Use `<mongo:client-settings cluster-hosts="..." />` instead
|
||||||
|
|
||||||
|
| `<mongo:db-factory writeConcern="..." />`
|
||||||
|
| NONE, NORMAL, SAFE, FSYNC_SAFE, REPLICAS_SAFE, MAJORITY
|
||||||
|
| W1, W2, W3, UNAKNOWLEDGED, AKNOWLEDGED, JOURNALED, MAJORITY
|
||||||
|
|===
|
||||||
|
|
||||||
|
.Removed XML Namespace Elements and Attributes:
|
||||||
|
|===
|
||||||
|
Element / Attribute | Replacement in 3.x | Comment
|
||||||
|
|
||||||
|
| `<mongo:db-factory mongo-ref="..." />`
|
||||||
|
| `<mongo:db-factory mongo-client-ref="..." />`
|
||||||
|
| Referencing a `com.mongodb.client.MongoClient`.
|
||||||
|
|
||||||
|
| `<mongo:mongo-client credentials="..." />`
|
||||||
|
| `<mongo:mongo-client credential="..." />`
|
||||||
|
| Single authentication data instead of list.
|
||||||
|
|
||||||
|
| `<mongo:client-options />`
|
||||||
|
| `<mongo:client-settings />`
|
||||||
|
| See `com.mongodb.MongoClientSettings` for details.
|
||||||
|
|===
|
||||||
|
|
||||||
|
.New XML Namespace Elements and Attributes:
|
||||||
|
|===
|
||||||
|
Element | Comment
|
||||||
|
|
||||||
|
| `<mongo:db-factory mongo-client-ref="..." />`
|
||||||
|
| Replacement for `<mongo:db-factory mongo-ref="..." />`
|
||||||
|
|
||||||
|
| `<mongo:db-factory connection-string="..." />`
|
||||||
|
| Replacement for `uri` and `client-uri`.
|
||||||
|
|
||||||
|
| `<mongo:mongo-client connection-string="..." />`
|
||||||
|
| Replacement for `uri` and `client-uri`.
|
||||||
|
|
||||||
|
| `<mongo:client-settings />`
|
||||||
|
| Namespace element for `com.mongodb.MongoClientSettings`.
|
||||||
|
|
||||||
|
|===
|
||||||
|
|
||||||
|
=== Java Configuration
|
||||||
|
|
||||||
|
.Java API changes
|
||||||
|
|===
|
||||||
|
Type | Comment
|
||||||
|
|
||||||
|
| `MongoClientFactoryBean`
|
||||||
|
| Creates `com.mongodb.client.MongoClient` instead of `com.mongodb.MongoClient` +
|
||||||
|
Uses `MongoClientSettings` instead of `MongoClientOptions`.
|
||||||
|
|
||||||
|
| `MongoDataIntegrityViolationException`
|
||||||
|
| Uses `WriteConcernResult` instead of `WriteResult`.
|
||||||
|
|
||||||
|
| `BulkOperationException`
|
||||||
|
| Uses `MongoBulkWriteException` and `com.mongodb.bulk.BulkWriteError` instead of `BulkWriteException` and `com.mongodb.BulkWriteError`
|
||||||
|
|
||||||
|
| `ReactiveMongoClientFactoryBean`
|
||||||
|
| Uses `com.mongodb.MongoClientSettings` instead of `com.mongodb.async.client.MongoClientSettings`
|
||||||
|
|
||||||
|
| `ReactiveMongoClientSettingsFactoryBean`
|
||||||
|
| Now produces `com.mongodb.MongoClientSettings` instead of `com.mongodb.async.client.MongoClientSettings`
|
||||||
|
|===
|
||||||
|
|
||||||
|
.Removed Java API:
|
||||||
|
|===
|
||||||
|
2.x | Replacement in 3.x | Comment
|
||||||
|
|
||||||
|
| `MongoClientOptionsFactoryBean`
|
||||||
|
| `MongoClientSettingsFactoryBean`
|
||||||
|
| Creating a `com.mongodb.MongoClientSettings`.
|
||||||
|
|
||||||
|
| `AbstractMongoConfiguration`
|
||||||
|
| `AbstractMongoClientConfiguration` +
|
||||||
|
(Available since 2.1)
|
||||||
|
| Using `com.mongodb.client.MongoClient`.
|
||||||
|
|
||||||
|
| `MongoDbFactory#getLegacyDb()`
|
||||||
|
| -
|
||||||
|
| -
|
||||||
|
|
||||||
|
| `SimpleMongoDbFactory`
|
||||||
|
| `SimpleMongoClientDbFactory` +
|
||||||
|
(Available since 2.1)
|
||||||
|
|
|
||||||
|
|
||||||
|
| `MapReduceOptions#getOutputType()`
|
||||||
|
| `MapReduceOptions#getMapReduceAction()`
|
||||||
|
| Returns `MapReduceAction` instead of `MapReduceCommand.OutputType`.
|
||||||
|
|
||||||
|
| `Meta\|Query` maxScan & snapshot
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|===
|
||||||
|
|
||||||
|
=== Other Changes
|
||||||
|
|
||||||
|
==== UUID Types
|
||||||
|
|
||||||
|
The MongoDB UUID representation can now be configured with different formats.
|
||||||
|
This has to be done via `MongoClientSettings` as shown in the snippet below.
|
||||||
|
|
||||||
|
.UUID Codec Configuration
|
||||||
|
====
|
||||||
|
[source,java]
|
||||||
|
----
|
||||||
|
static class Config extends AbstractMongoClientConfiguration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureClientSettings(MongoClientSettings.Builder builder) {
|
||||||
|
builder.uuidRepresentation(UuidRepresentation.STANDARD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
----
|
||||||
|
====
|
||||||
|
|
||||||
== Getting Help
|
== Getting Help
|
||||||
|
|
||||||
Having trouble with Spring Data? We’d love to help!
|
Having trouble with Spring Data? We’d love to help!
|
||||||
@@ -105,18 +237,17 @@ If you are just starting out with Spring, try one of the https://spring.io/guide
|
|||||||
* If you are upgrading, check out the https://docs.spring.io/spring-data/mongodb/docs/current/changelog.txt[changelog] for "`new and noteworthy`" features.
|
* If you are upgrading, check out the https://docs.spring.io/spring-data/mongodb/docs/current/changelog.txt[changelog] for "`new and noteworthy`" features.
|
||||||
* Ask a question - we monitor https://stackoverflow.com[stackoverflow.com] for questions tagged with https://stackoverflow.com/tags/spring-data[`spring-data-mongodb`].
|
* Ask a question - we monitor https://stackoverflow.com[stackoverflow.com] for questions tagged with https://stackoverflow.com/tags/spring-data[`spring-data-mongodb`].
|
||||||
You can also chat with the community on https://gitter.im/spring-projects/spring-data[Gitter].
|
You can also chat with the community on https://gitter.im/spring-projects/spring-data[Gitter].
|
||||||
* Report bugs with Spring Data MongoDB at https://jira.spring.io/browse/DATAMONGO[jira.spring.io/browse/DATAMONGO].
|
* Report bugs with Spring Data MongoDB at https://github.com/spring-projects/spring-data-mongodb/issues[github.com/spring-projects/spring-data-mongodb/issues].
|
||||||
|
|
||||||
== Reporting Issues
|
== Reporting Issues
|
||||||
|
|
||||||
Spring Data uses JIRA as issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:
|
Spring Data uses Github as issue tracking system to record bugs and feature requests.
|
||||||
|
If you want to raise an issue, please follow the recommendations below:
|
||||||
|
|
||||||
* Before you log a bug, please search the
|
* Before you log a bug, please search the https://github.com/spring-projects/spring-data-mongodb/issues[issue tracker] to see if someone has already reported the problem.
|
||||||
https://jira.spring.io/browse/DATAMONGO[issue tracker] to see if someone has already reported the problem.
|
* If the issue does not already exist, https://github.com/spring-projects/spring-data-mongodb/issues/new[create a new issue].
|
||||||
* If the issue doesn’t already exist, https://jira.spring.io/browse/DATAMONGO[create a new issue].
|
* Please provide as much information as possible with the issue report, we like to know the version of Spring Data that you are using, the JVM version, Stacktrace, etc.
|
||||||
* Please provide as much information as possible with the issue report, we like to know the version of Spring Data that you are using and JVM version.
|
* If you need to paste code, or include a stack trace use https://guides.github.com/features/mastering-markdown/[Markdown] code fences +++```+++.
|
||||||
* If you need to paste code, or include a stack trace use JIRA `{code}…{code}` escapes before and after your text.
|
|
||||||
* If possible try to create a test-case or project that replicates the issue. Attach a link to your code or a compressed file containing your code.
|
|
||||||
|
|
||||||
== Building from Source
|
== Building from Source
|
||||||
|
|
||||||
|
|||||||
15
ci/openjdk11-mongodb-4.2/Dockerfile
Normal file
15
ci/openjdk11-mongodb-4.2/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM adoptopenjdk/openjdk11:latest
|
||||||
|
|
||||||
|
ENV TZ=Etc/UTC
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
RUN set -eux; \
|
||||||
|
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
|
||||||
|
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv e162f504a20cdf15827f718d4b7c549a058f8b6b ; \
|
||||||
|
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list; \
|
||||||
|
echo ${TZ} > /etc/timezone;
|
||||||
|
|
||||||
|
RUN apt-get update ; \
|
||||||
|
apt-get install -y mongodb-org=4.2.0 mongodb-org-server=4.2.0 mongodb-org-shell=4.2.0 mongodb-org-mongos=4.2.0 mongodb-org-tools=4.2.0 ; \
|
||||||
|
apt-get clean; \
|
||||||
|
rm -rf /var/lib/apt/lists/*;
|
||||||
15
ci/openjdk14-mongodb-4.2/Dockerfile
Normal file
15
ci/openjdk14-mongodb-4.2/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM adoptopenjdk/openjdk14:latest
|
||||||
|
|
||||||
|
ENV TZ=Etc/UTC
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
RUN set -eux; \
|
||||||
|
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
|
||||||
|
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv e162f504a20cdf15827f718d4b7c549a058f8b6b ; \
|
||||||
|
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list; \
|
||||||
|
echo ${TZ} > /etc/timezone;
|
||||||
|
|
||||||
|
RUN apt-get update ; \
|
||||||
|
apt-get install -y mongodb-org=4.2.0 mongodb-org-server=4.2.0 mongodb-org-shell=4.2.0 mongodb-org-mongos=4.2.0 mongodb-org-tools=4.2.0 ; \
|
||||||
|
apt-get clean; \
|
||||||
|
rm -rf /var/lib/apt/lists/*;
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
FROM adoptopenjdk/openjdk8:latest
|
FROM adoptopenjdk/openjdk8:latest
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2
|
ENV TZ=Etc/UTC
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
RUN apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
|
RUN RUN set -eux; \
|
||||||
|
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
|
||||||
|
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 ; \
|
||||||
|
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list; \
|
||||||
|
echo ${TZ} > /etc/timezone;
|
||||||
|
|
||||||
RUN echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list
|
RUN apt-get update ; \
|
||||||
|
apt-get install -y mongodb-org=4.0.14 mongodb-org-server=4.0.14 mongodb-org-shell=4.0.14 mongodb-org-mongos=4.0.14 mongodb-org-tools=4.0.14 ; \
|
||||||
RUN apt-get update
|
apt-get clean; \
|
||||||
|
rm -rf /var/lib/apt/lists/*;
|
||||||
RUN apt-get install -y mongodb-org=4.0.9 mongodb-org-server=4.0.9 mongodb-org-shell=4.0.9 mongodb-org-mongos=4.0.9 mongodb-org-tools=4.0.9
|
|
||||||
|
|
||||||
RUN apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
FROM adoptopenjdk/openjdk8:latest
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2
|
|
||||||
|
|
||||||
RUN apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv 4B7C549A058F8B6B
|
|
||||||
|
|
||||||
RUN echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.1 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.1.list
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
|
|
||||||
RUN apt-get install -y mongodb-org-unstable=4.1.13 mongodb-org-unstable-server=4.1.13 mongodb-org-unstable-shell=4.1.13 mongodb-org-unstable-mongos=4.1.13 mongodb-org-unstable-tools=4.1.13
|
|
||||||
|
|
||||||
RUN apt-get clean \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
15
ci/openjdk8-mongodb-4.2/Dockerfile
Normal file
15
ci/openjdk8-mongodb-4.2/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM adoptopenjdk/openjdk8:latest
|
||||||
|
|
||||||
|
ENV TZ=Etc/UTC
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
RUN set -eux; \
|
||||||
|
apt-get update && apt-get install -y apt-transport-https apt-utils gnupg2 ; \
|
||||||
|
apt-key adv --keyserver hkps://keyserver.ubuntu.com:443 --recv e162f504a20cdf15827f718d4b7c549a058f8b6b ; \
|
||||||
|
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.2.list; \
|
||||||
|
echo ${TZ} > /etc/timezone;
|
||||||
|
|
||||||
|
RUN apt-get update ; \
|
||||||
|
apt-get install -y mongodb-org=4.2.0 mongodb-org-server=4.2.0 mongodb-org-shell=4.2.0 mongodb-org-mongos=4.2.0 mongodb-org-tools=4.2.0 ; \
|
||||||
|
apt-get clean; \
|
||||||
|
rm -rf /var/lib/apt/lists/*;
|
||||||
27
pom.xml
27
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>2.2.0.RC2</version>
|
<version>3.0.10.BUILD-SNAPSHOT</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.2.0.RC2</version>
|
<version>2.3.10.BUILD-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
<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.2.0.RC2</springdata.commons>
|
<springdata.commons>2.3.10.BUILD-SNAPSHOT</springdata.commons>
|
||||||
<mongo>3.11.0-rc0</mongo>
|
<mongo>4.0.6</mongo>
|
||||||
<mongo.reactivestreams>1.12.0-rc0</mongo.reactivestreams>
|
<mongo.reactivestreams>${mongo}</mongo.reactivestreams>
|
||||||
<jmh.version>1.19</jmh.version>
|
<jmh.version>1.19</jmh.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -127,15 +127,25 @@
|
|||||||
<!-- MongoDB -->
|
<!-- MongoDB -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongo-java-driver</artifactId>
|
<artifactId>mongodb-driver-core</artifactId>
|
||||||
<version>${mongo}</version>
|
<version>${mongo}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spring-libs-milestone</id>
|
<id>spring-libs-snapshot</id>
|
||||||
<url>https://repo.spring.io/libs-milestone</url>
|
<url>https://repo.spring.io/libs-snapshot</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-libs-snapshot</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
@@ -148,7 +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>
|
||||||
|
|
||||||
</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>2.2.0.RC2</version>
|
<version>3.0.10.BUILD-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -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>2.2.0.RC2</version>
|
<version>3.0.10.BUILD-SNAPSHOT</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>2.2.0.RC2</version>
|
<version>3.0.10.BUILD-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -65,6 +65,12 @@
|
|||||||
<artifactId>querydsl-mongodb</artifactId>
|
<artifactId>querydsl-mongodb</artifactId>
|
||||||
<version>${querydsl}</version>
|
<version>${querydsl}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
<artifactId>mongo-java-driver</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -82,28 +88,19 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- reactive -->
|
<!-- reactive -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
<artifactId>mongodb-driver-sync</artifactId>
|
||||||
<version>${mongo.reactivestreams}</version>
|
<version>${mongo}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mongodb</groupId>
|
<groupId>org.mongodb</groupId>
|
||||||
<artifactId>mongodb-driver-async</artifactId>
|
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
||||||
<version>${mongo}</version>
|
<version>${mongo.reactivestreams}</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.mongodb</groupId>
|
|
||||||
<artifactId>mongodb-driver-core</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.mongodb</groupId>
|
|
||||||
<artifactId>bson</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -253,6 +250,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit-pioneer</groupId>
|
||||||
|
<artifactId>junit-pioneer</artifactId>
|
||||||
|
<version>0.5.3</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.transaction</groupId>
|
<groupId>javax.transaction</groupId>
|
||||||
<artifactId>jta</artifactId>
|
<artifactId>jta</artifactId>
|
||||||
@@ -276,14 +280,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlinx</groupId>
|
<groupId>org.jetbrains.kotlinx</groupId>
|
||||||
<artifactId>kotlinx-coroutines-core</artifactId>
|
<artifactId>kotlinx-coroutines-core</artifactId>
|
||||||
<version>${kotlin-coroutines}</version>
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlinx</groupId>
|
<groupId>org.jetbrains.kotlinx</groupId>
|
||||||
<artifactId>kotlinx-coroutines-reactor</artifactId>
|
<artifactId>kotlinx-coroutines-reactor</artifactId>
|
||||||
<version>${kotlin-coroutines}</version>
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -342,12 +344,6 @@
|
|||||||
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
|
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
|
||||||
<reactor.trace.cancel>true</reactor.trace.cancel>
|
<reactor.trace.cancel>true</reactor.trace.cancel>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
<properties>
|
|
||||||
<property>
|
|
||||||
<name>listener</name>
|
|
||||||
<value>org.springframework.data.mongodb.test.util.CleanMongoDBJunitRunListener</value>
|
|
||||||
</property>
|
|
||||||
</properties>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,9 +19,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
import com.mongodb.BulkWriteError;
|
import com.mongodb.MongoBulkWriteException;
|
||||||
import com.mongodb.BulkWriteException;
|
import com.mongodb.bulk.BulkWriteError;
|
||||||
import com.mongodb.BulkWriteResult;
|
import com.mongodb.bulk.BulkWriteResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is thrown when errors occur during bulk operations.
|
* Is thrown when errors occur during bulk operations.
|
||||||
@@ -38,12 +38,12 @@ public class BulkOperationException extends DataAccessException {
|
|||||||
private final BulkWriteResult result;
|
private final BulkWriteResult result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link BulkOperationException} with the given message and source {@link BulkWriteException}.
|
* Creates a new {@link BulkOperationException} with the given message and source {@link MongoBulkWriteException}.
|
||||||
*
|
*
|
||||||
* @param message must not be {@literal null}.
|
* @param message must not be {@literal null}.
|
||||||
* @param source must not be {@literal null}.
|
* @param source must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public BulkOperationException(String message, BulkWriteException source) {
|
public BulkOperationException(String message, MongoBulkWriteException source) {
|
||||||
|
|
||||||
super(message, source);
|
super(message, source);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2019 the original author or authors.
|
* Copyright 2013-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,8 +25,10 @@ public class LazyLoadingException extends UncategorizedDataAccessException {
|
|||||||
private static final long serialVersionUID = -7089224903873220037L;
|
private static final long serialVersionUID = -7089224903873220037L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param msg
|
* Constructor for LazyLoadingException.
|
||||||
* @param cause
|
*
|
||||||
|
* @param msg the detail message.
|
||||||
|
* @param cause the exception thrown by underlying data access API.
|
||||||
*/
|
*/
|
||||||
public LazyLoadingException(String msg, Throwable cause) {
|
public LazyLoadingException(String msg, Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb;
|
||||||
|
|
||||||
|
import org.bson.codecs.configuration.CodecRegistry;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||||
|
import org.springframework.data.mongodb.core.MongoExceptionTranslator;
|
||||||
|
|
||||||
|
import com.mongodb.ClientSessionOptions;
|
||||||
|
import com.mongodb.client.ClientSession;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for factories creating {@link MongoDatabase} instances.
|
||||||
|
*
|
||||||
|
* @author Mark Pollack
|
||||||
|
* @author Thomas Darimont
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public interface MongoDatabaseFactory extends CodecRegistryProvider, MongoSessionProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a {@link MongoDatabase} from the underlying factory.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @throws DataAccessException
|
||||||
|
*/
|
||||||
|
MongoDatabase getMongoDatabase() throws DataAccessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a {@link MongoDatabase} instance to access the database with the given name.
|
||||||
|
*
|
||||||
|
* @param dbName must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @throws DataAccessException
|
||||||
|
*/
|
||||||
|
MongoDatabase getMongoDatabase(String dbName) throws DataAccessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposes a shared {@link MongoExceptionTranslator}.
|
||||||
|
*
|
||||||
|
* @return will never be {@literal null}.
|
||||||
|
*/
|
||||||
|
PersistenceExceptionTranslator getExceptionTranslator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the underlying {@link CodecRegistry} used by the MongoDB Java driver.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
default CodecRegistry getCodecRegistry() {
|
||||||
|
return getMongoDatabase().getCodecRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a {@link ClientSession} for given ClientSessionOptions.
|
||||||
|
*
|
||||||
|
* @param options must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
ClientSession getSession(ClientSessionOptions options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a {@link ClientSession} bound instance of {@link MongoDatabaseFactory} returning {@link MongoDatabase}
|
||||||
|
* instances that are aware and bound to a new session with given {@link ClientSessionOptions options}.
|
||||||
|
*
|
||||||
|
* @param options must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
default MongoDatabaseFactory withSession(ClientSessionOptions options) {
|
||||||
|
return withSession(getSession(options));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain a {@link ClientSession} bound instance of {@link MongoDatabaseFactory} returning {@link MongoDatabase}
|
||||||
|
* instances that are aware and bound to the given session.
|
||||||
|
*
|
||||||
|
* @param session must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
MongoDatabaseFactory withSession(ClientSession session);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the given {@link MongoDatabaseFactory} is bound to a {@link ClientSession} that has an
|
||||||
|
* {@link ClientSession#hasActiveTransaction() active transaction}.
|
||||||
|
*
|
||||||
|
* @return {@literal true} if there's an active transaction, {@literal false} otherwise.
|
||||||
|
* @since 2.1.3
|
||||||
|
*/
|
||||||
|
default boolean isTransactionActive() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,7 +27,7 @@ import com.mongodb.client.ClientSession;
|
|||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for managing a {@link MongoDatabase} instances via {@link MongoDbFactory}. Used for obtaining
|
* Helper class for managing a {@link MongoDatabase} instances via {@link MongoDatabaseFactory}. Used for obtaining
|
||||||
* {@link ClientSession session bound} resources, such as {@link MongoDatabase} and
|
* {@link ClientSession session bound} resources, such as {@link MongoDatabase} and
|
||||||
* {@link com.mongodb.client.MongoCollection} suitable for transactional usage.
|
* {@link com.mongodb.client.MongoCollection} suitable for transactional usage.
|
||||||
* <p />
|
* <p />
|
||||||
@@ -41,93 +41,94 @@ import com.mongodb.client.MongoDatabase;
|
|||||||
public class MongoDatabaseUtils {
|
public class MongoDatabaseUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDbFactory factory} using
|
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDatabaseFactory factory} using
|
||||||
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
|
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
|
||||||
* <p />
|
* <p />
|
||||||
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
||||||
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
||||||
*
|
*
|
||||||
* @param factory the {@link MongoDbFactory} to get the {@link MongoDatabase} from.
|
* @param factory the {@link MongoDatabaseFactory} to get the {@link MongoDatabase} from.
|
||||||
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
||||||
*/
|
*/
|
||||||
public static MongoDatabase getDatabase(MongoDbFactory factory) {
|
public static MongoDatabase getDatabase(MongoDatabaseFactory factory) {
|
||||||
return doGetMongoDatabase(null, factory, SessionSynchronization.ON_ACTUAL_TRANSACTION);
|
return doGetMongoDatabase(null, factory, SessionSynchronization.ON_ACTUAL_TRANSACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDbFactory factory}.
|
* Obtain the default {@link MongoDatabase database} form the given {@link MongoDatabaseFactory factory}.
|
||||||
* <p />
|
* <p />
|
||||||
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
||||||
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
||||||
*
|
*
|
||||||
* @param factory the {@link MongoDbFactory} to get the {@link MongoDatabase} from.
|
* @param factory the {@link MongoDatabaseFactory} to get the {@link MongoDatabase} from.
|
||||||
* @param sessionSynchronization the synchronization to use. Must not be {@literal null}.
|
* @param sessionSynchronization the synchronization to use. Must not be {@literal null}.
|
||||||
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
||||||
*/
|
*/
|
||||||
public static MongoDatabase getDatabase(MongoDbFactory factory, SessionSynchronization sessionSynchronization) {
|
public static MongoDatabase getDatabase(MongoDatabaseFactory factory, SessionSynchronization sessionSynchronization) {
|
||||||
return doGetMongoDatabase(null, factory, sessionSynchronization);
|
return doGetMongoDatabase(null, factory, sessionSynchronization);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the {@link MongoDatabase database} with given name form the given {@link MongoDbFactory factory} using
|
* Obtain the {@link MongoDatabase database} with given name form the given {@link MongoDatabaseFactory factory} using
|
||||||
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
|
* {@link SessionSynchronization#ON_ACTUAL_TRANSACTION native session synchronization}.
|
||||||
* <p />
|
* <p />
|
||||||
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
||||||
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
||||||
*
|
*
|
||||||
* @param dbName the name of the {@link MongoDatabase} to get.
|
* @param dbName the name of the {@link MongoDatabase} to get.
|
||||||
* @param factory the {@link MongoDbFactory} to get the {@link MongoDatabase} from.
|
* @param factory the {@link MongoDatabaseFactory} to get the {@link MongoDatabase} from.
|
||||||
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
||||||
*/
|
*/
|
||||||
public static MongoDatabase getDatabase(String dbName, MongoDbFactory factory) {
|
public static MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory) {
|
||||||
return doGetMongoDatabase(dbName, factory, SessionSynchronization.ON_ACTUAL_TRANSACTION);
|
return doGetMongoDatabase(dbName, factory, SessionSynchronization.ON_ACTUAL_TRANSACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the {@link MongoDatabase database} with given name form the given {@link MongoDbFactory factory}.
|
* Obtain the {@link MongoDatabase database} with given name form the given {@link MongoDatabaseFactory factory}.
|
||||||
* <p />
|
* <p />
|
||||||
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
* Registers a {@link MongoSessionSynchronization MongoDB specific transaction synchronization} within the current
|
||||||
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
* {@link Thread} if {@link TransactionSynchronizationManager#isSynchronizationActive() synchronization is active}.
|
||||||
*
|
*
|
||||||
* @param dbName the name of the {@link MongoDatabase} to get.
|
* @param dbName the name of the {@link MongoDatabase} to get.
|
||||||
* @param factory the {@link MongoDbFactory} to get the {@link MongoDatabase} from.
|
* @param factory the {@link MongoDatabaseFactory} to get the {@link MongoDatabase} from.
|
||||||
* @param sessionSynchronization the synchronization to use. Must not be {@literal null}.
|
* @param sessionSynchronization the synchronization to use. Must not be {@literal null}.
|
||||||
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
* @return the {@link MongoDatabase} that is potentially associated with a transactional {@link ClientSession}.
|
||||||
*/
|
*/
|
||||||
public static MongoDatabase getDatabase(String dbName, MongoDbFactory factory,
|
public static MongoDatabase getDatabase(@Nullable String dbName, MongoDatabaseFactory factory,
|
||||||
SessionSynchronization sessionSynchronization) {
|
SessionSynchronization sessionSynchronization) {
|
||||||
return doGetMongoDatabase(dbName, factory, sessionSynchronization);
|
return doGetMongoDatabase(dbName, factory, sessionSynchronization);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MongoDatabase doGetMongoDatabase(@Nullable String dbName, MongoDbFactory factory,
|
private static MongoDatabase doGetMongoDatabase(@Nullable String dbName, MongoDatabaseFactory factory,
|
||||||
SessionSynchronization sessionSynchronization) {
|
SessionSynchronization sessionSynchronization) {
|
||||||
|
|
||||||
Assert.notNull(factory, "Factory must not be null!");
|
Assert.notNull(factory, "Factory must not be null!");
|
||||||
|
|
||||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||||
return StringUtils.hasText(dbName) ? factory.getDb(dbName) : factory.getDb();
|
return StringUtils.hasText(dbName) ? factory.getMongoDatabase(dbName) : factory.getMongoDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientSession session = doGetSession(factory, sessionSynchronization);
|
ClientSession session = doGetSession(factory, sessionSynchronization);
|
||||||
|
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
return StringUtils.hasText(dbName) ? factory.getDb(dbName) : factory.getDb();
|
return StringUtils.hasText(dbName) ? factory.getMongoDatabase(dbName) : factory.getMongoDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
MongoDbFactory factoryToUse = factory.withSession(session);
|
MongoDatabaseFactory factoryToUse = factory.withSession(session);
|
||||||
return StringUtils.hasText(dbName) ? factoryToUse.getDb(dbName) : factoryToUse.getDb();
|
return StringUtils.hasText(dbName) ? factoryToUse.getMongoDatabase(dbName) : factoryToUse.getMongoDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the {@link MongoDbFactory} is actually bound to a {@link ClientSession} that has an active transaction, or
|
* Check if the {@link MongoDatabaseFactory} is actually bound to a {@link ClientSession} that has an active
|
||||||
* if a {@link TransactionSynchronization} has been registered for the {@link MongoDbFactory resource} and if the
|
* transaction, or if a {@link TransactionSynchronization} has been registered for the {@link MongoDatabaseFactory
|
||||||
* associated {@link ClientSession} has an {@link ClientSession#hasActiveTransaction() active transaction}.
|
* resource} and if the associated {@link ClientSession} has an {@link ClientSession#hasActiveTransaction() active
|
||||||
|
* transaction}.
|
||||||
*
|
*
|
||||||
* @param dbFactory the resource to check transactions for. Must not be {@literal null}.
|
* @param dbFactory the resource to check transactions for. Must not be {@literal null}.
|
||||||
* @return {@literal true} if the factory has an ongoing transaction.
|
* @return {@literal true} if the factory has an ongoing transaction.
|
||||||
* @since 2.1.3
|
* @since 2.1.3
|
||||||
*/
|
*/
|
||||||
public static boolean isTransactionActive(MongoDbFactory dbFactory) {
|
public static boolean isTransactionActive(MongoDatabaseFactory dbFactory) {
|
||||||
|
|
||||||
if (dbFactory.isTransactionActive()) {
|
if (dbFactory.isTransactionActive()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -138,7 +139,8 @@ public class MongoDatabaseUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static ClientSession doGetSession(MongoDbFactory dbFactory, SessionSynchronization sessionSynchronization) {
|
private static ClientSession doGetSession(MongoDatabaseFactory dbFactory,
|
||||||
|
SessionSynchronization sessionSynchronization) {
|
||||||
|
|
||||||
MongoResourceHolder resourceHolder = (MongoResourceHolder) TransactionSynchronizationManager.getResource(dbFactory);
|
MongoResourceHolder resourceHolder = (MongoResourceHolder) TransactionSynchronizationManager.getResource(dbFactory);
|
||||||
|
|
||||||
@@ -169,7 +171,7 @@ public class MongoDatabaseUtils {
|
|||||||
return resourceHolder.getSession();
|
return resourceHolder.getSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ClientSession createClientSession(MongoDbFactory dbFactory) {
|
private static ClientSession createClientSession(MongoDatabaseFactory dbFactory) {
|
||||||
return dbFactory.getSession(ClientSessionOptions.builder().causallyConsistent(true).build());
|
return dbFactory.getSession(ClientSessionOptions.builder().causallyConsistent(true).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +186,7 @@ public class MongoDatabaseUtils {
|
|||||||
|
|
||||||
private final MongoResourceHolder resourceHolder;
|
private final MongoResourceHolder resourceHolder;
|
||||||
|
|
||||||
MongoSessionSynchronization(MongoResourceHolder resourceHolder, MongoDbFactory dbFactory) {
|
MongoSessionSynchronization(MongoResourceHolder resourceHolder, MongoDatabaseFactory dbFactory) {
|
||||||
|
|
||||||
super(resourceHolder, dbFactory);
|
super(resourceHolder, dbFactory);
|
||||||
this.resourceHolder = resourceHolder;
|
this.resourceHolder = resourceHolder;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,14 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb;
|
package org.springframework.data.mongodb;
|
||||||
|
|
||||||
import org.bson.codecs.configuration.CodecRegistry;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
|
||||||
import org.springframework.data.mongodb.core.MongoExceptionTranslator;
|
|
||||||
|
|
||||||
import com.mongodb.ClientSessionOptions;
|
|
||||||
import com.mongodb.DB;
|
|
||||||
import com.mongodb.client.ClientSession;
|
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,92 +25,33 @@ import com.mongodb.client.MongoDatabase;
|
|||||||
* @author Mark Pollack
|
* @author Mark Pollack
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @deprecated since 3.0, use {@link MongoDatabaseFactory} instead.
|
||||||
*/
|
*/
|
||||||
public interface MongoDbFactory extends CodecRegistryProvider, MongoSessionProvider {
|
@Deprecated
|
||||||
|
public interface MongoDbFactory extends MongoDatabaseFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a default {@link MongoDatabase} instance.
|
* Creates a default {@link MongoDatabase} instance.
|
||||||
*
|
*
|
||||||
* @return
|
* @return never {@literal null}.
|
||||||
* @throws DataAccessException
|
* @throws DataAccessException
|
||||||
*/
|
* @deprecated since 3.0. Use {@link #getMongoDatabase()} instead.
|
||||||
MongoDatabase getDb() throws DataAccessException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link DB} instance to access the database with the given name.
|
|
||||||
*
|
|
||||||
* @param dbName must not be {@literal null} or empty.
|
|
||||||
* @return
|
|
||||||
* @throws DataAccessException
|
|
||||||
*/
|
|
||||||
MongoDatabase getDb(String dbName) throws DataAccessException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exposes a shared {@link MongoExceptionTranslator}.
|
|
||||||
*
|
|
||||||
* @return will never be {@literal null}.
|
|
||||||
*/
|
|
||||||
PersistenceExceptionTranslator getExceptionTranslator();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the legacy database entry point. Please consider {@link #getDb()} instead.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @deprecated since 2.1, use {@link #getDb()}. This method will be removed with a future version as it works only
|
|
||||||
* with the legacy MongoDB driver.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
DB getLegacyDb();
|
default MongoDatabase getDb() throws DataAccessException {
|
||||||
|
return getMongoDatabase();
|
||||||
/**
|
|
||||||
* Get the underlying {@link CodecRegistry} used by the MongoDB Java driver.
|
|
||||||
*
|
|
||||||
* @return never {@literal null}.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default CodecRegistry getCodecRegistry() {
|
|
||||||
return getDb().getCodecRegistry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain a {@link ClientSession} for given ClientSessionOptions.
|
* Obtain a {@link MongoDatabase} instance to access the database with the given name.
|
||||||
*
|
*
|
||||||
* @param options must not be {@literal null}.
|
* @param dbName must not be {@literal null} or empty.
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
* @since 2.1
|
* @throws DataAccessException
|
||||||
|
* @deprecated since 3.0. Use {@link #getMongoDatabase(String)} instead.
|
||||||
*/
|
*/
|
||||||
ClientSession getSession(ClientSessionOptions options);
|
@Deprecated
|
||||||
|
default MongoDatabase getDb(String dbName) throws DataAccessException {
|
||||||
/**
|
return getMongoDatabase(dbName);
|
||||||
* Obtain a {@link ClientSession} bound instance of {@link MongoDbFactory} returning {@link MongoDatabase} instances
|
|
||||||
* that are aware and bound to a new session with given {@link ClientSessionOptions options}.
|
|
||||||
*
|
|
||||||
* @param options must not be {@literal null}.
|
|
||||||
* @return never {@literal null}.
|
|
||||||
* @since 2.1
|
|
||||||
*/
|
|
||||||
default MongoDbFactory withSession(ClientSessionOptions options) {
|
|
||||||
return withSession(getSession(options));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtain a {@link ClientSession} bound instance of {@link MongoDbFactory} returning {@link MongoDatabase} instances
|
|
||||||
* that are aware and bound to the given session.
|
|
||||||
*
|
|
||||||
* @param session must not be {@literal null}.
|
|
||||||
* @return never {@literal null}.
|
|
||||||
* @since 2.1
|
|
||||||
*/
|
|
||||||
MongoDbFactory withSession(ClientSession session);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the given {@link MongoDbFactory} is bound to a {@link ClientSession} that has an
|
|
||||||
* {@link ClientSession#hasActiveTransaction() active transaction}.
|
|
||||||
*
|
|
||||||
* @return {@literal true} if there's an active transaction, {@literal false} otherwise.
|
|
||||||
* @since 2.1.3
|
|
||||||
*/
|
|
||||||
default boolean isTransactionActive() {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -36,15 +36,15 @@ import com.mongodb.client.ClientSession;
|
|||||||
class MongoResourceHolder extends ResourceHolderSupport {
|
class MongoResourceHolder extends ResourceHolderSupport {
|
||||||
|
|
||||||
private @Nullable ClientSession session;
|
private @Nullable ClientSession session;
|
||||||
private MongoDbFactory dbFactory;
|
private MongoDatabaseFactory dbFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link MongoResourceHolder} for a given {@link ClientSession session}.
|
* Create a new {@link MongoResourceHolder} for a given {@link ClientSession session}.
|
||||||
*
|
*
|
||||||
* @param session the associated {@link ClientSession}. Can be {@literal null}.
|
* @param session the associated {@link ClientSession}. Can be {@literal null}.
|
||||||
* @param dbFactory the associated {@link MongoDbFactory}. must not be {@literal null}.
|
* @param dbFactory the associated {@link MongoDatabaseFactory}. must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
MongoResourceHolder(@Nullable ClientSession session, MongoDbFactory dbFactory) {
|
MongoResourceHolder(@Nullable ClientSession session, MongoDatabaseFactory dbFactory) {
|
||||||
|
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.dbFactory = dbFactory;
|
this.dbFactory = dbFactory;
|
||||||
@@ -75,9 +75,9 @@ class MongoResourceHolder extends ResourceHolderSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the associated {@link MongoDbFactory}.
|
* @return the associated {@link MongoDatabaseFactory}.
|
||||||
*/
|
*/
|
||||||
public MongoDbFactory getDbFactory() {
|
public MongoDatabaseFactory getDbFactory() {
|
||||||
return dbFactory;
|
return dbFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -36,17 +36,18 @@ import com.mongodb.client.ClientSession;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link org.springframework.transaction.PlatformTransactionManager} implementation that manages
|
* A {@link org.springframework.transaction.PlatformTransactionManager} implementation that manages
|
||||||
* {@link ClientSession} based transactions for a single {@link MongoDbFactory}.
|
* {@link ClientSession} based transactions for a single {@link MongoDatabaseFactory}.
|
||||||
* <p />
|
* <p />
|
||||||
* Binds a {@link ClientSession} from the specified {@link MongoDbFactory} to the thread.
|
* Binds a {@link ClientSession} from the specified {@link MongoDatabaseFactory} to the thread.
|
||||||
* <p />
|
* <p />
|
||||||
* {@link TransactionDefinition#isReadOnly() Readonly} transactions operate on a {@link ClientSession} and enable causal
|
* {@link TransactionDefinition#isReadOnly() Readonly} transactions operate on a {@link ClientSession} and enable causal
|
||||||
* consistency, and also {@link ClientSession#startTransaction() start}, {@link ClientSession#commitTransaction()
|
* consistency, and also {@link ClientSession#startTransaction() start}, {@link ClientSession#commitTransaction()
|
||||||
* commit} or {@link ClientSession#abortTransaction() abort} a transaction.
|
* commit} or {@link ClientSession#abortTransaction() abort} a transaction.
|
||||||
* <p />
|
* <p />
|
||||||
* Application code is required to retrieve the {@link com.mongodb.client.MongoDatabase} via
|
* Application code is required to retrieve the {@link com.mongodb.client.MongoDatabase} via
|
||||||
* {@link MongoDatabaseUtils#getDatabase(MongoDbFactory)} instead of a standard {@link MongoDbFactory#getDb()} call.
|
* {@link MongoDatabaseUtils#getDatabase(MongoDatabaseFactory)} instead of a standard
|
||||||
* Spring classes such as {@link org.springframework.data.mongodb.core.MongoTemplate} use this strategy implicitly.
|
* {@link MongoDatabaseFactory#getMongoDatabase()} call. Spring classes such as
|
||||||
|
* {@link org.springframework.data.mongodb.core.MongoTemplate} use this strategy implicitly.
|
||||||
* <p />
|
* <p />
|
||||||
* By default failure of a {@literal commit} operation raises a {@link TransactionSystemException}. One may override
|
* By default failure of a {@literal commit} operation raises a {@link TransactionSystemException}. One may override
|
||||||
* {@link #doCommit(MongoTransactionObject)} to implement the
|
* {@link #doCommit(MongoTransactionObject)} to implement the
|
||||||
@@ -58,46 +59,46 @@ import com.mongodb.client.ClientSession;
|
|||||||
* @currentRead Shadow's Edge - Brent Weeks
|
* @currentRead Shadow's Edge - Brent Weeks
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
* @see <a href="https://www.mongodb.com/transactions">MongoDB Transaction Documentation</a>
|
* @see <a href="https://www.mongodb.com/transactions">MongoDB Transaction Documentation</a>
|
||||||
* @see MongoDatabaseUtils#getDatabase(MongoDbFactory, SessionSynchronization)
|
* @see MongoDatabaseUtils#getDatabase(MongoDatabaseFactory, SessionSynchronization)
|
||||||
*/
|
*/
|
||||||
public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
||||||
implements ResourceTransactionManager, InitializingBean {
|
implements ResourceTransactionManager, InitializingBean {
|
||||||
|
|
||||||
private @Nullable MongoDbFactory dbFactory;
|
private @Nullable MongoDatabaseFactory dbFactory;
|
||||||
private @Nullable TransactionOptions options;
|
private @Nullable TransactionOptions options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link MongoTransactionManager} for bean-style usage.
|
* Create a new {@link MongoTransactionManager} for bean-style usage.
|
||||||
* <p />
|
* <p />
|
||||||
* <strong>Note:</strong>The {@link MongoDbFactory db factory} has to be {@link #setDbFactory(MongoDbFactory) set}
|
* <strong>Note:</strong>The {@link MongoDatabaseFactory db factory} has to be
|
||||||
* before using the instance. Use this constructor to prepare a {@link MongoTransactionManager} via a
|
* {@link #setDbFactory(MongoDatabaseFactory) set} before using the instance. Use this constructor to prepare a
|
||||||
* {@link org.springframework.beans.factory.BeanFactory}.
|
* {@link MongoTransactionManager} via a {@link org.springframework.beans.factory.BeanFactory}.
|
||||||
* <p />
|
* <p />
|
||||||
* Optionally it is possible to set default {@link TransactionOptions transaction options} defining
|
* Optionally it is possible to set default {@link TransactionOptions transaction options} defining
|
||||||
* {@link com.mongodb.ReadConcern} and {@link com.mongodb.WriteConcern}.
|
* {@link com.mongodb.ReadConcern} and {@link com.mongodb.WriteConcern}.
|
||||||
*
|
*
|
||||||
* @see #setDbFactory(MongoDbFactory)
|
* @see #setDbFactory(MongoDatabaseFactory)
|
||||||
* @see #setTransactionSynchronization(int)
|
* @see #setTransactionSynchronization(int)
|
||||||
*/
|
*/
|
||||||
public MongoTransactionManager() {}
|
public MongoTransactionManager() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link MongoTransactionManager} obtaining sessions from the given {@link MongoDbFactory}.
|
* Create a new {@link MongoTransactionManager} obtaining sessions from the given {@link MongoDatabaseFactory}.
|
||||||
*
|
*
|
||||||
* @param dbFactory must not be {@literal null}.
|
* @param dbFactory must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public MongoTransactionManager(MongoDbFactory dbFactory) {
|
public MongoTransactionManager(MongoDatabaseFactory dbFactory) {
|
||||||
this(dbFactory, null);
|
this(dbFactory, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link MongoTransactionManager} obtaining sessions from the given {@link MongoDbFactory} applying the
|
* Create a new {@link MongoTransactionManager} obtaining sessions from the given {@link MongoDatabaseFactory}
|
||||||
* given {@link TransactionOptions options}, if present, when starting a new transaction.
|
* applying the given {@link TransactionOptions options}, if present, when starting a new transaction.
|
||||||
*
|
*
|
||||||
* @param dbFactory must not be {@literal null}.
|
* @param dbFactory must not be {@literal null}.
|
||||||
* @param options can be {@literal null}.
|
* @param options can be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public MongoTransactionManager(MongoDbFactory dbFactory, @Nullable TransactionOptions options) {
|
public MongoTransactionManager(MongoDatabaseFactory dbFactory, @Nullable TransactionOptions options) {
|
||||||
|
|
||||||
Assert.notNull(dbFactory, "DbFactory must not be null!");
|
Assert.notNull(dbFactory, "DbFactory must not be null!");
|
||||||
|
|
||||||
@@ -295,11 +296,11 @@ public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@link MongoDbFactory} that this instance should manage transactions for.
|
* Set the {@link MongoDatabaseFactory} that this instance should manage transactions for.
|
||||||
*
|
*
|
||||||
* @param dbFactory must not be {@literal null}.
|
* @param dbFactory must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public void setDbFactory(MongoDbFactory dbFactory) {
|
public void setDbFactory(MongoDatabaseFactory dbFactory) {
|
||||||
|
|
||||||
Assert.notNull(dbFactory, "DbFactory must not be null!");
|
Assert.notNull(dbFactory, "DbFactory must not be null!");
|
||||||
this.dbFactory = dbFactory;
|
this.dbFactory = dbFactory;
|
||||||
@@ -315,12 +316,12 @@ public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link MongoDbFactory} that this instance manages transactions for.
|
* Get the {@link MongoDatabaseFactory} that this instance manages transactions for.
|
||||||
*
|
*
|
||||||
* @return can be {@literal null}.
|
* @return can be {@literal null}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public MongoDbFactory getDbFactory() {
|
public MongoDatabaseFactory getDbFactory() {
|
||||||
return dbFactory;
|
return dbFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +330,7 @@ public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
* @see org.springframework.transaction.support.ResourceTransactionManager#getResourceFactory()
|
* @see org.springframework.transaction.support.ResourceTransactionManager#getResourceFactory()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MongoDbFactory getResourceFactory() {
|
public MongoDatabaseFactory getResourceFactory() {
|
||||||
return getRequiredDbFactory();
|
return getRequiredDbFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +345,7 @@ public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
|
|
||||||
private MongoResourceHolder newResourceHolder(TransactionDefinition definition, ClientSessionOptions options) {
|
private MongoResourceHolder newResourceHolder(TransactionDefinition definition, ClientSessionOptions options) {
|
||||||
|
|
||||||
MongoDbFactory dbFactory = getResourceFactory();
|
MongoDatabaseFactory dbFactory = getResourceFactory();
|
||||||
|
|
||||||
MongoResourceHolder resourceHolder = new MongoResourceHolder(dbFactory.getSession(options), dbFactory);
|
MongoResourceHolder resourceHolder = new MongoResourceHolder(dbFactory.getSession(options), dbFactory);
|
||||||
resourceHolder.setTimeoutIfNotDefaulted(determineTimeout(definition));
|
resourceHolder.setTimeoutIfNotDefaulted(determineTimeout(definition));
|
||||||
@@ -355,7 +356,7 @@ public class MongoTransactionManager extends AbstractPlatformTransactionManager
|
|||||||
/**
|
/**
|
||||||
* @throws IllegalStateException if {@link #dbFactory} is {@literal null}.
|
* @throws IllegalStateException if {@link #dbFactory} is {@literal null}.
|
||||||
*/
|
*/
|
||||||
private MongoDbFactory getRequiredDbFactory() {
|
private MongoDatabaseFactory getRequiredDbFactory() {
|
||||||
|
|
||||||
Assert.state(dbFactory != null,
|
Assert.state(dbFactory != null,
|
||||||
"MongoTransactionManager operates upon a MongoDbFactory. Did you forget to provide one? It's required.");
|
"MongoTransactionManager operates upon a MongoDbFactory. Did you forget to provide one? It's required.");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2019 the original author or authors.
|
* Copyright 2016-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -31,6 +31,7 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
|||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Mathieu Ouellet
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
||||||
@@ -38,19 +39,19 @@ public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
|||||||
/**
|
/**
|
||||||
* Creates a default {@link MongoDatabase} instance.
|
* Creates a default {@link MongoDatabase} instance.
|
||||||
*
|
*
|
||||||
* @return
|
* @return never {@literal null}.
|
||||||
* @throws DataAccessException
|
* @throws DataAccessException
|
||||||
*/
|
*/
|
||||||
MongoDatabase getMongoDatabase() throws DataAccessException;
|
Mono<MongoDatabase> getMongoDatabase() throws DataAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link MongoDatabase} instance to access the database with the given name.
|
* Obtain a {@link MongoDatabase} instance to access the database with the given name.
|
||||||
*
|
*
|
||||||
* @param dbName must not be {@literal null} or empty.
|
* @param dbName must not be {@literal null} or empty.
|
||||||
* @return
|
* @return never {@literal null}.
|
||||||
* @throws DataAccessException
|
* @throws DataAccessException
|
||||||
*/
|
*/
|
||||||
MongoDatabase getMongoDatabase(String dbName) throws DataAccessException;
|
Mono<MongoDatabase> getMongoDatabase(String dbName) throws DataAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes a shared {@link MongoExceptionTranslator}.
|
* Exposes a shared {@link MongoExceptionTranslator}.
|
||||||
@@ -64,10 +65,7 @@ public interface ReactiveMongoDatabaseFactory extends CodecRegistryProvider {
|
|||||||
*
|
*
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
@Override
|
CodecRegistry getCodecRegistry();
|
||||||
default CodecRegistry getCodecRegistry() {
|
|
||||||
return getMongoDatabase().getCodecRegistry();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain a {@link Mono} emitting a {@link ClientSession} for given {@link ClientSessionOptions options}.
|
* Obtain a {@link Mono} emitting a {@link ClientSession} for given {@link ClientSessionOptions options}.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019 the original author or authors.
|
* Copyright 2019-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,6 +41,7 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
|||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Mathieu Ouellet
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
public class ReactiveMongoDatabaseUtils {
|
public class ReactiveMongoDatabaseUtils {
|
||||||
@@ -142,14 +143,13 @@ public class ReactiveMongoDatabaseUtils {
|
|||||||
.flatMap(synchronizationManager -> {
|
.flatMap(synchronizationManager -> {
|
||||||
|
|
||||||
return doGetSession(synchronizationManager, factory, sessionSynchronization) //
|
return doGetSession(synchronizationManager, factory, sessionSynchronization) //
|
||||||
.map(it -> getMongoDatabaseOrDefault(dbName, factory.withSession(it)));
|
.flatMap(it -> getMongoDatabaseOrDefault(dbName, factory.withSession(it)));
|
||||||
})
|
}) //
|
||||||
.onErrorResume(NoTransactionException.class,
|
.onErrorResume(NoTransactionException.class, e -> getMongoDatabaseOrDefault(dbName, factory))
|
||||||
e -> Mono.fromSupplier(() -> getMongoDatabaseOrDefault(dbName, factory)))
|
.switchIfEmpty(getMongoDatabaseOrDefault(dbName, factory));
|
||||||
.defaultIfEmpty(getMongoDatabaseOrDefault(dbName, factory));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MongoDatabase getMongoDatabaseOrDefault(@Nullable String dbName,
|
private static Mono<MongoDatabase> getMongoDatabaseOrDefault(@Nullable String dbName,
|
||||||
ReactiveMongoDatabaseFactory factory) {
|
ReactiveMongoDatabaseFactory factory) {
|
||||||
return StringUtils.hasText(dbName) ? factory.getMongoDatabase(dbName) : factory.getMongoDatabase();
|
return StringUtils.hasText(dbName) ? factory.getMongoDatabase(dbName) : factory.getMongoDatabase();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019 the original author or authors.
|
* Copyright 2019-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -42,7 +42,7 @@ class ReactiveMongoResourceHolder extends ResourceHolderSupport {
|
|||||||
* Create a new {@link ReactiveMongoResourceHolder} for a given {@link ClientSession session}.
|
* Create a new {@link ReactiveMongoResourceHolder} for a given {@link ClientSession session}.
|
||||||
*
|
*
|
||||||
* @param session the associated {@link ClientSession}. Can be {@literal null}.
|
* @param session the associated {@link ClientSession}. Can be {@literal null}.
|
||||||
* @param databaseFactory the associated {@link MongoDbFactory}. must not be {@literal null}.
|
* @param databaseFactory the associated {@link MongoDatabaseFactory}. must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
ReactiveMongoResourceHolder(@Nullable ClientSession session, ReactiveMongoDatabaseFactory databaseFactory) {
|
ReactiveMongoResourceHolder(@Nullable ClientSession session, ReactiveMongoDatabaseFactory databaseFactory) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019 the original author or authors.
|
* Copyright 2019-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.util.Version;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.mongodb.MongoDriverInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that exposes the SpringData MongoDB specific information like the current {@link Version} or
|
||||||
|
* {@link MongoDriverInformation driver information}.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public class SpringDataMongoDB {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataMongoDB.class);
|
||||||
|
|
||||||
|
private static final Version FALLBACK_VERSION = new Version(3);
|
||||||
|
private static final MongoDriverInformation DRIVER_INFORMATION = MongoDriverInformation
|
||||||
|
.builder(MongoDriverInformation.builder().build()).driverName("spring-data").build();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain the SpringData MongoDB specific driver information.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public static MongoDriverInformation driverInformation() {
|
||||||
|
return DRIVER_INFORMATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the "Implementation-Version" manifest attribute from the jar file.
|
||||||
|
* <p />
|
||||||
|
* Note that some ClassLoaders do not expose the package metadata, hence this class might not be able to determine the
|
||||||
|
* version in all environments. In this case the current Major version is returned as a fallback.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public static Version version() {
|
||||||
|
|
||||||
|
Package pkg = SpringDataMongoDB.class.getPackage();
|
||||||
|
String versionString = (pkg != null ? pkg.getImplementationVersion() : null);
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(versionString)) {
|
||||||
|
|
||||||
|
LOGGER.debug("Unable to find Spring Data MongoDB version.");
|
||||||
|
return FALLBACK_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Version.parse(versionString);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.debug("Cannot read Spring Data MongoDB version '{}'.", versionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALLBACK_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,17 +17,22 @@ package org.springframework.data.mongodb.config;
|
|||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||||
|
import org.springframework.data.mongodb.SpringDataMongoDB;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory;
|
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
|
||||||
import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
||||||
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
||||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||||
|
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
import com.mongodb.MongoClientSettings;
|
||||||
|
import com.mongodb.MongoClientSettings.Builder;
|
||||||
import com.mongodb.client.MongoClient;
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for Spring Data MongoDB configuration using JavaConfig with {@link com.mongodb.client.MongoClient}.
|
* Base class for Spring Data MongoDB configuration using JavaConfig with {@link com.mongodb.client.MongoClient}.
|
||||||
@@ -35,40 +40,44 @@ import com.mongodb.client.MongoClient;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
* @see MongoConfigurationSupport
|
* @see MongoConfigurationSupport
|
||||||
* @see AbstractMongoConfiguration
|
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public abstract class AbstractMongoClientConfiguration extends MongoConfigurationSupport {
|
public abstract class AbstractMongoClientConfiguration extends MongoConfigurationSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
|
* Return the {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
|
||||||
* {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}.
|
* {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}. <br />
|
||||||
|
* Override {@link #mongoClientSettings()} to configure connection details.
|
||||||
*
|
*
|
||||||
* @return
|
* @return never {@literal null}.
|
||||||
|
* @see #mongoClientSettings()
|
||||||
|
* @see #configureClientSettings(Builder)
|
||||||
*/
|
*/
|
||||||
public abstract MongoClient mongoClient();
|
public MongoClient mongoClient() {
|
||||||
|
return createMongoClient(mongoClientSettings());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link MongoTemplate}.
|
* Creates a {@link MongoTemplate}.
|
||||||
*
|
*
|
||||||
* @return
|
* @see #mongoDbFactory()
|
||||||
|
* @see #mappingMongoConverter(MongoDatabaseFactory, MongoCustomConversions, MongoMappingContext)
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MongoTemplate mongoTemplate() throws Exception {
|
public MongoTemplate mongoTemplate(MongoDatabaseFactory databaseFactory, MappingMongoConverter converter) {
|
||||||
return new MongoTemplate(mongoDbFactory(), mappingMongoConverter());
|
return new MongoTemplate(databaseFactory, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link MongoClient}
|
* Creates a {@link org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory} to be used by the
|
||||||
* instance configured in {@link #mongoClient()}.
|
* {@link MongoTemplate}. Will use the {@link MongoClient} instance configured in {@link #mongoClient()}.
|
||||||
*
|
*
|
||||||
* @see #mongoClient()
|
* @see #mongoClient()
|
||||||
* @see #mongoTemplate()
|
* @see #mongoTemplate(MongoDatabaseFactory, MappingMongoConverter)
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MongoDbFactory mongoDbFactory() {
|
public MongoDatabaseFactory mongoDbFactory() {
|
||||||
return new SimpleMongoClientDbFactory(mongoClient(), getDatabaseName());
|
return new SimpleMongoClientDatabaseFactory(mongoClient(), getDatabaseName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,21 +100,32 @@ public abstract class AbstractMongoClientConfiguration extends MongoConfiguratio
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
|
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
|
||||||
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
|
* {@link #mongoMappingContext(MongoCustomConversions)}. Will get {@link #customConversions()} applied.
|
||||||
*
|
*
|
||||||
* @see #customConversions()
|
* @see #customConversions()
|
||||||
* @see #mongoMappingContext()
|
* @see #mongoMappingContext(MongoCustomConversions)
|
||||||
* @see #mongoDbFactory()
|
* @see #mongoDbFactory()
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MappingMongoConverter mappingMongoConverter() throws Exception {
|
public MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory databaseFactory,
|
||||||
|
MongoCustomConversions customConversions, MongoMappingContext mappingContext) {
|
||||||
|
|
||||||
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory());
|
DbRefResolver dbRefResolver = new DefaultDbRefResolver(databaseFactory);
|
||||||
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext());
|
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
|
||||||
converter.setCustomConversions(customConversions());
|
converter.setCustomConversions(customConversions);
|
||||||
|
converter.setCodecRegistryProvider(databaseFactory);
|
||||||
|
|
||||||
return converter;
|
return converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the Reactive Streams {@link com.mongodb.reactivestreams.client.MongoClient} instance with given
|
||||||
|
* {@link MongoClientSettings}.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected MongoClient createMongoClient(MongoClientSettings settings) {
|
||||||
|
return MongoClients.create(settings, SpringDataMongoDB.driverInformation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011-2019 the original author or authors.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.mongodb.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
|
||||||
import org.springframework.data.mongodb.core.convert.DbRefResolver;
|
|
||||||
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
|
||||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
|
|
||||||
import com.mongodb.MongoClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for Spring Data MongoDB configuration using JavaConfig with {@link com.mongodb.MongoClient}.
|
|
||||||
* <p />
|
|
||||||
* <strong>INFO:</strong>In case you want to use {@link com.mongodb.client.MongoClients} for configuration please refer
|
|
||||||
* to {@link AbstractMongoClientConfiguration}.
|
|
||||||
*
|
|
||||||
* @author Mark Pollack
|
|
||||||
* @author Oliver Gierke
|
|
||||||
* @author Thomas Darimont
|
|
||||||
* @author Ryan Tenney
|
|
||||||
* @author Christoph Strobl
|
|
||||||
* @author Mark Paluch
|
|
||||||
* @see MongoConfigurationSupport
|
|
||||||
* @see AbstractMongoClientConfiguration
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public abstract class AbstractMongoConfiguration extends MongoConfigurationSupport {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
|
|
||||||
* {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract MongoClient mongoClient();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link MongoTemplate}.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public MongoTemplate mongoTemplate() throws Exception {
|
|
||||||
return new MongoTemplate(mongoDbFactory(), mappingMongoConverter());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link MongoClient}
|
|
||||||
* instance configured in {@link #mongoClient()}.
|
|
||||||
*
|
|
||||||
* @see #mongoClient()
|
|
||||||
* @see #mongoTemplate()
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public MongoDbFactory mongoDbFactory() {
|
|
||||||
return new SimpleMongoDbFactory(mongoClient(), getDatabaseName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the base package to scan for mapped {@link Document}s. Will return the package name of the configuration
|
|
||||||
* class' (the concrete class, not this one here) by default. So if you have a {@code com.acme.AppConfig} extending
|
|
||||||
* {@link AbstractMongoConfiguration} the base package will be considered {@code com.acme} unless the method is
|
|
||||||
* overridden to implement alternate behavior.
|
|
||||||
*
|
|
||||||
* @return the base package to scan for mapped {@link Document} classes or {@literal null} to not enable scanning for
|
|
||||||
* entities.
|
|
||||||
* @deprecated use {@link #getMappingBasePackages()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Nullable
|
|
||||||
protected String getMappingBasePackage() {
|
|
||||||
|
|
||||||
Package mappingBasePackage = getClass().getPackage();
|
|
||||||
return mappingBasePackage == null ? null : mappingBasePackage.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
|
|
||||||
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
|
|
||||||
*
|
|
||||||
* @see #customConversions()
|
|
||||||
* @see #mongoMappingContext()
|
|
||||||
* @see #mongoDbFactory()
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public MappingMongoConverter mappingMongoConverter() throws Exception {
|
|
||||||
|
|
||||||
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory());
|
|
||||||
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext());
|
|
||||||
converter.setCustomConversions(customConversions());
|
|
||||||
|
|
||||||
return converter;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2019 the original author or authors.
|
* Copyright 2016-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,13 +18,19 @@ package org.springframework.data.mongodb.config;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
|
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
|
||||||
|
import org.springframework.data.mongodb.SpringDataMongoDB;
|
||||||
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
||||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
|
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
|
||||||
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||||
|
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||||
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
|
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
|
|
||||||
|
import com.mongodb.MongoClientSettings;
|
||||||
|
import com.mongodb.MongoClientSettings.Builder;
|
||||||
import com.mongodb.reactivestreams.client.MongoClient;
|
import com.mongodb.reactivestreams.client.MongoClient;
|
||||||
|
import com.mongodb.reactivestreams.client.MongoClients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for reactive Spring Data MongoDB configuration using JavaConfig.
|
* Base class for reactive Spring Data MongoDB configuration using JavaConfig.
|
||||||
@@ -34,25 +40,33 @@ import com.mongodb.reactivestreams.client.MongoClient;
|
|||||||
* @since 2.0
|
* @since 2.0
|
||||||
* @see MongoConfigurationSupport
|
* @see MongoConfigurationSupport
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public abstract class AbstractReactiveMongoConfiguration extends MongoConfigurationSupport {
|
public abstract class AbstractReactiveMongoConfiguration extends MongoConfigurationSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Reactive Streams {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want
|
* Return the Reactive Streams {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want
|
||||||
* to expose a {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}.
|
* to expose a {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}. <br />
|
||||||
|
* Override {@link #mongoClientSettings()} to configure connection details.
|
||||||
*
|
*
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
|
* @see #mongoClientSettings()
|
||||||
|
* @see #configureClientSettings(Builder)
|
||||||
*/
|
*/
|
||||||
public abstract MongoClient reactiveMongoClient();
|
public MongoClient reactiveMongoClient() {
|
||||||
|
return createReactiveMongoClient(mongoClientSettings());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link ReactiveMongoOperations}.
|
* Creates {@link ReactiveMongoOperations}.
|
||||||
*
|
*
|
||||||
|
* @see #reactiveMongoDbFactory()
|
||||||
|
* @see #mappingMongoConverter(ReactiveMongoDatabaseFactory, MongoCustomConversions, MongoMappingContext)
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public ReactiveMongoOperations reactiveMongoTemplate() throws Exception {
|
public ReactiveMongoTemplate reactiveMongoTemplate(ReactiveMongoDatabaseFactory databaseFactory,
|
||||||
return new ReactiveMongoTemplate(reactiveMongoDbFactory(), mappingMongoConverter());
|
MappingMongoConverter mongoConverter) {
|
||||||
|
return new ReactiveMongoTemplate(databaseFactory, mongoConverter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +74,7 @@ public abstract class AbstractReactiveMongoConfiguration extends MongoConfigurat
|
|||||||
* {@link MongoClient} instance configured in {@link #reactiveMongoClient()}.
|
* {@link MongoClient} instance configured in {@link #reactiveMongoClient()}.
|
||||||
*
|
*
|
||||||
* @see #reactiveMongoClient()
|
* @see #reactiveMongoClient()
|
||||||
* @see #reactiveMongoTemplate()
|
* @see #reactiveMongoTemplate(ReactiveMongoDatabaseFactory, MappingMongoConverter)
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@@ -70,20 +84,31 @@ public abstract class AbstractReactiveMongoConfiguration extends MongoConfigurat
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link MappingMongoConverter} using the configured {@link #reactiveMongoDbFactory()} and
|
* Creates a {@link MappingMongoConverter} using the configured {@link #reactiveMongoDbFactory()} and
|
||||||
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
|
* {@link #mongoMappingContext(MongoCustomConversions)}. Will get {@link #customConversions()} applied.
|
||||||
*
|
*
|
||||||
* @see #customConversions()
|
* @see #customConversions()
|
||||||
* @see #mongoMappingContext()
|
* @see #mongoMappingContext(MongoCustomConversions)
|
||||||
* @see #reactiveMongoDbFactory()
|
* @see #reactiveMongoDbFactory()
|
||||||
* @return never {@literal null}.
|
* @return never {@literal null}.
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MappingMongoConverter mappingMongoConverter() throws Exception {
|
public MappingMongoConverter mappingMongoConverter(ReactiveMongoDatabaseFactory databaseFactory,
|
||||||
|
MongoCustomConversions customConversions, MongoMappingContext mappingContext) {
|
||||||
|
|
||||||
MappingMongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mongoMappingContext());
|
MappingMongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
|
||||||
converter.setCustomConversions(customConversions());
|
converter.setCustomConversions(customConversions);
|
||||||
|
converter.setCodecRegistryProvider(databaseFactory);
|
||||||
|
|
||||||
return converter;
|
return converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the Reactive Streams {@link MongoClient} instance with given {@link MongoClientSettings}.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected MongoClient createReactiveMongoClient(MongoClientSettings settings) {
|
||||||
|
return MongoClients.create(settings, SpringDataMongoDB.driverInformation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.config;
|
||||||
|
|
||||||
|
import java.beans.PropertyEditorSupport;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.mongodb.ConnectionString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a {@link String} to a {@link com.mongodb.ConnectionString}.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public class ConnectionStringPropertyEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setAsText(@Nullable String connectionString) {
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(connectionString)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(new ConnectionString(connectionString));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2019 the original author or authors.
|
* Copyright 2013-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -42,21 +42,21 @@ public @interface EnableMongoAuditing {
|
|||||||
/**
|
/**
|
||||||
* Configures the {@link AuditorAware} bean to be used to lookup the current principal.
|
* Configures the {@link AuditorAware} bean to be used to lookup the current principal.
|
||||||
*
|
*
|
||||||
* @return
|
* @return empty {@link String} by default.
|
||||||
*/
|
*/
|
||||||
String auditorAwareRef() default "";
|
String auditorAwareRef() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures whether the creation and modification dates are set. Defaults to {@literal true}.
|
* Configures whether the creation and modification dates are set. Defaults to {@literal true}.
|
||||||
*
|
*
|
||||||
* @return
|
* @return {@literal true} by default.
|
||||||
*/
|
*/
|
||||||
boolean setDates() default true;
|
boolean setDates() default true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures whether the entity shall be marked as modified on creation. Defaults to {@literal true}.
|
* Configures whether the entity shall be marked as modified on creation. Defaults to {@literal true}.
|
||||||
*
|
*
|
||||||
* @return
|
* @return {@literal true} by default.
|
||||||
*/
|
*/
|
||||||
boolean modifyOnCreate() default true;
|
boolean modifyOnCreate() default true;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public @interface EnableMongoAuditing {
|
|||||||
* Configures a {@link DateTimeProvider} bean name that allows customizing the {@link org.joda.time.DateTime} to be
|
* Configures a {@link DateTimeProvider} bean name that allows customizing the {@link org.joda.time.DateTime} to be
|
||||||
* used for setting creation and modification dates.
|
* used for setting creation and modification dates.
|
||||||
*
|
*
|
||||||
* @return
|
* @return empty {@link String} by default.
|
||||||
*/
|
*/
|
||||||
String dateTimeProviderRef() default "";
|
String dateTimeProviderRef() default "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2019 the original author or authors.
|
* Copyright 2013-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -96,6 +96,9 @@ public class MappingMongoConverterParser implements BeanDefinitionParser {
|
|||||||
String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
|
String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
|
||||||
id = StringUtils.hasText(id) ? id : DEFAULT_CONVERTER_BEAN_NAME;
|
id = StringUtils.hasText(id) ? id : DEFAULT_CONVERTER_BEAN_NAME;
|
||||||
|
|
||||||
|
String autoIndexCreation = element.getAttribute("auto-index-creation");
|
||||||
|
boolean autoIndexCreationEnabled = StringUtils.hasText(autoIndexCreation) && Boolean.valueOf(autoIndexCreation);
|
||||||
|
|
||||||
parserContext.pushContainingComponent(new CompositeComponentDefinition("Mapping Mongo Converter", element));
|
parserContext.pushContainingComponent(new CompositeComponentDefinition("Mapping Mongo Converter", element));
|
||||||
|
|
||||||
BeanDefinition conversionsDefinition = getCustomConversions(element, parserContext);
|
BeanDefinition conversionsDefinition = getCustomConversions(element, parserContext);
|
||||||
@@ -199,6 +202,11 @@ public class MappingMongoConverterParser implements BeanDefinitionParser {
|
|||||||
|
|
||||||
public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext,
|
public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext,
|
||||||
@Nullable BeanDefinition conversionsDefinition, @Nullable String converterId) {
|
@Nullable BeanDefinition conversionsDefinition, @Nullable String converterId) {
|
||||||
|
return potentiallyCreateMappingContext(element, parserContext, conversionsDefinition, converterId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String potentiallyCreateMappingContext(Element element, ParserContext parserContext,
|
||||||
|
@Nullable BeanDefinition conversionsDefinition, @Nullable String converterId, boolean autoIndexCreation) {
|
||||||
|
|
||||||
String ctxRef = element.getAttribute("mapping-context-ref");
|
String ctxRef = element.getAttribute("mapping-context-ref");
|
||||||
|
|
||||||
@@ -226,6 +234,8 @@ public class MappingMongoConverterParser implements BeanDefinitionParser {
|
|||||||
mappingContextBuilder.addPropertyValue("simpleTypeHolder", simpleTypesDefinition);
|
mappingContextBuilder.addPropertyValue("simpleTypeHolder", simpleTypesDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mappingContextBuilder.addPropertyValue("autoIndexCreation", autoIndexCreation);
|
||||||
|
|
||||||
parseFieldNamingStrategy(element, parserContext.getReaderContext(), mappingContextBuilder);
|
parseFieldNamingStrategy(element, parserContext.getReaderContext(), mappingContextBuilder);
|
||||||
|
|
||||||
ctxRef = converterId == null || DEFAULT_CONVERTER_BEAN_NAME.equals(converterId) ? MAPPING_CONTEXT_BEAN_NAME
|
ctxRef = converterId == null || DEFAULT_CONVERTER_BEAN_NAME.equals(converterId) ? MAPPING_CONTEXT_BEAN_NAME
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2019 the original author or authors.
|
* Copyright 2013-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -50,10 +50,11 @@ public class MongoClientParser implements BeanDefinitionParser {
|
|||||||
|
|
||||||
ParsingUtils.setPropertyValue(builder, element, "port", "port");
|
ParsingUtils.setPropertyValue(builder, element, "port", "port");
|
||||||
ParsingUtils.setPropertyValue(builder, element, "host", "host");
|
ParsingUtils.setPropertyValue(builder, element, "host", "host");
|
||||||
ParsingUtils.setPropertyValue(builder, element, "credentials", "credentials");
|
ParsingUtils.setPropertyValue(builder, element, "credential", "credential");
|
||||||
|
ParsingUtils.setPropertyValue(builder, element, "replica-set", "replicaSet");
|
||||||
|
ParsingUtils.setPropertyValue(builder, element, "connection-string", "connectionString");
|
||||||
|
|
||||||
MongoParsingUtils.parseMongoClientOptions(element, builder);
|
MongoParsingUtils.parseMongoClientSettings(element, builder);
|
||||||
MongoParsingUtils.parseReplicaSet(element, builder);
|
|
||||||
|
|
||||||
String defaultedId = StringUtils.hasText(id) ? id : BeanNames.MONGO_BEAN_NAME;
|
String defaultedId = StringUtils.hasText(id) ? id : BeanNames.MONGO_BEAN_NAME;
|
||||||
|
|
||||||
@@ -62,22 +63,34 @@ public class MongoClientParser implements BeanDefinitionParser {
|
|||||||
BeanComponentDefinition mongoComponent = helper.getComponent(builder, defaultedId);
|
BeanComponentDefinition mongoComponent = helper.getComponent(builder, defaultedId);
|
||||||
parserContext.registerBeanComponent(mongoComponent);
|
parserContext.registerBeanComponent(mongoComponent);
|
||||||
|
|
||||||
BeanComponentDefinition serverAddressPropertyEditor = helper.getComponent(MongoParsingUtils
|
BeanComponentDefinition connectionStringPropertyEditor = helper
|
||||||
.getServerAddressPropertyEditorBuilder());
|
.getComponent(MongoParsingUtils.getConnectionStringPropertyEditorBuilder());
|
||||||
|
parserContext.registerBeanComponent(connectionStringPropertyEditor);
|
||||||
|
|
||||||
|
BeanComponentDefinition serverAddressPropertyEditor = helper
|
||||||
|
.getComponent(MongoParsingUtils.getServerAddressPropertyEditorBuilder());
|
||||||
parserContext.registerBeanComponent(serverAddressPropertyEditor);
|
parserContext.registerBeanComponent(serverAddressPropertyEditor);
|
||||||
|
|
||||||
BeanComponentDefinition writeConcernEditor = helper.getComponent(MongoParsingUtils
|
BeanComponentDefinition writeConcernEditor = helper
|
||||||
.getWriteConcernPropertyEditorBuilder());
|
.getComponent(MongoParsingUtils.getWriteConcernPropertyEditorBuilder());
|
||||||
parserContext.registerBeanComponent(writeConcernEditor);
|
parserContext.registerBeanComponent(writeConcernEditor);
|
||||||
|
|
||||||
BeanComponentDefinition readPreferenceEditor = helper.getComponent(MongoParsingUtils
|
BeanComponentDefinition readConcernEditor = helper
|
||||||
.getReadPreferencePropertyEditorBuilder());
|
.getComponent(MongoParsingUtils.getReadConcernPropertyEditorBuilder());
|
||||||
|
parserContext.registerBeanComponent(readConcernEditor);
|
||||||
|
|
||||||
|
BeanComponentDefinition readPreferenceEditor = helper
|
||||||
|
.getComponent(MongoParsingUtils.getReadPreferencePropertyEditorBuilder());
|
||||||
parserContext.registerBeanComponent(readPreferenceEditor);
|
parserContext.registerBeanComponent(readPreferenceEditor);
|
||||||
|
|
||||||
BeanComponentDefinition credentialsEditor = helper.getComponent(MongoParsingUtils
|
BeanComponentDefinition credentialsEditor = helper
|
||||||
.getMongoCredentialPropertyEditor());
|
.getComponent(MongoParsingUtils.getMongoCredentialPropertyEditor());
|
||||||
parserContext.registerBeanComponent(credentialsEditor);
|
parserContext.registerBeanComponent(credentialsEditor);
|
||||||
|
|
||||||
|
BeanComponentDefinition uuidRepresentationEditor = helper
|
||||||
|
.getComponent(MongoParsingUtils.getUUidRepresentationEditorBuilder());
|
||||||
|
parserContext.registerBeanComponent(uuidRepresentationEditor);
|
||||||
|
|
||||||
parserContext.popAndRegisterContainingComponent();
|
parserContext.popAndRegisterContainingComponent();
|
||||||
|
|
||||||
return mongoComponent.getBeanDefinition();
|
return mongoComponent.getBeanDefinition();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2019 the original author or authors.
|
* Copyright 2016-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,6 +20,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.bson.UuidRepresentation;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||||
@@ -31,11 +32,15 @@ import org.springframework.data.mapping.model.CamelCaseAbbreviatingFieldNamingSt
|
|||||||
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
import org.springframework.data.mapping.model.FieldNamingStrategy;
|
||||||
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
|
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
|
||||||
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
|
||||||
|
import org.springframework.data.mongodb.core.convert.MongoCustomConversions.MongoConverterConfigurationAdapter;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.mongodb.MongoClientSettings;
|
||||||
|
import com.mongodb.MongoClientSettings.Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for Spring Data MongoDB to be extended for JavaConfiguration usage.
|
* Base class for Spring Data MongoDB to be extended for JavaConfiguration usage.
|
||||||
*
|
*
|
||||||
@@ -75,11 +80,12 @@ public abstract class MongoConfigurationSupport {
|
|||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public MongoMappingContext mongoMappingContext() throws ClassNotFoundException {
|
public MongoMappingContext mongoMappingContext(MongoCustomConversions customConversions)
|
||||||
|
throws ClassNotFoundException {
|
||||||
|
|
||||||
MongoMappingContext mappingContext = new MongoMappingContext();
|
MongoMappingContext mappingContext = new MongoMappingContext();
|
||||||
mappingContext.setInitialEntitySet(getInitialEntitySet());
|
mappingContext.setInitialEntitySet(getInitialEntitySet());
|
||||||
mappingContext.setSimpleTypeHolder(customConversions().getSimpleTypeHolder());
|
mappingContext.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
|
||||||
mappingContext.setFieldNamingStrategy(fieldNamingStrategy());
|
mappingContext.setFieldNamingStrategy(fieldNamingStrategy());
|
||||||
mappingContext.setAutoIndexCreation(autoIndexCreation());
|
mappingContext.setAutoIndexCreation(autoIndexCreation());
|
||||||
|
|
||||||
@@ -88,14 +94,30 @@ public abstract class MongoConfigurationSupport {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register custom {@link Converter}s in a {@link CustomConversions} object if required. These
|
* Register custom {@link Converter}s in a {@link CustomConversions} object if required. These
|
||||||
* {@link CustomConversions} will be registered with the {@link #mappingMongoConverter()} and
|
* {@link CustomConversions} will be registered with the
|
||||||
* {@link #mongoMappingContext()}. Returns an empty {@link MongoCustomConversions} instance by default.
|
* {@link org.springframework.data.mongodb.core.convert.MappingMongoConverter} and {@link MongoMappingContext}.
|
||||||
|
* Returns an empty {@link MongoCustomConversions} instance by default.
|
||||||
|
* <p>
|
||||||
|
* <strong>NOTE:</strong> Use {@link #configureConverters(MongoConverterConfigurationAdapter)} to configure MongoDB
|
||||||
|
* native simple types and register custom {@link Converter converters}.
|
||||||
*
|
*
|
||||||
* @return must not be {@literal null}.
|
* @return must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public CustomConversions customConversions() {
|
public MongoCustomConversions customConversions() {
|
||||||
return new MongoCustomConversions(Collections.emptyList());
|
return MongoCustomConversions.create(this::configureConverters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration hook for {@link MongoCustomConversions} creation.
|
||||||
|
*
|
||||||
|
* @param converterConfigurationAdapter never {@literal null}.
|
||||||
|
* @since 2.3
|
||||||
|
* @see MongoConverterConfigurationAdapter#useNativeDriverJavaTimeCodecs()
|
||||||
|
* @see MongoConverterConfigurationAdapter#useSpringDataJavaTimeCodecs()
|
||||||
|
*/
|
||||||
|
protected void configureConverters(MongoConverterConfigurationAdapter converterConfigurationAdapter) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,11 +199,36 @@ public abstract class MongoConfigurationSupport {
|
|||||||
* Configure whether to automatically create indices for domain types by deriving the
|
* Configure whether to automatically create indices for domain types by deriving the
|
||||||
* {@link org.springframework.data.mongodb.core.index.IndexDefinition} from the entity or not.
|
* {@link org.springframework.data.mongodb.core.index.IndexDefinition} from the entity or not.
|
||||||
*
|
*
|
||||||
* @return {@literal true} by default. <br />
|
* @return {@literal false} by default. <br />
|
||||||
* <strong>INFO</strong>: As of 3.x the default will be set to {@literal false}.
|
* <strong>INFO</strong>: As of 3.x the default is set to {@literal false}; In 2.x it was {@literal true}.
|
||||||
* @since 2.2
|
* @since 2.2
|
||||||
*/
|
*/
|
||||||
protected boolean autoIndexCreation() {
|
protected boolean autoIndexCreation() {
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the {@link MongoClientSettings} used to create the actual {@literal MongoClient}. <br />
|
||||||
|
* Override either this method, or use {@link #configureClientSettings(Builder)} to alter the setup.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected MongoClientSettings mongoClientSettings() {
|
||||||
|
|
||||||
|
MongoClientSettings.Builder builder = MongoClientSettings.builder();
|
||||||
|
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
|
||||||
|
configureClientSettings(builder);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure {@link MongoClientSettings} via its {@link Builder} API.
|
||||||
|
*
|
||||||
|
* @param builder never {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected void configureClientSettings(MongoClientSettings.Builder builder) {
|
||||||
|
// customization hook
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,14 +32,12 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
|||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.data.config.BeanComponentDefinitionBuilder;
|
import org.springframework.data.config.BeanComponentDefinitionBuilder;
|
||||||
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
|
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
|
||||||
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
|
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
import com.mongodb.ConnectionString;
|
||||||
import com.mongodb.MongoClientURI;
|
|
||||||
import com.mongodb.MongoURI;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link BeanDefinitionParser} to parse {@code db-factory} elements into {@link BeanDefinition}s.
|
* {@link BeanDefinitionParser} to parse {@code db-factory} elements into {@link BeanDefinition}s.
|
||||||
@@ -84,10 +82,11 @@ public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|||||||
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
|
||||||
|
|
||||||
// Common setup
|
// Common setup
|
||||||
BeanDefinitionBuilder dbFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(SimpleMongoDbFactory.class);
|
BeanDefinitionBuilder dbFactoryBuilder = BeanDefinitionBuilder
|
||||||
|
.genericBeanDefinition(SimpleMongoClientDatabaseFactory.class);
|
||||||
setPropertyValue(dbFactoryBuilder, element, "write-concern", "writeConcern");
|
setPropertyValue(dbFactoryBuilder, element, "write-concern", "writeConcern");
|
||||||
|
|
||||||
BeanDefinition mongoUri = getMongoUri(element, parserContext);
|
BeanDefinition mongoUri = getConnectionString(element, parserContext);
|
||||||
|
|
||||||
if (mongoUri != null) {
|
if (mongoUri != null) {
|
||||||
|
|
||||||
@@ -97,7 +96,8 @@ public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|||||||
|
|
||||||
BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, parserContext);
|
BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, parserContext);
|
||||||
|
|
||||||
String mongoRef = element.getAttribute("mongo-ref");
|
String mongoRef = element.getAttribute("mongo-client-ref");
|
||||||
|
|
||||||
String dbname = element.getAttribute("dbname");
|
String dbname = element.getAttribute("dbname");
|
||||||
|
|
||||||
// Defaulting
|
// Defaulting
|
||||||
@@ -119,8 +119,8 @@ public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default {@link BeanDefinition} of a {@link Mongo} instance and returns the name under which the
|
* Registers a default {@link BeanDefinition} of a {@link com.mongodb.client.MongoClient} instance and returns the
|
||||||
* {@link Mongo} instance was registered under.
|
* name under which the {@link com.mongodb.client.MongoClient} instance was registered under.
|
||||||
*
|
*
|
||||||
* @param element must not be {@literal null}.
|
* @param element must not be {@literal null}.
|
||||||
* @param parserContext must not be {@literal null}.
|
* @param parserContext must not be {@literal null}.
|
||||||
@@ -136,8 +136,7 @@ public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link BeanDefinition} for a {@link MongoURI} or {@link MongoClientURI} depending on configured
|
* Creates a {@link BeanDefinition} for a {@link ConnectionString} depending on configured attributes. <br />
|
||||||
* attributes. <br />
|
|
||||||
* Errors when configured element contains {@literal uri} or {@literal client-uri} along with other attributes except
|
* Errors when configured element contains {@literal uri} or {@literal client-uri} along with other attributes except
|
||||||
* {@literal write-concern} and/or {@literal id}.
|
* {@literal write-concern} and/or {@literal id}.
|
||||||
*
|
*
|
||||||
@@ -146,11 +145,19 @@ public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|||||||
* @return {@literal null} in case no client-/uri defined.
|
* @return {@literal null} in case no client-/uri defined.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private BeanDefinition getMongoUri(Element element, ParserContext parserContext) {
|
private BeanDefinition getConnectionString(Element element, ParserContext parserContext) {
|
||||||
|
|
||||||
boolean hasClientUri = element.hasAttribute("client-uri");
|
String type = null;
|
||||||
|
|
||||||
if (!hasClientUri && !element.hasAttribute("uri")) {
|
if (element.hasAttribute("client-uri")) {
|
||||||
|
type = "client-uri";
|
||||||
|
} else if (element.hasAttribute("connection-string")) {
|
||||||
|
type = "connection-string";
|
||||||
|
} else if (element.hasAttribute("uri")) {
|
||||||
|
type = "uri";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(type)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,16 +171,12 @@ public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
|||||||
|
|
||||||
if (element.getAttributes().getLength() > allowedAttributesCount) {
|
if (element.getAttributes().getLength() > allowedAttributesCount) {
|
||||||
|
|
||||||
parserContext.getReaderContext().error(
|
parserContext.getReaderContext().error("Configure either MongoDB " + type + " or details individually!",
|
||||||
"Configure either " + (hasClientUri ? "Mongo Client URI" : "Mongo URI") + " or details individually!",
|
|
||||||
parserContext.extractSource(element));
|
parserContext.extractSource(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> type = MongoClientURI.class;
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ConnectionString.class);
|
||||||
String uri = hasClientUri ? element.getAttribute("client-uri") : element.getAttribute("uri");
|
builder.addConstructorArgValue(element.getAttribute(type));
|
||||||
|
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(type);
|
|
||||||
builder.addConstructorArgValue(uri);
|
|
||||||
|
|
||||||
return builder.getBeanDefinition();
|
return builder.getBeanDefinition();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.config.CustomEditorConfigurer;
|
|||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.support.ManagedMap;
|
import org.springframework.beans.factory.support.ManagedMap;
|
||||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||||
import org.springframework.data.mongodb.core.MongoClientOptionsFactoryBean;
|
import org.springframework.data.mongodb.core.MongoClientSettingsFactoryBean;
|
||||||
import org.springframework.util.xml.DomUtils;
|
import org.springframework.util.xml.DomUtils;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
@@ -43,60 +43,78 @@ abstract class MongoParsingUtils {
|
|||||||
private MongoParsingUtils() {}
|
private MongoParsingUtils() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the mongo replica-set element.
|
* Parses the {@code mongo:client-settings} sub-element. Populates the given attribute factory with the proper
|
||||||
*
|
|
||||||
* @param parserContext the parser context
|
|
||||||
* @param element the mongo element
|
|
||||||
* @param mongoBuilder the bean definition builder to populate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static void parseReplicaSet(Element element, BeanDefinitionBuilder mongoBuilder) {
|
|
||||||
setPropertyValue(mongoBuilder, element, "replica-set", "replicaSetSeeds");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the {@code mongo:client-options} sub-element. Populates the given attribute factory with the proper
|
|
||||||
* attributes.
|
* attributes.
|
||||||
*
|
*
|
||||||
* @param element must not be {@literal null}.
|
* @param element
|
||||||
* @param mongoClientBuilder must not be {@literal null}.
|
* @param mongoClientBuilder
|
||||||
* @return
|
* @return
|
||||||
* @since 1.7
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public static boolean parseMongoClientOptions(Element element, BeanDefinitionBuilder mongoClientBuilder) {
|
public static boolean parseMongoClientSettings(Element element, BeanDefinitionBuilder mongoClientBuilder) {
|
||||||
|
|
||||||
Element optionsElement = DomUtils.getChildElementByTagName(element, "client-options");
|
Element settingsElement = DomUtils.getChildElementByTagName(element, "client-settings");
|
||||||
|
if (settingsElement == null) {
|
||||||
if (optionsElement == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BeanDefinitionBuilder clientOptionsDefBuilder = BeanDefinitionBuilder
|
BeanDefinitionBuilder clientOptionsDefBuilder = BeanDefinitionBuilder
|
||||||
.genericBeanDefinition(MongoClientOptionsFactoryBean.class);
|
.genericBeanDefinition(MongoClientSettingsFactoryBean.class);
|
||||||
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "description", "description");
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "application-name", "applicationName");
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "min-connections-per-host", "minConnectionsPerHost");
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "read-preference", "readPreference");
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "connections-per-host", "connectionsPerHost");
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "read-concern", "readConcern");
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "threads-allowed-to-block-for-connection-multiplier",
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "write-concern", "writeConcern");
|
||||||
"threadsAllowedToBlockForConnectionMultiplier");
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "retry-reads", "retryReads");
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "max-wait-time", "maxWaitTime");
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "retry-writes", "retryWrites");
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "max-connection-idle-time", "maxConnectionIdleTime");
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "uuid-representation", "uUidRepresentation");
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "max-connection-life-time", "maxConnectionLifeTime");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "connect-timeout", "connectTimeout");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "socket-timeout", "socketTimeout");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "socket-keep-alive", "socketKeepAlive");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "read-preference", "readPreference");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "write-concern", "writeConcern");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "heartbeat-frequency", "heartbeatFrequency");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "min-heartbeat-frequency", "minHeartbeatFrequency");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "heartbeat-connect-timeout", "heartbeatConnectTimeout");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "heartbeat-socket-timeout", "heartbeatSocketTimeout");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "ssl", "ssl");
|
|
||||||
setPropertyReference(clientOptionsDefBuilder, optionsElement, "ssl-socket-factory-ref", "sslSocketFactory");
|
|
||||||
setPropertyReference(clientOptionsDefBuilder, optionsElement, "encryption-settings-ref", "autoEncryptionSettings");
|
|
||||||
setPropertyValue(clientOptionsDefBuilder, optionsElement, "server-selection-timeout", "serverSelectionTimeout");
|
|
||||||
|
|
||||||
mongoClientBuilder.addPropertyValue("mongoClientOptions", clientOptionsDefBuilder.getBeanDefinition());
|
// SocketSettings
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "socket-connect-timeout", "socketConnectTimeoutMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "socket-read-timeout", "socketReadTimeoutMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "socket-receive-buffer-size", "socketReceiveBufferSize");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "socket-send-buffer-size", "socketSendBufferSize");
|
||||||
|
|
||||||
|
// Server Settings
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "server-heartbeat-frequency",
|
||||||
|
"serverHeartbeatFrequencyMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "server-min-heartbeat-frequency",
|
||||||
|
"serverMinHeartbeatFrequencyMS");
|
||||||
|
|
||||||
|
// Cluster Settings
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "cluster-srv-host", "clusterSrvHost");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "cluster-hosts", "clusterHosts");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "cluster-connection-mode", "clusterConnectionMode");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "cluster-type", "custerRequiredClusterType");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "cluster-local-threshold", "clusterLocalThresholdMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "cluster-server-selection-timeout",
|
||||||
|
"clusterServerSelectionTimeoutMS");
|
||||||
|
|
||||||
|
// Connection Pool Settings
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-max-size", "poolMaxSize");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-min-size", "poolMinSize");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-max-wait-time", "poolMaxWaitTimeMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-max-connection-life-time",
|
||||||
|
"poolMaxConnectionLifeTimeMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-max-connection-idle-time",
|
||||||
|
"poolMaxConnectionIdleTimeMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-maintenance-initial-delay",
|
||||||
|
"poolMaintenanceInitialDelayMS");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "connection-pool-maintenance-frequency",
|
||||||
|
"poolMaintenanceFrequencyMS");
|
||||||
|
|
||||||
|
// SSL Settings
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "ssl-enabled", "sslEnabled");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "ssl-invalid-host-name-allowed",
|
||||||
|
"sslInvalidHostNameAllowed");
|
||||||
|
setPropertyValue(clientOptionsDefBuilder, settingsElement, "ssl-provider", "sslProvider");
|
||||||
|
|
||||||
|
// Field level encryption
|
||||||
|
setPropertyReference(clientOptionsDefBuilder, settingsElement, "encryption-settings-ref", "autoEncryptionSettings");
|
||||||
|
|
||||||
|
// and the rest
|
||||||
|
|
||||||
|
mongoClientBuilder.addPropertyValue("mongoClientSettings", clientOptionsDefBuilder.getBeanDefinition());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -118,6 +136,24 @@ abstract class MongoParsingUtils {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
|
||||||
|
* {@link ReadConcernPropertyEditor}.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
static BeanDefinitionBuilder getReadConcernPropertyEditorBuilder() {
|
||||||
|
|
||||||
|
Map<String, Class<?>> customEditors = new ManagedMap<>();
|
||||||
|
customEditors.put("com.mongodb.ReadConcern", ReadConcernPropertyEditor.class);
|
||||||
|
|
||||||
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
|
||||||
|
builder.addPropertyValue("customEditors", customEditors);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One should only register one bean definition but want to have the convenience of using
|
* One should only register one bean definition but want to have the convenience of using
|
||||||
* AbstractSingleBeanDefinitionParser but have the side effect of registering a 'default' property editor with the
|
* AbstractSingleBeanDefinitionParser but have the side effect of registering a 'default' property editor with the
|
||||||
@@ -125,7 +161,7 @@ abstract class MongoParsingUtils {
|
|||||||
*/
|
*/
|
||||||
static BeanDefinitionBuilder getServerAddressPropertyEditorBuilder() {
|
static BeanDefinitionBuilder getServerAddressPropertyEditorBuilder() {
|
||||||
|
|
||||||
Map<String, String> customEditors = new ManagedMap<String, String>();
|
Map<String, String> customEditors = new ManagedMap<>();
|
||||||
customEditors.put("com.mongodb.ServerAddress[]",
|
customEditors.put("com.mongodb.ServerAddress[]",
|
||||||
"org.springframework.data.mongodb.config.ServerAddressPropertyEditor");
|
"org.springframework.data.mongodb.config.ServerAddressPropertyEditor");
|
||||||
|
|
||||||
@@ -143,7 +179,7 @@ abstract class MongoParsingUtils {
|
|||||||
*/
|
*/
|
||||||
static BeanDefinitionBuilder getReadPreferencePropertyEditorBuilder() {
|
static BeanDefinitionBuilder getReadPreferencePropertyEditorBuilder() {
|
||||||
|
|
||||||
Map<String, Class<?>> customEditors = new ManagedMap<String, Class<?>>();
|
Map<String, Class<?>> customEditors = new ManagedMap<>();
|
||||||
customEditors.put("com.mongodb.ReadPreference", ReadPreferencePropertyEditor.class);
|
customEditors.put("com.mongodb.ReadPreference", ReadPreferencePropertyEditor.class);
|
||||||
|
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
|
||||||
@@ -169,4 +205,41 @@ abstract class MongoParsingUtils {
|
|||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
|
||||||
|
* {@link ConnectionStringPropertyEditor}.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
static BeanDefinitionBuilder getConnectionStringPropertyEditorBuilder() {
|
||||||
|
|
||||||
|
Map<String, Class<?>> customEditors = new ManagedMap<>();
|
||||||
|
customEditors.put("com.mongodb.ConnectionString", ConnectionStringPropertyEditor.class);
|
||||||
|
|
||||||
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
|
||||||
|
builder.addPropertyValue("customEditors", customEditors);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
|
||||||
|
* {@link ConnectionStringPropertyEditor}.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
static BeanDefinitionBuilder getUUidRepresentationEditorBuilder() {
|
||||||
|
|
||||||
|
Map<String, Class<?>> customEditors = new ManagedMap<>();
|
||||||
|
customEditors.put("org.bson.UuidRepresentation", UUidRepresentationPropertyEditor.class);
|
||||||
|
|
||||||
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
|
||||||
|
builder.addPropertyValue("customEditors", customEditors);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.config;
|
||||||
|
|
||||||
|
import java.beans.PropertyEditorSupport;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.mongodb.ReadConcern;
|
||||||
|
import com.mongodb.ReadConcernLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a {@link String} to a {@link ReadConcern}. If it is a well know {@link String} as identified by the
|
||||||
|
* {@link ReadConcernLevel#fromString(String)}.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public class ReadConcernPropertyEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setAsText(@Nullable String readConcernString) {
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(readConcernString)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(new ReadConcern(ReadConcernLevel.fromString(readConcernString)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.config;
|
||||||
|
|
||||||
|
import java.beans.PropertyEditorSupport;
|
||||||
|
|
||||||
|
import org.bson.UuidRepresentation;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a {@link String} to a {@link UuidRepresentation}.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
public class UUidRepresentationPropertyEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setAsText(@Nullable String value) {
|
||||||
|
|
||||||
|
if (!StringUtils.hasText(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(UuidRepresentation.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,7 +34,7 @@ import com.mongodb.WriteConcern;
|
|||||||
public class WriteConcernPropertyEditor extends PropertyEditorSupport {
|
public class WriteConcernPropertyEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a string to a List<ServerAddress>
|
* Parse a string to a {@link WriteConcern}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setAsText(@Nullable String writeConcernString) {
|
public void setAsText(@Nullable String writeConcernString) {
|
||||||
@@ -51,6 +51,5 @@ public class WriteConcernPropertyEditor extends PropertyEditorSupport {
|
|||||||
// pass on the string to the constructor
|
// pass on the string to the constructor
|
||||||
setValue(new WriteConcern(writeConcernString));
|
setValue(new WriteConcern(writeConcernString));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -94,7 +94,6 @@ public interface BulkOperations {
|
|||||||
* Add a list of updates to the bulk operation. For each update request, all matching documents are updated.
|
* Add a list of updates to the bulk operation. For each update request, all matching documents are updated.
|
||||||
*
|
*
|
||||||
* @param updates Update operations to perform.
|
* @param updates Update operations to perform.
|
||||||
* @return The bulk operation.
|
|
||||||
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
||||||
*/
|
*/
|
||||||
BulkOperations updateMulti(List<Pair<Query, Update>> updates);
|
BulkOperations updateMulti(List<Pair<Query, Update>> updates);
|
||||||
@@ -105,7 +104,6 @@ public interface BulkOperations {
|
|||||||
*
|
*
|
||||||
* @param query Update criteria.
|
* @param query Update criteria.
|
||||||
* @param update Update operation to perform.
|
* @param update Update operation to perform.
|
||||||
* @return The bulk operation.
|
|
||||||
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
||||||
*/
|
*/
|
||||||
BulkOperations upsert(Query query, Update update);
|
BulkOperations upsert(Query query, Update update);
|
||||||
@@ -115,7 +113,6 @@ public interface BulkOperations {
|
|||||||
* else an insert.
|
* else an insert.
|
||||||
*
|
*
|
||||||
* @param updates Updates/insert operations to perform.
|
* @param updates Updates/insert operations to perform.
|
||||||
* @return The bulk operation.
|
|
||||||
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
* @return the current {@link BulkOperations} instance with the update added, will never be {@literal null}.
|
||||||
*/
|
*/
|
||||||
BulkOperations upsert(List<Pair<Query, Update>> updates);
|
BulkOperations upsert(List<Pair<Query, Update>> updates);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -29,7 +29,7 @@ import com.mongodb.client.MongoCollection;
|
|||||||
* @author Grame Rocher
|
* @author Grame Rocher
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author John Brisbin
|
* @author John Brisbin
|
||||||
* @auhtor Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public interface CollectionCallback<T> {
|
public interface CollectionCallback<T> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -95,7 +95,7 @@ public class CollectionOptions {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new {@link CollectionOptions} with already given settings and capped set to {@literal true}. <br />
|
* Create new {@link CollectionOptions} with already given settings and capped set to {@literal true}. <br />
|
||||||
* <strong>NOTE</strong> Using capped collections requires defining {@link #size(int)}.
|
* <strong>NOTE</strong> Using capped collections requires defining {@link #size(long)}.
|
||||||
*
|
*
|
||||||
* @return new {@link CollectionOptions}.
|
* @return new {@link CollectionOptions}.
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
|||||||
@@ -0,0 +1,227 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.mongodb.core;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value object representing a count query. Count queries using {@code $near} or {@code $nearSphere} require a rewrite
|
||||||
|
* to {@code $geoWithin}.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @author Mark Paluch
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
class CountQuery {
|
||||||
|
|
||||||
|
private Document source;
|
||||||
|
|
||||||
|
private CountQuery(Document source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CountQuery of(Document source) {
|
||||||
|
return new CountQuery(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the query {@link Document} that can be used with {@code countDocuments()}. Potentially rewrites the query
|
||||||
|
* to be usable with {@code countDocuments()}.
|
||||||
|
*
|
||||||
|
* @return the query {@link Document} that can be used with {@code countDocuments()}.
|
||||||
|
*/
|
||||||
|
public Document toQueryDocument() {
|
||||||
|
|
||||||
|
if (!requiresRewrite(source)) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
Document target = new Document();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : source.entrySet()) {
|
||||||
|
|
||||||
|
if (entry.getValue() instanceof Document && requiresRewrite(entry.getValue())) {
|
||||||
|
|
||||||
|
Document theValue = (Document) entry.getValue();
|
||||||
|
target.putAll(createGeoWithin(entry.getKey(), theValue, source.get("$and")));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.getValue() instanceof Collection && requiresRewrite(entry.getValue())) {
|
||||||
|
|
||||||
|
Collection<?> source = (Collection<?>) entry.getValue();
|
||||||
|
|
||||||
|
target.put(entry.getKey(), rewriteCollection(source));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("$and".equals(entry.getKey()) && target.containsKey("$and")) {
|
||||||
|
// Expect $and to be processed with Document and createGeoWithin.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param valueToInspect
|
||||||
|
* @return {@code true} if the enclosing element needs to be rewritten.
|
||||||
|
*/
|
||||||
|
private boolean requiresRewrite(Object valueToInspect) {
|
||||||
|
|
||||||
|
if (valueToInspect instanceof Document) {
|
||||||
|
return requiresRewrite((Document) valueToInspect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valueToInspect instanceof Collection) {
|
||||||
|
return requiresRewrite((Collection) valueToInspect);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean requiresRewrite(Collection<?> collection) {
|
||||||
|
|
||||||
|
for (Object o : collection) {
|
||||||
|
if (o instanceof Document && requiresRewrite((Document) o)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean requiresRewrite(Document document) {
|
||||||
|
|
||||||
|
if (containsNear(document)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Object entry : document.values()) {
|
||||||
|
|
||||||
|
if (requiresRewrite(entry)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<Object> rewriteCollection(Collection<?> source) {
|
||||||
|
|
||||||
|
Collection<Object> rewrittenCollection = new ArrayList<>(source.size());
|
||||||
|
|
||||||
|
for (Object item : source) {
|
||||||
|
if (item instanceof Document && requiresRewrite(item)) {
|
||||||
|
rewrittenCollection.add(CountQuery.of((Document) item).toQueryDocument());
|
||||||
|
} else {
|
||||||
|
rewrittenCollection.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rewrittenCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrite the near query for field {@code key} to {@code $geoWithin}.
|
||||||
|
*
|
||||||
|
* @param key the queried field.
|
||||||
|
* @param source source {@link Document}.
|
||||||
|
* @param $and potentially existing {@code $and} condition.
|
||||||
|
* @return the rewritten query {@link Document}.
|
||||||
|
*/
|
||||||
|
private static Document createGeoWithin(String key, Document source, @Nullable Object $and) {
|
||||||
|
|
||||||
|
boolean spheric = source.containsKey("$nearSphere");
|
||||||
|
Object $near = spheric ? source.get("$nearSphere") : source.get("$near");
|
||||||
|
|
||||||
|
Number maxDistance = source.containsKey("$maxDistance") ? (Number) source.get("$maxDistance") : Double.MAX_VALUE;
|
||||||
|
List<Object> $centerMax = Arrays.asList(toCenterCoordinates($near), maxDistance);
|
||||||
|
Document $geoWithinMax = new Document("$geoWithin",
|
||||||
|
new Document(spheric ? "$centerSphere" : "$center", $centerMax));
|
||||||
|
|
||||||
|
if (!containsNearWithMinDistance(source)) {
|
||||||
|
return new Document(key, $geoWithinMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
Number minDistance = (Number) source.get("$minDistance");
|
||||||
|
List<Object> $centerMin = Arrays.asList(toCenterCoordinates($near), minDistance);
|
||||||
|
Document $geoWithinMin = new Document("$geoWithin",
|
||||||
|
new Document(spheric ? "$centerSphere" : "$center", $centerMin));
|
||||||
|
|
||||||
|
List<Document> criteria = new ArrayList<>();
|
||||||
|
|
||||||
|
if ($and != null) {
|
||||||
|
if ($and instanceof Collection) {
|
||||||
|
criteria.addAll((Collection) $and);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot rewrite query as it contains an '$and' element that is not a Collection!: Offending element: "
|
||||||
|
+ $and);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
criteria.add(new Document("$nor", Collections.singletonList(new Document(key, $geoWithinMin))));
|
||||||
|
criteria.add(new Document(key, $geoWithinMax));
|
||||||
|
return new Document("$and", criteria);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsNear(Document source) {
|
||||||
|
return source.containsKey("$near") || source.containsKey("$nearSphere");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsNearWithMinDistance(Document source) {
|
||||||
|
|
||||||
|
if (!containsNear(source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.containsKey("$minDistance");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object toCenterCoordinates(Object value) {
|
||||||
|
|
||||||
|
if (ObjectUtils.isArray(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Point) {
|
||||||
|
return Arrays.asList(((Point) value).getX(), ((Point) value).getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Document && ((Document) value).containsKey("x")) {
|
||||||
|
|
||||||
|
Document point = (Document) value;
|
||||||
|
return Arrays.asList(point.get("x"), point.get("y"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,9 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.core;
|
package org.springframework.data.mongodb.core;
|
||||||
|
|
||||||
import org.bson.Document;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import com.mongodb.ReadPreference;
|
||||||
import com.mongodb.client.FindIterable;
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple callback interface to allow customization of a {@link FindIterable}.
|
* Simple callback interface to allow customization of a {@link FindIterable}.
|
||||||
@@ -25,12 +31,53 @@ import com.mongodb.client.FindIterable;
|
|||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
interface CursorPreparer {
|
public interface CursorPreparer extends ReadPreferenceAware {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default {@link CursorPreparer} just passing on the given {@link FindIterable}.
|
||||||
|
*
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
CursorPreparer NO_OP_PREPARER = (iterable -> iterable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the given cursor (apply limits, skips and so on). Returns the prepared cursor.
|
* Prepare the given cursor (apply limits, skips and so on). Returns the prepared cursor.
|
||||||
*
|
*
|
||||||
* @param cursor
|
* @param iterable must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
FindIterable<Document> prepare(FindIterable<Document> cursor);
|
FindIterable<Document> prepare(FindIterable<Document> iterable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply query specific settings to {@link MongoCollection} and initate a find operation returning a
|
||||||
|
* {@link FindIterable} via the given {@link Function find} function.
|
||||||
|
*
|
||||||
|
* @param collection must not be {@literal null}.
|
||||||
|
* @param find must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @throws IllegalArgumentException if one of the required arguments is {@literal null}.
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
default FindIterable<Document> initiateFind(MongoCollection<Document> collection,
|
||||||
|
Function<MongoCollection<Document>, FindIterable<Document>> find) {
|
||||||
|
|
||||||
|
Assert.notNull(collection, "Collection must not be null!");
|
||||||
|
Assert.notNull(find, "Find function must not be null!");
|
||||||
|
|
||||||
|
if (hasReadPreference()) {
|
||||||
|
collection = collection.withReadPreference(getReadPreference());
|
||||||
|
}
|
||||||
|
|
||||||
|
return prepare(find.apply(collection));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the {@link ReadPreference} to apply or {@literal null} if none defined.
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
default ReadPreference getReadPreference() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.core;
|
package org.springframework.data.mongodb.core;
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,6 +32,7 @@ import org.springframework.data.mapping.callback.EntityCallbacks;
|
|||||||
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
||||||
import org.springframework.data.mongodb.core.convert.UpdateMapper;
|
import org.springframework.data.mongodb.core.convert.UpdateMapper;
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.event.AfterSaveCallback;
|
||||||
import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent;
|
import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent;
|
||||||
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertCallback;
|
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertCallback;
|
||||||
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent;
|
import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent;
|
||||||
@@ -38,6 +42,8 @@ import org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent;
|
|||||||
import org.springframework.data.mongodb.core.query.Collation;
|
import org.springframework.data.mongodb.core.query.Collation;
|
||||||
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.core.query.Update;
|
||||||
|
import org.springframework.data.mongodb.core.query.UpdateDefinition;
|
||||||
|
import org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter;
|
||||||
import org.springframework.data.util.Pair;
|
import org.springframework.data.util.Pair;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -47,9 +53,6 @@ import com.mongodb.bulk.BulkWriteResult;
|
|||||||
import com.mongodb.client.MongoCollection;
|
import com.mongodb.client.MongoCollection;
|
||||||
import com.mongodb.client.model.*;
|
import com.mongodb.client.model.*;
|
||||||
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.Value;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation for {@link BulkOperations}.
|
* Default implementation for {@link BulkOperations}.
|
||||||
*
|
*
|
||||||
@@ -60,6 +63,7 @@ import lombok.Value;
|
|||||||
* @author Minsu Kim
|
* @author Minsu Kim
|
||||||
* @author Jens Schauder
|
* @author Jens Schauder
|
||||||
* @author Michail Nikolaev
|
* @author Michail Nikolaev
|
||||||
|
* @author Roman Puchkovskiy
|
||||||
* @since 1.9
|
* @since 1.9
|
||||||
*/
|
*/
|
||||||
class DefaultBulkOperations implements BulkOperations {
|
class DefaultBulkOperations implements BulkOperations {
|
||||||
@@ -298,6 +302,7 @@ class DefaultBulkOperations implements BulkOperations {
|
|||||||
Assert.state(result != null, "Result must not be null.");
|
Assert.state(result != null, "Result must not be null.");
|
||||||
|
|
||||||
models.forEach(this::maybeEmitAfterSaveEvent);
|
models.forEach(this::maybeEmitAfterSaveEvent);
|
||||||
|
models.forEach(this::maybeInvokeAfterSaveCallback);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -349,9 +354,7 @@ class DefaultBulkOperations implements BulkOperations {
|
|||||||
Assert.notNull(query, "Query must not be null!");
|
Assert.notNull(query, "Query must not be null!");
|
||||||
Assert.notNull(update, "Update must not be null!");
|
Assert.notNull(update, "Update must not be null!");
|
||||||
|
|
||||||
UpdateOptions options = new UpdateOptions();
|
UpdateOptions options = computeUpdateOptions(query, update, upsert);
|
||||||
options.upsert(upsert);
|
|
||||||
query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation);
|
|
||||||
|
|
||||||
if (multi) {
|
if (multi) {
|
||||||
addModel(update, new UpdateManyModel<>(query.getQueryObject(), update.getUpdateObject(), options));
|
addModel(update, new UpdateManyModel<>(query.getQueryObject(), update.getUpdateObject(), options));
|
||||||
@@ -421,38 +424,52 @@ class DefaultBulkOperations implements BulkOperations {
|
|||||||
models.add(new SourceAwareWriteModelHolder(source, model));
|
models.add(new SourceAwareWriteModelHolder(source, model));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeEmitBeforeSaveEvent(SourceAwareWriteModelHolder it) {
|
private void maybeEmitBeforeSaveEvent(SourceAwareWriteModelHolder holder) {
|
||||||
|
|
||||||
if (it.getModel() instanceof InsertOneModel) {
|
if (holder.getModel() instanceof InsertOneModel) {
|
||||||
|
|
||||||
Document target = ((InsertOneModel<Document>) it.getModel()).getDocument();
|
Document target = ((InsertOneModel<Document>) holder.getModel()).getDocument();
|
||||||
maybeEmitEvent(new BeforeSaveEvent<>(it.getSource(), target, collectionName));
|
maybeEmitEvent(new BeforeSaveEvent<>(holder.getSource(), target, collectionName));
|
||||||
} else if (it.getModel() instanceof ReplaceOneModel) {
|
} else if (holder.getModel() instanceof ReplaceOneModel) {
|
||||||
|
|
||||||
Document target = ((ReplaceOneModel<Document>) it.getModel()).getReplacement();
|
Document target = ((ReplaceOneModel<Document>) holder.getModel()).getReplacement();
|
||||||
maybeEmitEvent(new BeforeSaveEvent<>(it.getSource(), target, collectionName));
|
maybeEmitEvent(new BeforeSaveEvent<>(holder.getSource(), target, collectionName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeEmitAfterSaveEvent(SourceAwareWriteModelHolder it) {
|
private void maybeEmitAfterSaveEvent(SourceAwareWriteModelHolder holder) {
|
||||||
|
|
||||||
if (it.getModel() instanceof InsertOneModel) {
|
if (holder.getModel() instanceof InsertOneModel) {
|
||||||
|
|
||||||
Document target = ((InsertOneModel<Document>) it.getModel()).getDocument();
|
Document target = ((InsertOneModel<Document>) holder.getModel()).getDocument();
|
||||||
maybeEmitEvent(new AfterSaveEvent<>(it.getSource(), target, collectionName));
|
maybeEmitEvent(new AfterSaveEvent<>(holder.getSource(), target, collectionName));
|
||||||
} else if (it.getModel() instanceof ReplaceOneModel) {
|
} else if (holder.getModel() instanceof ReplaceOneModel) {
|
||||||
|
|
||||||
Document target = ((ReplaceOneModel<Document>) it.getModel()).getReplacement();
|
Document target = ((ReplaceOneModel<Document>) holder.getModel()).getReplacement();
|
||||||
maybeEmitEvent(new AfterSaveEvent<>(it.getSource(), target, collectionName));
|
maybeEmitEvent(new AfterSaveEvent<>(holder.getSource(), target, collectionName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void maybeInvokeAfterSaveCallback(SourceAwareWriteModelHolder holder) {
|
||||||
|
|
||||||
|
if (holder.getModel() instanceof InsertOneModel) {
|
||||||
|
|
||||||
|
Document target = ((InsertOneModel<Document>) holder.getModel()).getDocument();
|
||||||
|
maybeInvokeAfterSaveCallback(holder.getSource(), target);
|
||||||
|
} else if (holder.getModel() instanceof ReplaceOneModel) {
|
||||||
|
|
||||||
|
Document target = ((ReplaceOneModel<Document>) holder.getModel()).getReplacement();
|
||||||
|
maybeInvokeAfterSaveCallback(holder.getSource(), target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <E extends MongoMappingEvent<T>, T> E maybeEmitEvent(E event) {
|
private <E extends MongoMappingEvent<T>, T> E maybeEmitEvent(E event) {
|
||||||
|
|
||||||
if (null != bulkOperationContext.getEventPublisher()) {
|
if (bulkOperationContext.getEventPublisher() == null) {
|
||||||
bulkOperationContext.getEventPublisher().publishEvent(event);
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bulkOperationContext.getEventPublisher().publishEvent(event);
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,6 +492,16 @@ class DefaultBulkOperations implements BulkOperations {
|
|||||||
collectionName);
|
collectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object maybeInvokeAfterSaveCallback(Object value, Document mappedDocument) {
|
||||||
|
|
||||||
|
if (bulkOperationContext.getEntityCallbacks() == null) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bulkOperationContext.getEntityCallbacks().callback(AfterSaveCallback.class, value, mappedDocument,
|
||||||
|
collectionName);
|
||||||
|
}
|
||||||
|
|
||||||
private static BulkWriteOptions getBulkWriteOptions(BulkMode bulkMode) {
|
private static BulkWriteOptions getBulkWriteOptions(BulkMode bulkMode) {
|
||||||
|
|
||||||
BulkWriteOptions options = new BulkWriteOptions();
|
BulkWriteOptions options = new BulkWriteOptions();
|
||||||
@@ -489,6 +516,29 @@ class DefaultBulkOperations implements BulkOperations {
|
|||||||
throw new IllegalStateException("BulkMode was null!");
|
throw new IllegalStateException("BulkMode was null!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param filterQuery The {@link Query} to read a potential {@link Collation} from. Must not be {@literal null}.
|
||||||
|
* @param update The {@link Update} to apply
|
||||||
|
* @param upsert flag to indicate if document should be upserted.
|
||||||
|
* @return new instance of {@link UpdateOptions}.
|
||||||
|
*/
|
||||||
|
private static UpdateOptions computeUpdateOptions(Query filterQuery, UpdateDefinition update, boolean upsert) {
|
||||||
|
|
||||||
|
UpdateOptions options = new UpdateOptions();
|
||||||
|
options.upsert(upsert);
|
||||||
|
|
||||||
|
if (update.hasArrayFilters()) {
|
||||||
|
List<Document> list = new ArrayList<>(update.getArrayFilters().size());
|
||||||
|
for (ArrayFilter arrayFilter : update.getArrayFilters()) {
|
||||||
|
list.add(arrayFilter.asDocument());
|
||||||
|
}
|
||||||
|
options.arrayFilters(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
filterQuery.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link BulkOperationContext} holds information about
|
* {@link BulkOperationContext} holds information about
|
||||||
* {@link org.springframework.data.mongodb.core.BulkOperations.BulkMode} the entity in use as well as references to
|
* {@link org.springframework.data.mongodb.core.BulkOperations.BulkMode} the entity in use as well as references to
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2019 the original author or authors.
|
* Copyright 2011-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||||
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
||||||
import org.springframework.data.mongodb.core.index.IndexDefinition;
|
import org.springframework.data.mongodb.core.index.IndexDefinition;
|
||||||
import org.springframework.data.mongodb.core.index.IndexInfo;
|
import org.springframework.data.mongodb.core.index.IndexInfo;
|
||||||
@@ -64,7 +64,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
|||||||
* {@link DefaultIndexOperations#DefaultIndexOperations(MongoOperations, String, Class)}.
|
* {@link DefaultIndexOperations#DefaultIndexOperations(MongoOperations, String, Class)}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DefaultIndexOperations(MongoDbFactory mongoDbFactory, String collectionName, QueryMapper queryMapper) {
|
public DefaultIndexOperations(MongoDatabaseFactory mongoDbFactory, String collectionName, QueryMapper queryMapper) {
|
||||||
this(mongoDbFactory, collectionName, queryMapper, null);
|
this(mongoDbFactory, collectionName, queryMapper, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
|||||||
* {@link DefaultIndexOperations#DefaultIndexOperations(MongoOperations, String, Class)}.
|
* {@link DefaultIndexOperations#DefaultIndexOperations(MongoOperations, String, Class)}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DefaultIndexOperations(MongoDbFactory mongoDbFactory, String collectionName, QueryMapper queryMapper,
|
public DefaultIndexOperations(MongoDatabaseFactory mongoDbFactory, String collectionName, QueryMapper queryMapper,
|
||||||
@Nullable Class<?> type) {
|
@Nullable Class<?> type) {
|
||||||
|
|
||||||
Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null!");
|
Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null!");
|
||||||
@@ -127,7 +127,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
|||||||
indexOptions = addPartialFilterIfPresent(indexOptions, indexDefinition.getIndexOptions(), entity);
|
indexOptions = addPartialFilterIfPresent(indexOptions, indexDefinition.getIndexOptions(), entity);
|
||||||
indexOptions = addDefaultCollationIfRequired(indexOptions, entity);
|
indexOptions = addDefaultCollationIfRequired(indexOptions, entity);
|
||||||
|
|
||||||
Document mappedKeys = mapper.getMappedObject(indexDefinition.getIndexKeys(), entity);
|
Document mappedKeys = mapper.getMappedSort(indexDefinition.getIndexKeys(), entity);
|
||||||
return collection.createIndex(mappedKeys, indexOptions);
|
return collection.createIndex(mappedKeys, indexOptions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
|||||||
|
|
||||||
Assert.isInstanceOf(Document.class, sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY));
|
Assert.isInstanceOf(Document.class, sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY));
|
||||||
return ops.partialFilterExpression(
|
return ops.partialFilterExpression(
|
||||||
mapper.getMappedObject((Document) sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY), entity));
|
mapper.getMappedSort((Document) sourceOptions.get(PARTIAL_FILTER_EXPRESSION_KEY), entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
|
private static IndexOptions addDefaultCollationIfRequired(IndexOptions ops, MongoPersistentEntity<?> entity) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2019 the original author or authors.
|
* Copyright 2016-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,13 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.core;
|
package org.springframework.data.mongodb.core;
|
||||||
|
|
||||||
import org.springframework.data.mongodb.MongoDbFactory;
|
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||||
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
import org.springframework.data.mongodb.core.convert.QueryMapper;
|
||||||
import org.springframework.data.mongodb.core.index.IndexOperations;
|
import org.springframework.data.mongodb.core.index.IndexOperations;
|
||||||
import org.springframework.data.mongodb.core.index.IndexOperationsProvider;
|
import org.springframework.data.mongodb.core.index.IndexOperationsProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link IndexOperationsProvider} to obtain {@link IndexOperations} from a given {@link MongoDbFactory}.
|
* {@link IndexOperationsProvider} to obtain {@link IndexOperations} from a given {@link MongoDatabaseFactory}.
|
||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
@@ -29,14 +29,14 @@ import org.springframework.data.mongodb.core.index.IndexOperationsProvider;
|
|||||||
*/
|
*/
|
||||||
class DefaultIndexOperationsProvider implements IndexOperationsProvider {
|
class DefaultIndexOperationsProvider implements IndexOperationsProvider {
|
||||||
|
|
||||||
private final MongoDbFactory mongoDbFactory;
|
private final MongoDatabaseFactory mongoDbFactory;
|
||||||
private final QueryMapper mapper;
|
private final QueryMapper mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mongoDbFactory must not be {@literal null}.
|
* @param mongoDbFactory must not be {@literal null}.
|
||||||
* @param mapper must not be {@literal null}.
|
* @param mapper must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
DefaultIndexOperationsProvider(MongoDbFactory mongoDbFactory, QueryMapper mapper) {
|
DefaultIndexOperationsProvider(MongoDatabaseFactory mongoDbFactory, QueryMapper mapper) {
|
||||||
|
|
||||||
this.mongoDbFactory = mongoDbFactory;
|
this.mongoDbFactory = mongoDbFactory;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2019 the original author or authors.
|
* Copyright 2016-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2019 the original author or authors.
|
* Copyright 2014-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,7 +23,7 @@ import com.mongodb.MongoException;
|
|||||||
/**
|
/**
|
||||||
* An interface used by {@link MongoTemplate} for processing documents returned from a MongoDB query on a per-document
|
* An interface used by {@link MongoTemplate} for processing documents returned from a MongoDB query on a per-document
|
||||||
* basis. Implementations of this interface perform the actual work of prcoessing each document but don't need to worry
|
* basis. Implementations of this interface perform the actual work of prcoessing each document but don't need to worry
|
||||||
* about exception handling. {@MongoException}s will be caught and translated by the calling MongoTemplate An
|
* about exception handling. {@link MongoException}s will be caught and translated by the calling MongoTemplate An
|
||||||
* DocumentCallbackHandler is typically stateful: It keeps the result state within the object, to be available later for
|
* DocumentCallbackHandler is typically stateful: It keeps the result state within the object, to be available later for
|
||||||
* later inspection.
|
* later inspection.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -66,7 +66,7 @@ class EntityOperations {
|
|||||||
* Creates a new {@link Entity} for the given bean.
|
* Creates a new {@link Entity} for the given bean.
|
||||||
*
|
*
|
||||||
* @param entity must not be {@literal null}.
|
* @param entity must not be {@literal null}.
|
||||||
* @return
|
* @return new instance of {@link Entity}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public <T> Entity<T> forEntity(T entity) {
|
public <T> Entity<T> forEntity(T entity) {
|
||||||
@@ -89,7 +89,7 @@ class EntityOperations {
|
|||||||
*
|
*
|
||||||
* @param entity must not be {@literal null}.
|
* @param entity must not be {@literal null}.
|
||||||
* @param conversionService must not be {@literal null}.
|
* @param conversionService must not be {@literal null}.
|
||||||
* @return
|
* @return new instance of {@link AdaptibleEntity}.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public <T> AdaptibleEntity<T> forEntity(T entity, ConversionService conversionService) {
|
public <T> AdaptibleEntity<T> forEntity(T entity, ConversionService conversionService) {
|
||||||
@@ -108,6 +108,10 @@ class EntityOperations {
|
|||||||
return AdaptibleMappedEntity.of(entity, context, conversionService);
|
return AdaptibleMappedEntity.of(entity, context, conversionService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param entityClass should not be null.
|
||||||
|
* @return the {@link MongoPersistentEntity#getCollection() collection name}.
|
||||||
|
*/
|
||||||
public String determineCollectionName(@Nullable Class<?> entityClass) {
|
public String determineCollectionName(@Nullable Class<?> entityClass) {
|
||||||
|
|
||||||
if (entityClass == null) {
|
if (entityClass == null) {
|
||||||
@@ -138,7 +142,7 @@ class EntityOperations {
|
|||||||
* {@code _id} if no identifier property can be found.
|
* {@code _id} if no identifier property can be found.
|
||||||
*
|
*
|
||||||
* @param type must not be {@literal null}.
|
* @param type must not be {@literal null}.
|
||||||
* @return
|
* @return never {@literal null}.
|
||||||
*/
|
*/
|
||||||
public String getIdPropertyName(Class<?> type) {
|
public String getIdPropertyName(Class<?> type) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -88,9 +88,9 @@ public interface ExecutableAggregationOperation {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply pipeline operations as specified and stream all matching elements. <br />
|
* Apply pipeline operations as specified and stream all matching elements. <br />
|
||||||
* Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.Cursor}
|
* Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable}
|
||||||
*
|
*
|
||||||
* @return a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.Cursor} that needs to be closed.
|
* @return a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed.
|
||||||
* Never {@literal null}.
|
* Never {@literal null}.
|
||||||
*/
|
*/
|
||||||
CloseableIterator<T> stream();
|
CloseableIterator<T> stream();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.data.geo.GeoResults;
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
|
||||||
import org.springframework.data.mongodb.core.query.NearQuery;
|
import org.springframework.data.mongodb.core.query.NearQuery;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
@@ -43,7 +44,7 @@ import com.mongodb.client.MongoCollection;
|
|||||||
* query(Human.class)
|
* query(Human.class)
|
||||||
* .inCollection("star-wars")
|
* .inCollection("star-wars")
|
||||||
* .as(Jedi.class)
|
* .as(Jedi.class)
|
||||||
* .matching(query(where("firstname").is("luke")))
|
* .matching(where("firstname").is("luke"))
|
||||||
* .all();
|
* .all();
|
||||||
* </code>
|
* </code>
|
||||||
* </pre>
|
* </pre>
|
||||||
@@ -117,7 +118,7 @@ public interface ExecutableFindOperation {
|
|||||||
/**
|
/**
|
||||||
* Stream all matching elements.
|
* Stream all matching elements.
|
||||||
*
|
*
|
||||||
* @return a {@link Stream} that wraps the a Mongo DB {@link com.mongodb.Cursor} that needs to be closed. Never
|
* @return a {@link Stream} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed. Never
|
||||||
* {@literal null}.
|
* {@literal null}.
|
||||||
*/
|
*/
|
||||||
Stream<T> stream();
|
Stream<T> stream();
|
||||||
@@ -170,6 +171,18 @@ public interface ExecutableFindOperation {
|
|||||||
*/
|
*/
|
||||||
TerminatingFind<T> matching(Query query);
|
TerminatingFind<T> matching(Query query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||||
|
*
|
||||||
|
* @param criteria must not be {@literal null}.
|
||||||
|
* @return new instance of {@link TerminatingFind}.
|
||||||
|
* @throws IllegalArgumentException if criteria is {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
default TerminatingFind<T> matching(CriteriaDefinition criteria) {
|
||||||
|
return matching(Query.query(criteria));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the filter query for the geoNear execution.
|
* Set the filter query for the geoNear execution.
|
||||||
*
|
*
|
||||||
@@ -291,9 +304,21 @@ public interface ExecutableFindOperation {
|
|||||||
*
|
*
|
||||||
* @param query must not be {@literal null}.
|
* @param query must not be {@literal null}.
|
||||||
* @return new instance of {@link TerminatingDistinct}.
|
* @return new instance of {@link TerminatingDistinct}.
|
||||||
* @throws IllegalArgumentException if resultType is {@literal null}.
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
*/
|
*/
|
||||||
TerminatingDistinct<T> matching(Query query);
|
TerminatingDistinct<T> matching(Query query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||||
|
*
|
||||||
|
* @param criteria must not be {@literal null}.
|
||||||
|
* @return new instance of {@link TerminatingDistinct}.
|
||||||
|
* @throws IllegalArgumentException if criteria is {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
default TerminatingDistinct<T> matching(CriteriaDefinition criteria) {
|
||||||
|
return matching(Query.query(criteria));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.core;
|
package org.springframework.data.mongodb.core;
|
||||||
|
|
||||||
|
import com.mongodb.ReadPreference;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -256,9 +257,9 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
|||||||
* @see org.springframework.data.mongodb.core.CursorPreparer#prepare(com.mongodb.clientFindIterable)
|
* @see org.springframework.data.mongodb.core.CursorPreparer#prepare(com.mongodb.clientFindIterable)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FindIterable<Document> prepare(FindIterable<Document> cursor) {
|
public FindIterable<Document> prepare(FindIterable<Document> iterable) {
|
||||||
|
|
||||||
FindIterable<Document> target = delegate != null ? delegate.prepare(cursor) : cursor;
|
FindIterable<Document> target = delegate != null ? delegate.prepare(iterable) : iterable;
|
||||||
return limit.map(target::limit).orElse(target);
|
return limit.map(target::limit).orElse(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,6 +268,11 @@ class ExecutableFindOperationSupport implements ExecutableFindOperation {
|
|||||||
this.limit = Optional.of(limit);
|
this.limit = Optional.of(limit);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReadPreference getReadPreference() {
|
||||||
|
return delegate.getReadPreference();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,6 +19,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.springframework.data.mongodb.core.ExecutableFindOperation.ExecutableFind;
|
import org.springframework.data.mongodb.core.ExecutableFindOperation.ExecutableFind;
|
||||||
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
|
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
|
||||||
|
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +45,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Mark Paluch
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
public interface ExecutableMapReduceOperation {
|
public interface ExecutableMapReduceOperation {
|
||||||
@@ -146,6 +148,18 @@ public interface ExecutableMapReduceOperation {
|
|||||||
* @throws IllegalArgumentException if query is {@literal null}.
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
*/
|
*/
|
||||||
TerminatingMapReduce<T> matching(Query query);
|
TerminatingMapReduce<T> matching(Query query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||||
|
*
|
||||||
|
* @param criteria must not be {@literal null}.
|
||||||
|
* @return new instance of {@link TerminatingMapReduce}.
|
||||||
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
default TerminatingMapReduce<T> matching(CriteriaDefinition criteria) {
|
||||||
|
return matching(Query.query(criteria));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.core;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
|
||||||
import com.mongodb.client.result.DeleteResult;
|
import com.mongodb.client.result.DeleteResult;
|
||||||
@@ -119,6 +120,18 @@ public interface ExecutableRemoveOperation {
|
|||||||
* @throws IllegalArgumentException if query is {@literal null}.
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
*/
|
*/
|
||||||
TerminatingRemove<T> matching(Query query);
|
TerminatingRemove<T> matching(Query query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||||
|
*
|
||||||
|
* @param criteria must not be {@literal null}.
|
||||||
|
* @return new instance of {@link TerminatingRemove}.
|
||||||
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
default TerminatingRemove<T> matching(CriteriaDefinition criteria) {
|
||||||
|
return matching(Query.query(criteria));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,8 +17,11 @@ package org.springframework.data.mongodb.core;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.data.mongodb.core.aggregation.AggregationUpdate;
|
||||||
|
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
|
||||||
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.core.query.Update;
|
||||||
|
import org.springframework.data.mongodb.core.query.UpdateDefinition;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
import com.mongodb.client.result.UpdateResult;
|
import com.mongodb.client.result.UpdateResult;
|
||||||
@@ -151,13 +154,16 @@ public interface ExecutableUpdateOperation {
|
|||||||
interface UpdateWithUpdate<T> {
|
interface UpdateWithUpdate<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@link Update} to be applied.
|
* Set the {@link UpdateDefinition} to be applied.
|
||||||
*
|
*
|
||||||
* @param update must not be {@literal null}.
|
* @param update must not be {@literal null}.
|
||||||
* @return new instance of {@link TerminatingUpdate}.
|
* @return new instance of {@link TerminatingUpdate}.
|
||||||
* @throws IllegalArgumentException if update is {@literal null}.
|
* @throws IllegalArgumentException if update is {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
* @see Update
|
||||||
|
* @see AggregationUpdate
|
||||||
*/
|
*/
|
||||||
TerminatingUpdate<T> apply(Update update);
|
TerminatingUpdate<T> apply(UpdateDefinition update);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify {@code replacement} object.
|
* Specify {@code replacement} object.
|
||||||
@@ -205,6 +211,18 @@ public interface ExecutableUpdateOperation {
|
|||||||
* @throws IllegalArgumentException if query is {@literal null}.
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
*/
|
*/
|
||||||
UpdateWithUpdate<T> matching(Query query);
|
UpdateWithUpdate<T> matching(Query query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filter {@link CriteriaDefinition criteria} to be used.
|
||||||
|
*
|
||||||
|
* @param criteria must not be {@literal null}.
|
||||||
|
* @return new instance of {@link UpdateWithUpdate}.
|
||||||
|
* @throws IllegalArgumentException if query is {@literal null}.
|
||||||
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
default UpdateWithUpdate<T> matching(CriteriaDefinition criteria) {
|
||||||
|
return matching(Query.query(criteria));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.experimental.FieldDefaults;
|
import lombok.experimental.FieldDefaults;
|
||||||
|
|
||||||
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.core.query.UpdateDefinition;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -67,7 +67,7 @@ class ExecutableUpdateOperationSupport implements ExecutableUpdateOperation {
|
|||||||
@NonNull MongoTemplate template;
|
@NonNull MongoTemplate template;
|
||||||
@NonNull Class domainType;
|
@NonNull Class domainType;
|
||||||
Query query;
|
Query query;
|
||||||
@Nullable Update update;
|
@Nullable UpdateDefinition update;
|
||||||
@Nullable String collection;
|
@Nullable String collection;
|
||||||
@Nullable FindAndModifyOptions findAndModifyOptions;
|
@Nullable FindAndModifyOptions findAndModifyOptions;
|
||||||
@Nullable FindAndReplaceOptions findAndReplaceOptions;
|
@Nullable FindAndReplaceOptions findAndReplaceOptions;
|
||||||
@@ -76,10 +76,10 @@ class ExecutableUpdateOperationSupport implements ExecutableUpdateOperation {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.mongodb.core.ExecutableUpdateOperation.UpdateWithUpdate#apply(Update)
|
* @see org.springframework.data.mongodb.core.ExecutableUpdateOperation.UpdateWithUpdate#apply(org.springframework.data.mongodb.core.query.UpdateDefinition)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TerminatingUpdate<T> apply(Update update) {
|
public TerminatingUpdate<T> apply(UpdateDefinition update) {
|
||||||
|
|
||||||
Assert.notNull(update, "Update must not be null!");
|
Assert.notNull(update, "Update must not be null!");
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 the original author or authors.
|
* Copyright 2010-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -78,7 +78,7 @@ public class FindAndModifyOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new {@link FindAndModifyOptions} based on option of given {@litearl source}.
|
* Create new {@link FindAndModifyOptions} based on option of given {@literal source}.
|
||||||
*
|
*
|
||||||
* @param source can be {@literal null}.
|
* @param source can be {@literal null}.
|
||||||
* @return new instance of {@link FindAndModifyOptions}.
|
* @return new instance of {@link FindAndModifyOptions}.
|
||||||
@@ -117,8 +117,8 @@ public class FindAndModifyOptions {
|
|||||||
/**
|
/**
|
||||||
* Define the {@link Collation} specifying language-specific rules for string comparison.
|
* Define the {@link Collation} specifying language-specific rules for string comparison.
|
||||||
*
|
*
|
||||||
* @param collation
|
* @param collation can be {@literal null}.
|
||||||
* @return
|
* @return this.
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public FindAndModifyOptions collation(@Nullable Collation collation) {
|
public FindAndModifyOptions collation(@Nullable Collation collation) {
|
||||||
@@ -142,7 +142,7 @@ public class FindAndModifyOptions {
|
|||||||
/**
|
/**
|
||||||
* Get the {@link Collation} specifying language-specific rules for string comparison.
|
* Get the {@link Collation} specifying language-specific rules for string comparison.
|
||||||
*
|
*
|
||||||
* @return
|
* @return never {@literal null}.
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public Optional<Collation> getCollation() {
|
public Optional<Collation> getCollation() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018-2019 the original author or authors.
|
* Copyright 2018-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -116,7 +116,7 @@ public class FindAndReplaceOptions {
|
|||||||
/**
|
/**
|
||||||
* Get the bit indicating to return the replacement document.
|
* Get the bit indicating to return the replacement document.
|
||||||
*
|
*
|
||||||
* @return
|
* @return {@literal true} if set.
|
||||||
*/
|
*/
|
||||||
public boolean isReturnNew() {
|
public boolean isReturnNew() {
|
||||||
return returnNew;
|
return returnNew;
|
||||||
@@ -125,7 +125,7 @@ public class FindAndReplaceOptions {
|
|||||||
/**
|
/**
|
||||||
* Get the bit indicating if to create a new document if not exists.
|
* Get the bit indicating if to create a new document if not exists.
|
||||||
*
|
*
|
||||||
* @return
|
* @return {@literal true} if set.
|
||||||
*/
|
*/
|
||||||
public boolean isUpsert() {
|
public boolean isUpsert() {
|
||||||
return upsert;
|
return upsert;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2019 the original author or authors.
|
* Copyright 2016-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,19 +15,69 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.mongodb.core;
|
package org.springframework.data.mongodb.core;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import com.mongodb.ReadPreference;
|
||||||
import com.mongodb.reactivestreams.client.FindPublisher;
|
import com.mongodb.reactivestreams.client.FindPublisher;
|
||||||
|
import com.mongodb.reactivestreams.client.MongoCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple callback interface to allow customization of a {@link FindPublisher}.
|
* Simple callback interface to allow customization of a {@link FindPublisher}.
|
||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @author Konstantin Volivach
|
||||||
*/
|
*/
|
||||||
interface FindPublisherPreparer {
|
public interface FindPublisherPreparer extends ReadPreferenceAware {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default {@link FindPublisherPreparer} just passing on the given {@link FindPublisher}.
|
||||||
|
*
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
FindPublisherPreparer NO_OP_PREPARER = (findPublisher -> findPublisher);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the given cursor (apply limits, skips and so on). Returns the prepared cursor.
|
* Prepare the given cursor (apply limits, skips and so on). Returns the prepared cursor.
|
||||||
*
|
*
|
||||||
* @param findPublisher must not be {@literal null}.
|
* @param findPublisher must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
<T> FindPublisher<T> prepare(FindPublisher<T> findPublisher);
|
FindPublisher<Document> prepare(FindPublisher<Document> findPublisher);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply query specific settings to {@link MongoCollection} and initate a find operation returning a
|
||||||
|
* {@link FindPublisher} via the given {@link Function find} function.
|
||||||
|
*
|
||||||
|
* @param collection must not be {@literal null}.
|
||||||
|
* @param find must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @throws IllegalArgumentException if one of the required arguments is {@literal null}.
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
default FindPublisher<Document> initiateFind(MongoCollection<Document> collection,
|
||||||
|
Function<MongoCollection<Document>, FindPublisher<Document>> find) {
|
||||||
|
|
||||||
|
Assert.notNull(collection, "Collection must not be null!");
|
||||||
|
Assert.notNull(find, "Find function must not be null!");
|
||||||
|
|
||||||
|
if (hasReadPreference()) {
|
||||||
|
collection = collection.withReadPreference(getReadPreference());
|
||||||
|
}
|
||||||
|
|
||||||
|
return prepare(find.apply(collection));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the {@link ReadPreference} to apply or {@literal null} if none defined.
|
||||||
|
* @since 2.2
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
default ReadPreference getReadPreference() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user