File tree Expand file tree Collapse file tree 4 files changed +28
-28
lines changed
google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection Expand file tree Collapse file tree 4 files changed +28
-28
lines changed Original file line number Diff line number Diff line change 1616
1717package com .google .cloud .spanner .connection ;
1818
19- import com .google .cloud .spanner .connection .ClientSideStatementImpl .CompileException ;
20-
2119/**
2220 * A {@link ClientSideStatementExecutor} is used to compile {@link ClientSideStatement}s from the
2321 * json source file, and to execute these against a {@link Connection} (through a {@link
2422 * ConnectionStatementExecutor}).
2523 */
2624interface ClientSideStatementExecutor {
2725
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-
3926 /**
4027 * Executes the {@link ClientSideStatementImpl} that has been compiled and registered with this
4128 * executor on the specified connection.
Original file line number Diff line number Diff line change 1919import com .google .cloud .spanner .SpannerException ;
2020import com .google .cloud .spanner .connection .StatementResult .ResultType ;
2121import com .google .common .base .Preconditions ;
22+ import java .lang .reflect .Constructor ;
2223import java .lang .reflect .InvocationTargetException ;
2324import java .util .Collections ;
2425import java .util .List ;
@@ -143,10 +144,12 @@ public String getMessage() {
143144 ClientSideStatementImpl compile () throws CompileException {
144145 try {
145146 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 );
150153 return this ;
151154 } catch (Exception e ) {
152155 throw new CompileException (e , this );
Original file line number Diff line number Diff line change 2424 * SHOW AUTOCOMMIT. The executor just calls a method with no parameters.
2525 */
2626class ClientSideStatementNoParamExecutor implements ClientSideStatementExecutor {
27- private Method method ;
27+ private final Method method ;
2828
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 {
3337 try {
3438 this .method = ConnectionStatementExecutor .class .getDeclaredMethod (statement .getMethodName ());
3539 } catch (NoSuchMethodException | SecurityException e ) {
Original file line number Diff line number Diff line change 3030 * AUTOCOMMIT=TRUE.
3131 */
3232class 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 ;
3737
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+ */
3845 @ SuppressWarnings ("unchecked" )
39- @ Override
40- public void compile (ClientSideStatementImpl statement ) throws CompileException {
46+ ClientSideStatementSetExecutor (ClientSideStatementImpl statement ) throws CompileException {
4147 Preconditions .checkNotNull (statement .getSetStatement ());
4248 try {
4349 this .statement = statement ;
You can’t perform that action at this time.
0 commit comments