// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.finapp;

import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import io.grpc.ManagedChannelBuilder;

final class DatabaseModule extends AbstractModule {

  @Override
  protected void configure() {}

  @Provides
  @Singleton
  DatabaseClient provideDatabaseClient(
      @ArgsModule.SpannerHost String spannerHost,
      @ArgsModule.SpannerPort int spannerPort,
      @ArgsModule.SpannerProjectId String spannerProjectId,
      @ArgsModule.SpannerInstanceId String spannerInstanceId,
      @ArgsModule.SpannerDatabaseId String spannerDatabaseId) {
    SpannerOptions spannerOptions = SpannerOptions.getDefaultInstance();
    Spanner spanner =
        spannerOptions.toBuilder()
            .setChannelProvider(
                // Configure GRPC channel explicitly, to simplify deployment on GKE. The default
                // configuration requires a grpclb to be available.
                FixedTransportChannelProvider.create(
                    GrpcTransportChannel.create(
                        ManagedChannelBuilder.forAddress(spannerHost, spannerPort).build())))
            .build()
            .getService();
    return spanner.getDatabaseClient(
        DatabaseId.of(spannerProjectId, spannerInstanceId, spannerDatabaseId));
  }
}

@@ -1595,24 +1595,16 @@
 panner =
-%0A       
  spanner
@@ -1626,437 +1626,16 @@
 er()
-%0A            .setChannelProvider(%0A                // Configure GRPC channel explicitly, to simplify deployment on GKE. The default%0A                // configuration requires a grpclb to be available.%0A                FixedTransportChannelProvider.create(%0A                    GrpcTransportChannel.create(%0A                        ManagedChannelBuilder.forAddress(spannerHost, spannerPort).build())))%0A            .build()%0A            
+.build()
 .get

Remove setChannelProvider call (#3)