Search in sources :

Example 1 with ConnectionServiceClient

use of com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient in project java-bigqueryconnection by googleapis.

the class CreateConnection method createConnection.

public static void createConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        LocationName parent = LocationName.of(projectId, location);
        CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
        Connection response = client.createConnection(request);
        System.out.println("Connection created successfully :" + response.getName());
    }
}
Also used : ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) Connection(com.google.cloud.bigquery.connection.v1.Connection) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName)

Example 2 with ConnectionServiceClient

use of com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient in project java-bigqueryconnection by googleapis.

the class ShareConnection method shareConnection.

public static void shareConnection(String projectId, String location, String connectionId) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        ResourceName resource = ConnectionName.of(projectId, location, connectionId);
        Binding binding = Binding.newBuilder().addMembers("group:example-analyst-group@google.com").setRole("roles/bigquery.connectionUser").build();
        Policy policy = Policy.newBuilder().addBindings(binding).build();
        SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource.toString()).setPolicy(policy).build();
        client.setIamPolicy(request);
        System.out.println("Connection shared successfully");
    }
}
Also used : Binding(com.google.iam.v1.Binding) Policy(com.google.iam.v1.Policy) ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) SetIamPolicyRequest(com.google.iam.v1.SetIamPolicyRequest) ResourceName(com.google.api.resourcenames.ResourceName)

Example 3 with ConnectionServiceClient

use of com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient in project java-bigqueryconnection by googleapis.

the class UpdateConnection method updateConnection.

public static void updateConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        ConnectionName name = ConnectionName.of(projectId, location, connectionId);
        FieldMask updateMask = FieldMaskUtil.fromString("description");
        UpdateConnectionRequest request = UpdateConnectionRequest.newBuilder().setName(name.toString()).setConnection(connection).setUpdateMask(updateMask).build();
        Connection response = client.updateConnection(request);
        System.out.println("Connection updated successfully :" + response.getDescription());
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) UpdateConnectionRequest(com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest) Connection(com.google.cloud.bigquery.connection.v1.Connection) FieldMask(com.google.protobuf.FieldMask)

Example 4 with ConnectionServiceClient

use of com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient in project java-spring-boot-2021 by hocyadav.

the class GoogleBigQueryImpl method getConnection.

public static void getConnection(String projectId, String location, String connectionId) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        ConnectionName name = ConnectionName.of(projectId, location, connectionId);
        GetConnectionRequest request = GetConnectionRequest.newBuilder().setName(name.toString()).build();
        Connection response = client.getConnection(request);
        System.out.println("Connection info retrieved successfully :" + response.getName());
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) Connection(com.google.cloud.bigquery.connection.v1.Connection) GetConnectionRequest(com.google.cloud.bigquery.connection.v1.GetConnectionRequest)

Example 5 with ConnectionServiceClient

use of com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient in project java-bigqueryconnection by googleapis.

the class DeleteConnection method deleteConnection.

public static void deleteConnection(String projectId, String location, String connectionName) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        ConnectionName name = ConnectionName.of(projectId, location, connectionName);
        DeleteConnectionRequest request = DeleteConnectionRequest.newBuilder().setName(name.toString()).build();
        client.deleteConnection(request);
        System.out.println("Connection deleted successfully");
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) DeleteConnectionRequest(com.google.cloud.bigquery.connection.v1.DeleteConnectionRequest)

Aggregations

ConnectionServiceClient (com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient)9 Connection (com.google.cloud.bigquery.connection.v1.Connection)5 ConnectionName (com.google.cloud.bigquery.connection.v1.ConnectionName)4 LocationName (com.google.cloud.bigquery.connection.v1.LocationName)4 CreateConnectionRequest (com.google.cloud.bigquery.connection.v1.CreateConnectionRequest)2 GetConnectionRequest (com.google.cloud.bigquery.connection.v1.GetConnectionRequest)2 ListConnectionsRequest (com.google.cloud.bigquery.connection.v1.ListConnectionsRequest)2 ResourceName (com.google.api.resourcenames.ResourceName)1 AwsAccessRole (com.google.cloud.bigquery.connection.v1.AwsAccessRole)1 DeleteConnectionRequest (com.google.cloud.bigquery.connection.v1.DeleteConnectionRequest)1 UpdateConnectionRequest (com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest)1 Binding (com.google.iam.v1.Binding)1 Policy (com.google.iam.v1.Policy)1 SetIamPolicyRequest (com.google.iam.v1.SetIamPolicyRequest)1 FieldMask (com.google.protobuf.FieldMask)1