Search in sources :

Example 1 with DropDatabaseRequest

use of com.google.spanner.admin.database.v1.DropDatabaseRequest in project java-spanner by googleapis.

the class DatabaseAdminClient method dropDatabase.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Drops (aka deletes) a Cloud Spanner database. Completed backups for the database will be
 * retained according to their `expire_time`. Note: Cloud Spanner might continue to accept
 * requests for a few seconds after the database has been deleted.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
 *   DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
 *   databaseAdminClient.dropDatabase(database);
 * }
 * }</pre>
 *
 * @param database Required. The database to be dropped.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void dropDatabase(DatabaseName database) {
    DropDatabaseRequest request = DropDatabaseRequest.newBuilder().setDatabase(database == null ? null : database.toString()).build();
    dropDatabase(request);
}
Also used : DropDatabaseRequest(com.google.spanner.admin.database.v1.DropDatabaseRequest)

Example 2 with DropDatabaseRequest

use of com.google.spanner.admin.database.v1.DropDatabaseRequest in project java-spanner by googleapis.

the class DatabaseAdminClient method dropDatabase.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Drops (aka deletes) a Cloud Spanner database. Completed backups for the database will be
 * retained according to their `expire_time`. Note: Cloud Spanner might continue to accept
 * requests for a few seconds after the database has been deleted.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
 *   String database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString();
 *   databaseAdminClient.dropDatabase(database);
 * }
 * }</pre>
 *
 * @param database Required. The database to be dropped.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void dropDatabase(String database) {
    DropDatabaseRequest request = DropDatabaseRequest.newBuilder().setDatabase(database).build();
    dropDatabase(request);
}
Also used : DropDatabaseRequest(com.google.spanner.admin.database.v1.DropDatabaseRequest)

Example 3 with DropDatabaseRequest

use of com.google.spanner.admin.database.v1.DropDatabaseRequest in project java-spanner by googleapis.

the class GapicSpannerRpc method dropDatabase.

@Override
public void dropDatabase(String databaseName) throws SpannerException {
    acquireAdministrativeRequestsRateLimiter();
    final DropDatabaseRequest request = DropDatabaseRequest.newBuilder().setDatabase(databaseName).build();
    final GrpcCallContext context = newCallContext(null, databaseName, request, DatabaseAdminGrpc.getDropDatabaseMethod());
    runWithRetryOnAdministrativeRequestsExceeded(() -> {
        get(databaseAdminStub.dropDatabaseCallable().futureCall(request, context));
        return null;
    });
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) DropDatabaseRequest(com.google.spanner.admin.database.v1.DropDatabaseRequest)

Example 4 with DropDatabaseRequest

use of com.google.spanner.admin.database.v1.DropDatabaseRequest in project java-spanner by googleapis.

the class DatabaseAdminClientTest method dropDatabaseTest2.

@Test
public void dropDatabaseTest2() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String database = "database1789464955";
    client.dropDatabase(database);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DropDatabaseRequest actualRequest = ((DropDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(database, actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DropDatabaseRequest(com.google.spanner.admin.database.v1.DropDatabaseRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 5 with DropDatabaseRequest

use of com.google.spanner.admin.database.v1.DropDatabaseRequest in project java-spanner by googleapis.

the class DatabaseAdminClientTest method dropDatabaseTest.

@Test
public void dropDatabaseTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    client.dropDatabase(database);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DropDatabaseRequest actualRequest = ((DropDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(database.toString(), actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) DropDatabaseRequest(com.google.spanner.admin.database.v1.DropDatabaseRequest) Test(org.junit.Test)

Aggregations

DropDatabaseRequest (com.google.spanner.admin.database.v1.DropDatabaseRequest)5 AbstractMessage (com.google.protobuf.AbstractMessage)2 Empty (com.google.protobuf.Empty)2 Test (org.junit.Test)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)1