Skip to content

Commit

Permalink
chore: fix lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
arpan14 committed Jan 10, 2024
1 parent 1d2ed9b commit 03bef0c
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ static void addAndDropDatabaseRole(
try {
System.out.println("Waiting for role create operation to complete...");
databaseAdminClient.updateDatabaseDdlAsync(
DatabaseName.of(projectId, instanceId, databaseId),
ImmutableList.of(
String.format("CREATE ROLE `%s`", parentRole),
String.format("GRANT SELECT ON TABLE Albums TO ROLE `%s`", parentRole),
String.format("CREATE ROLE `%s`", childRole),
String.format("GRANT ROLE `%s` TO ROLE `%s`", parentRole, childRole))).get(5, TimeUnit.MINUTES);
DatabaseName.of(projectId, instanceId, databaseId),
ImmutableList.of(
String.format("CREATE ROLE `%s`", parentRole),
String.format("GRANT SELECT ON TABLE Albums TO ROLE `%s`", parentRole),
String.format("CREATE ROLE `%s`", childRole),
String.format("GRANT ROLE `%s` TO ROLE `%s`", parentRole, childRole)))
.get(5, TimeUnit.MINUTES);
System.out.printf(
"Created roles %s and %s and granted privileges%n", parentRole, childRole);
// Delete role and membership.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ static void addJsonbColumn(String projectId, String instanceId, String databaseI
// Wait for the operation to finish.
// This will throw an ExecutionException if the operation fails.
databaseAdminClient.updateDatabaseDdlAsync(
DatabaseName.of(projectId, instanceId, databaseId),
ImmutableList.of("ALTER TABLE Venues ADD COLUMN VenueDetails JSONB")).get();
DatabaseName.of(projectId, instanceId, databaseId),
ImmutableList.of("ALTER TABLE Venues ADD COLUMN VenueDetails JSONB")).get();
System.out.printf("Successfully added column `VenueDetails`%n");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_add_numeric_column]

import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
import com.google.common.collect.ImmutableList;
import com.google.spanner.admin.database.v1.DatabaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_alter_sequence]

import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ResultSet;
Expand All @@ -34,6 +35,7 @@
import java.util.concurrent.TimeoutException;

public class AlterSequenceSample {

static void alterSequence() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
Expand All @@ -42,7 +44,8 @@ static void alterSequence() throws IOException {
alterSequence(projectId, instanceId, databaseId);
}

static void alterSequence(String projectId, String instanceId, String databaseId) throws IOException {
static void alterSequence(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();
try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_alter_table_with_foreign_key_delete_cascade]

import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
import com.google.common.collect.ImmutableList;
import com.google.spanner.admin.database.v1.DatabaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void createDatabaseWithVersionRetentionPeriod(String projectId,
.setParent(InstanceName.of(projectId, instanceId).toString())
.setCreateStatement("CREATE DATABASE `" + databaseId + "`")
.addAllExtraStatements(Lists.newArrayList("ALTER DATABASE " + "`" + databaseId + "`"
+ " SET OPTIONS ( version_retention_period = '" + versionRetentionPeriod + "' )")).build();
+ " SET OPTIONS ( version_retention_period = '" + versionRetentionPeriod + "' )"))
.build();
Database database =
databaseAdminClient.createDatabaseAsync(request).get();
System.out.println("Created database [" + database.getName() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

//[START spanner_create_instance]

import com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient;
import com.google.spanner.admin.instance.v1.CreateInstanceRequest;
import com.google.spanner.admin.instance.v1.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_create_sequence]

import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ResultSet;
Expand All @@ -34,6 +35,7 @@
import java.util.concurrent.TimeoutException;

public class CreateSequenceSample {

static void createSequence() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
Expand All @@ -42,7 +44,8 @@ static void createSequence() throws IOException {
createSequence(projectId, instanceId, databaseId);
}

static void createSequence(String projectId, String instanceId, String databaseId) throws IOException {
static void createSequence(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();

try (Spanner spanner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_create_table_with_foreign_key_delete_cascade]

import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
import com.google.common.collect.ImmutableList;
import com.google.spanner.admin.database.v1.CreateDatabaseRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_drop_foreign_key_constraint_delete_cascade]

import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
import com.google.common.collect.ImmutableList;
import com.google.spanner.admin.database.v1.DatabaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_drop_sequence]

import com.google.cloud.spanner.SpannerExceptionFactory;
import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
import com.google.common.collect.ImmutableList;
Expand All @@ -27,6 +28,7 @@
import java.util.concurrent.TimeoutException;

public class DropSequenceSample {

static void dropSequence() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
Expand All @@ -35,7 +37,8 @@ static void dropSequence() throws IOException {
dropSequence(projectId, instanceId, databaseId);
}

static void dropSequence(String projectId, String instanceId, String databaseId) throws IOException {
static void dropSequence(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();
try {
databaseAdminClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void listDatabases(String projectId, String instanceId) throws IOExceptio

System.out.println("Databases for projects/" + projectId + "/instances/" + instanceId);

for(ListDatabasesPage page: response.iteratePages()) {
for (ListDatabasesPage page : response.iteratePages()) {
for (Database database : page.iterateAll()) {
final String defaultLeader = database.getDefaultLeader().equals("")
? "" : "(default leader = " + database.getDefaultLeader() + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_postgresql_alter_sequence]

import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ResultSet;
Expand All @@ -34,6 +35,7 @@
import java.util.concurrent.TimeoutException;

public class PgAlterSequenceSample {

static void pgAlterSequence() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
Expand All @@ -42,7 +44,8 @@ static void pgAlterSequence() throws IOException {
pgAlterSequence(projectId, instanceId, databaseId);
}

static void pgAlterSequence(String projectId, String instanceId, String databaseId) throws IOException {
static void pgAlterSequence(String projectId, String instanceId, String databaseId)
throws IOException {
try (Spanner spanner =
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
final DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ static void pgCaseSensitivity() throws IOException {
pgCaseSensitivity(projectId, instanceId, databaseId);
}

static void pgCaseSensitivity(String projectId, String instanceId, String databaseId) throws IOException {
static void pgCaseSensitivity(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();

try (Spanner spanner =
Expand All @@ -58,17 +59,17 @@ static void pgCaseSensitivity(String projectId, String instanceId, String databa
// See https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
// for more information.
databaseAdminClient.updateDatabaseDdlAsync(
DatabaseName.of(projectId, instanceId, databaseId),
Lists.newArrayList(
"CREATE TABLE Singers ("
// SingerId will be folded to `singerid`.
+ " SingerId bigint NOT NULL PRIMARY KEY,"
// FirstName and LastName are double-quoted and will therefore retain their
// mixed case and are case-sensitive. This means that any statement that
// references any of these columns must use double quotes.
+ " \"FirstName\" varchar(1024) NOT NULL,"
+ " \"LastName\" varchar(1024) NOT NULL"
+ ")")).get();
DatabaseName.of(projectId, instanceId, databaseId),
Lists.newArrayList(
"CREATE TABLE Singers ("
// SingerId will be folded to `singerid`.
+ " SingerId bigint NOT NULL PRIMARY KEY,"
// FirstName and LastName are double-quoted and will therefore retain their
// mixed case and are case-sensitive. This means that any statement that
// references any of these columns must use double quotes.
+ " \"FirstName\" varchar(1024) NOT NULL,"
+ " \"LastName\" varchar(1024) NOT NULL"
+ ")")).get();

DatabaseClient client =
spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_postgresql_create_sequence]

import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.ResultSet;
Expand All @@ -34,6 +35,7 @@
import java.util.concurrent.TimeoutException;

public class PgCreateSequenceSample {

static void pgCreateSequence() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
Expand All @@ -42,7 +44,8 @@ static void pgCreateSequence() throws IOException {
pgCreateSequence(projectId, instanceId, databaseId);
}

static void pgCreateSequence(String projectId, String instanceId, String databaseId) throws IOException {
static void pgCreateSequence(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();

try (Spanner spanner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_postgresql_drop_sequence]

import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerExceptionFactory;
import com.google.cloud.spanner.SpannerOptions;
Expand All @@ -29,6 +30,7 @@
import java.util.concurrent.TimeoutException;

public class PgDropSequenceSample {

static void pgDropSequence() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
Expand All @@ -37,7 +39,8 @@ static void pgDropSequence() throws IOException {
pgDropSequence(projectId, instanceId, databaseId);
}

static void pgDropSequence(String projectId, String instanceId, String databaseId) throws IOException {
static void pgDropSequence(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();

try (Spanner spanner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ static void pgInterleavedTable() throws IOException {
pgInterleavedTable(projectId, instanceId, databaseId);
}

static void pgInterleavedTable(String projectId, String instanceId, String databaseId) throws IOException {
static void pgInterleavedTable(String projectId, String instanceId, String databaseId)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();
try {
// The Spanner PostgreSQL dialect extends the PostgreSQL dialect with certain Spanner
Expand All @@ -45,18 +46,18 @@ static void pgInterleavedTable(String projectId, String instanceId, String datab
databaseAdminClient.updateDatabaseDdlAsync(DatabaseName.of(projectId,
instanceId,
databaseId),
Arrays.asList(
"CREATE TABLE Singers ("
+ " SingerId bigint NOT NULL PRIMARY KEY,"
+ " FirstName varchar(1024) NOT NULL,"
+ " LastName varchar(1024) NOT NULL"
+ ")",
"CREATE TABLE Albums ("
+ " SingerId bigint NOT NULL,"
+ " AlbumId bigint NOT NULL,"
+ " Title varchar(1024) NOT NULL,"
+ " PRIMARY KEY (SingerId, AlbumId)"
+ ") INTERLEAVE IN PARENT Singers ON DELETE CASCADE")).get();
Arrays.asList(
"CREATE TABLE Singers ("
+ " SingerId bigint NOT NULL PRIMARY KEY,"
+ " FirstName varchar(1024) NOT NULL,"
+ " LastName varchar(1024) NOT NULL"
+ ")",
"CREATE TABLE Albums ("
+ " SingerId bigint NOT NULL,"
+ " AlbumId bigint NOT NULL,"
+ " Title varchar(1024) NOT NULL,"
+ " PRIMARY KEY (SingerId, AlbumId)"
+ ") INTERLEAVE IN PARENT Singers ON DELETE CASCADE")).get();
System.out.println("Created interleaved table hierarchy using PostgreSQL dialect");
} catch (ExecutionException e) {
// If the operation failed during execution, expose the cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.example.spanner.admin.generated;

// [START spanner_update_database]

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.spanner.SpannerExceptionFactory;
import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static void updateDatabaseWithDefaultLeader() throws IOException {
}

static void updateDatabaseWithDefaultLeader(
String projectId, String instanceId, String databaseId, String defaultLeader) throws IOException {
String projectId, String instanceId, String databaseId, String defaultLeader)
throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Integration tests for FGAC samples for GoogleStandardSql dialect. */
/**
* Integration tests for FGAC samples for GoogleStandardSql dialect.
*/
@RunWith(JUnit4.class)
public class DatabaseRolesIT extends SampleTestBaseV2 {

Expand All @@ -47,7 +49,8 @@ public static void createTestDatabase() throws Exception {
final CreateDatabaseRequest request =
CreateDatabaseRequest.newBuilder()
.setParent(
com.google.spanner.admin.database.v1.InstanceName.of(projectId, instanceId).toString())
com.google.spanner.admin.database.v1.InstanceName.of(projectId, instanceId)
.toString())
.setCreateStatement("CREATE DATABASE `" + database + "`")
.addAllExtraStatements(Lists.newArrayList(
"CREATE TABLE Singers ("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void testGetDatabaseDdl() throws Exception {
final CreateDatabaseRequest request =
CreateDatabaseRequest.newBuilder()
.setParent(
com.google.spanner.admin.database.v1.InstanceName.of(projectId, multiRegionalInstanceId).toString())
com.google.spanner.admin.database.v1.InstanceName.of(projectId,
multiRegionalInstanceId).toString())
.setCreateStatement("CREATE DATABASE `" + databaseId + "`")
.addAllExtraStatements(Lists.newArrayList(
"CREATE TABLE Singers (Id INT64 NOT NULL) PRIMARY KEY (Id)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static String getInstanceName(final String projectId, final String instanceId) {

static String getCreateDatabaseStatement(
final String databaseName, final DatabaseDialect dialect) {
if(dialect == DatabaseDialect.GOOGLE_STANDARD_SQL) {
if (dialect == DatabaseDialect.GOOGLE_STANDARD_SQL) {
return "CREATE DATABASE `" + databaseName + "`";
} else {
return "CREATE DATABASE \"" + databaseName + "\"";
Expand Down
Loading

0 comments on commit 03bef0c

Please sign in to comment.