From 742cddd256e8310fbbe670e542918d66ad5e9d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Fri, 13 Dec 2024 13:56:42 +0100 Subject: [PATCH] chore: make valid connection properties public Make the list of valid connection properties public, so tools that depend on the Connection API can use this to for example generate documentation for valid properties. --- .../connection/ConnectionProperties.java | 3 +-- .../connection/ConnectionProperty.java | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java index 0ca9b7256e2..972a2970a09 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java @@ -115,7 +115,6 @@ import com.google.common.collect.ImmutableMap; import com.google.spanner.v1.DirectedReadOptions; import java.time.Duration; -import java.util.Map; /** * Utility class that defines all known connection properties. This class will eventually replace @@ -541,7 +540,7 @@ class ConnectionProperties { BooleanConverter.INSTANCE, Context.USER); - static final Map> CONNECTION_PROPERTIES = + static final ImmutableMap> CONNECTION_PROPERTIES = CONNECTION_PROPERTIES_BUILDER.build(); /** Utility method for creating a new core {@link ConnectionProperty}. */ diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperty.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperty.java index c203d44203b..cb5c9f5db79 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperty.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperty.java @@ -19,6 +19,7 @@ import com.google.cloud.spanner.ErrorCode; import com.google.cloud.spanner.SpannerExceptionFactory; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import java.util.Locale; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -37,12 +38,16 @@ * connection state is an opt-in. */ public class ConnectionProperty { + /** The list of all supported connection properties. */ + public static ImmutableList> VALID_CONNECTION_PROPERTIES = + ImmutableList.copyOf(ConnectionProperties.CONNECTION_PROPERTIES.values()); + /** * Context indicates when a {@link ConnectionProperty} may be set. Each higher-ordinal value * includes the preceding values, meaning that a {@link ConnectionProperty} with {@link * Context#USER} can be set both at connection startup and during the connection's lifetime. */ - enum Context { + public enum Context { /** The property can only be set at startup of the connection. */ STARTUP, /** @@ -163,35 +168,38 @@ ConnectionPropertyValue convert(@Nullable String stringValue) { return new ConnectionPropertyValue<>(this, convertedValue, convertedValue); } - String getKey() { + @Nonnull + public String getKey() { return this.key; } - boolean hasExtension() { + public boolean hasExtension() { return this.extension != null; } - String getExtension() { + public String getExtension() { return this.extension; } - String getName() { + @Nonnull + public String getName() { return this.name; } - String getDescription() { + @Nonnull + public String getDescription() { return this.description; } - T getDefaultValue() { + public T getDefaultValue() { return this.defaultValue; } - T[] getValidValues() { + public T[] getValidValues() { return this.validValues; } - Context getContext() { + public Context getContext() { return this.context; } }