Repository navigation
Expand file tree
/
Copy pathIndexOptions.java
More file actions
171 lines (145 loc) · 5.05 KB
/
Copy pathIndexOptions.java
File metadata and controls
171 lines (145 loc) · 5.05 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*-
* #%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.create.table;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.statement.select.PlainSelect;
/** Index implementation options explicitly present in an index or supporting-key declaration. */
public class IndexOptions implements Serializable {
public enum Clustering {
CLUSTERED, NONCLUSTERED
}
private String using;
private List<IndexSpecOption> specOptions;
private String commentText;
private Clustering clustering;
private Boolean nullsDistinct;
private List<String> includeColumns;
private List<IndexOption> storageParameters;
private String tableSpace;
public String getUsing() {
return using;
}
public void setUsing(String using) {
this.using = using;
}
/**
* Returns the mutable, ordered options written after the key list, or null when unset. An index
* type written before the key list is {@link #getUsing()} instead.
*/
public List<IndexSpecOption> getSpecOptions() {
return specOptions;
}
/** Copies the list membership and retains the option nodes; null clears the options. */
public void setSpecOptions(List<IndexSpecOption> specOptions) {
this.specOptions = specOptions == null ? null : new ArrayList<>(specOptions);
}
public IndexOptions addSpecOptions(IndexSpecOption... options) {
return addSpecOptions(Arrays.asList(options));
}
public IndexOptions addSpecOptions(Collection<? extends IndexSpecOption> options) {
if (specOptions == null) {
specOptions = new ArrayList<>();
}
specOptions.addAll(options);
return this;
}
/**
* Returns an unmodifiable token snapshot of {@link #getSpecOptions()}, such as
* {@code [KEY_BLOCK_SIZE, =, 8, COMMENT, 'text']}, or null when unset. Edit the option nodes
* instead of the snapshot.
*/
public List<String> getIndexSpec() {
if (specOptions == null) {
return null;
}
List<String> tokens = new ArrayList<>();
for (IndexSpecOption option : specOptions) {
tokens.addAll(option.getTokens());
}
return Collections.unmodifiableList(tokens);
}
/**
* Replaces all options after the key list with one opaque option holding a copy of the tokens,
* without parsing them. Null clears the options; an empty list stores no options.
*/
public void setIndexSpec(List<String> indexSpec) {
if (indexSpec == null) {
specOptions = null;
return;
}
specOptions = new ArrayList<>();
if (!indexSpec.isEmpty()) {
specOptions.add(IndexSpecOption.raw(indexSpec));
}
}
public String getCommentText() {
return commentText;
}
public void setCommentText(String commentText) {
this.commentText = commentText;
}
public Clustering getClustering() {
return clustering;
}
public void setClustering(Clustering clustering) {
this.clustering = clustering;
}
public Boolean getNullsDistinct() {
return nullsDistinct;
}
public void setNullsDistinct(Boolean nullsDistinct) {
this.nullsDistinct = nullsDistinct;
}
public List<String> getIncludeColumns() {
return includeColumns;
}
public void setIncludeColumns(List<String> includeColumns) {
this.includeColumns = includeColumns == null ? null : new ArrayList<>(includeColumns);
}
public List<IndexOption> getStorageParameters() {
return storageParameters;
}
public void setStorageParameters(List<IndexOption> storageParameters) {
this.storageParameters =
storageParameters == null ? null : new ArrayList<>(storageParameters);
}
public String getTableSpace() {
return tableSpace;
}
public void setTableSpace(String tableSpace) {
this.tableSpace = tableSpace;
}
public String nullsDistinctClause() {
return nullsDistinct == null ? ""
: nullsDistinct ? " NULLS DISTINCT" : " NULLS NOT DISTINCT";
}
public String clusteringClause() {
return clustering == null ? "" : " " + clustering;
}
public void appendTo(StringBuilder sql, Consumer<Expression> expressionPrinter) {
if (includeColumns != null) {
sql.append(" INCLUDE ").append(PlainSelect.getStringList(includeColumns, true, true));
}
if (storageParameters != null) {
sql.append(" WITH ");
IndexOption.appendListTo(sql, storageParameters, expressionPrinter);
}
if (tableSpace != null) {
sql.append(" USING INDEX TABLESPACE ").append(tableSpace);
}
}
}