|
9 | 9 | */ |
10 | 10 | package net.sf.jsqlparser.statement.analyze; |
11 | 11 |
|
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.Collection; |
| 14 | +import java.util.Collections; |
| 15 | +import java.util.List; |
| 16 | +import java.util.stream.Collectors; |
| 17 | +import net.sf.jsqlparser.schema.Column; |
12 | 18 | import net.sf.jsqlparser.schema.Table; |
13 | 19 | import net.sf.jsqlparser.statement.Statement; |
14 | 20 | import net.sf.jsqlparser.statement.StatementVisitor; |
15 | 21 |
|
16 | 22 | public class Analyze implements Statement { |
17 | 23 |
|
18 | | - private Table table; |
| 24 | + public enum Modifier { |
| 25 | + NO_WRITE_TO_BINLOG, LOCAL |
| 26 | + } |
| 27 | + |
| 28 | + public enum HistogramAction { |
| 29 | + UPDATE, DROP |
| 30 | + } |
| 31 | + |
| 32 | + private final List<Table> tables = new ArrayList<>(); |
| 33 | + private boolean tableKeyword; |
| 34 | + private Modifier modifier; |
| 35 | + private HistogramAction histogramAction; |
| 36 | + private final List<Column> histogramColumns = new ArrayList<>(); |
| 37 | + private Integer histogramBucketCount; |
19 | 38 |
|
20 | 39 | @Override |
21 | 40 | public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
22 | 41 | return statementVisitor.visit(this, context); |
23 | 42 | } |
24 | 43 |
|
25 | 44 | public Table getTable() { |
26 | | - return table; |
| 45 | + return tables.isEmpty() ? null : tables.get(0); |
27 | 46 | } |
28 | 47 |
|
29 | 48 | public void setTable(Table table) { |
30 | | - this.table = table; |
| 49 | + tables.clear(); |
| 50 | + if (table != null) { |
| 51 | + tables.add(table); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + public List<Table> getTables() { |
| 56 | + return Collections.unmodifiableList(tables); |
| 57 | + } |
| 58 | + |
| 59 | + public void setTables(Collection<? extends Table> tables) { |
| 60 | + this.tables.clear(); |
| 61 | + if (tables != null) { |
| 62 | + this.tables.addAll(tables); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + public boolean isTableKeyword() { |
| 67 | + return tableKeyword; |
| 68 | + } |
| 69 | + |
| 70 | + public void setTableKeyword(boolean tableKeyword) { |
| 71 | + this.tableKeyword = tableKeyword; |
| 72 | + } |
| 73 | + |
| 74 | + public Modifier getModifier() { |
| 75 | + return modifier; |
| 76 | + } |
| 77 | + |
| 78 | + public void setModifier(Modifier modifier) { |
| 79 | + this.modifier = modifier; |
| 80 | + } |
| 81 | + |
| 82 | + public HistogramAction getHistogramAction() { |
| 83 | + return histogramAction; |
| 84 | + } |
| 85 | + |
| 86 | + public void setHistogramAction(HistogramAction histogramAction) { |
| 87 | + this.histogramAction = histogramAction; |
| 88 | + } |
| 89 | + |
| 90 | + public List<Column> getHistogramColumns() { |
| 91 | + return Collections.unmodifiableList(histogramColumns); |
| 92 | + } |
| 93 | + |
| 94 | + public void setHistogramColumns(Collection<? extends Column> columns) { |
| 95 | + histogramColumns.clear(); |
| 96 | + if (columns != null) { |
| 97 | + histogramColumns.addAll(columns); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + public Integer getHistogramBucketCount() { |
| 102 | + return histogramBucketCount; |
| 103 | + } |
| 104 | + |
| 105 | + public void setHistogramBucketCount(Integer histogramBucketCount) { |
| 106 | + this.histogramBucketCount = histogramBucketCount; |
31 | 107 | } |
32 | 108 |
|
33 | 109 | @Override |
34 | 110 | public String toString() { |
35 | | - return "ANALYZE " + table.toString(); |
| 111 | + StringBuilder builder = new StringBuilder("ANALYZE"); |
| 112 | + if (modifier != null) { |
| 113 | + builder.append(" ").append(modifier); |
| 114 | + } |
| 115 | + if (tableKeyword) { |
| 116 | + builder.append(" TABLE"); |
| 117 | + } |
| 118 | + builder.append(" ").append(tables.stream().map(Table::toString) |
| 119 | + .collect(Collectors.joining(", "))); |
| 120 | + if (histogramAction != null) { |
| 121 | + builder.append(" ").append(histogramAction).append(" HISTOGRAM ON ") |
| 122 | + .append(histogramColumns.stream().map(Column::toString) |
| 123 | + .collect(Collectors.joining(", "))); |
| 124 | + if (histogramBucketCount != null) { |
| 125 | + builder.append(" WITH ").append(histogramBucketCount).append(" BUCKETS"); |
| 126 | + } |
| 127 | + } |
| 128 | + return builder.toString(); |
36 | 129 | } |
37 | 130 |
|
38 | 131 | public Analyze withTable(Table table) { |
39 | 132 | this.setTable(table); |
40 | 133 | return this; |
41 | 134 | } |
| 135 | + |
| 136 | + public Analyze withTables(Collection<? extends Table> tables) { |
| 137 | + setTables(tables); |
| 138 | + return this; |
| 139 | + } |
| 140 | + |
| 141 | + public Analyze addTables(Table... tables) { |
| 142 | + Collections.addAll(this.tables, tables); |
| 143 | + return this; |
| 144 | + } |
| 145 | + |
| 146 | + public Analyze withTableKeyword(boolean tableKeyword) { |
| 147 | + setTableKeyword(tableKeyword); |
| 148 | + return this; |
| 149 | + } |
| 150 | + |
| 151 | + public Analyze withModifier(Modifier modifier) { |
| 152 | + setModifier(modifier); |
| 153 | + return this; |
| 154 | + } |
| 155 | + |
| 156 | + public Analyze withHistogramAction(HistogramAction histogramAction) { |
| 157 | + setHistogramAction(histogramAction); |
| 158 | + return this; |
| 159 | + } |
| 160 | + |
| 161 | + public Analyze withHistogramColumns(Collection<? extends Column> columns) { |
| 162 | + setHistogramColumns(columns); |
| 163 | + return this; |
| 164 | + } |
| 165 | + |
| 166 | + public Analyze addHistogramColumns(Column... columns) { |
| 167 | + Collections.addAll(histogramColumns, columns); |
| 168 | + return this; |
| 169 | + } |
| 170 | + |
| 171 | + public Analyze withHistogramBucketCount(Integer histogramBucketCount) { |
| 172 | + setHistogramBucketCount(histogramBucketCount); |
| 173 | + return this; |
| 174 | + } |
42 | 175 | } |
0 commit comments