-
Notifications
You must be signed in to change notification settings - Fork 57
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
[Feature] transactional support #249
base: main
Are you sure you want to change the base?
Conversation
@Zyqsempai this is the contribution we offered earlier this year |
ce89c66
to
0ab0fa4
Compare
The additional documentation can be found in a gist: spring-data-reference-repositories-transactions.md |
@MalteJoe @jakobjoachim its on the way |
Thanks for this awesome contribution, I will review it as soon as I will have time. |
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.
Hi @aburmeis,
as far as I can see, ArangoTransactionManager
assumes that the db and all the collection involved in the transaction already exist when beginning the transaction. Unfortunately, this is not the case with the current implementation. In fact db and collections are currently initialized lazily. They are checked if exist only when the first operation upon them is performed. This behavior should change, as pointed out in #125 and all data definitions like db, collections, indexes, should be checked on startup.
A further complication derives from the fact that we should support SPEL expressions in dbs and collections names, i.e. see
Line 40 in 7224786
@Document("#{tenantProvider.getId()}_collection") |
It should be possible checking existence of db and collections in the ArangoTransactionManager
, but note that in case you need to create a collection, you should remember to dinamically evaluate the name in case it contains a SPEL expression and consider the related create options (https://github.com/arangodb/spring-data/blob/286b502d78bee5e5d5f551b4c2213238919fe625/src/main/java/com/arangodb/springframework/annotation/Document.java). To do it, you should ideally have the related entity class, see
spring-data/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java
Lines 176 to 181 in eb46251
private ArangoCollection _collection(final Class<?> entityClass, final Object id) { | |
final ArangoPersistentEntity<?> persistentEntity = converter.getMappingContext() | |
.getRequiredPersistentEntity(entityClass); | |
final String name = determineCollectionFromId(id).orElse(persistentEntity.getCollection()); | |
return _collection(name, persistentEntity, persistentEntity.getCollectionOptions()); | |
} |
Therefore, instead of using labels strings to specify write collections of the transaction, it would be ideal having a dedicated annotation which would allow specify the entity classes directly (eg. @ArangoTransaction(writeCollections = {Actor.class, Movie.class})
).
54c7fbd
to
3307750
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
3307750
to
8c14e8a
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
8c14e8a
to
68c60f7
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
1 similar comment
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
2c98ca6
to
541b112
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
541b112
to
499fe1a
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
2 similar comments
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
e75199b
to
25b8270
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
1 similar comment
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
aa938a2
to
0ffeb3c
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
… as they will be removed with driver 7)
41ee67a
to
23d40a9
Compare
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Malte Jörgens.
|
As mentioned in #80 this introduces a platform transaction manager based on Arango stream transactions. Do do so, all queries and the simple repository have to use options including the transaction id. As stream transactions need all collections written on creation, additional ones can be passed as labels from the
@Transactional
annotation.The
ArangoTransactionManager
will handle each transaction as one stream transaction allowing implicit read from undeclared collections. Isolation level will be repeatable read (serialisable is not supported). All write collections have to be declared, either explicit using@Transactional(label = {"Entities", "hasEdge"})
or implicit from the first AQLWITH
(will be combined as the stream transaction begin is postponed until the first query is fired). Any defined transaction timeout is used as lock timeout of the stream transaction.The manager implements
Propagation.REQUIRED
andPropagation.SUPPORTS
only (REQUIRED
is the default). Any other will fail due to lack of suspend/resume implementation.Transaction management is enabled the following way:
The typical use case would make all public methods of a service transactional read only and the mutating ones declaring the collections:
You can also use programmatic transactions with support from
TransactionAttributeTemplate
. Either create one usingDefaultTransactionAttribute
or set labels before callingexecute()
.