Repository navigation
Expand file tree
/
Copy pathSetPasswordStatement.java
More file actions
130 lines (109 loc) · 3.77 KB
/
Copy pathSetPasswordStatement.java
File metadata and controls
130 lines (109 loc) · 3.77 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
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement;
import java.util.function.Consumer;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.statement.create.user.UserAccount;
/**
* MySQL/MariaDB {@code SET PASSWORD [FOR user] {= password | TO RANDOM}
* [REPLACE 'current'] [RETAIN CURRENT PASSWORD]}. The password is an expression, usually a string
* literal; MariaDB also accepts {@code PASSWORD('...')}.
*/
public class SetPasswordStatement implements Statement {
private UserAccount account;
private Expression password;
private boolean random;
private StringValue currentCredential;
private boolean retainCurrentPassword;
/** The account after {@code FOR}, or null for the current user. */
public UserAccount getAccount() {
return account;
}
public void setAccount(UserAccount account) {
this.account = account;
}
/** The password after {@code =}; null for {@code TO RANDOM}. */
public Expression getPassword() {
return password;
}
public void setPassword(Expression password) {
this.password = password;
}
/** Whether the statement generates a password with {@code TO RANDOM}. */
public boolean isRandom() {
return random;
}
public void setRandom(boolean random) {
this.random = random;
}
/** The current password of {@code REPLACE 'current'}, or null when omitted. */
public StringValue getCurrentCredential() {
return currentCredential;
}
public void setCurrentCredential(StringValue currentCredential) {
this.currentCredential = currentCredential;
}
public boolean isRetainCurrentPassword() {
return retainCurrentPassword;
}
public void setRetainCurrentPassword(boolean retainCurrentPassword) {
this.retainCurrentPassword = retainCurrentPassword;
}
/** Shares statement rendering while letting deparsers render the password expression. */
public StringBuilder appendTo(StringBuilder builder, Consumer<Expression> expressionRenderer) {
builder.append("SET PASSWORD");
if (account != null) {
builder.append(" FOR ").append(account);
}
if (random) {
builder.append(" TO RANDOM");
} else {
builder.append(" = ");
expressionRenderer.accept(password);
}
if (currentCredential != null) {
builder.append(" REPLACE ").append(currentCredential);
}
if (retainCurrentPassword) {
builder.append(" RETAIN CURRENT PASSWORD");
}
return builder;
}
@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return appendTo(builder, builder::append).toString();
}
public SetPasswordStatement withAccount(UserAccount account) {
setAccount(account);
return this;
}
public SetPasswordStatement withPassword(Expression password) {
setPassword(password);
return this;
}
public SetPasswordStatement withRandom(boolean random) {
setRandom(random);
return this;
}
public SetPasswordStatement withCurrentCredential(StringValue currentCredential) {
setCurrentCredential(currentCredential);
return this;
}
public SetPasswordStatement withRetainCurrentPassword(boolean retainCurrentPassword) {
setRetainCurrentPassword(retainCurrentPassword);
return this;
}
}