|
25 | 25 |
|
26 | 26 | package net.sf.jsqlparser.statement; |
27 | 27 |
|
28 | | -import net.sf.jsqlparser.parser.ASTNodeAccessImpl; |
| 28 | +import java.util.Objects; |
29 | 29 |
|
30 | 30 | /** |
| 31 | + * ROLLBACK, or its PostgreSQL spelling ABORT. |
| 32 | + * |
31 | 33 | * @author are |
32 | 34 | */ |
33 | | -public class RollbackStatement extends ASTNodeAccessImpl implements Statement { |
34 | | - private TransactionKeyword keyword; |
35 | | - private TransactionChain chain; |
| 35 | +public class RollbackStatement extends TransactionCompletionStatement { |
| 36 | + /** The keyword that starts the statement; ABORT has no savepoint or FORCE form. */ |
| 37 | + public enum Command { |
| 38 | + ROLLBACK, ABORT |
| 39 | + } |
| 40 | + |
| 41 | + private Command command = Command.ROLLBACK; |
36 | 42 | private boolean usingSavepointKeyword = false; |
37 | 43 | private String savepointName = null; |
38 | 44 | private String forceDistributedTransactionIdentifier = null; |
39 | 45 |
|
40 | | - public TransactionKeyword getKeyword() { |
41 | | - return keyword; |
| 46 | + public Command getCommand() { |
| 47 | + return command; |
42 | 48 | } |
43 | 49 |
|
44 | | - public void setKeyword(TransactionKeyword keyword) { |
45 | | - this.keyword = keyword; |
| 50 | + public void setCommand(Command command) { |
| 51 | + this.command = Objects.requireNonNull(command, "command"); |
46 | 52 | } |
47 | 53 |
|
48 | | - public RollbackStatement withKeyword(TransactionKeyword keyword) { |
49 | | - setKeyword(keyword); |
| 54 | + public RollbackStatement withCommand(Command command) { |
| 55 | + setCommand(command); |
50 | 56 | return this; |
51 | 57 | } |
52 | 58 |
|
53 | | - public TransactionChain getChain() { |
54 | | - return chain; |
55 | | - } |
56 | | - |
57 | | - public void setChain(TransactionChain chain) { |
58 | | - this.chain = chain; |
| 59 | + public RollbackStatement withKeyword(TransactionKeyword keyword) { |
| 60 | + setKeyword(keyword); |
| 61 | + return this; |
59 | 62 | } |
60 | 63 |
|
61 | 64 | public RollbackStatement withChain(TransactionChain chain) { |
62 | 65 | setChain(chain); |
63 | 66 | return this; |
64 | 67 | } |
65 | 68 |
|
| 69 | + public RollbackStatement withRelease(TransactionRelease release) { |
| 70 | + setRelease(release); |
| 71 | + return this; |
| 72 | + } |
| 73 | + |
66 | 74 | public boolean isUsingWorkKeyword() { |
67 | | - return keyword == TransactionKeyword.WORK; |
| 75 | + return getKeyword() == TransactionKeyword.WORK; |
68 | 76 | } |
69 | 77 |
|
70 | 78 | public void setUsingWorkKeyword(boolean usingWorkKeyword) { |
71 | 79 | if (usingWorkKeyword) { |
72 | | - keyword = TransactionKeyword.WORK; |
73 | | - } else if (keyword == TransactionKeyword.WORK) { |
74 | | - keyword = null; |
| 80 | + setKeyword(TransactionKeyword.WORK); |
| 81 | + } else if (getKeyword() == TransactionKeyword.WORK) { |
| 82 | + setKeyword(null); |
75 | 83 | } |
76 | 84 | } |
77 | 85 |
|
@@ -121,27 +129,23 @@ public RollbackStatement withForceDistributedTransactionIdentifier( |
121 | 129 | return this; |
122 | 130 | } |
123 | 131 |
|
| 132 | + @Override |
| 133 | + public boolean isPostgresSpelling() { |
| 134 | + return command == Command.ABORT; |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
124 | 138 | public StringBuilder appendTo(StringBuilder builder) { |
125 | | - builder.append("ROLLBACK"); |
126 | | - if (keyword != null) { |
127 | | - builder.append(' ').append(keyword); |
128 | | - } |
| 139 | + builder.append(command); |
| 140 | + appendKeyword(builder); |
129 | 141 | if (savepointName != null && !savepointName.trim().isEmpty()) { |
130 | 142 | builder.append(" TO ").append(usingSavepointKeyword ? "SAVEPOINT " : "") |
131 | 143 | .append(savepointName); |
132 | 144 | } else if (forceDistributedTransactionIdentifier != null |
133 | 145 | && !forceDistributedTransactionIdentifier.trim().isEmpty()) { |
134 | 146 | builder.append(" FORCE ").append(forceDistributedTransactionIdentifier); |
135 | 147 | } |
136 | | - if (chain != null) { |
137 | | - builder.append(' ').append(chain); |
138 | | - } |
139 | | - return builder; |
140 | | - } |
141 | | - |
142 | | - @Override |
143 | | - public String toString() { |
144 | | - return appendTo(new StringBuilder()).toString(); |
| 148 | + return appendCompletion(builder); |
145 | 149 | } |
146 | 150 |
|
147 | 151 | @Override |
|
0 commit comments