-
Notifications
You must be signed in to change notification settings - Fork 192
Transaction Support #1487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Transaction Support #1487
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6ec1381
fix flaky test writesAndReadsCustomFieldsConvertedClass (#1264)
yyfMichaelYan af66ada
Prepare 4.3 GA (2021.1.0).
schauder 00e05e4
After release cleanups.
schauder ef22b3d
Handle Collection<> parameters to repository query methods. (#1271)
mikereiche 5dbf182
Incorporate changes from 5.0.x and bump Couchbase SDK. (#1287)
mikereiche ecadff6
Prepare 4.4 M1 (2021.2.0).
christophstrobl ebe33cf
After release cleanups.
christophstrobl da7d241
Prepare 4.4 M2 (2021.2.0).
christophstrobl 1fdbf6d
After release cleanups.
christophstrobl 4a04419
Add mechanism for save to do one of insert, replace or upsert. (#1316)
mikereiche 13d266e
Prepare 4.4 M3 (2021.2.0).
mp911de e83bd41
After release cleanups.
mp911de 9af8ece
Use Java 17 to build snapshots for Artifactory.
mp911de d5ca390
Reinstate CouchbaseCache documentation. (#1357)
mikereiche 5f03d1e
Fix update to cache documentation. (#1359)
mikereiche b02959d
Support derived queries on repositories defined with an abstract enti…
mikereiche edadede
Add support for Couchbase Transactions.
mikereiche e20ed08
Rebase with main.
mikereiche e2df8e7
Rebased and tidied transaction branch.
mikereiche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/couchbase/client/java/transactions/AttemptContextReactiveAccessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
/* | ||
* Copyright 2021-2022 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 com.couchbase.client.java.transactions; | ||
|
||
import com.couchbase.client.core.annotation.Stability; | ||
import com.couchbase.client.core.transaction.CoreTransactionAttemptContext; | ||
import com.couchbase.client.java.codec.JsonSerializer; | ||
|
||
/** | ||
* To access the ReactiveTransactionAttemptContext held by TransactionAttemptContext | ||
* | ||
* @author Michael Reiche | ||
*/ | ||
@Stability.Internal | ||
public class AttemptContextReactiveAccessor { | ||
public static ReactiveTransactionAttemptContext createReactiveTransactionAttemptContext( | ||
CoreTransactionAttemptContext core, JsonSerializer jsonSerializer) { | ||
return new ReactiveTransactionAttemptContext(core, jsonSerializer); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Role; | ||
import org.springframework.core.type.filter.AnnotationTypeFilter; | ||
import org.springframework.data.convert.CustomConversions; | ||
import org.springframework.data.couchbase.CouchbaseClientFactory; | ||
|
@@ -40,9 +41,16 @@ | |
import org.springframework.data.couchbase.core.mapping.Document; | ||
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping; | ||
import org.springframework.data.couchbase.repository.config.RepositoryOperationsMapping; | ||
import org.springframework.data.couchbase.transaction.CouchbaseCallbackTransactionManager; | ||
import org.springframework.data.couchbase.transaction.CouchbaseTransactionInterceptor; | ||
import org.springframework.data.couchbase.transaction.CouchbaseTransactionalOperator; | ||
import org.springframework.data.mapping.model.CamelCaseAbbreviatingFieldNamingStrategy; | ||
import org.springframework.data.mapping.model.FieldNamingStrategy; | ||
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy; | ||
import org.springframework.transaction.TransactionManager; | ||
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource; | ||
import org.springframework.transaction.interceptor.TransactionAttributeSource; | ||
import org.springframework.transaction.interceptor.TransactionInterceptor; | ||
import org.springframework.util.ClassUtils; | ||
import org.springframework.util.StringUtils; | ||
|
||
|
@@ -123,7 +131,7 @@ protected Authenticator authenticator() { | |
* @param couchbaseCluster the cluster reference from the SDK. | ||
* @return the initialized factory. | ||
*/ | ||
@Bean | ||
@Bean(name = BeanNames.COUCHBASE_CLIENT_FACTORY) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make name explicit |
||
public CouchbaseClientFactory couchbaseClientFactory(final Cluster couchbaseCluster) { | ||
return new SimpleCouchbaseClientFactory(couchbaseCluster, getBucketName(), getScopeName()); | ||
} | ||
|
@@ -280,9 +288,8 @@ public TranslationService couchbaseTranslationService() { | |
|
||
/** | ||
* Creates a {@link CouchbaseMappingContext} equipped with entity classes scanned from the mapping base package. | ||
* | ||
*/ | ||
@Bean | ||
@Bean(BeanNames.COUCHBASE_MAPPING_CONTEXT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make name explicit |
||
public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customConversions) throws Exception { | ||
CouchbaseMappingContext mappingContext = new CouchbaseMappingContext(); | ||
mappingContext.setInitialEntitySet(getInitialEntitySet()); | ||
|
@@ -310,6 +317,44 @@ public ObjectMapper couchbaseObjectMapper() { | |
return mapper; | ||
} | ||
|
||
/** | ||
* The default blocking transaction manager. It is an implementation of CallbackPreferringTransactionManager | ||
* CallbackPreferrringTransactionmanagers do not play well with test-cases that rely | ||
* on @TestTransaction/@BeforeTransaction/@AfterTransaction | ||
* | ||
* @param clientFactory | ||
* @return | ||
*/ | ||
@Bean(BeanNames.COUCHBASE_TRANSACTION_MANAGER) | ||
CouchbaseCallbackTransactionManager couchbaseTransactionManager(CouchbaseClientFactory clientFactory) { | ||
return new CouchbaseCallbackTransactionManager(clientFactory); | ||
} | ||
|
||
/** | ||
* The default TransactionalOperator. | ||
* | ||
* @param couchbaseCallbackTransactionManager | ||
* @return | ||
*/ | ||
@Bean(BeanNames.COUCHBASE_TRANSACTIONAL_OPERATOR) | ||
public CouchbaseTransactionalOperator couchbaseTransactionalOperator( | ||
CouchbaseCallbackTransactionManager couchbaseCallbackTransactionManager) { | ||
return CouchbaseTransactionalOperator.create(couchbaseCallbackTransactionManager); | ||
} | ||
|
||
@Bean | ||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) | ||
public TransactionInterceptor transactionInterceptor(TransactionManager couchbaseTransactionManager) { | ||
TransactionAttributeSource transactionAttributeSource = new AnnotationTransactionAttributeSource(); | ||
TransactionInterceptor interceptor = new CouchbaseTransactionInterceptor(couchbaseTransactionManager, | ||
transactionAttributeSource); | ||
interceptor.setTransactionAttributeSource(transactionAttributeSource); | ||
if (couchbaseTransactionManager != null) { | ||
interceptor.setTransactionManager(couchbaseTransactionManager); | ||
} | ||
return interceptor; | ||
} | ||
|
||
/** | ||
* Configure whether to automatically create indices for domain types by deriving the from the entity or not. | ||
*/ | ||
|
@@ -375,5 +420,4 @@ private boolean nonShadowedJacksonPresent() { | |
public QueryScanConsistency getDefaultConsistency() { | ||
return null; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better checking for invalid scope/collection specification.