You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/src/main/asciidoc/firestore.adoc
+38
Original file line number
Diff line number
Diff line change
@@ -180,6 +180,44 @@ Read documents are locked until the transaction finishes with a commit or a roll
180
180
If an `Exception` is thrown within a transaction, the rollback operation is executed.
181
181
Otherwise, the commit operation is executed.
182
182
183
+
===== Declarative Transactions with @Transactional Annotation
184
+
185
+
This feature requires a bean of `SpannerTransactionManager`, which is provided when using `spring-cloud-gcp-starter-data-firestore`.
186
+
187
+
`FirestoreTemplate` and `FirestoreReactiveRepository` support running methods with the `@Transactional` https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative[annotation] as transactions.
188
+
If a method annotated with `@Transactional` calls another method also annotated, then both methods will work within the same transaction.
189
+
190
+
One way to use this feature is illustrated here. You would need to do the following:
191
+
192
+
. Annotate your configuration class with the `@EnableTransactionManagement` annotation.
193
+
194
+
. Create a service class that has methods annotated with `@Transactional`:
Now when you call the methods annotated with `@Transactional` on your service object, a transaction will be automatically started.
218
+
If an error occurs during the execution of a method annotated with `@Transactional`, the transaction will be rolled back.
219
+
If no error occurs, the transaction will be committed.
220
+
183
221
=== Reactive Repository Sample
184
222
185
223
A https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-data-firestore-sample[sample application] is available.
Copy file name to clipboardexpand all lines: spring-cloud-gcp-data-firestore/src/main/java/org/springframework/cloud/gcp/data/firestore/transaction/ReactiveFirestoreTransactionManager.java
Copy file name to clipboardexpand all lines: spring-cloud-gcp-data-firestore/src/test/java/org/springframework/cloud/gcp/data/firestore/it/FirestoreIntegrationTests.java
Copy file name to clipboardexpand all lines: spring-cloud-gcp-data-firestore/src/test/java/org/springframework/cloud/gcp/data/firestore/it/FirestoreIntegrationTestsConfiguration.java
Copy file name to clipboardexpand all lines: spring-cloud-gcp-data-firestore/src/test/java/org/springframework/cloud/gcp/data/firestore/it/FirestoreRepositoryIntegrationTests.java
0 commit comments