34
34
import java .util .Objects ;
35
35
import java .util .Set ;
36
36
import java .util .concurrent .Callable ;
37
+ import java .util .logging .Level ;
38
+ import java .util .logging .Logger ;
37
39
38
40
/**
39
41
* Internal class for the Spanner Connection API.
@@ -91,8 +93,7 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
91
93
*/
92
94
93
95
/** 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 ;
96
97
97
98
/**
98
99
* 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) {
104
105
* #commit()} method is called directly, we do not have a {@link ParsedStatement}, and the method
105
106
* uses this statement instead in order to use the same logic as the other statements.
106
107
*/
107
- static final ParsedStatement COMMIT_STATEMENT =
108
- AbstractStatementParser .getInstance (Dialect .GOOGLE_STANDARD_SQL )
109
- .parse (Statement .of ("COMMIT" ));
108
+ static final ParsedStatement COMMIT_STATEMENT ;
110
109
111
110
/** 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 ;
115
112
116
113
/**
117
114
* Create a RUN BATCH statement to use with the {@link #executeBatchUpdate(Iterable)} method to
@@ -124,9 +121,22 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
124
121
* and the method uses this statement instead in order to use the same logic as the other
125
122
* statements.
126
123
*/
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
+ }
130
140
131
141
/** The type of statement that has been recognized by the parser. */
132
142
@ InternalApi
0 commit comments