Skip to content

Commit fa8ee88

Browse files
committed
Merge branch 'main' of github.com:spring-projects/spring-data-couchbase into datacouch_1145_transaction_support
2 parents 778b10e + d9327ce commit fa8ee88

File tree

142 files changed

+3331
-1295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+3331
-1295
lines changed

.mvn/wrapper/maven-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Fri Sep 10 15:38:05 CEST 2021
2-
distributionUrl=https\://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
1+
#Tue Feb 22 13:59:13 CET 2022
2+
distributionUrl=https\://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip

Jenkinsfile

+26-49
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
def p = [:]
2+
node {
3+
checkout scm
4+
p = readProperties interpolate: true, file: 'ci/pipeline.properties'
5+
}
6+
17
pipeline {
28
agent none
39

@@ -12,7 +18,7 @@ pipeline {
1218
}
1319

1420
stages {
15-
stage("test: baseline (jdk8)") {
21+
stage("test: baseline (main)") {
1622
when {
1723
anyOf {
1824
branch 'main'
@@ -25,14 +31,14 @@ pipeline {
2531
options { timeout(time: 30, unit: 'MINUTES') }
2632

2733
environment {
28-
DOCKER_HUB = credentials('hub.docker.com-springbuildmaster')
29-
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
34+
DOCKER_HUB = credentials("${p['docker.credentials']}")
35+
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
3036
}
3137

3238
steps {
3339
script {
34-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
35-
docker.image('adoptopenjdk/openjdk8:latest').inside('-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v $HOME:/tmp/jenkins-home') {
40+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
41+
docker.image(p['docker.java.main.image']).inside(p['docker.java.inside.docker']) {
3642
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
3743
sh 'PROFILE=ci ci/test.sh'
3844
sh "ci/clean.sh"
@@ -50,47 +56,47 @@ pipeline {
5056
}
5157
}
5258
parallel {
53-
stage("test: baseline (jdk11)") {
59+
stage("test: baseline (next)") {
5460
agent {
5561
label 'data'
5662
}
5763
options { timeout(time: 30, unit: 'MINUTES') }
5864

5965
environment {
60-
DOCKER_HUB = credentials('hub.docker.com-springbuildmaster')
61-
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
66+
DOCKER_HUB = credentials("${p['docker.credentials']}")
67+
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
6268
}
6369

6470
steps {
6571
script {
66-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
67-
docker.image('adoptopenjdk/openjdk11:latest').inside('-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v $HOME:/tmp/jenkins-home') {
72+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
73+
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
6874
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
69-
sh 'PROFILE=ci,java11 ci/test.sh'
75+
sh 'PROFILE=ci ci/test.sh'
7076
sh "ci/clean.sh"
7177
}
7278
}
7379
}
7480
}
7581
}
7682

77-
stage("test: baseline (jdk16)") {
83+
stage("test: baseline (LTS)") {
7884
agent {
7985
label 'data'
8086
}
8187
options { timeout(time: 30, unit: 'MINUTES') }
8288

8389
environment {
84-
DOCKER_HUB = credentials('hub.docker.com-springbuildmaster')
85-
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
90+
DOCKER_HUB = credentials("${p['docker.credentials']}")
91+
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
8692
}
8793

8894
steps {
8995
script {
90-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
91-
docker.image('adoptopenjdk/openjdk16:latest').inside('-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v $HOME:/tmp/jenkins-home') {
96+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
97+
docker.image(p['docker.java.lts.image']).inside(p['docker.java.inside.docker']) {
9298
sh "docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}"
93-
sh 'PROFILE=ci,java11 ci/test.sh'
99+
sh 'PROFILE=ci ci/test.sh'
94100
sh "ci/clean.sh"
95101
}
96102
}
@@ -113,13 +119,13 @@ pipeline {
113119
options { timeout(time: 20, unit: 'MINUTES') }
114120

115121
environment {
116-
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
122+
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
117123
}
118124

119125
steps {
120126
script {
121-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
122-
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
127+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
128+
docker.image(p['docker.java.lts.image']).inside(p['docker.java.inside.basic']) {
123129
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pci,artifactory -Dmaven.repo.local=/tmp/jenkins-home/.m2/spring-data-couchbase-non-root ' +
124130
'-Dartifactory.server=https://repo.spring.io ' +
125131
"-Dartifactory.username=${ARTIFACTORY_USR} " +
@@ -133,35 +139,6 @@ pipeline {
133139
}
134140
}
135141
}
136-
137-
stage('Publish documentation') {
138-
when {
139-
branch 'main'
140-
}
141-
agent {
142-
label 'data'
143-
}
144-
options { timeout(time: 20, unit: 'MINUTES') }
145-
146-
environment {
147-
ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c')
148-
}
149-
150-
steps {
151-
script {
152-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
153-
docker.image('adoptopenjdk/openjdk8:latest').inside('-v $HOME:/tmp/jenkins-home') {
154-
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -s settings.xml -Pci,distribute -Dmaven.repo.local=/tmp/jenkins-home/.m2/spring-data-couchbase-non-root ' +
155-
'-Dartifactory.server=https://repo.spring.io ' +
156-
"-Dartifactory.username=${ARTIFACTORY_USR} " +
157-
"-Dartifactory.password=${ARTIFACTORY_PSW} " +
158-
"-Dartifactory.distribution-repository=temp-private-local " +
159-
'-Dmaven.test.skip=true clean deploy -U -B'
160-
}
161-
}
162-
}
163-
}
164-
}
165142
}
166143

167144
post {

ci/pipeline.properties

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Java versions
2+
java.main.tag=8u322-b06-jdk
3+
java.next.tag=11.0.14.1_1-jdk
4+
java.lts.tag=17.0.2_8-jdk
5+
6+
# Docker container images - standard
7+
docker.java.main.image=harbor-repo.vmware.com/dockerhub-proxy-cache/library/eclipse-temurin:${java.main.tag}
8+
docker.java.next.image=harbor-repo.vmware.com/dockerhub-proxy-cache/library/eclipse-temurin:${java.next.tag}
9+
docker.java.lts.image=harbor-repo.vmware.com/dockerhub-proxy-cache/library/eclipse-temurin:${java.lts.tag}
10+
11+
# Supported versions of MongoDB
12+
docker.mongodb.4.0.version=4.0.28
13+
docker.mongodb.4.4.version=4.4.12
14+
docker.mongodb.5.0.version=5.0.6
15+
16+
# Supported versions of Redis
17+
docker.redis.6.version=6.2.6
18+
19+
# Supported versions of Cassandra
20+
docker.cassandra.3.version=3.11.12
21+
22+
# Docker environment settings
23+
docker.java.inside.basic=-v $HOME:/tmp/jenkins-home
24+
docker.java.inside.docker=-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v $HOME:/tmp/jenkins-home
25+
26+
# Credentials
27+
docker.registry=
28+
docker.credentials=hub.docker.com-springbuildmaster
29+
artifactory.credentials=02bd1690-b54f-4c9f-819d-a77cb7a9822c

pom.xml

+7-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.springframework.data</groupId>
77
<artifactId>spring-data-couchbase</artifactId>
8-
<version>4.3.0-SNAPSHOT</version>
8+
<version>4.4.0-SNAPSHOT</version>
99

1010
<name>Spring Data Couchbase</name>
1111
<description>Spring Data integration for Couchbase</description>
@@ -14,16 +14,16 @@
1414
<parent>
1515
<groupId>org.springframework.data.build</groupId>
1616
<artifactId>spring-data-parent</artifactId>
17-
<version>2.6.0-RC1</version>
17+
<version>2.7.0-SNAPSHOT</version>
1818
</parent>
1919

2020
<properties>
21-
<couchbase>3.2.5-SNAPSHOT</couchbase>
22-
<couchbase.osgi>3.2.5-SNAPSHOT</couchbase.osgi>
23-
<springdata.commons>2.6.0-SNAPSHOT</springdata.commons>
24-
<couchbase-transactions>1.2.2</couchbase-transactions>
21+
<couchbase>3.2.5</couchbase>
22+
<couchbase.osgi>3.2.5</couchbase.osgi>
23+
<springdata.commons>2.7.0-SNAPSHOT</springdata.commons>
2524
<java-module-name>spring.data.couchbase</java-module-name>
26-
<spring.boot>2.6.0-RC1</spring.boot>
25+
<couchbase-transactions>1.2.2</couchbase-transactions>
26+
<spring.boot>2.7.0-SNAPSHOT</spring.boot>
2727
</properties>
2828

2929
<dependencyManagement>
@@ -266,12 +266,6 @@
266266

267267
</dependencies>
268268

269-
<!--
270-
<modules>
271-
<module>../demo</module>
272-
</modules>
273-
-->
274-
275269
<repositories>
276270
<repository>
277271
<id>spring-libs-snapshot</id>

src/main/asciidoc/caching.adoc

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[[couchbase.caching]]
2+
= Caching
3+
4+
This chapter describes additional support for caching and `@Cacheable`.
5+
6+
[[caching.usage]]
7+
== Configuration & Usage
8+
9+
Technically, caching is not part of spring-data, but is implemented directly in the spring core. Most database implementations in the spring-data package can't support `@Cacheable`, because it is not possible to store arbitrary data.
10+
11+
Couchbase supports both binary and JSON data, so you can get both out of the same database.
12+
13+
To make it work, you need to add the `@EnableCaching` annotation and configure the `cacheManager` bean:
14+
15+
.`AbstractCouchbaseConfiguration` for Caching
16+
====
17+
[source,java]
18+
----
19+
20+
@Configuration
21+
@EnableCaching
22+
public class Config extends AbstractCouchbaseConfiguration {
23+
// general methods
24+
25+
@Bean
26+
public CouchbaseCacheManager cacheManager(CouchbaseTemplate couchbaseTemplate) throws Exception {
27+
CouchbaseCacheManager.CouchbaseCacheManagerBuilder builder = CouchbaseCacheManager.CouchbaseCacheManagerBuilder
28+
.fromConnectionFactory(couchbaseTemplate.getCouchbaseClientFactory());
29+
return builder.build();
30+
}
31+
32+
----
33+
====
34+
35+
The `persistent` identifier can then be used on the `@Cacheable` annotation to identify the cache manager to use (you can have more than one configured).
36+
37+
Once it is set up, you can annotate every method with the `@Cacheable` annotation to transparently cache it in your couchbase bucket. You can also customize how the key is generated.
38+
39+
.Caching example
40+
====
41+
[source,java]
42+
----
43+
@Cacheable(value="persistent", key="'longrunsim-'+#time")
44+
public String simulateLongRun(long time) {
45+
try {
46+
Thread.sleep(time);
47+
} catch(Exception ex) {
48+
System.out.println("This shouldnt happen...");
49+
}
50+
return "I've slept " + time + " miliseconds.;
51+
}
52+
----
53+
====
54+
55+
If you run the method multiple times, you'll see a set operation happening first, followed by multiple get operations and no sleep time (which fakes the expensive execution). You can store whatever you want, if it is JSON of course you can access it through views and look at it in the Web UI.
56+
57+
Note that to use cache.clear() or catch.invalidate(), the bucket must have a primary key.

src/main/asciidoc/collections.adoc

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[[couchbase.collections]]
2+
= Collection Support
3+
4+
Couchbase supports https://docs.couchbase.com/server/current/learn/data/scopes-and-collections.html[Scopes and Collections]. This section documents on how to use it with Spring Data Couchbase.
5+
6+
The https://github.com/couchbaselabs/try-cb-spring[try-cb-spring] sample application is a working example of using Scopes and Collections in Spring Data Couchbase.
7+
8+
The 2021 Couchbase Connect presentation on Collections in Spring Data can be found at https://www.youtube.com/watch?v=MrplTeEFItk[Presentation Only] and https://web.cvent.com/hub/events/1dce8283-986d-4de9-8368-94c98f60df01/sessions/9ee89a85-833c-4e0c-81b0-807864fa351b?goBackHref=%2Fevents%2F1dce8283-986d-4de9-8368-94c98f60df01%2Fsessions&goBackName=Add%2FView+Sessions&goBackTab=all[Presentation with Slide Deck]
9+
10+
== Requirements
11+
12+
- Couchbase Server 7.0 or above.
13+
- Spring Data Couchbase 4.3.1 or above.
14+
15+
== Getting Started & Configuration
16+
17+
18+
=== Scope and Collection Specification
19+
There are several mechanisms of specifying scopes and collections, and these may be combined, or one mechanism may override another.
20+
First some definitions for scopes and collections. An unspecified scope indicates that the default scope is to be used, likewise, an
21+
unspecified collection indicates that the default collection is to be used.
22+
There are only three combinations of scopes and collections that are valid. (1) the default scope and the default collection; (2) the default
23+
scope and a non-default collection; and (3) a non-default scope and a non-default collection. It is not possible to have a non-default
24+
scope and a default collection as non-default scopes do not contain a default collections, neither can one be created.
25+
26+
A scope can be specified in the configuration:
27+
[source,java]
28+
----
29+
@Configuration
30+
static class Config extends AbstractCouchbaseConfiguration {
31+
32+
// Usual Setup
33+
@Override public String getConnectionString() { /* ... */ }
34+
35+
// optionally specify the scope in the Configuration
36+
@Override
37+
protected String getScopeName() {
38+
return "myScope"; // or a variable etc.;
39+
}
40+
41+
}
42+
----
43+
Scopes and Collections can be specified as annotations on entity classes and repositories:
44+
[source,java]
45+
----
46+
@Document
47+
@Scope("travel")
48+
@Collection("airport")
49+
public class Airport {...
50+
----
51+
52+
[source,java]
53+
----
54+
@Scope("travel")
55+
@Collection("airport")
56+
public interface AirportRepository extends CouchbaseRepository<Airport, String> ...
57+
----
58+
59+
Scopes and Collections can be specified on templates using the inScope(scopeName) and inCollection(collectionName) fluent APIs:
60+
[source,java]
61+
----
62+
List<Airport> airports = template.findByQuery(Airport.class).inScope("archived").all()
63+
----
64+
65+
Scopes and Collections can be specified on repositories that extend DynamicProxyable using the withScope(scopeName) and withCollection(collectionName) APIs:
66+
[source,java]
67+
----
68+
public interface AirportRepository extends CouchbaseRepository<Airport, String>, DynamicProxyable<AirportRepository>{...}
69+
...
70+
List<Airport> airports = airportRepository.withScope("archived").findByName(iata);
71+
----
72+
73+
.The order of precedence is:
74+
. inScope()/inCollection() of the template fluent api
75+
. withScope()/withCollection() of the template/repository object
76+
. annotation of the repository method
77+
. annotation of the repository interface
78+
. annotation of the entity object
79+
. getScope() of the configuration
80+

src/main/asciidoc/index.adoc

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
= Spring Data Couchbase - Reference Documentation
2-
Michael Nitschinger, Oliver Gierke, Simon Baslé
2+
Michael Nitschinger, Oliver Gierke, Simon Baslé, Michael Reiche
33
:revnumber: {version}
44
:revdate: {localdate}
55
:spring-data-commons-docs: ../../../../spring-data-commons/src/main/asciidoc
66

7-
(C) 2014-2019 The original author(s).
7+
(C) 2014-2022 The original author(s).
88

99
NOTE: Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
1010

@@ -24,8 +24,9 @@ include::repository.adoc[]
2424
include::reactiverepository.adoc[]
2525
include::template.adoc[]
2626
include::transactions.adoc[]
27-
// (daschl) disabled the ansijoins docs since it is being overhauled for 4.x
28-
// include::ansijoins.adoc[]
27+
include::collections.adoc[]
28+
include::ansijoins.adoc[]
29+
include::caching.adoc[]
2930
:leveloffset: -1
3031

3132
[[appendix]]

0 commit comments

Comments
 (0)