@@ -42,10 +42,12 @@ class DatabaseClientImpl implements DatabaseClient {
4242 this .pool = pool ;
4343 }
4444
45+ @ VisibleForTesting
4546 PooledSession getReadSession () {
4647 return pool .getReadSession ();
4748 }
4849
50+ @ VisibleForTesting
4951 PooledSession getReadWriteSession () {
5052 return pool .getReadWriteSession ();
5153 }
@@ -60,7 +62,6 @@ public Timestamp write(final Iterable<Mutation> mutations) throws SpannerExcepti
6062 Span span = tracer .spanBuilder (READ_WRITE_TRANSACTION ).startSpan ();
6163 try (Scope s = tracer .withSpan (span )) {
6264 return runWithSessionRetry (
63- SessionMode .READ_WRITE ,
6465 new Function <Session , Timestamp >() {
6566 @ Override
6667 public Timestamp apply (Session session ) {
@@ -80,7 +81,6 @@ public Timestamp writeAtLeastOnce(final Iterable<Mutation> mutations) throws Spa
8081 Span span = tracer .spanBuilder (READ_WRITE_TRANSACTION ).startSpan ();
8182 try (Scope s = tracer .withSpan (span )) {
8283 return runWithSessionRetry (
83- SessionMode .READ_WRITE ,
8484 new Function <Session , Timestamp >() {
8585 @ Override
8686 public Timestamp apply (Session session ) {
@@ -188,7 +188,6 @@ public long executePartitionedUpdate(final Statement stmt) {
188188 Span span = tracer .spanBuilder (PARTITION_DML_TRANSACTION ).startSpan ();
189189 try (Scope s = tracer .withSpan (span )) {
190190 return runWithSessionRetry (
191- SessionMode .READ , // PartitionedUpdate does not need a prepared tx.
192191 new Function <Session , Long >() {
193192 @ Override
194193 public Long apply (Session session ) {
@@ -201,22 +200,13 @@ public Long apply(Session session) {
201200 }
202201 }
203202
204- private enum SessionMode {
205- READ ,
206- READ_WRITE ;
207- }
208-
209- private <T > T runWithSessionRetry (SessionMode sessionMode , Function <Session , T > callable ) {
210- PooledSession session =
211- sessionMode == SessionMode .READ ? getReadSession () : getReadWriteSession ();
203+ private <T > T runWithSessionRetry (Function <Session , T > callable ) {
204+ PooledSession session = getReadWriteSession ();
212205 while (true ) {
213206 try {
214207 return callable .apply (session );
215208 } catch (SessionNotFoundException e ) {
216- session =
217- sessionMode == SessionMode .READ
218- ? pool .replaceReadSession (e , session )
219- : pool .replaceReadWriteSession (e , session );
209+ session = pool .replaceReadWriteSession (e , session );
220210 }
221211 }
222212 }
0 commit comments