-
Notifications
You must be signed in to change notification settings - Fork 141
feat: add support for Proto Columns to Connection API #2495
Changes from all commits
10ee620
7feaf10
02a31b6
7746e08
dcbe166
76fdd77
33044c4
ad0873a
a5f1697
e8fed61
b15dd75
0c9f4f6
f97b249
a42761b
865fc0c
f1e3f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,11 @@ | |
| import com.google.cloud.spanner.connection.PgTransactionMode.IsolationLevel; | ||
| import com.google.common.base.Function; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Strings; | ||
| import com.google.protobuf.Duration; | ||
| import com.google.protobuf.util.Durations; | ||
| import com.google.spanner.v1.RequestOptions.Priority; | ||
| import java.util.Base64; | ||
| import java.util.EnumSet; | ||
| import java.util.HashMap; | ||
| import java.util.Locale; | ||
|
|
@@ -494,4 +496,46 @@ public String convert(String value) { | |
| return value.substring(7).trim(); | ||
| } | ||
| } | ||
|
|
||
| /** Converter for converting Base64 encoded string to byte[] */ | ||
| static class ProtoDescriptorsConverter implements ClientSideStatementValueConverter<byte[]> { | ||
|
|
||
| public ProtoDescriptorsConverter(String allowedValues) {} | ||
|
|
||
| @Override | ||
| public Class<byte[]> getParameterClass() { | ||
| return byte[].class; | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] convert(String value) { | ||
| if (value == null || value.length() == 0 || value.equalsIgnoreCase("null")) { | ||
| return null; | ||
| } | ||
| try { | ||
| return Base64.getDecoder().decode(value); | ||
| } catch (IllegalArgumentException e) { | ||
| return null; | ||
|
harshachinta marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| /** Converter for converting String that take in file path as input to String */ | ||
| static class ProtoDescriptorsFileConverter implements ClientSideStatementValueConverter<String> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We supporting reading from the file here? If Yes where should file be located just on resources or local path ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we are supporting reading from a file path given through a client side statement. This is needed to support ORM's and other frameworks. This discussion is available in the design doc. |
||
|
|
||
| public ProtoDescriptorsFileConverter(String allowedValues) {} | ||
|
|
||
| @Override | ||
| public Class<String> getParameterClass() { | ||
| return String.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String convert(String filePath) { | ||
| if (Strings.isNullOrEmpty(filePath)) { | ||
| return null; | ||
| } | ||
| return filePath; | ||
|
harshachinta marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |||||
| import java.util.Iterator; | ||||||
| import java.util.concurrent.ExecutionException; | ||||||
| import java.util.concurrent.TimeUnit; | ||||||
| import javax.annotation.Nonnull; | ||||||
|
|
||||||
| /** | ||||||
| * Internal connection API for Google Cloud Spanner. This interface may introduce breaking changes | ||||||
|
|
@@ -382,6 +383,25 @@ default String getStatementTag() { | |||||
| throw new UnsupportedOperationException(); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Sets the proto descriptors to use for the next DDL statement (single or batch) that will be | ||||||
| * executed. The proto descriptor is automatically cleared after the statement is executed. | ||||||
| * | ||||||
| * @param protoDescriptors The proto descriptors to use with the next DDL statement (single or | ||||||
| * batch) that will be executed on this connection. | ||||||
| */ | ||||||
| default void setProtoDescriptors(@Nonnull byte[] protoDescriptors) { | ||||||
| throw new UnsupportedOperationException(); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @return The proto descriptor that will be used with the next DDL statement (single or batch) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * that is executed on this connection. | ||||||
| */ | ||||||
| default byte[] getProtoDescriptors() { | ||||||
| throw new UnsupportedOperationException(); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @return <code>true</code> if this connection will automatically retry read/write transactions | ||||||
| * that abort. This method may only be called when the connection is in read/write | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add a
NonNullannotation to the argument here. Similarly in other places wherever a null value is not expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These convert methods are not used by customers and is getting called from link. We generally use this annotation to warn users when they pass
null. But here it is used in code internally and as users don't use this function, I guess it is not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is being called from the same package and not meant to be public to customers. Then, should we make the methods package-protected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods cannot be package-private, because they implement a method from an interface. The class itself is package-private, which protects the class and all its methods from being used by 'outside' users.