@@ -51,14 +51,18 @@ public void setup() {
51
51
parser = AbstractStatementParser .getInstance (dialect );
52
52
}
53
53
54
+ ParsedStatement parse (String sql ) {
55
+ return parser .parse (Statement .of (sql ));
56
+ }
57
+
54
58
@ Test
55
59
public void testExecuteGetAutocommit () {
56
60
ParsedStatement statement = parser .parse (Statement .of ("show variable autocommit" ));
57
61
ConnectionImpl connection = mock (ConnectionImpl .class );
58
62
ConnectionStatementExecutorImpl executor = mock (ConnectionStatementExecutorImpl .class );
59
63
when (executor .getConnection ()).thenReturn (connection );
60
64
when (executor .statementShowAutocommit ()).thenCallRealMethod ();
61
- statement .getClientSideStatement ().execute (executor , "show variable autocommit" );
65
+ statement .getClientSideStatement ().execute (executor , statement );
62
66
verify (connection , times (1 )).isAutocommit ();
63
67
}
64
68
@@ -70,9 +74,7 @@ public void testExecuteGetReadOnly() {
70
74
ConnectionImpl connection = mock (ConnectionImpl .class );
71
75
when (connection .getDialect ()).thenReturn (dialect );
72
76
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
73
- statement
74
- .getClientSideStatement ()
75
- .execute (executor , String .format ("show variable %sreadonly" , getNamespace (dialect )));
77
+ statement .getClientSideStatement ().execute (executor , statement );
76
78
verify (connection , times (1 )).isReadOnly ();
77
79
}
78
80
@@ -86,10 +88,7 @@ public void testExecuteGetAutocommitDmlMode() {
86
88
when (connection .getDialect ()).thenReturn (dialect );
87
89
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
88
90
when (connection .getAutocommitDmlMode ()).thenReturn (AutocommitDmlMode .TRANSACTIONAL );
89
- statement
90
- .getClientSideStatement ()
91
- .execute (
92
- executor , String .format ("show variable %sautocommit_dml_mode" , getNamespace (dialect )));
91
+ statement .getClientSideStatement ().execute (executor , statement );
93
92
verify (connection , times (1 )).getAutocommitDmlMode ();
94
93
}
95
94
@@ -102,7 +101,7 @@ public void testExecuteGetStatementTimeout() {
102
101
when (executor .statementShowStatementTimeout ()).thenCallRealMethod ();
103
102
when (connection .hasStatementTimeout ()).thenReturn (true );
104
103
when (connection .getStatementTimeout (TimeUnit .NANOSECONDS )).thenReturn (1L );
105
- statement .getClientSideStatement ().execute (executor , "show variable statement_timeout" );
104
+ statement .getClientSideStatement ().execute (executor , statement );
106
105
verify (connection , times (2 )).getStatementTimeout (TimeUnit .NANOSECONDS );
107
106
}
108
107
@@ -115,9 +114,7 @@ public void testExecuteGetReadTimestamp() {
115
114
when (connection .getDialect ()).thenReturn (dialect );
116
115
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
117
116
when (connection .getReadTimestampOrNull ()).thenReturn (Timestamp .now ());
118
- statement
119
- .getClientSideStatement ()
120
- .execute (executor , String .format ("show variable %sread_timestamp" , getNamespace (dialect )));
117
+ statement .getClientSideStatement ().execute (executor , statement );
121
118
verify (connection , times (1 )).getReadTimestampOrNull ();
122
119
}
123
120
@@ -130,10 +127,7 @@ public void testExecuteGetCommitTimestamp() {
130
127
when (connection .getDialect ()).thenReturn (dialect );
131
128
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
132
129
when (connection .getCommitTimestampOrNull ()).thenReturn (Timestamp .now ());
133
- statement
134
- .getClientSideStatement ()
135
- .execute (
136
- executor , String .format ("show variable %scommit_timestamp" , getNamespace (dialect )));
130
+ statement .getClientSideStatement ().execute (executor , statement );
137
131
verify (connection , times (1 )).getCommitTimestampOrNull ();
138
132
}
139
133
@@ -147,10 +141,7 @@ public void testExecuteGetReadOnlyStaleness() {
147
141
when (connection .getDialect ()).thenReturn (dialect );
148
142
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
149
143
when (connection .getReadOnlyStaleness ()).thenReturn (TimestampBound .strong ());
150
- statement
151
- .getClientSideStatement ()
152
- .execute (
153
- executor , String .format ("show variable %sread_only_staleness" , getNamespace (dialect )));
144
+ statement .getClientSideStatement ().execute (executor , statement );
154
145
verify (connection , times (1 )).getReadOnlyStaleness ();
155
146
}
156
147
@@ -164,10 +155,7 @@ public void testExecuteGetOptimizerVersion() {
164
155
when (connection .getDialect ()).thenReturn (dialect );
165
156
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
166
157
when (connection .getOptimizerVersion ()).thenReturn ("1" );
167
- statement
168
- .getClientSideStatement ()
169
- .execute (
170
- executor , String .format ("show variable %soptimizer_version" , getNamespace (dialect )));
158
+ statement .getClientSideStatement ().execute (executor , statement );
171
159
verify (connection , times (1 )).getOptimizerVersion ();
172
160
}
173
161
@@ -182,11 +170,7 @@ public void testExecuteGetOptimizerStatisticsPackage() {
182
170
when (connection .getDialect ()).thenReturn (dialect );
183
171
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
184
172
when (connection .getOptimizerStatisticsPackage ()).thenReturn ("custom-package" );
185
- statement
186
- .getClientSideStatement ()
187
- .execute (
188
- executor ,
189
- String .format ("show variable %soptimizer_statistics_package" , getNamespace (dialect )));
173
+ statement .getClientSideStatement ().execute (executor , statement );
190
174
verify (connection , times (1 )).getOptimizerStatisticsPackage ();
191
175
}
192
176
@@ -196,7 +180,7 @@ public void testExecuteBegin() {
196
180
for (String statement : subject .getClientSideStatement ().getExampleStatements ()) {
197
181
ConnectionImpl connection = mock (ConnectionImpl .class );
198
182
ConnectionStatementExecutorImpl executor = new ConnectionStatementExecutorImpl (connection );
199
- subject .getClientSideStatement ().execute (executor , statement );
183
+ subject .getClientSideStatement ().execute (executor , parse ( statement ) );
200
184
verify (connection , times (1 )).beginTransaction ();
201
185
}
202
186
}
@@ -209,7 +193,7 @@ public void testExecuteCommit() {
209
193
ConnectionStatementExecutorImpl executor = mock (ConnectionStatementExecutorImpl .class );
210
194
when (executor .getConnection ()).thenReturn (connection );
211
195
when (executor .statementCommit ()).thenCallRealMethod ();
212
- subject .getClientSideStatement ().execute (executor , statement );
196
+ subject .getClientSideStatement ().execute (executor , parse ( statement ) );
213
197
verify (connection , times (1 )).commit ();
214
198
}
215
199
}
@@ -222,7 +206,7 @@ public void testExecuteRollback() {
222
206
ConnectionStatementExecutorImpl executor = mock (ConnectionStatementExecutorImpl .class );
223
207
when (executor .getConnection ()).thenReturn (connection );
224
208
when (executor .statementRollback ()).thenCallRealMethod ();
225
- subject .getClientSideStatement ().execute (executor , statement );
209
+ subject .getClientSideStatement ().execute (executor , parse ( statement ) );
226
210
verify (connection , times (1 )).rollback ();
227
211
}
228
212
}
0 commit comments