-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathAttachStatement.java
More file actions
121 lines (100 loc) · 3.04 KB
/
Copy pathAttachStatement.java
File metadata and controls
121 lines (100 loc) · 3.04 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
/*-
* #%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 net.sf.jsqlparser.statement.select.PlainSelect;
import java.util.List;
/**
* DuckDB's {@code ATTACH [DATABASE] [IF NOT EXISTS] path [AS alias] [(options)]}, which adds
* another database file or remote database to the session.
*
* @see <a href="https://duckdb.org/docs/stable/sql/statements/attach">ATTACH</a>
*/
public class AttachStatement implements Statement {
private String databasePath;
private String alias;
private boolean usingDatabaseKeyword;
private boolean ifNotExists;
private List<String> options;
public String getDatabasePath() {
return databasePath;
}
public void setDatabasePath(String databasePath) {
this.databasePath = databasePath;
}
public AttachStatement withDatabasePath(String databasePath) {
setDatabasePath(databasePath);
return this;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
public AttachStatement withAlias(String alias) {
setAlias(alias);
return this;
}
public boolean isUsingDatabaseKeyword() {
return usingDatabaseKeyword;
}
public void setUsingDatabaseKeyword(boolean usingDatabaseKeyword) {
this.usingDatabaseKeyword = usingDatabaseKeyword;
}
public AttachStatement withUsingDatabaseKeyword(boolean usingDatabaseKeyword) {
setUsingDatabaseKeyword(usingDatabaseKeyword);
return this;
}
public boolean isIfNotExists() {
return ifNotExists;
}
public void setIfNotExists(boolean ifNotExists) {
this.ifNotExists = ifNotExists;
}
public AttachStatement withIfNotExists(boolean ifNotExists) {
setIfNotExists(ifNotExists);
return this;
}
public List<String> getOptions() {
return options;
}
public void setOptions(List<String> options) {
this.options = options;
}
public AttachStatement withOptions(List<String> options) {
setOptions(options);
return this;
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append("ATTACH ");
if (usingDatabaseKeyword) {
builder.append("DATABASE ");
}
if (ifNotExists) {
builder.append("IF NOT EXISTS ");
}
builder.append(databasePath);
if (alias != null) {
builder.append(" AS ").append(alias);
}
if (options != null && !options.isEmpty()) {
builder.append(" ").append(PlainSelect.getStringList(options, true, true));
}
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);
}
}