Skip to content

Commit b4a93d7

Browse files
committed
Support for @transactional for blocking and reactive Transactionmanager.
Closes 1145.
1 parent 3cc9af0 commit b4a93d7

File tree

116 files changed

+10065
-679
lines changed

Some content is hidden

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

116 files changed

+10065
-679
lines changed

pom.xml

+62-9
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
<couchbase>3.2.5</couchbase>
2222
<couchbase.osgi>3.2.5</couchbase.osgi>
2323
<springdata.commons>2.7.0-SNAPSHOT</springdata.commons>
24-
<java-module-name>spring.data.couchbase</java-module-name>
2524
<couchbase-transactions>1.2.2</couchbase-transactions>
25+
<java-module-name>spring.data.couchbase</java-module-name>
26+
<!--
27+
<spring.boot>2.6.0-RC1</spring.boot>
28+
-->
2629
</properties>
2730

2831
<dependencyManagement>
@@ -39,13 +42,32 @@
3942

4043
<dependencies>
4144

45+
<!--
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-web</artifactId>
49+
<version>${spring.boot}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-aop</artifactId>
54+
<version>${spring.boot}</version>
55+
</dependency>
56+
-->
57+
58+
4259
<dependency>
4360
<groupId>com.couchbase.client</groupId>
4461
<artifactId>couchbase-transactions</artifactId>
4562
<version>${couchbase-transactions}</version>
63+
<exclusions>
64+
<exclusion>
65+
<groupId>com.couchbase.client</groupId>
66+
<artifactId>java-client</artifactId>
67+
</exclusion>
68+
</exclusions>
4669
</dependency>
4770

48-
4971
<dependency>
5072
<groupId>org.springframework</groupId>
5173
<artifactId>spring-context-support</artifactId>
@@ -67,12 +89,6 @@
6789
<version>${springdata.commons}</version>
6890
</dependency>
6991

70-
<dependency>
71-
<groupId>com.couchbase.client</groupId>
72-
<artifactId>java-client</artifactId>
73-
<version>${couchbase}</version>
74-
</dependency>
75-
7692
<dependency>
7793
<groupId>org.springframework</groupId>
7894
<artifactId>spring-test</artifactId>
@@ -189,7 +205,14 @@
189205
<dependency>
190206
<groupId>com.squareup.okhttp3</groupId>
191207
<artifactId>okhttp</artifactId>
192-
<version>4.4.0</version>
208+
<version>4.8.1</version>
209+
<scope>test</scope>
210+
</dependency>
211+
212+
<dependency>
213+
<groupId>com.squareup.okhttp3</groupId>
214+
<artifactId>okhttp-tls</artifactId>
215+
<version>4.8.1</version>
193216
<scope>test</scope>
194217
</dependency>
195218

@@ -221,6 +244,36 @@
221244
<version>4.0.3</version>
222245
<scope>test</scope>
223246
</dependency>
247+
<dependency>
248+
<groupId>com.couchbase.client</groupId>
249+
<artifactId>couchbase-transactions</artifactId>
250+
<version>${couchbase-transactions}</version>
251+
<scope>compile</scope>
252+
<exclusions>
253+
<exclusion>
254+
<groupId>com.couchbase.client</groupId>
255+
<artifactId>java-client</artifactId>
256+
</exclusion>
257+
</exclusions>
258+
</dependency>
259+
<dependency>
260+
<groupId>org.testcontainers</groupId>
261+
<artifactId>testcontainers</artifactId>
262+
</dependency>
263+
264+
<dependency>
265+
<groupId>com.couchbase.client</groupId>
266+
<artifactId>java-client</artifactId>
267+
<version>3.2.5</version>
268+
</dependency>
269+
270+
<dependency>
271+
<groupId>ch.qos.logback</groupId>
272+
<artifactId>logback-classic</artifactId>
273+
<version>1.2.5</version>
274+
<scope>compile</scope>
275+
</dependency>
276+
224277

225278
</dependencies>
226279

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
import com.couchbase.client.core.annotation.Stability;
20+
import com.couchbase.transactions.config.MergedTransactionConfig;
21+
import com.couchbase.transactions.config.PerTransactionConfig;
22+
import com.couchbase.transactions.config.PerTransactionConfigBuilder;
23+
import com.couchbase.transactions.config.TransactionConfig;
24+
import com.couchbase.transactions.forwards.Supported;
25+
import com.couchbase.transactions.log.TransactionLogger;
26+
27+
import java.time.Duration;
28+
import java.time.temporal.ChronoUnit;
29+
import java.util.Optional;
30+
import java.util.UUID;
31+
32+
/**
33+
* To access the AttemptContextReactive held by AttemptContext
34+
*
35+
* @author Michael Reiche
36+
*/
37+
public class AttemptContextReactiveAccessor {
38+
39+
public static AttemptContextReactive getACR(AttemptContext attemptContext) {
40+
return attemptContext.ctx();
41+
}
42+
43+
public static AttemptContext from(AttemptContextReactive attemptContextReactive) {
44+
return new AttemptContext(attemptContextReactive);
45+
}
46+
47+
public static TransactionLogger getLogger(AttemptContextReactive attemptContextReactive){
48+
return attemptContextReactive.LOGGER;
49+
}
50+
@Stability.Internal
51+
public static AttemptContextReactive newAttemptContextReactive(TransactionsReactive transactions){
52+
PerTransactionConfig perConfig = PerTransactionConfigBuilder.create().build();
53+
MergedTransactionConfig merged = new MergedTransactionConfig(transactions.config(), Optional.of(perConfig));
54+
55+
TransactionContext overall = new TransactionContext(
56+
transactions.cleanup().clusterData().cluster().environment().requestTracer(),
57+
transactions.cleanup().clusterData().cluster().environment().eventBus(),
58+
UUID.randomUUID().toString(), now(), Duration.ZERO, merged);
59+
60+
String txnId = UUID.randomUUID().toString();
61+
overall.LOGGER.info(configDebug(transactions.config(), perConfig));
62+
return transactions.createAttemptContext(overall, merged, txnId);
63+
}
64+
65+
private static Duration now() {
66+
return Duration.of(System.nanoTime(), ChronoUnit.NANOS);
67+
}
68+
69+
static private String configDebug(TransactionConfig config, PerTransactionConfig perConfig) {
70+
StringBuilder sb = new StringBuilder();
71+
sb.append("library version: ");
72+
sb.append(TransactionsReactive.class.getPackage().getImplementationVersion());
73+
sb.append(" config: ");
74+
sb.append("atrs=");
75+
sb.append(config.numAtrs());
76+
sb.append(", metadataCollection=");
77+
sb.append(config.metadataCollection());
78+
sb.append(", expiry=");
79+
sb.append(perConfig.expirationTime().orElse(config.transactionExpirationTime()).toMillis());
80+
sb.append("msecs durability=");
81+
sb.append(config.durabilityLevel());
82+
sb.append(" per-txn config=");
83+
sb.append(" durability=");
84+
sb.append(perConfig.durabilityLevel());
85+
sb.append(", supported=");
86+
sb.append(Supported.SUPPORTED);
87+
return sb.toString();
88+
}
89+
90+
}

0 commit comments

Comments
 (0)