52
52
53
53
public class ExplicitTransaction implements Transaction , ResultResourcesHandler
54
54
{
55
+ private static final String BEGIN_QUERY = "BEGIN" ;
56
+ private static final String COMMIT_QUERY = "COMMIT" ;
57
+ private static final String ROLLBACK_QUERY = "ROLLBACK" ;
58
+
55
59
private enum State
56
60
{
57
61
/** The transaction is running with no explicit success or failure marked */
@@ -104,7 +108,7 @@ public void begin( Bookmark initialBookmark )
104
108
{
105
109
Map <String ,Value > parameters = initialBookmark .asBeginTransactionParameters ();
106
110
107
- connection .run ( "BEGIN" , parameters , NoOpResponseHandler .INSTANCE );
111
+ connection .run ( BEGIN_QUERY , parameters , NoOpResponseHandler .INSTANCE );
108
112
connection .pullAll ( NoOpResponseHandler .INSTANCE );
109
113
110
114
if ( !initialBookmark .isEmpty () )
@@ -118,7 +122,7 @@ public InternalFuture<ExplicitTransaction> beginAsync( Bookmark initialBookmark
118
122
InternalPromise <ExplicitTransaction > beginTxPromise = asyncConnection .newPromise ();
119
123
120
124
Map <String ,Value > parameters = initialBookmark .asBeginTransactionParameters ();
121
- asyncConnection .run ( "BEGIN" , parameters , NoOpResponseHandler .INSTANCE );
125
+ asyncConnection .run ( BEGIN_QUERY , parameters , NoOpResponseHandler .INSTANCE );
122
126
123
127
if ( initialBookmark .isEmpty () )
124
128
{
@@ -163,7 +167,8 @@ public void close()
163
167
{
164
168
try
165
169
{
166
- connection .run ( "COMMIT" , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
170
+ connection .run ( COMMIT_QUERY , Collections .<String ,Value >emptyMap (),
171
+ NoOpResponseHandler .INSTANCE );
167
172
connection .pullAll ( new BookmarkResponseHandler ( this ) );
168
173
connection .sync ();
169
174
state = State .COMMITTED ;
@@ -202,7 +207,7 @@ else if ( state == State.FAILED )
202
207
203
208
private void rollbackTx ()
204
209
{
205
- connection .run ( "ROLLBACK" , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
210
+ connection .run ( ROLLBACK_QUERY , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
206
211
connection .pullAll ( new BookmarkResponseHandler ( this ) );
207
212
connection .sync ();
208
213
state = State .ROLLED_BACK ;
@@ -271,7 +276,7 @@ private InternalFuture<Void> doCommitAsync()
271
276
{
272
277
InternalPromise <Void > commitTxPromise = asyncConnection .newPromise ();
273
278
274
- asyncConnection .run ( "COMMIT" , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
279
+ asyncConnection .run ( COMMIT_QUERY , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
275
280
asyncConnection .pullAll ( new CommitTxResponseHandler ( commitTxPromise , this ) );
276
281
asyncConnection .flush ();
277
282
@@ -289,7 +294,7 @@ public Void apply( Void ignore )
289
294
private InternalFuture <Void > doRollbackAsync ()
290
295
{
291
296
InternalPromise <Void > rollbackTxPromise = asyncConnection .newPromise ();
292
- asyncConnection .run ( "ROLLBACK" , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
297
+ asyncConnection .run ( ROLLBACK_QUERY , Collections .<String ,Value >emptyMap (), NoOpResponseHandler .INSTANCE );
293
298
asyncConnection .pullAll ( new RollbackTxResponseHandler ( rollbackTxPromise ) );
294
299
asyncConnection .flush ();
295
300
0 commit comments