16
16
class ArangoTransaction implements SmartTransactionObject {
17
17
18
18
private final ArangoDatabase database ;
19
+
20
+ private final Set <String > writeCollections = new HashSet <>();
19
21
private TransactionDefinition definition ;
20
22
private StreamTransactionEntity transaction ;
21
23
@@ -29,19 +31,22 @@ boolean exists() {
29
31
30
32
void configure (TransactionDefinition definition ) {
31
33
this .definition = definition ;
34
+ if (definition instanceof TransactionAttribute ) {
35
+ writeCollections .addAll (((TransactionAttribute ) definition ).getLabels ());
36
+ }
32
37
}
33
38
34
- String begin (Collection <String > collections ) {
39
+ String getOrBegin (Collection <String > collections ) {
35
40
if (transaction != null ) {
36
- throw new IllegalTransactionStateException ("Stream transaction already started" );
37
- }
38
- Set <String > allCollections = new HashSet <>(collections );
39
- if (definition instanceof TransactionAttribute ) {
40
- allCollections .addAll (((TransactionAttribute ) definition ).getLabels ());
41
+ if (!writeCollections .containsAll (collections )) {
42
+ throw new IllegalTransactionStateException ("Stream transaction already started, no additional collections allowed" );
43
+ }
44
+ return transaction .getId ();
41
45
}
46
+ writeCollections .addAll (collections );
42
47
StreamTransactionOptions options = new StreamTransactionOptions ()
43
48
.allowImplicit (true )
44
- .writeCollections (allCollections .toArray (new String [0 ]))
49
+ .writeCollections (writeCollections .toArray (new String [0 ]))
45
50
.lockTimeout (definition .getTimeout () == -1 ? 0 : definition .getTimeout ());
46
51
transaction = database .beginStreamTransaction (options );
47
52
return transaction .getId ();
0 commit comments