Repository navigation
Expand file tree
/
Copy pathRollbackStatement.java
More file actions
156 lines (130 loc) · 4.78 KB
/
Copy pathRollbackStatement.java
File metadata and controls
156 lines (130 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
/*
* Copyright (C) 2021 JSQLParser.
*
* This library is free software; you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation; either version
* 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library;
* if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
package net.sf.jsqlparser.statement;
import java.util.Objects;
/**
* ROLLBACK, or its PostgreSQL spelling ABORT.
*
* @author are
*/
public class RollbackStatement extends TransactionCompletionStatement {
/** The keyword that starts the statement; ABORT has no savepoint or FORCE form. */
public enum Command {
ROLLBACK, ABORT
}
private Command command = Command.ROLLBACK;
private boolean usingSavepointKeyword = false;
private String savepointName = null;
private String forceDistributedTransactionIdentifier = null;
public Command getCommand() {
return command;
}
public void setCommand(Command command) {
this.command = Objects.requireNonNull(command, "command");
}
public RollbackStatement withCommand(Command command) {
setCommand(command);
return this;
}
public RollbackStatement withKeyword(TransactionKeyword keyword) {
setKeyword(keyword);
return this;
}
public RollbackStatement withChain(TransactionChain chain) {
setChain(chain);
return this;
}
public RollbackStatement withRelease(TransactionRelease release) {
setRelease(release);
return this;
}
public boolean isUsingWorkKeyword() {
return getKeyword() == TransactionKeyword.WORK;
}
public void setUsingWorkKeyword(boolean usingWorkKeyword) {
if (usingWorkKeyword) {
setKeyword(TransactionKeyword.WORK);
} else if (getKeyword() == TransactionKeyword.WORK) {
setKeyword(null);
}
}
public RollbackStatement withUsingWorkKeyword(boolean usingWorkKeyword) {
setUsingWorkKeyword(usingWorkKeyword);
return this;
}
public boolean isUsingSavepointKeyword() {
return usingSavepointKeyword;
}
public void setUsingSavepointKeyword(boolean usingSavepointKeyword) {
this.usingSavepointKeyword = usingSavepointKeyword;
}
public RollbackStatement withUsingSavepointKeyword(boolean usingSavepointKeyword) {
this.usingSavepointKeyword = usingSavepointKeyword;
return this;
}
public String getSavepointName() {
return savepointName;
}
public void setSavepointName(String savepointName) {
this.savepointName = savepointName;
}
public RollbackStatement withSavepointName(String savepointName) {
this.savepointName = savepointName;
return this;
}
public String getForceDistributedTransactionIdentifier() {
return forceDistributedTransactionIdentifier;
}
public void setForceDistributedTransactionIdentifier(
String forceDistributedTransactionIdentifier) {
this.forceDistributedTransactionIdentifier = forceDistributedTransactionIdentifier;
}
public RollbackStatement withForceDistributedTransactionIdentifier(
String forceDistributedTransactionIdentifier) {
this.forceDistributedTransactionIdentifier = forceDistributedTransactionIdentifier;
return this;
}
@Override
public boolean isPostgresSpelling() {
return command == Command.ABORT;
}
@Override
public StringBuilder appendTo(StringBuilder builder) {
builder.append(command);
appendKeyword(builder);
if (savepointName != null && !savepointName.trim().isEmpty()) {
builder.append(" TO ").append(usingSavepointKeyword ? "SAVEPOINT " : "")
.append(savepointName);
} else if (forceDistributedTransactionIdentifier != null
&& !forceDistributedTransactionIdentifier.trim().isEmpty()) {
builder.append(" FORCE ").append(forceDistributedTransactionIdentifier);
}
return appendCompletion(builder);
}
@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}