Skip to content

Commit 778b10e

Browse files
committed
Support for @transactional for blocking and reactive Transactionmanager.
Closes 1145.
1 parent 1679651 commit 778b10e

File tree

102 files changed

+7934
-586
lines changed

Some content is hidden

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

102 files changed

+7934
-586
lines changed

pom.xml

+67-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
<parent>
1515
<groupId>org.springframework.data.build</groupId>
1616
<artifactId>spring-data-parent</artifactId>
17-
<version>2.6.0-SNAPSHOT</version>
17+
<version>2.6.0-RC1</version>
1818
</parent>
1919

2020
<properties>
21-
<couchbase>3.2.1</couchbase>
22-
<couchbase.osgi>3.2.1</couchbase.osgi>
21+
<couchbase>3.2.5-SNAPSHOT</couchbase>
22+
<couchbase.osgi>3.2.5-SNAPSHOT</couchbase.osgi>
2323
<springdata.commons>2.6.0-SNAPSHOT</springdata.commons>
24-
<couchbase-transactions>1.2.1</couchbase-transactions>
24+
<couchbase-transactions>1.2.2</couchbase-transactions>
2525
<java-module-name>spring.data.couchbase</java-module-name>
26+
<spring.boot>2.6.0-RC1</spring.boot>
2627
</properties>
2728

2829
<dependencyManagement>
@@ -39,13 +40,30 @@
3940

4041
<dependencies>
4142

43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-web</artifactId>
46+
<version>${spring.boot}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-aop</artifactId>
51+
<version>${spring.boot}</version>
52+
</dependency>
53+
54+
4255
<dependency>
4356
<groupId>com.couchbase.client</groupId>
4457
<artifactId>couchbase-transactions</artifactId>
4558
<version>${couchbase-transactions}</version>
59+
<exclusions>
60+
<exclusion>
61+
<groupId>com.couchbase.client</groupId>
62+
<artifactId>java-client</artifactId>
63+
</exclusion>
64+
</exclusions>
4665
</dependency>
4766

48-
4967
<dependency>
5068
<groupId>org.springframework</groupId>
5169
<artifactId>spring-context-support</artifactId>
@@ -67,12 +85,6 @@
6785
<version>${springdata.commons}</version>
6886
</dependency>
6987

70-
<dependency>
71-
<groupId>com.couchbase.client</groupId>
72-
<artifactId>java-client</artifactId>
73-
<version>${couchbase}</version>
74-
</dependency>
75-
7688
<dependency>
7789
<groupId>org.springframework</groupId>
7890
<artifactId>spring-test</artifactId>
@@ -221,9 +233,45 @@
221233
<version>4.0.3</version>
222234
<scope>test</scope>
223235
</dependency>
236+
<dependency>
237+
<groupId>com.couchbase.client</groupId>
238+
<artifactId>couchbase-transactions</artifactId>
239+
<version>${couchbase-transactions}</version>
240+
<scope>compile</scope>
241+
<exclusions>
242+
<exclusion>
243+
<groupId>com.couchbase.client</groupId>
244+
<artifactId>java-client</artifactId>
245+
</exclusion>
246+
</exclusions>
247+
</dependency>
248+
<dependency>
249+
<groupId>org.testcontainers</groupId>
250+
<artifactId>testcontainers</artifactId>
251+
</dependency>
252+
253+
<dependency>
254+
<groupId>com.couchbase.client</groupId>
255+
<artifactId>java-client</artifactId>
256+
<version>3.2.4-SNAPSHOT</version>
257+
</dependency>
258+
259+
<dependency>
260+
<groupId>ch.qos.logback</groupId>
261+
<artifactId>logback-classic</artifactId>
262+
<version>1.2.5</version>
263+
<scope>compile</scope>
264+
</dependency>
265+
224266

225267
</dependencies>
226268

269+
<!--
270+
<modules>
271+
<module>../demo</module>
272+
</modules>
273+
-->
274+
227275
<repositories>
228276
<repository>
229277
<id>spring-libs-snapshot</id>
@@ -307,6 +355,14 @@
307355
<groupId>org.asciidoctor</groupId>
308356
<artifactId>asciidoctor-maven-plugin</artifactId>
309357
</plugin>
358+
<plugin>
359+
<groupId>org.apache.maven.plugins</groupId>
360+
<artifactId>maven-compiler-plugin</artifactId>
361+
<configuration>
362+
<source>11</source>
363+
<target>11</target>
364+
</configuration>
365+
</plugin>
310366
</plugins>
311367
</build>
312368
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
/*
3+
* Copyright 2021 the original author or authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.couchbase.transactions;
18+
19+
/**
20+
* To access the AttemptContextReactive held by AttemptContext
21+
*
22+
* @author Michael Reiche
23+
*/
24+
public class AttemptContextReactiveAccessor {
25+
26+
public static AttemptContextReactive getACR(AttemptContext attemptContext) {
27+
return attemptContext.ctx();
28+
}
29+
}

src/main/java/org/springframework/data/couchbase/CouchbaseClientFactory.java

+12
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818

1919
import java.io.Closeable;
2020

21+
import com.couchbase.transactions.AttemptContextReactive;
22+
import com.couchbase.transactions.Transactions;
23+
import com.couchbase.transactions.config.TransactionConfig;
2124
import org.springframework.dao.support.PersistenceExceptionTranslator;
2225

2326
import com.couchbase.client.java.Bucket;
2427
import com.couchbase.client.java.Cluster;
2528
import com.couchbase.client.java.Collection;
2629
import com.couchbase.client.java.Scope;
30+
import org.springframework.data.couchbase.transaction.ClientSession;
31+
import org.springframework.data.couchbase.transaction.ClientSessionOptions;
32+
import org.springframework.data.couchbase.transaction.CouchbaseStuffHandle;
2733

2834
/**
2935
* The {@link CouchbaseClientFactory} is the main way to get access to the managed SDK instance and resources.
@@ -73,4 +79,10 @@ public interface CouchbaseClientFactory extends Closeable {
7379
*/
7480
PersistenceExceptionTranslator getExceptionTranslator();
7581

82+
ClientSession getSession(ClientSessionOptions options, Transactions transactions,
83+
TransactionConfig config , AttemptContextReactive atr);
84+
85+
CouchbaseClientFactory with(CouchbaseStuffHandle txOp);
86+
87+
CouchbaseStuffHandle getTransactionalOperator();
7688
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2016-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.couchbase;
17+
18+
import com.couchbase.client.java.Bucket;
19+
import com.couchbase.client.java.Cluster;
20+
import com.couchbase.client.java.ClusterInterface;
21+
import com.couchbase.client.java.Collection;
22+
import com.couchbase.client.java.Scope;
23+
import com.couchbase.transactions.AttemptContextReactive;
24+
import com.couchbase.transactions.Transactions;
25+
import com.couchbase.transactions.config.TransactionConfig;
26+
import org.springframework.data.couchbase.transaction.ClientSession;
27+
import org.springframework.data.couchbase.transaction.ClientSessionOptions;
28+
import org.springframework.data.couchbase.transaction.CouchbaseStuffHandle;
29+
import reactor.core.publisher.Mono;
30+
31+
import org.springframework.dao.support.PersistenceExceptionTranslator;
32+
33+
import java.io.IOException;
34+
35+
36+
/**
37+
* Interface for factories creating reactive {@link Cluster} instances.
38+
*
39+
* @author Mark Paluch
40+
* @author Christoph Strobl
41+
* @author Mathieu Ouellet
42+
* @since 2.0
43+
*/
44+
public interface ReactiveCouchbaseClientFactory /*extends CodecRegistryProvider*/ {
45+
46+
/**
47+
* Provides access to the managed SDK {@link Cluster} reference.
48+
*/
49+
//Cluster getCluster();
50+
51+
Mono<ClusterInterface> getCluster();
52+
53+
/**
54+
* Provides access to the managed SDK {@link Bucket} reference.
55+
*/
56+
Mono<Bucket> getBucket();
57+
58+
/**
59+
* Provides access to the managed SDK {@link Scope} reference.
60+
*/
61+
//Scope getScope();
62+
63+
Mono<Scope> getScope();
64+
65+
/**
66+
* Provides access to a collection (identified by its name) in managed SDK {@link Scope} reference.
67+
*
68+
* @param name the name of the collection. If null is passed in, the default collection is assumed.
69+
*/
70+
//Collection getCollection(String name);
71+
72+
Mono<Collection> getCollection(String name);
73+
/**
74+
* Provides access to the default collection.
75+
*/
76+
Mono<Collection> getDefaultCollection();
77+
78+
/**
79+
* Returns a new {@link CouchbaseClientFactory} set to the scope given as an argument.
80+
*
81+
* @param scopeName the name of the scope to use for all collection access.
82+
* @return a new client factory, bound to the other scope.
83+
*/
84+
ReactiveCouchbaseClientFactory withScope(String scopeName);
85+
86+
/**
87+
* The exception translator used on the factory.
88+
*/
89+
PersistenceExceptionTranslator getExceptionTranslator();
90+
91+
Mono<ClientSession> getSession(ClientSessionOptions options, Transactions transactions, TransactionConfig config);
92+
93+
String getBucketName();
94+
95+
String getScopeName();
96+
97+
void close() throws IOException;
98+
99+
Mono<ClientSession> getSession(ClientSessionOptions options);
100+
101+
ClientSession getSession(ClientSessionOptions options, Transactions transactions, TransactionConfig config,
102+
AttemptContextReactive atr);
103+
104+
/*
105+
* (non-Javadoc)
106+
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#withSession(com.mongodb.session.ClientSession)
107+
*/
108+
ReactiveCouchbaseClientFactory withSession(ClientSession session);
109+
110+
/*
111+
* (non-Javadoc)
112+
* @see org.springframework.data.mongodb.ReactiveMongoDatabaseFactory#isTransactionActive()
113+
*/
114+
boolean isTransactionActive();
115+
116+
CouchbaseStuffHandle getTransactionalOperator();
117+
118+
ReactiveCouchbaseClientFactory with(CouchbaseStuffHandle txOp);
119+
}

0 commit comments

Comments
 (0)