Skip to content

Commit 1658a51

Browse files
authored
Batch read connection api native adjustments (#2569)
* chore: add ClientSideStatementPartitionExecutor to SpannerFeature * chore: wrap AbstractStatementParser static initialization in try/catch * chore: add ClientSideStatementRunPartitionExecutor to SpannerFeature * chore: add ClientSideStatementRunPartitionedQueryExecutor to SpannerFeature * chore: lint formatting
1 parent 89889ee commit 1658a51

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/AbstractStatementParser.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.Objects;
3535
import java.util.Set;
3636
import java.util.concurrent.Callable;
37+
import java.util.logging.Level;
38+
import java.util.logging.Logger;
3739

3840
/**
3941
* Internal class for the Spanner Connection API.
@@ -91,8 +93,7 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
9193
*/
9294

9395
/** Begins a transaction. */
94-
static final ParsedStatement BEGIN_STATEMENT =
95-
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("BEGIN"));
96+
static final ParsedStatement BEGIN_STATEMENT;
9697

9798
/**
9899
* Create a COMMIT statement to use with the {@link #commit()} method to allow it to be cancelled,
@@ -104,14 +105,10 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
104105
* #commit()} method is called directly, we do not have a {@link ParsedStatement}, and the method
105106
* uses this statement instead in order to use the same logic as the other statements.
106107
*/
107-
static final ParsedStatement COMMIT_STATEMENT =
108-
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
109-
.parse(Statement.of("COMMIT"));
108+
static final ParsedStatement COMMIT_STATEMENT;
110109

111110
/** The {@link Statement} and {@link Callable} for rollbacks */
112-
static final ParsedStatement ROLLBACK_STATEMENT =
113-
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
114-
.parse(Statement.of("ROLLBACK"));
111+
static final ParsedStatement ROLLBACK_STATEMENT;
115112

116113
/**
117114
* Create a RUN BATCH statement to use with the {@link #executeBatchUpdate(Iterable)} method to
@@ -124,9 +121,22 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
124121
* and the method uses this statement instead in order to use the same logic as the other
125122
* statements.
126123
*/
127-
static final ParsedStatement RUN_BATCH_STATEMENT =
128-
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
129-
.parse(Statement.of("RUN BATCH"));
124+
static final ParsedStatement RUN_BATCH_STATEMENT;
125+
126+
static {
127+
try {
128+
BEGIN_STATEMENT = getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("BEGIN"));
129+
COMMIT_STATEMENT = getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("COMMIT"));
130+
ROLLBACK_STATEMENT = getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("ROLLBACK"));
131+
RUN_BATCH_STATEMENT =
132+
getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("RUN BATCH"));
133+
134+
} catch (Throwable ex) {
135+
Logger logger = Logger.getLogger(AbstractStatementParser.class.getName());
136+
logger.log(Level.SEVERE, "Static initialization failure.", ex);
137+
throw ex;
138+
}
139+
}
130140

131141
/** The type of statement that has been recognized by the parser. */
132142
@InternalApi

google-cloud-spanner/src/main/java/com/google/cloud/spanner/nativeimage/SpannerFeature.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ final class SpannerFeature implements Feature {
4343
"com.google.cloud.spanner.connection.ClientSideStatementPgBeginExecutor";
4444
private static final String CLIENT_SIDE_STATEMENT_EXPLAIN_EXECUTOR =
4545
"com.google.cloud.spanner.connection.ClientSideStatementExplainExecutor";
46+
private static final String CLIENT_SIDE_STATEMENT_PARTITION_EXECUTOR =
47+
"com.google.cloud.spanner.connection.ClientSideStatementPartitionExecutor";
48+
private static final String CLIENT_SIDE_STATEMENT_RUN_PARTITION_EXECUTOR =
49+
"com.google.cloud.spanner.connection.ClientSideStatementRunPartitionExecutor";
50+
private static final String CLIENT_SIDE_STATEMENT_RUN_PARTITIONED_QUERY_EXECUTOR =
51+
"com.google.cloud.spanner.connection.ClientSideStatementRunPartitionedQueryExecutor";
4652
private static final String ABSTRACT_STATEMENT_PARSER =
4753
"com.google.cloud.spanner.connection.AbstractStatementParser";
4854
private static final String STATEMENT_PARSER =
@@ -70,6 +76,17 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
7076
if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) {
7177
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR);
7278
}
79+
if (access.findClassByName(CLIENT_SIDE_STATEMENT_PARTITION_EXECUTOR) != null) {
80+
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_PARTITION_EXECUTOR);
81+
}
82+
if (access.findClassByName(CLIENT_SIDE_STATEMENT_RUN_PARTITION_EXECUTOR) != null) {
83+
NativeImageUtils.registerClassForReflection(
84+
access, CLIENT_SIDE_STATEMENT_RUN_PARTITION_EXECUTOR);
85+
}
86+
if (access.findClassByName(CLIENT_SIDE_STATEMENT_RUN_PARTITIONED_QUERY_EXECUTOR) != null) {
87+
NativeImageUtils.registerClassForReflection(
88+
access, CLIENT_SIDE_STATEMENT_RUN_PARTITIONED_QUERY_EXECUTOR);
89+
}
7390
if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) {
7491
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER);
7592
}

0 commit comments

Comments
 (0)