@@ -881,7 +881,11 @@ public static CloseableExecutorProvider createAsyncExecutorProvider(
881881 }
882882
883883 protected SpannerOptions (Builder builder ) {
884- super (SpannerFactory .class , SpannerRpcFactory .class , builder , new SpannerDefaults ());
884+ super (
885+ SpannerFactory .class ,
886+ SpannerRpcFactory .class ,
887+ Builder .prepareBuilder (builder ),
888+ new SpannerDefaults ());
885889 numChannels = builder .numChannels == null ? DEFAULT_CHANNELS : builder .numChannels ;
886890 Preconditions .checkArgument (
887891 numChannels >= 1 && numChannels <= MAX_CHANNELS ,
@@ -1221,6 +1225,25 @@ public GoogleCredentials getDefaultSpannerOmniCredentials() {
12211225 /** Builder for {@link SpannerOptions} instances. */
12221226 public static class Builder
12231227 extends ServiceOptions .Builder <Spanner , SpannerOptions , SpannerOptions .Builder > {
1228+ private static Builder prepareBuilder (Builder builder ) {
1229+ if (builder .instanceType == InstanceType .OMNI ) {
1230+ builder .enableBuiltInMetrics = false ;
1231+ builder .setProjectId (SPANNER_OMNI_PROJECT_ID );
1232+ builder .configureOmniHost ();
1233+ if (builder .sessionPoolOptions == null ) {
1234+ builder .sessionPoolOptions =
1235+ SessionPoolOptions .newBuilder ().setExperimentalHost ().build ();
1236+ } else {
1237+ builder .sessionPoolOptions =
1238+ builder .sessionPoolOptions .toBuilder ().setExperimentalHost ().build ();
1239+ }
1240+ if (builder .credentials == null ) {
1241+ builder .setCredentials (environment .getDefaultSpannerOmniCredentials ());
1242+ }
1243+ }
1244+ return builder ;
1245+ }
1246+
12241247 static final int DEFAULT_PREFETCH_CHUNKS = 4 ;
12251248 static final QueryOptions DEFAULT_QUERY_OPTIONS = QueryOptions .getDefaultInstance ();
12261249 static final DecodeMode DEFAULT_DECODE_MODE = DecodeMode .DIRECT ;
@@ -2219,18 +2242,6 @@ public Builder setAutoTaggingTracerLimit(int autoTaggingTracerLimit) {
22192242 @ SuppressWarnings ("rawtypes" )
22202243 @ Override
22212244 public SpannerOptions build () {
2222- if (this .instanceType == InstanceType .OMNI ) {
2223- this .enableBuiltInMetrics = false ;
2224- super .setProjectId (SPANNER_OMNI_PROJECT_ID );
2225- if (this .sessionPoolOptions == null ) {
2226- this .sessionPoolOptions = SessionPoolOptions .newBuilder ().setExperimentalHost ().build ();
2227- } else {
2228- this .sessionPoolOptions =
2229- this .sessionPoolOptions .toBuilder ().setExperimentalHost ().build ();
2230- }
2231- configureOmniHost ();
2232- super .setHost (this .host );
2233- }
22342245 // Set the host of emulator has been set.
22352246 if (emulatorHost != null && this .instanceType != InstanceType .OMNI ) {
22362247 if (!emulatorHost .startsWith ("http" )) {
@@ -2242,8 +2253,6 @@ public SpannerOptions build() {
22422253 this .setChannelConfigurator (ManagedChannelBuilder ::usePlaintext );
22432254 // As we are using plain text, we should never send any credentials.
22442255 this .setCredentials (NoCredentials .getInstance ());
2245- } else if (this .instanceType == InstanceType .OMNI && credentials == null ) {
2246- credentials = environment .getDefaultSpannerOmniCredentials ();
22472256 }
22482257 if (this .numChannels == null ) {
22492258 this .numChannels =
0 commit comments