1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.dynamic.sql.delete;
17
18 import java.util.Objects;
19 import java.util.Optional;
20
21 import org.jspecify.annotations.Nullable;
22 import org.mybatis.dynamic.sql.SqlTable;
23 import org.mybatis.dynamic.sql.common.CommonBuilder;
24 import org.mybatis.dynamic.sql.common.OrderByModel;
25 import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
26 import org.mybatis.dynamic.sql.delete.render.DeleteRenderer;
27 import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
28 import org.mybatis.dynamic.sql.render.RenderingStrategy;
29 import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
30
31 public class DeleteModel {
32 private final SqlTable table;
33 private final @Nullable String tableAlias;
34 private final @Nullable EmbeddedWhereModel whereModel;
35 private final @Nullable Long limit;
36 private final @Nullable OrderByModel orderByModel;
37 private final StatementConfiguration statementConfiguration;
38
39 private DeleteModel(Builder builder) {
40 table = Objects.requireNonNull(builder.table());
41 whereModel = builder.whereModel();
42 tableAlias = builder.tableAlias();
43 limit = builder.limit();
44 orderByModel = builder.orderByModel();
45 statementConfiguration = Objects.requireNonNull(builder.statementConfiguration());
46 }
47
48 public SqlTable table() {
49 return table;
50 }
51
52 public Optional<String> tableAlias() {
53 return Optional.ofNullable(tableAlias);
54 }
55
56 public Optional<EmbeddedWhereModel> whereModel() {
57 return Optional.ofNullable(whereModel);
58 }
59
60 public Optional<Long> limit() {
61 return Optional.ofNullable(limit);
62 }
63
64 public Optional<OrderByModel> orderByModel() {
65 return Optional.ofNullable(orderByModel);
66 }
67
68 public StatementConfiguration statementConfiguration() {
69 return statementConfiguration;
70 }
71
72 public DeleteStatementProvider render(RenderingStrategy renderingStrategy) {
73 return DeleteRenderer.withDeleteModel(this)
74 .withRenderingStrategy(renderingStrategy)
75 .build()
76 .render();
77 }
78
79 public static Builder withTable(SqlTable table) {
80 return new Builder().withTable(table);
81 }
82
83 public static class Builder extends CommonBuilder<Builder> {
84 @Override
85 protected Builder getThis() {
86 return this;
87 }
88
89 public DeleteModel build() {
90 return new DeleteModel(this);
91 }
92 }
93 }