forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateIndex.java
More file actions
137 lines (107 loc) · 3.35 KB
/
CreateIndex.java
File metadata and controls
137 lines (107 loc) · 3.35 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
/*-
* #%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.create.index;
import static java.util.stream.Collectors.joining;
import java.util.*;
import net.sf.jsqlparser.schema.*;
import net.sf.jsqlparser.statement.*;
import net.sf.jsqlparser.statement.create.table.*;
public class CreateIndex implements Statement {
private Table table;
private Index index;
private List<String> tailParameters;
private boolean indexTypeBeforeOn = false;
private boolean usingIfNotExists = false;
public boolean isIndexTypeBeforeOn() {
return indexTypeBeforeOn;
}
public void setIndexTypeBeforeOn(boolean indexTypeBeforeOn) {
this.indexTypeBeforeOn = indexTypeBeforeOn;
}
public boolean isUsingIfNotExists() {
return usingIfNotExists;
}
public CreateIndex setUsingIfNotExists(boolean usingIfNotExists) {
this.usingIfNotExists = usingIfNotExists;
return this;
}
@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
public Index getIndex() {
return index;
}
public void setIndex(Index index) {
this.index = index;
}
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
public List<String> getTailParameters() {
return tailParameters;
}
public void setTailParameters(List<String> tailParameters) {
this.tailParameters = tailParameters;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("CREATE ");
if (index.getType() != null) {
buffer.append(index.getType());
buffer.append(" ");
}
buffer.append("INDEX ");
if (usingIfNotExists) {
buffer.append("IF NOT EXISTS ");
}
buffer.append(index.getName());
if (index.getUsing() != null && isIndexTypeBeforeOn()) {
buffer.append(" USING ");
buffer.append(index.getUsing());
}
buffer.append(" ON ");
buffer.append(table.getFullyQualifiedName());
if (index.getUsing() != null && !isIndexTypeBeforeOn()) {
buffer.append(" USING ");
buffer.append(index.getUsing());
}
if (index.getColumnsNames() != null) {
buffer.append(" (");
buffer.append(
index.getColumns().stream()
.map(Index.ColumnParams::toString)
.collect(joining(", ")));
buffer.append(")");
if (tailParameters != null) {
for (String param : tailParameters) {
buffer.append(" ").append(param);
}
}
}
return buffer.toString();
}
public CreateIndex withTable(Table table) {
this.setTable(table);
return this;
}
public CreateIndex withIndex(Index index) {
this.setIndex(index);
return this;
}
public CreateIndex withTailParameters(List<String> tailParameters) {
this.setTailParameters(tailParameters);
return this;
}
}