|
39 | 39 | import org.springframework.data.r2dbc.function.operation.Bindings;
|
40 | 40 | import org.springframework.data.r2dbc.function.operation.PreparedOperation;
|
41 | 41 | import org.springframework.data.r2dbc.support.StatementRenderUtil;
|
42 |
| -import org.springframework.data.relational.core.sql.AssignValue; |
43 |
| -import org.springframework.data.relational.core.sql.Assignment; |
44 | 42 | import org.springframework.data.relational.core.sql.Column;
|
45 | 43 | import org.springframework.data.relational.core.sql.Condition;
|
46 | 44 | import org.springframework.data.relational.core.sql.Delete;
|
47 |
| -import org.springframework.data.relational.core.sql.DeleteBuilder; |
48 | 45 | import org.springframework.data.relational.core.sql.Expression;
|
49 | 46 | import org.springframework.data.relational.core.sql.Insert;
|
50 | 47 | import org.springframework.data.relational.core.sql.OrderByField;
|
|
54 | 51 | import org.springframework.data.relational.core.sql.StatementBuilder;
|
55 | 52 | import org.springframework.data.relational.core.sql.Table;
|
56 | 53 | import org.springframework.data.relational.core.sql.Update;
|
57 |
| -import org.springframework.data.relational.core.sql.UpdateBuilder; |
58 | 54 | import org.springframework.data.relational.core.sql.render.RenderContext;
|
59 | 55 | import org.springframework.data.relational.core.sql.render.SqlRenderer;
|
60 | 56 | import org.springframework.lang.Nullable;
|
@@ -169,197 +165,6 @@ private Collection<? extends OrderByField> createOrderByFields(Table table, Sort
|
169 | 165 | return fields;
|
170 | 166 | }
|
171 | 167 |
|
172 |
| - /* |
173 |
| - * (non-Javadoc) |
174 |
| - * @see org.springframework.data.r2dbc.function.StatementFactory#insert(java.lang.String, java.util.Collection, java.util.function.Consumer) |
175 |
| - */ |
176 |
| - @Override |
177 |
| - public PreparedOperation<Insert> insert(String tableName, Collection<String> generatedKeysNames, |
178 |
| - Consumer<StatementBinderBuilder> binderConsumer) { |
179 |
| - |
180 |
| - Assert.hasText(tableName, "Table must not be empty"); |
181 |
| - Assert.notNull(generatedKeysNames, "Generated key names must not be null"); |
182 |
| - Assert.notNull(binderConsumer, "Binder Consumer must not be null"); |
183 |
| - |
184 |
| - DefaultBinderBuilder binderBuilder = new DefaultBinderBuilder() { |
185 |
| - @Override |
186 |
| - public void filterBy(String identifier, SettableValue settable) { |
187 |
| - throw new InvalidDataAccessApiUsageException("Filter-Binding for INSERT not supported. Use bind(…)"); |
188 |
| - } |
189 |
| - }; |
190 |
| - |
191 |
| - binderConsumer.accept(binderBuilder); |
192 |
| - |
193 |
| - return withDialect((dialect, renderContext) -> { |
194 |
| - |
195 |
| - BindMarkers bindMarkers = dialect.getBindMarkersFactory().create(); |
196 |
| - Table table = Table.create(tableName); |
197 |
| - |
198 |
| - Map<BindMarker, SettableValue> expressionBindings = new LinkedHashMap<>(); |
199 |
| - List<Expression> expressions = new ArrayList<>(); |
200 |
| - binderBuilder.forEachBinding((column, settableValue) -> { |
201 |
| - |
202 |
| - BindMarker bindMarker = bindMarkers.next(column); |
203 |
| - |
204 |
| - expressions.add(SQL.bindMarker(bindMarker.getPlaceholder())); |
205 |
| - expressionBindings.put(bindMarker, settableValue); |
206 |
| - }); |
207 |
| - |
208 |
| - if (expressions.isEmpty()) { |
209 |
| - throw new IllegalStateException("INSERT contains no value expressions"); |
210 |
| - } |
211 |
| - |
212 |
| - Binding binding = binderBuilder.build(table, bindMarkers).withBindings(expressionBindings); |
213 |
| - Insert insert = StatementBuilder.insert().into(table).columns(table.columns(binderBuilder.bindings.keySet())) |
214 |
| - .values(expressions).build(); |
215 |
| - |
216 |
| - return new DefaultPreparedOperation<Insert>(insert, renderContext, binding.toBindings()) { |
217 |
| - @Override |
218 |
| - public Statement bind(Statement to) { |
219 |
| - return super.bind(to).returnGeneratedValues(generatedKeysNames.toArray(new String[0])); |
220 |
| - } |
221 |
| - }; |
222 |
| - }); |
223 |
| - } |
224 |
| - |
225 |
| - /* |
226 |
| - * (non-Javadoc) |
227 |
| - * @see org.springframework.data.r2dbc.function.StatementFactory#update(java.lang.String, java.util.function.Consumer) |
228 |
| - */ |
229 |
| - @Override |
230 |
| - public PreparedOperation<Update> update(String tableName, Consumer<StatementBinderBuilder> binderConsumer) { |
231 |
| - |
232 |
| - Assert.hasText(tableName, "Table must not be empty"); |
233 |
| - Assert.notNull(binderConsumer, "Binder Consumer must not be null"); |
234 |
| - |
235 |
| - DefaultBinderBuilder binderBuilder = new DefaultBinderBuilder(); |
236 |
| - |
237 |
| - binderConsumer.accept(binderBuilder); |
238 |
| - |
239 |
| - return withDialect((dialect, renderContext) -> { |
240 |
| - |
241 |
| - BindMarkers bindMarkers = dialect.getBindMarkersFactory().create(); |
242 |
| - Table table = Table.create(tableName); |
243 |
| - |
244 |
| - Map<BindMarker, SettableValue> assignmentBindings = new LinkedHashMap<>(); |
245 |
| - List<Assignment> assignments = new ArrayList<>(); |
246 |
| - binderBuilder.forEachBinding((column, settableValue) -> { |
247 |
| - |
248 |
| - BindMarker bindMarker = bindMarkers.next(column); |
249 |
| - AssignValue assignment = table.column(column).set(SQL.bindMarker(bindMarker.getPlaceholder())); |
250 |
| - |
251 |
| - assignments.add(assignment); |
252 |
| - assignmentBindings.put(bindMarker, settableValue); |
253 |
| - }); |
254 |
| - |
255 |
| - if (assignments.isEmpty()) { |
256 |
| - throw new IllegalStateException("UPDATE contains no assignments"); |
257 |
| - } |
258 |
| - |
259 |
| - UpdateBuilder.UpdateWhere updateBuilder = StatementBuilder.update(table).set(assignments); |
260 |
| - |
261 |
| - Binding binding = binderBuilder.build(table, bindMarkers).withBindings(assignmentBindings); |
262 |
| - Update update; |
263 |
| - |
264 |
| - if (binding.hasCondition()) { |
265 |
| - update = updateBuilder.where(binding.getCondition()).build(); |
266 |
| - } else { |
267 |
| - update = updateBuilder.build(); |
268 |
| - } |
269 |
| - |
270 |
| - return new DefaultPreparedOperation<>(update, renderContext, binding.toBindings()); |
271 |
| - }); |
272 |
| - } |
273 |
| - |
274 |
| - @Override |
275 |
| - public PreparedOperation<Update> update(String tableName, BiConsumer<Table, UpdateConfigurer> configurerConsumer) { |
276 |
| - |
277 |
| - Assert.hasText(tableName, "Table must not be empty"); |
278 |
| - Assert.notNull(configurerConsumer, "Configurer Consumer must not be null"); |
279 |
| - |
280 |
| - return withDialect((dialect, renderContext) -> { |
281 |
| - |
282 |
| - DefaultUpdateConfigurer configurer = new DefaultUpdateConfigurer(dialect.getBindMarkersFactory().create()); |
283 |
| - Table table = Table.create(tableName); |
284 |
| - configurerConsumer.accept(table, configurer); |
285 |
| - |
286 |
| - UpdateBuilder.UpdateWhere updateBuilder = StatementBuilder.update(table).set(configurer.assignments); |
287 |
| - |
288 |
| - if (configurer.condition != null) { |
289 |
| - updateBuilder.where(configurer.condition); |
290 |
| - } |
291 |
| - |
292 |
| - Update update = updateBuilder.build(); |
293 |
| - return new DefaultPreparedOperation<>(update, renderContext, configurer.bindings); |
294 |
| - }); |
295 |
| - } |
296 |
| - |
297 |
| - /* |
298 |
| - * (non-Javadoc) |
299 |
| - * @see org.springframework.data.r2dbc.function.StatementFactory#delete(java.lang.String, java.util.function.Consumer) |
300 |
| - */ |
301 |
| - @Override |
302 |
| - public PreparedOperation<Delete> delete(String tableName, Consumer<StatementBinderBuilder> binderConsumer) { |
303 |
| - |
304 |
| - Assert.hasText(tableName, "Table must not be empty"); |
305 |
| - Assert.notNull(binderConsumer, "Binder Consumer must not be null"); |
306 |
| - |
307 |
| - DefaultBinderBuilder binderBuilder = new DefaultBinderBuilder() { |
308 |
| - @Override |
309 |
| - public void bind(String identifier, SettableValue settable) { |
310 |
| - throw new InvalidDataAccessApiUsageException("Binding for DELETE not supported. Use filterBy(…)"); |
311 |
| - } |
312 |
| - }; |
313 |
| - |
314 |
| - binderConsumer.accept(binderBuilder); |
315 |
| - |
316 |
| - return withDialect((dialect, renderContext) -> { |
317 |
| - |
318 |
| - Table table = Table.create(tableName); |
319 |
| - DeleteBuilder.DeleteWhere deleteBuilder = StatementBuilder.delete().from(table); |
320 |
| - |
321 |
| - BindMarkers bindMarkers = dialect.getBindMarkersFactory().create(); |
322 |
| - Binding binding = binderBuilder.build(table, bindMarkers); |
323 |
| - Delete delete; |
324 |
| - |
325 |
| - if (binding.hasCondition()) { |
326 |
| - delete = deleteBuilder.where(binding.getCondition()).build(); |
327 |
| - } else { |
328 |
| - delete = deleteBuilder.build(); |
329 |
| - } |
330 |
| - |
331 |
| - return new DefaultPreparedOperation<>(delete, renderContext, binding.toBindings()); |
332 |
| - }); |
333 |
| - } |
334 |
| - |
335 |
| - @Override |
336 |
| - public PreparedOperation<Delete> delete(String tableName, BiConsumer<Table, BindConfigurer> configurerConsumer) { |
337 |
| - |
338 |
| - Assert.hasText(tableName, "Table must not be empty"); |
339 |
| - Assert.notNull(configurerConsumer, "Configurer Consumer must not be null"); |
340 |
| - |
341 |
| - return withDialect((dialect, renderContext) -> { |
342 |
| - |
343 |
| - Table table = Table.create(tableName); |
344 |
| - DeleteBuilder.DeleteWhere deleteBuilder = StatementBuilder.delete().from(table); |
345 |
| - |
346 |
| - BindMarkers bindMarkers = dialect.getBindMarkersFactory().create(); |
347 |
| - DefaultBindConfigurer configurer = new DefaultBindConfigurer(bindMarkers); |
348 |
| - |
349 |
| - configurerConsumer.accept(table, configurer); |
350 |
| - |
351 |
| - Delete delete; |
352 |
| - |
353 |
| - if (configurer.condition != null) { |
354 |
| - delete = deleteBuilder.where(configurer.condition).build(); |
355 |
| - } else { |
356 |
| - delete = deleteBuilder.build(); |
357 |
| - } |
358 |
| - |
359 |
| - return new DefaultPreparedOperation<>(delete, renderContext, configurer.bindings); |
360 |
| - }); |
361 |
| - } |
362 |
| - |
363 | 168 | private <T> T withDialect(BiFunction<Dialect, RenderContext, T> action) {
|
364 | 169 |
|
365 | 170 | Assert.notNull(action, "Action must not be null");
|
@@ -668,39 +473,6 @@ public SelectConfigurer withSort(Sort sort) {
|
668 | 473 | }
|
669 | 474 | }
|
670 | 475 |
|
671 |
| - /** |
672 |
| - * Default {@link UpdateConfigurer} implementation. |
673 |
| - */ |
674 |
| - static class DefaultUpdateConfigurer extends DefaultBindConfigurer implements UpdateConfigurer { |
675 |
| - |
676 |
| - Collection<? extends Assignment> assignments; |
677 |
| - |
678 |
| - DefaultUpdateConfigurer(BindMarkers bindMarkers) { |
679 |
| - super(bindMarkers); |
680 |
| - } |
681 |
| - |
682 |
| - @Override |
683 |
| - public UpdateConfigurer withBindings(Bindings bindings) { |
684 |
| - super.withBindings(bindings); |
685 |
| - return this; |
686 |
| - } |
687 |
| - |
688 |
| - @Override |
689 |
| - public UpdateConfigurer withAssignments(Collection<? extends Assignment> assignments) { |
690 |
| - |
691 |
| - Assert.notNull(assignments, "Assignments must not be null"); |
692 |
| - |
693 |
| - this.assignments = assignments; |
694 |
| - return this; |
695 |
| - } |
696 |
| - |
697 |
| - @Override |
698 |
| - public UpdateConfigurer withWhere(Condition condition) { |
699 |
| - super.withWhere(condition); |
700 |
| - return this; |
701 |
| - } |
702 |
| - } |
703 |
| - |
704 | 476 | /**
|
705 | 477 | * Default {@link SelectConfigurer} implementation.
|
706 | 478 | */
|
|
0 commit comments