Skip to content

Commit

Permalink
chore: make valid connection properties public
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olavloite committed Dec 13, 2024
1 parent 8547735 commit 742cddd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -541,7 +540,7 @@ class ConnectionProperties {
BooleanConverter.INSTANCE,
Context.USER);

static final Map<String, ConnectionProperty<?>> CONNECTION_PROPERTIES =
static final ImmutableMap<String, ConnectionProperty<?>> CONNECTION_PROPERTIES =
CONNECTION_PROPERTIES_BUILDER.build();

/** Utility method for creating a new core {@link ConnectionProperty}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,12 +38,16 @@
* connection state is an opt-in.
*/
public class ConnectionProperty<T> {
/** The list of all supported connection properties. */
public static ImmutableList<ConnectionProperty<?>> 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,
/**
Expand Down Expand Up @@ -163,35 +168,38 @@ ConnectionPropertyValue<T> 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;
}
}

0 comments on commit 742cddd

Please sign in to comment.