Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java-spanner/samples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.76.0</version>
<version>26.79.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -228,7 +228,7 @@
<archive>
<index>false</index>
<manifest>
<mainClass>com.example.spanner.admin.archived.SpannerSample</mainClass>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is intentional as we want to pick the newer version the mentioned class. Do you see any problems with this?

<mainClass>com.example.spanner.SpannerSample</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, else this cause compilation failure. essentially its missing is current version of code.


public class MutableCredentialsExample {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.example.spanner;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.setExperimentalHostSpannerOptions;

import com.google.api.gax.paging.Page;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
Expand Down Expand Up @@ -1192,17 +1195,19 @@ static void queryWithNumeric(DatabaseClient dbClient) {

// [START spanner_postgresql_create_client_with_query_options]
static void clientWithQueryOptions(DatabaseId db) {
SpannerOptions options =
SpannerOptions.newBuilder()
.setDefaultQueryOptions(
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
builder.setDefaultQueryOptions(
db, ExecuteSqlRequest.QueryOptions
.newBuilder()
.setOptimizerVersion("1")
// The list of available statistics packages can be found by querying the
// "INFORMATION_SCHEMA.spanner_postgresql_STATISTICS" table.
.setOptimizerStatisticsPackage("latest")
.build())
.build();
.build());
if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
SpannerOptions options = builder.build();
Spanner spanner = options.getService();
DatabaseClient dbClient = spanner.getDatabaseClient(db);
try (ResultSet resultSet =
Expand Down Expand Up @@ -1548,7 +1553,11 @@ public static void main(String[] args) {
printUsageAndExit();
}
// [START spanner_init_client]
SpannerOptions options = SpannerOptions.newBuilder().build();
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
SpannerOptions options = builder.build();
Spanner spanner = options.getService();
DatabaseAdminClient dbAdminClient = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.example.spanner;

//[START spanner_query_information_schema_database_options]
// [START spanner_query_information_schema_database_options]

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.setExperimentalHostSpannerOptions;

import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
Expand All @@ -37,33 +40,34 @@ static void queryInformationSchemaDatabaseOptions() {

static void queryInformationSchemaDatabaseOptions(
String projectId, String instanceId, String databaseId) {
try (Spanner spanner = SpannerOptions
.newBuilder()
.setProjectId(projectId)
.build()
.getService()) {
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
builder.setProjectId(projectId);
if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
try (Spanner spanner = builder.build().getService()) {
final DatabaseId id = DatabaseId.of(projectId, instanceId, databaseId);
final DatabaseClient databaseClient = spanner.getDatabaseClient(id);

try (ResultSet resultSet = databaseClient
.singleUse()
.executeQuery(Statement.of(
"SELECT OPTION_NAME, OPTION_VALUE"
+ " FROM INFORMATION_SCHEMA.DATABASE_OPTIONS"
+ " WHERE OPTION_NAME = 'default_leader'")
)) {
try (ResultSet resultSet =
databaseClient
.singleUse()
.executeQuery(
Statement.of(
"SELECT OPTION_NAME, OPTION_VALUE"
+ " FROM INFORMATION_SCHEMA.DATABASE_OPTIONS"
+ " WHERE OPTION_NAME = 'default_leader'"))) {
if (resultSet.next()) {
final String optionName = resultSet.getString("OPTION_NAME");
final String optionValue = resultSet.getString("OPTION_VALUE");

System.out.println("The " + optionName + " for " + id + " is " + optionValue);
} else {
System.out.println(
"Database " + id + " does not have a value for option 'default_leader'"
);
"Database " + id + " does not have a value for option 'default_leader'");
}
}
}
}
}
//[END spanner_query_information_schema_database_options]
// [END spanner_query_information_schema_database_options]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.example.spanner;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.setExperimentalHostSpannerOptions;

import com.google.cloud.Timestamp;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
Expand Down Expand Up @@ -554,7 +557,11 @@ public static void main(String[] args) {
if (args.length != 3 && args.length != 4) {
printUsageAndExit();
}
SpannerOptions options = SpannerOptions.newBuilder().build();
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
SpannerOptions options = builder.build();
Spanner spanner = options.getService();
DatabaseAdminClient dbAdminClient = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.example.spanner;

import static com.google.cloud.spanner.testing.ExperimentalHostHelper.isExperimentalHost;
import static com.google.cloud.spanner.testing.ExperimentalHostHelper.setExperimentalHostSpannerOptions;

import static com.google.cloud.spanner.Type.StructField;

import com.google.api.gax.longrunning.OperationFuture;
Expand Down Expand Up @@ -1503,17 +1506,19 @@ static void queryWithNumeric(DatabaseClient dbClient) {

// [START spanner_create_client_with_query_options]
static void clientWithQueryOptions(DatabaseId db) {
SpannerOptions options =
SpannerOptions.newBuilder()
.setDefaultQueryOptions(
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
builder.setDefaultQueryOptions(
db, QueryOptions
.newBuilder()
.setOptimizerVersion("1")
// The list of available statistics packages can be found by querying the
// "INFORMATION_SCHEMA.SPANNER_STATISTICS" table.
.setOptimizerStatisticsPackage("latest")
.build())
.build();
.build());
if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
SpannerOptions options = builder.build();
Spanner spanner = options.getService();
DatabaseClient dbClient = spanner.getDatabaseClient(db);
try (ResultSet resultSet =
Expand Down Expand Up @@ -2231,7 +2236,11 @@ public static void main(String[] args) {
printUsageAndExit();
}
// [START init_client]
SpannerOptions options = SpannerOptions.newBuilder().build();
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
if (isExperimentalHost()) {
setExperimentalHostSpannerOptions(builder);
}
SpannerOptions options = builder.build();
Spanner spanner = options.getService();
DatabaseAdminClient dbAdminClient = null;
try {
Expand Down
Loading