# Migrating from DataClient to DataConnection

3.7.0-rc 3.6.0 (latest) 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 In this document we describe how to migrate existing code that uses `DataClient` to use `DataConnection`.

All examples use the following aliases:

    namespace gc = ::google::cloud;
    namespace cbt = ::google::cloud::bigtable;

### Simple case

    cbt::Table OldCode() {
      auto data_client = cbt::MakeDataClient("project-id", "instance-id");
      return cbt::Table(data_client, "table-id");
    }

    cbt::Table UpdatedCode() {
      auto connection = cbt::MakeDataConnection();
      return cbt::Table(
          connection, cbt::TableResource("project-id", "instance-id", "table-id"));
    }

Note that the `DataConnection` is not associated with any resource ids. They are instead packaged as a `TableResource` and passed as a single object to `Table`.

### Optional configuration

Note that there is only one `Table` constructor that accepts a `DataConnection`. All configuration is done via the `Options` parameter.

#### Set an application profile id

    cbt::Table OldCode() {
      auto data_client = cbt::MakeDataClient("project-id", "instance-id");
      return cbt::Table(data_client, "app-profile-id", "table-id");
    }

    cbt::Table UpdatedCode() {
      auto connection = cbt::MakeDataConnection();
      return cbt::Table(
          connection, cbt::TableResource("project-id", "instance-id", "table-id"),
          gc::Options{}.set<cbt::AppProfileIdOption>("app-profile-id"));
    }

#### Set a custom retry policy

    cbt::Table OldCode() {
      auto data_client = cbt::MakeDataClient("project-id", "instance-id");
      return cbt::Table(data_client, "table-id",
                        cbt::LimitedErrorCountRetryPolicy(7));
    }

    cbt::Table UpdatedCode() {
      auto connection = cbt::MakeDataConnection();
      return cbt::Table(connection,
                        cbt::TableResource("project-id", "instance-id", "table-id"),
                        gc::Options{}.set<cbt::DataRetryPolicyOption>(
                            cbt::DataLimitedErrorCountRetryPolicy(7).clone()));
    }

The retry, backoff, and idempotency policies are packaged in `Options` as `shared_ptr`s, instead of passed by value as variadic parameters to `Table(..., Policies&&)`.

Also note that the retry and backoff policy types have changed. If you defined your own policy, extending `RPCRetryPolicy` or `RPCBackoffPolicy`, it will not be compatible with the new types. The new policies do not have a `Setup(grpc::ClientContext&)` function. This function has not been included because we believe that setting up the `grpc::ClientContext`...

1. Should not be tied to the retry policies.
2. Is unlikely to be needed by external customers.

If you do need a `Setup()` feature, please [open a feature request](https://github.com/googleapis/google-cloud-cpp/issues/new/choose) explaining your use case, and we will be happy to accommodate you.