Skip to content

Commit a334569

Browse files
committed
Prettier impl of ExplicitTransaction#isOpen()
Made transaction state enum responsible for knowing if transaction is open or closed. This seems prettier than large boolean expression.
1 parent a51a15f commit a334569

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

driver/src/main/java/org/neo4j/driver/internal/ExplicitTransaction.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,31 @@ public class ExplicitTransaction implements Transaction
5656
private enum State
5757
{
5858
/** The transaction is running with no explicit success or failure marked */
59-
ACTIVE,
59+
ACTIVE( true ),
6060

6161
/** Running, user marked for success, meaning it'll value committed */
62-
MARKED_SUCCESS,
62+
MARKED_SUCCESS( true ),
6363

6464
/** User marked as failed, meaning it'll be rolled back. */
65-
MARKED_FAILED,
65+
MARKED_FAILED( true ),
6666

6767
/**
6868
* This transaction has been explicitly terminated by calling {@link Session#reset()}.
6969
*/
70-
TERMINATED,
70+
TERMINATED( false ),
7171

7272
/** This transaction has successfully committed */
73-
COMMITTED,
73+
COMMITTED( false ),
7474

7575
/** This transaction has been rolled back */
76-
ROLLED_BACK
76+
ROLLED_BACK( false );
77+
78+
final boolean txOpen;
79+
80+
State( boolean txOpen )
81+
{
82+
this.txOpen = txOpen;
83+
}
7784
}
7885

7986
private final Connection connection;
@@ -289,7 +296,7 @@ public CompletionStage<StatementResultCursor> runAsync( Statement statement )
289296
@Override
290297
public boolean isOpen()
291298
{
292-
return state != State.COMMITTED && state != State.ROLLED_BACK && state != State.TERMINATED;
299+
return state.txOpen;
293300
}
294301

295302
private void ensureCanRunQueries()

0 commit comments

Comments
 (0)