Skip to content

Commit 8dd5994

Browse files
committed
Update transactions documentation for native transaction support.
Closes #1454,#1512.
1 parent a40b865 commit 8dd5994

18 files changed

+280
-210
lines changed

README.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,29 @@ It can be staged and accessed via :
194194
----
195195
https://mikereiche.github.io/staged/index.html
196196

197+
=== Building and staging reference documentation for review
198+
199+
[source,bash]
200+
----
201+
export MY_GIT_USER=<github-user>
202+
mvn generate-resources
203+
docs=`pwd`/target/site/reference/html
204+
pushd /tmp
205+
mkdir $$
206+
cd $$
207+
# see https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site
208+
# this examples uses a repository named "staged"
209+
git clone [email protected]:${MY_GIT_USER}/staged.git -b gh-pages
210+
cd staged
211+
cp -R $docs/* .
212+
git add .
213+
git commit --message "stage for review"
214+
git push origin gh-pages
215+
popd
216+
----
217+
218+
The generated documentation is available from `target/site/reference/html/index.html`.
219+
197220
== Examples
198221

199222
* https://github.com/spring-projects/spring-data-examples/[Spring Data Examples] contains example projects that explain specific features in more detail.

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
5252
import org.springframework.transaction.interceptor.TransactionAttributeSource;
5353
import org.springframework.transaction.interceptor.TransactionInterceptor;
54+
import org.springframework.transaction.support.TransactionTemplate;
5455
import org.springframework.util.ClassUtils;
5556
import org.springframework.util.StringUtils;
5657

@@ -330,6 +331,16 @@ CouchbaseCallbackTransactionManager couchbaseTransactionManager(CouchbaseClientF
330331
return new CouchbaseCallbackTransactionManager(clientFactory);
331332
}
332333

334+
/**
335+
* The default transaction template manager.
336+
*
337+
* @param couchbaseTransactionManager
338+
* @return
339+
*/
340+
@Bean(BeanNames.COUCHBASE_TRANSACTION_TEMPLATE)
341+
TransactionTemplate couchbaseTransactionTemplate(CouchbaseCallbackTransactionManager couchbaseTransactionManager) {
342+
return new TransactionTemplate(couchbaseTransactionManager);
343+
}
333344
/**
334345
* The default TransactionalOperator.
335346
*

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/config/BeanNames.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@ public class BeanNames {
6464

6565
public static final String COUCHBASE_TRANSACTION_MANAGER = "couchbaseTransactionManager";
6666

67+
public static final String COUCHBASE_TRANSACTION_TEMPLATE = "couchbaseTransactionTemplate";
68+
6769
public static final String COUCHBASE_TRANSACTIONAL_OPERATOR = "couchbaseTransactionalOperator";
6870
}

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbasePersonTransactionReactiveIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void shouldRollbackAfterException() {
108108

109109
@Test
110110
public void shouldRollbackAfterExceptionOfTxAnnotatedMethod() {
111-
assertThrowsWithCause(() -> personService.declarativeSavePersonErrors(WalterWhite).blockLast(),
111+
assertThrowsWithCause(() -> personService.declarativeSavePersonErrors(WalterWhite).block(),
112112
TransactionSystemUnambiguousException.class, SimulateFailureException.class);
113113
}
114114

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalNonAllowableOperationsIntegrationTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.data.couchbase.util.ClusterType;
3737
import org.springframework.data.couchbase.util.IgnoreWhen;
3838
import org.springframework.data.couchbase.util.JavaIntegrationTests;
39-
import org.springframework.stereotype.Component;
4039
import org.springframework.stereotype.Service;
4140
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4241
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -114,9 +113,7 @@ public void upsertById() {
114113
});
115114
}
116115

117-
@Service
118-
@Component
119-
@EnableTransactionManagement
116+
@Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
120117
static class PersonService {
121118
final CouchbaseOperations personOperations;
122119

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalOptionsIntegrationTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.data.couchbase.util.ClusterType;
3737
import org.springframework.data.couchbase.util.IgnoreWhen;
3838
import org.springframework.data.couchbase.util.JavaIntegrationTests;
39-
import org.springframework.stereotype.Component;
4039
import org.springframework.stereotype.Service;
4140
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4241
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -100,9 +99,7 @@ public void supportedIsolation() {
10099
personService.supportedIsolation();
101100
}
102101

103-
@Service
104-
@Component
105-
@EnableTransactionManagement
102+
@Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
106103
static class PersonService {
107104
final CouchbaseOperations ops;
108105

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalPropagationIntegrationTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.springframework.data.couchbase.util.IgnoreWhen;
4444
import org.springframework.data.couchbase.util.JavaIntegrationTests;
4545
import org.springframework.lang.Nullable;
46-
import org.springframework.stereotype.Component;
4746
import org.springframework.stereotype.Service;
4847
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4948
import org.springframework.transaction.IllegalTransactionStateException;
@@ -285,9 +284,7 @@ public void callDefaultThatCallsDefaultRetries() {
285284
assertEquals(3, attempts.get());
286285
}
287286

288-
@Service
289-
@Component
290-
@EnableTransactionManagement
287+
@Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
291288
static class PersonService {
292289
final CouchbaseOperations ops;
293290

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalRepositoryIntegrationTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.springframework.data.couchbase.util.ClusterType;
4141
import org.springframework.data.couchbase.util.IgnoreWhen;
4242
import org.springframework.data.couchbase.util.JavaIntegrationTests;
43-
import org.springframework.stereotype.Component;
4443
import org.springframework.stereotype.Service;
4544
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4645
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -114,7 +113,6 @@ public void saveRolledBack() {
114113
String id = UUID.randomUUID().toString();
115114

116115
assertThrowsWithCause(() -> {
117-
;
118116
userService.run(repo -> {
119117
User user = repo.save(new User(id, "Ada", "Lovelace"));
120118
SimulateFailureException.throwEx("fail");
@@ -125,9 +123,7 @@ public void saveRolledBack() {
125123
assertNull(user);
126124
}
127125

128-
@Service
129-
@Component
130-
@EnableTransactionManagement
126+
@Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
131127
static class UserService {
132128
@Autowired UserRepository userRepo;
133129

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalTemplateIntegrationTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.springframework.data.couchbase.util.ClusterType;
5353
import org.springframework.data.couchbase.util.IgnoreWhen;
5454
import org.springframework.data.couchbase.util.JavaIntegrationTests;
55-
import org.springframework.stereotype.Component;
5655
import org.springframework.stereotype.Service;
5756
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5857
import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -366,9 +365,7 @@ public void removeEntityById() {
366365
}, TransactionSystemUnambiguousException.class, IllegalArgumentException.class);
367366
}
368367

369-
@Service
370-
@Component
371-
@EnableTransactionManagement
368+
@Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
372369
static class PersonService {
373370
final CouchbaseOperations personOperations;
374371
final ReactiveCouchbaseOperations personOperationsRx;

spring-data-couchbase/src/test/java/org/springframework/data/couchbase/transactions/CouchbaseTransactionalUnsettableParametersIntegrationTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636
import org.springframework.data.couchbase.util.ClusterType;
3737
import org.springframework.data.couchbase.util.IgnoreWhen;
3838
import org.springframework.data.couchbase.util.JavaIntegrationTests;
39-
import org.springframework.stereotype.Component;
4039
import org.springframework.stereotype.Service;
4140
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
42-
import org.springframework.transaction.annotation.EnableTransactionManagement;
4341
import org.springframework.transaction.annotation.Transactional;
4442

4543
import com.couchbase.client.core.msg.kv.DurabilityLevel;
@@ -202,9 +200,7 @@ public void findWithOptions() {
202200
});
203201
}
204202

205-
@Service
206-
@Component
207-
@EnableTransactionManagement
203+
@Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
208204
static class PersonService {
209205
final CouchbaseOperations personOperations;
210206

0 commit comments

Comments
 (0)