3636import com .google .cloud .spanner .Options .ListOption ;
3737import com .google .cloud .spanner .Options .QueryOption ;
3838import com .google .cloud .spanner .Options .ReadOption ;
39+ import com .google .cloud .spanner .spi .v1 .GapicSpannerRpc ;
3940import com .google .cloud .spanner .spi .v1 .SpannerRpc ;
4041import com .google .cloud .spanner .spi .v1 .SpannerRpc .Paginated ;
4142import com .google .common .annotations .VisibleForTesting ;
8182import io .opencensus .trace .Span ;
8283import io .opencensus .trace .Tracer ;
8384import io .opencensus .trace .Tracing ;
84-
8585import java .io .IOException ;
8686import java .io .Serializable ;
8787import java .util .AbstractList ;
@@ -134,7 +134,8 @@ class SpannerImpl extends BaseService<SpannerOptions> implements Spanner {
134134 }
135135
136136 private final Random random = new Random ();
137- private final SpannerRpc rpc ;
137+ private final SpannerRpc rawGrpcRpc ;
138+ private final SpannerRpc gapicRpc ;
138139 private final int defaultPrefetchChunks ;
139140
140141 @ GuardedBy ("this" )
@@ -146,16 +147,26 @@ class SpannerImpl extends BaseService<SpannerOptions> implements Spanner {
146147 @ GuardedBy ("this" )
147148 private boolean spannerIsClosed = false ;
148149
149- SpannerImpl (SpannerRpc rpc , int defaultPrefetchChunks , SpannerOptions options ) {
150+ SpannerImpl (
151+ SpannerRpc rawGrpcRpc ,
152+ SpannerRpc gapicRpc ,
153+ int defaultPrefetchChunks ,
154+ SpannerOptions options ) {
150155 super (options );
151- this .rpc = rpc ;
156+ this .rawGrpcRpc = rawGrpcRpc ;
157+ this .gapicRpc = gapicRpc ;
152158 this .defaultPrefetchChunks = defaultPrefetchChunks ;
153- this .dbAdminClient = new DatabaseAdminClientImpl (options .getProjectId (), rpc );
154- this .instanceClient = new InstanceAdminClientImpl (options .getProjectId (), rpc , dbAdminClient );
159+ this .dbAdminClient = new DatabaseAdminClientImpl (options .getProjectId (), gapicRpc );
160+ this .instanceClient =
161+ new InstanceAdminClientImpl (options .getProjectId (), gapicRpc , dbAdminClient );
155162 }
156163
157164 SpannerImpl (SpannerOptions options ) {
158- this (options .getSpannerRpcV1 (), options .getPrefetchChunks (), options );
165+ this (
166+ options .getSpannerRpcV1 (),
167+ GapicSpannerRpc .create (options ),
168+ options .getPrefetchChunks (),
169+ options );
159170 }
160171
161172 private static ExponentialBackOff newBackOff () {
@@ -255,7 +266,8 @@ Session createSession(final DatabaseId db) throws SpannerException {
255266 new Callable <com .google .spanner .v1 .Session >() {
256267 @ Override
257268 public com .google .spanner .v1 .Session call () throws Exception {
258- return rpc .createSession (db .getName (), getOptions ().getSessionLabels (), options );
269+ return rawGrpcRpc .createSession (
270+ db .getName (), getOptions ().getSessionLabels (), options );
259271 }
260272 });
261273 span .end ();
@@ -794,7 +806,7 @@ public Timestamp writeAtLeastOnce(Iterable<Mutation> mutations) throws SpannerEx
794806 new Callable <CommitResponse >() {
795807 @ Override
796808 public CommitResponse call () throws Exception {
797- return rpc .commit (request , options );
809+ return rawGrpcRpc .commit (request , options );
798810 }
799811 });
800812 Timestamp t = Timestamp .fromProto (response .getCommitTimestamp ());
@@ -816,7 +828,7 @@ public ReadContext singleUse() {
816828
817829 @ Override
818830 public ReadContext singleUse (TimestampBound bound ) {
819- return setActive (new SingleReadContext (this , bound , rpc , defaultPrefetchChunks ));
831+ return setActive (new SingleReadContext (this , bound , rawGrpcRpc , defaultPrefetchChunks ));
820832 }
821833
822834 @ Override
@@ -826,7 +838,8 @@ public ReadOnlyTransaction singleUseReadOnlyTransaction() {
826838
827839 @ Override
828840 public ReadOnlyTransaction singleUseReadOnlyTransaction (TimestampBound bound ) {
829- return setActive (new SingleUseReadOnlyTransaction (this , bound , rpc , defaultPrefetchChunks ));
841+ return setActive (
842+ new SingleUseReadOnlyTransaction (this , bound , rawGrpcRpc , defaultPrefetchChunks ));
830843 }
831844
832845 @ Override
@@ -836,12 +849,13 @@ public ReadOnlyTransaction readOnlyTransaction() {
836849
837850 @ Override
838851 public ReadOnlyTransaction readOnlyTransaction (TimestampBound bound ) {
839- return setActive (new MultiUseReadOnlyTransaction (this , bound , rpc , defaultPrefetchChunks ));
852+ return setActive (
853+ new MultiUseReadOnlyTransaction (this , bound , rawGrpcRpc , defaultPrefetchChunks ));
840854 }
841855
842856 @ Override
843857 public TransactionRunner readWriteTransaction () {
844- return setActive (new TransactionRunnerImpl (this , rpc , defaultPrefetchChunks ));
858+ return setActive (new TransactionRunnerImpl (this , rawGrpcRpc , defaultPrefetchChunks ));
845859 }
846860
847861 @ Override
@@ -858,7 +872,7 @@ public void close() {
858872 new Callable <Void >() {
859873 @ Override
860874 public Void call () throws Exception {
861- rpc .deleteSession (name , options );
875+ rawGrpcRpc .deleteSession (name , options );
862876 return null ;
863877 }
864878 });
@@ -884,7 +898,7 @@ ByteString beginTransaction() {
884898 new Callable <Transaction >() {
885899 @ Override
886900 public Transaction call () throws Exception {
887- return rpc .beginTransaction (request , options );
901+ return rawGrpcRpc .beginTransaction (request , options );
888902 }
889903 });
890904 if (txn .getId ().isEmpty ()) {
0 commit comments