Skip to content

Commit

Permalink
fix sample indentations
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Aug 11, 2022
1 parent 7483a57 commit 71dbda6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 59 deletions.
Expand Up @@ -26,35 +26,32 @@
import java.util.concurrent.ExecutionException;

public class ListRolesSample {
static void listRoles() throws InterruptedException, ExecutionException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
String instanceId = "my-instance";
String databaseId = "my-database";
listRoles(projectId, instanceId, databaseId);
}
static void listRoles() throws InterruptedException, ExecutionException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
String instanceId = "my-instance";
String databaseId = "my-database";
listRoles(projectId, instanceId, databaseId);
}

static void listRoles(String projectId, String instanceId, String databaseId) {
try (Spanner spanner =
SpannerOptions.newBuilder()
.setProjectId(projectId)
.build()
.getService()) {
final DatabaseAdminClient adminClient = spanner.getDatabaseAdminClient();
String databasePath = DatabaseId.of(projectId, instanceId, databaseId).getName();
for (DatabaseRole role : adminClient.listDatabaseRoles(instanceId, databaseId).iterateAll()) {
if (!role.getName().startsWith(databasePath + "/databaseRoles/")) {
throw new RuntimeException(
"Role +"
+ role.getName()
+ "does not have prefix ["
+ databasePath
+ "/databaseRoles/"
+ "]");
}
System.out.printf("%s%n", role.getName());
}
static void listRoles(String projectId, String instanceId, String databaseId) {
try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
final DatabaseAdminClient adminClient = spanner.getDatabaseAdminClient();
String databasePath = DatabaseId.of(projectId, instanceId, databaseId).getName();
for (DatabaseRole role : adminClient.listDatabaseRoles(instanceId, databaseId).iterateAll()) {
if (!role.getName().startsWith(databasePath + "/databaseRoles/")) {
throw new RuntimeException(
"Role +"
+ role.getName()
+ "does not have prefix ["
+ databasePath
+ "/databaseRoles/"
+ "]");
}
System.out.printf("%s%n", role.getName());
}
}
}
}
// [END spanner_list_database_roles]
// [END spanner_list_database_roles]
Expand Up @@ -28,38 +28,38 @@
import java.util.concurrent.ExecutionException;

public class ReadDataWithRoleSample {
static void readDataWithRole() throws InterruptedException, ExecutionException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
String instanceId = "my-instance";
String databaseId = "my-database";
String role = "my-role";
readDataWithRole(projectId, instanceId, databaseId, role);
}
static void readDataWithRole() throws InterruptedException, ExecutionException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
String instanceId = "my-instance";
String databaseId = "my-database";
String role = "my-role";
readDataWithRole(projectId, instanceId, databaseId, role);
}

static void readDataWithRole(String projectId, String instanceId, String databaseId, String role)
throws InterruptedException, ExecutionException {
try (Spanner spanner =
SpannerOptions.newBuilder()
.setProjectId(projectId)
.setDatabaseRole(role)
.build()
.getService()) {
final DatabaseClient dbClient =
spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
try (ResultSet resultSet =
dbClient
.singleUse()
.read(
"Albums",
KeySet.all(), // Read all rows in a table.
Arrays.asList("SingerId", "AlbumId", "AlbumTitle"))) {
while (resultSet.next()) {
System.out.printf(
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
}
}
static void readDataWithRole(String projectId, String instanceId, String databaseId, String role)
throws InterruptedException, ExecutionException {
try (Spanner spanner =
SpannerOptions.newBuilder()
.setProjectId(projectId)
.setDatabaseRole(role)
.build()
.getService()) {
final DatabaseClient dbClient =
spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
try (ResultSet resultSet =
dbClient
.singleUse()
.read(
"Albums",
KeySet.all(), // Read all rows in a table.
Arrays.asList("SingerId", "AlbumId", "AlbumTitle"))) {
while (resultSet.next()) {
System.out.printf(
"%d %d %s\n", resultSet.getLong(0), resultSet.getLong(1), resultSet.getString(2));
}
}
}
}
}
// [END spanner_read_data_with_database_role]
// [END spanner_read_data_with_database_role]

0 comments on commit 71dbda6

Please sign in to comment.