@@ -174,19 +174,9 @@ private Collection<PreparedStatement> generatePreparedStatementForDDL(final SQLE
174
174
}
175
175
176
176
private PreparedStatement generatePreparedStatement (final SQLExecutionUnit sqlExecutionUnit ) throws SQLException {
177
- Optional <GeneratedKey > generatedKey = getGeneratedKey ();
178
177
Connection connection = getConnection ().getConnection (sqlExecutionUnit .getDataSource (), routeResult .getSqlStatement ().getType ());
179
- if (returnGeneratedKeys && generatedKey .isPresent ()) {
180
- return connection .prepareStatement (sqlExecutionUnit .getSql (), RETURN_GENERATED_KEYS );
181
- }
182
- return connection .prepareStatement (sqlExecutionUnit .getSql (), resultSetType , resultSetConcurrency , resultSetHoldability );
183
- }
184
-
185
- private Optional <GeneratedKey > getGeneratedKey () {
186
- if (null != routeResult && routeResult .getSqlStatement () instanceof InsertStatement ) {
187
- return Optional .fromNullable (((InsertStatement ) routeResult .getSqlStatement ()).getGeneratedKey ());
188
- }
189
- return Optional .absent ();
178
+ return returnGeneratedKeys ? connection .prepareStatement (sqlExecutionUnit .getSql (), RETURN_GENERATED_KEYS )
179
+ : connection .prepareStatement (sqlExecutionUnit .getSql (), resultSetType , resultSetConcurrency , resultSetHoldability );
190
180
}
191
181
192
182
@ Override
@@ -211,28 +201,6 @@ public void addBatch() throws SQLException {
211
201
}
212
202
}
213
203
214
- @ Override
215
- public int [] executeBatch () throws SQLException {
216
- try {
217
- return new BatchPreparedStatementExecutor (getConnection ().getShardingContext ().getExecutorEngine (),
218
- getConnection ().getShardingContext ().getDatabaseType (), routeResult .getSqlStatement ().getType (), batchStatementUnits , parameterSets ).executeBatch ();
219
- } finally {
220
- clearBatch ();
221
- }
222
- }
223
-
224
- @ Override
225
- public ResultSet getGeneratedKeys () throws SQLException {
226
- Optional <GeneratedKey > generatedKey = getGeneratedKey ();
227
- if (returnGeneratedKeys && generatedKey .isPresent ()) {
228
- return new GeneratedKeysResultSet (routeResult .getGeneratedKeys ().iterator (), generatedKey .get ().getColumn (), this );
229
- }
230
- if (1 == routedStatements .size ()) {
231
- return routedStatements .iterator ().next ().getGeneratedKeys ();
232
- }
233
- return new GeneratedKeysResultSet ();
234
- }
235
-
236
204
private List <BatchPreparedStatementUnit > routeBatch () throws SQLException {
237
205
List <BatchPreparedStatementUnit > result = new ArrayList <>();
238
206
routeResult = routingEngine .route (getParameters ());
@@ -260,6 +228,35 @@ public boolean apply(final BatchPreparedStatementUnit input) {
260
228
return result ;
261
229
}
262
230
231
+ @ Override
232
+ public int [] executeBatch () throws SQLException {
233
+ try {
234
+ return new BatchPreparedStatementExecutor (getConnection ().getShardingContext ().getExecutorEngine (),
235
+ getConnection ().getShardingContext ().getDatabaseType (), routeResult .getSqlStatement ().getType (), batchStatementUnits , parameterSets ).executeBatch ();
236
+ } finally {
237
+ clearBatch ();
238
+ }
239
+ }
240
+
241
+ @ Override
242
+ public ResultSet getGeneratedKeys () throws SQLException {
243
+ Optional <GeneratedKey > generatedKey = getGeneratedKey ();
244
+ if (returnGeneratedKeys && generatedKey .isPresent ()) {
245
+ return new GeneratedKeysResultSet (routeResult .getGeneratedKeys ().iterator (), generatedKey .get ().getColumn (), this );
246
+ }
247
+ if (1 == routedStatements .size ()) {
248
+ return routedStatements .iterator ().next ().getGeneratedKeys ();
249
+ }
250
+ return new GeneratedKeysResultSet ();
251
+ }
252
+
253
+ private Optional <GeneratedKey > getGeneratedKey () {
254
+ if (null != routeResult && routeResult .getSqlStatement () instanceof InsertStatement ) {
255
+ return Optional .fromNullable (((InsertStatement ) routeResult .getSqlStatement ()).getGeneratedKey ());
256
+ }
257
+ return Optional .absent ();
258
+ }
259
+
263
260
@ Override
264
261
public ResultSet getResultSet () throws SQLException {
265
262
if (null != currentResultSet ) {
0 commit comments