File tree
Expand file treeCollapse file tree4 files changed
+28
-28
lines changed google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection
Expand file treeCollapse file tree4 files changed
+28
-28
lines changed Original file line number | Diff line number | Diff line change |
---|
|
16 | 16 |
|
17 | 17 | package com.google.cloud.spanner.connection;
|
18 | 18 |
|
19 |
| -import com.google.cloud.spanner.connection.ClientSideStatementImpl.CompileException; |
20 |
| - |
21 | 19 | /**
|
22 | 20 | * A {@link ClientSideStatementExecutor} is used to compile {@link ClientSideStatement}s from the
|
23 | 21 | * json source file, and to execute these against a {@link Connection} (through a {@link
|
24 | 22 | * ConnectionStatementExecutor}).
|
25 | 23 | */
|
26 | 24 | interface ClientSideStatementExecutor {
|
27 | 25 |
|
28 |
| -/** |
29 |
| -* Compiles the given {@link ClientSideStatementImpl} and registers this statement with this |
30 |
| -* executor. A statement must be compiled before it can be executed. The parser automatically |
31 |
| -* compiles all available statements during initialization. |
32 |
| -* |
33 |
| -* @param statement The statement to compile. |
34 |
| -* @throws CompileException If the statement could not be compiled. This should never happen, as |
35 |
| -* it would indicate that an invalid statement has been defined in the source file. |
36 |
| -*/ |
37 |
| -void compile(ClientSideStatementImpl statement) throws CompileException; |
38 |
| - |
39 | 26 | /**
|
40 | 27 | * Executes the {@link ClientSideStatementImpl} that has been compiled and registered with this
|
41 | 28 | * executor on the specified connection.
|
|
Original file line number | Diff line number | Diff line change |
---|
|
19 | 19 | import com.google.cloud.spanner.SpannerException;
|
20 | 20 | import com.google.cloud.spanner.connection.StatementResult.ResultType;
|
21 | 21 | import com.google.common.base.Preconditions;
|
| 22 | +import java.lang.reflect.Constructor; |
22 | 23 | import java.lang.reflect.InvocationTargetException;
|
23 | 24 | import java.util.Collections;
|
24 | 25 | import java.util.List;
|
@@ -143,10 +144,12 @@ public String getMessage() {
|
143 | 144 | ClientSideStatementImpl compile() throws CompileException {
|
144 | 145 | try {
|
145 | 146 | this.pattern = Pattern.compile(regex);
|
146 |
| -this.executor = |
147 |
| -(ClientSideStatementExecutor) |
148 |
| -Class.forName(getClass().getPackage().getName() + "." + executorName).newInstance(); |
149 |
| -this.executor.compile(this); |
| 147 | +@SuppressWarnings("unchecked") |
| 148 | +Constructor<ClientSideStatementExecutor> constructor = |
| 149 | +(Constructor<ClientSideStatementExecutor>) |
| 150 | +Class.forName(getClass().getPackage().getName() + "." + executorName) |
| 151 | +.getDeclaredConstructor(ClientSideStatementImpl.class); |
| 152 | +this.executor = constructor.newInstance(this); |
150 | 153 | return this;
|
151 | 154 | } catch (Exception e) {
|
152 | 155 | throw new CompileException(e, this);
|
|
Original file line number | Diff line number | Diff line change |
---|
|
24 | 24 | * SHOW AUTOCOMMIT. The executor just calls a method with no parameters.
|
25 | 25 | */
|
26 | 26 | class ClientSideStatementNoParamExecutor implements ClientSideStatementExecutor {
|
27 |
| -private Method method; |
| 27 | +private final Method method; |
28 | 28 |
|
29 |
| -ClientSideStatementNoParamExecutor() {} |
30 |
| - |
31 |
| -@Override |
32 |
| -public void compile(ClientSideStatementImpl statement) throws CompileException { |
| 29 | +/** |
| 30 | +* Creates and compiles the given {@link ClientSideStatementImpl}. |
| 31 | +* |
| 32 | +* @param statement The statement to compile. |
| 33 | +* @throws CompileException If the statement could not be compiled. This should never happen, as |
| 34 | +* it would indicate that an invalid statement has been defined in the source file. |
| 35 | +*/ |
| 36 | +ClientSideStatementNoParamExecutor(ClientSideStatementImpl statement) throws CompileException { |
33 | 37 | try {
|
34 | 38 | this.method = ConnectionStatementExecutor.class.getDeclaredMethod(statement.getMethodName());
|
35 | 39 | } catch (NoSuchMethodException | SecurityException e) {
|
|
Original file line number | Diff line number | Diff line change |
---|
|
30 | 30 | * AUTOCOMMIT=TRUE.
|
31 | 31 | */
|
32 | 32 | class ClientSideStatementSetExecutor<T> implements ClientSideStatementExecutor {
|
33 |
| -private ClientSideStatementImpl statement; |
34 |
| -private Method method; |
35 |
| -private ClientSideStatementValueConverter<T> converter; |
36 |
| -private Pattern allowedValuesPattern; |
| 33 | +private final ClientSideStatementImpl statement; |
| 34 | +private final Method method; |
| 35 | +private final ClientSideStatementValueConverter<T> converter; |
| 36 | +private final Pattern allowedValuesPattern; |
37 | 37 |
|
| 38 | +/** |
| 39 | +* Creates and compiles the given {@link ClientSideStatementImpl}. |
| 40 | +* |
| 41 | +* @param statement The statement to compile. |
| 42 | +* @throws CompileException If the statement could not be compiled. This should never happen, as |
| 43 | +* it would indicate that an invalid statement has been defined in the source file. |
| 44 | +*/ |
38 | 45 | @SuppressWarnings("unchecked")
|
39 |
| -@Override |
40 |
| -public void compile(ClientSideStatementImpl statement) throws CompileException { |
| 46 | +ClientSideStatementSetExecutor(ClientSideStatementImpl statement) throws CompileException { |
41 | 47 | Preconditions.checkNotNull(statement.getSetStatement());
|
42 | 48 | try {
|
43 | 49 | this.statement = statement;
|
|
You can’t perform that action at this time.
0 commit comments