|
36 | 36 | */
|
37 | 37 | public class UpdateDeParser {
|
38 | 38 |
|
39 |
| - private StringBuilder buffer; |
40 |
| - private ExpressionVisitor expressionVisitor; |
41 |
| - private SelectVisitor selectVisitor; |
| 39 | + private StringBuilder buffer; |
| 40 | + private ExpressionVisitor expressionVisitor; |
| 41 | + private SelectVisitor selectVisitor; |
42 | 42 |
|
43 |
| - /** |
44 |
| - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse |
45 |
| - * expressions. It has to share the same<br> |
46 |
| - * StringBuilder (buffer parameter) as this object in order to work |
47 |
| - * @param selectVisitor a {@link SelectVisitor} to de-parse |
48 |
| - * {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the |
49 |
| - * same<br> |
50 |
| - * StringBuilder (buffer parameter) as this object in order to work |
51 |
| - * @param buffer the buffer that will be filled with the select |
52 |
| - */ |
53 |
| - public UpdateDeParser(ExpressionVisitor expressionVisitor, SelectVisitor selectVisitor, StringBuilder buffer) { |
54 |
| - this.buffer = buffer; |
55 |
| - this.expressionVisitor = expressionVisitor; |
56 |
| - this.selectVisitor = selectVisitor; |
57 |
| - } |
| 43 | + /** |
| 44 | + * @param expressionVisitor a {@link ExpressionVisitor} to de-parse |
| 45 | + * expressions. It has to share the same<br> |
| 46 | + * StringBuilder (buffer parameter) as this object in order to work |
| 47 | + * @param selectVisitor a {@link SelectVisitor} to de-parse |
| 48 | + * {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the |
| 49 | + * same<br> |
| 50 | + * StringBuilder (buffer parameter) as this object in order to work |
| 51 | + * @param buffer the buffer that will be filled with the select |
| 52 | + */ |
| 53 | + public UpdateDeParser(ExpressionVisitor expressionVisitor, SelectVisitor selectVisitor, StringBuilder buffer) { |
| 54 | + this.buffer = buffer; |
| 55 | + this.expressionVisitor = expressionVisitor; |
| 56 | + this.selectVisitor = selectVisitor; |
| 57 | + } |
58 | 58 |
|
59 |
| - public StringBuilder getBuffer() { |
60 |
| - return buffer; |
61 |
| - } |
| 59 | + public StringBuilder getBuffer() { |
| 60 | + return buffer; |
| 61 | + } |
62 | 62 |
|
63 |
| - public void setBuffer(StringBuilder buffer) { |
64 |
| - this.buffer = buffer; |
65 |
| - } |
| 63 | + public void setBuffer(StringBuilder buffer) { |
| 64 | + this.buffer = buffer; |
| 65 | + } |
66 | 66 |
|
67 |
| - public void deParse(Update update) { |
68 |
| - buffer.append("UPDATE ").append(PlainSelect.getStringList(update.getTables(), true, false)).append(" SET "); |
69 |
| - |
70 |
| - if (!update.isUseSelect()) { |
71 |
| - for (int i = 0; i < update.getColumns().size(); i++) { |
72 |
| - Column column = update.getColumns().get(i); |
73 |
| - buffer.append(column.getFullyQualifiedName()).append(" = "); |
74 |
| - |
75 |
| - Expression expression = update.getExpressions().get(i); |
76 |
| - expression.accept(expressionVisitor); |
77 |
| - if (i < update.getColumns().size() - 1) { |
78 |
| - buffer.append(", "); |
79 |
| - } |
80 |
| - } |
81 |
| - } else { |
82 |
| - if (update.isUseColumnsBrackets()) { |
83 |
| - buffer.append("("); |
84 |
| - } |
85 |
| - for (int i = 0; i < update.getColumns().size(); i++) { |
86 |
| - if (i != 0) { |
87 |
| - buffer.append(", "); |
88 |
| - } |
89 |
| - Column column = update.getColumns().get(i); |
90 |
| - buffer.append(column.getFullyQualifiedName()); |
91 |
| - } |
92 |
| - if (update.isUseColumnsBrackets()) { |
93 |
| - buffer.append(")"); |
94 |
| - } |
95 |
| - buffer.append(" = "); |
96 |
| - buffer.append("("); |
97 |
| - Select select = update.getSelect(); |
98 |
| - select.getSelectBody().accept(selectVisitor); |
99 |
| - buffer.append(")"); |
100 |
| - } |
101 |
| - |
102 |
| - if (update.getFromItem() != null) { |
103 |
| - buffer.append(" FROM ").append(update.getFromItem()); |
104 |
| - if (update.getJoins() != null) { |
105 |
| - for (Join join : update.getJoins()) { |
106 |
| - if (join.isSimple()) { |
107 |
| - buffer.append(", ").append(join); |
108 |
| - } else { |
109 |
| - buffer.append(" ").append(join); |
110 |
| - } |
111 |
| - } |
112 |
| - } |
113 |
| - } |
| 67 | + public void deParse(Update update) { |
| 68 | + buffer.append("UPDATE ").append(PlainSelect.getStringList(update.getTables(), true, false)).append(" SET "); |
114 | 69 |
|
115 |
| - if (update.getWhere() != null) { |
116 |
| - buffer.append(" WHERE "); |
117 |
| - update.getWhere().accept(expressionVisitor); |
118 |
| - } |
| 70 | + if (!update.isUseSelect()) { |
| 71 | + for (int i = 0; i < update.getColumns().size(); i++) { |
| 72 | + Column column = update.getColumns().get(i); |
| 73 | + buffer.append(column.getFullyQualifiedName()).append(" = "); |
119 | 74 |
|
120 |
| - } |
| 75 | + Expression expression = update.getExpressions().get(i); |
| 76 | + expression.accept(expressionVisitor); |
| 77 | + if (i < update.getColumns().size() - 1) { |
| 78 | + buffer.append(", "); |
| 79 | + } |
| 80 | + } |
| 81 | + } else { |
| 82 | + if (update.isUseColumnsBrackets()) { |
| 83 | + buffer.append("("); |
| 84 | + } |
| 85 | + for (int i = 0; i < update.getColumns().size(); i++) { |
| 86 | + if (i != 0) { |
| 87 | + buffer.append(", "); |
| 88 | + } |
| 89 | + Column column = update.getColumns().get(i); |
| 90 | + buffer.append(column.getFullyQualifiedName()); |
| 91 | + } |
| 92 | + if (update.isUseColumnsBrackets()) { |
| 93 | + buffer.append(")"); |
| 94 | + } |
| 95 | + buffer.append(" = "); |
| 96 | + buffer.append("("); |
| 97 | + Select select = update.getSelect(); |
| 98 | + select.getSelectBody().accept(selectVisitor); |
| 99 | + buffer.append(")"); |
| 100 | + } |
121 | 101 |
|
122 |
| - public ExpressionVisitor getExpressionVisitor() { |
123 |
| - return expressionVisitor; |
124 |
| - } |
| 102 | + if (update.getFromItem() != null) { |
| 103 | + buffer.append(" FROM ").append(update.getFromItem()); |
| 104 | + if (update.getJoins() != null) { |
| 105 | + for (Join join : update.getJoins()) { |
| 106 | + if (join.isSimple()) { |
| 107 | + buffer.append(", ").append(join); |
| 108 | + } else { |
| 109 | + buffer.append(" ").append(join); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + } |
125 | 114 |
|
126 |
| - public void setExpressionVisitor(ExpressionVisitor visitor) { |
127 |
| - expressionVisitor = visitor; |
128 |
| - } |
| 115 | + if (update.getWhere() != null) { |
| 116 | + buffer.append(" WHERE "); |
| 117 | + update.getWhere().accept(expressionVisitor); |
| 118 | + } |
| 119 | + |
| 120 | + } |
| 121 | + |
| 122 | + public ExpressionVisitor getExpressionVisitor() { |
| 123 | + return expressionVisitor; |
| 124 | + } |
| 125 | + |
| 126 | + public void setExpressionVisitor(ExpressionVisitor visitor) { |
| 127 | + expressionVisitor = visitor; |
| 128 | + } |
129 | 129 | }
|
0 commit comments