|
| 1 | +/* |
| 2 | + Copyright 2018 Google LLC |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package com.example.bigquerydatatransfer; |
| 18 | + |
| 19 | +// [START bigquery_datatransfer_quickstart] |
| 20 | +// Imports the Google Cloud client library |
| 21 | +import com.google.cloud.bigquery.datatransfer.v1.DataSource; |
| 22 | +import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient; |
| 23 | +import com.google.cloud.bigquery.datatransfer.v1.ListDataSourcesRequest; |
| 24 | +import com.google.cloud.bigquery.datatransfer.v1.PagedResponseWrappers.ListDataSourcesPagedResponse; |
| 25 | + |
| 26 | +public class QuickstartSample { |
| 27 | + /** |
| 28 | + * List available data sources for the BigQuery Data Transfer service. |
| 29 | + */ |
| 30 | + public static void main(String... args) throws Exception { |
| 31 | + // Sets your Google Cloud Platform project ID. |
| 32 | + // String projectId = "YOUR_PROJECT_ID"; |
| 33 | + String projectId = args[0]; |
| 34 | + |
| 35 | + // Instantiate a client. If you don't specify credentials when constructing a client, the |
| 36 | + // client library will look for credentials in the environment, such as the |
| 37 | + // GOOGLE_APPLICATION_CREDENTIALS environment variable. |
| 38 | + try (DataTransferServiceClient client = DataTransferServiceClient.create()) { |
| 39 | + // Request the list of available data sources. |
| 40 | + String parent = String.format("projects/%s", projectId); |
| 41 | + ListDataSourcesRequest request = |
| 42 | + ListDataSourcesRequest.newBuilder() |
| 43 | + .setParent(parent) |
| 44 | + .build(); |
| 45 | + ListDataSourcesPagedResponse response = client.listDataSources(request); |
| 46 | + |
| 47 | + // Print the results. |
| 48 | + System.out.println("Supported Data Sources:"); |
| 49 | + for (DataSource dataSource : response.iterateAll()) { |
| 50 | + System.out.println(dataSource.getDisplayName()); |
| 51 | + System.out.printf("\tID: %s%n", dataSource.getDataSourceId()); |
| 52 | + System.out.printf("\tFull path: %s%n", dataSource.getName()); |
| 53 | + System.out.printf("\tDescription: %s%n", dataSource.getDescription()); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +// [END bigquery_datatransfer_quickstart] |
0 commit comments