Repository navigation
Expand file tree
/
Copy pathResetStatement.java
More file actions
104 lines (86 loc) · 2.64 KB
/
Copy pathResetStatement.java
File metadata and controls
104 lines (86 loc) · 2.64 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
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
/**
* PostgreSQL {@code RESET configuration_parameter}, {@code RESET ALL} and {@code RESET TIME ZONE},
* and MySQL {@code RESET PERSIST [[IF EXISTS] system_var_name]}, which {@link #isPersist()} marks.
*
* @see <a href="https://www.postgresql.org/docs/current/sql-reset.html">PostgreSQL RESET</a>
* @see <a href="https://dev.mysql.com/doc/refman/8.4/en/reset-persist.html">MySQL RESET PERSIST</a>
*/
public final class ResetStatement extends ASTNodeAccessImpl implements Statement {
private String name = "";
private boolean persist;
private boolean ifExists;
public ResetStatement() {
// empty constructor
}
public ResetStatement(String name) {
add(name);
}
public void add(String name) {
this.name = name;
}
/**
* Returns the parameter or, for RESET PERSIST, the system variable; null when RESET PERSIST
* names none and removes every persisted variable.
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/** Whether this is MySQL RESET PERSIST, which removes persisted global system variables. */
public boolean isPersist() {
return persist;
}
public void setPersist(boolean persist) {
this.persist = persist;
}
public ResetStatement withPersist(boolean persist) {
setPersist(persist);
return this;
}
/** Whether RESET PERSIST has IF EXISTS before the variable name. */
public boolean isIfExists() {
return ifExists;
}
public void setIfExists(boolean ifExists) {
this.ifExists = ifExists;
}
public ResetStatement withIfExists(boolean ifExists) {
setIfExists(ifExists);
return this;
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append("RESET ");
if (!persist) {
return builder.append(name);
}
builder.append("PERSIST");
if (ifExists) {
builder.append(" IF EXISTS");
}
if (name != null && !name.isEmpty()) {
builder.append(' ').append(name);
}
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}