-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathCommentTarget.java
More file actions
104 lines (88 loc) · 2.78 KB
/
Copy pathCommentTarget.java
File metadata and controls
104 lines (88 loc) · 2.78 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 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.comment;
import java.io.Serializable;
import java.util.function.Consumer;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.RoutineReference;
/** A catalog object addressed by COMMENT, rather than a function invocation or a query. */
public class CommentTarget implements Serializable {
public enum Kind {
INDEX, SCHEMA, SEQUENCE, DOMAIN, TYPE, MATERIALIZED_VIEW, FUNCTION, CONSTRAINT
}
private Kind kind;
private Table name;
private RoutineReference routine;
private Table relation;
private boolean onDomain;
public Kind getKind() {
return kind;
}
public void setKind(Kind kind) {
this.kind = kind;
}
/** The object's identifier; using Table preserves the individual name components. */
public Table getName() {
return name;
}
public void setName(Table name) {
this.name = name;
}
public RoutineReference getRoutine() {
return routine;
}
public void setRoutine(RoutineReference routine) {
this.routine = routine;
}
/** The table or domain owning a constraint, distinguished by {@link #isOnDomain()}. */
public Table getRelation() {
return relation;
}
public void setRelation(Table relation) {
this.relation = relation;
}
public boolean isOnDomain() {
return onDomain;
}
public void setOnDomain(boolean onDomain) {
this.onDomain = onDomain;
}
/** Returns only an explicitly named table/view, never an index, type, function or domain. */
public Table getReferencedRelation() {
if (kind == Kind.MATERIALIZED_VIEW) {
return name;
}
return kind == Kind.CONSTRAINT && !onDomain ? relation : null;
}
public StringBuilder appendTo(StringBuilder builder, Consumer<Table> relationWriter) {
builder.append(kind.name().replace('_', ' ')).append(' ');
if (kind == Kind.FUNCTION) {
builder.append(routine);
} else if (kind == Kind.MATERIALIZED_VIEW) {
relationWriter.accept(name);
} else {
builder.append(name);
if (kind == Kind.CONSTRAINT) {
builder.append(" ON ");
if (onDomain) {
builder.append("DOMAIN ").append(relation);
} else {
relationWriter.accept(relation);
}
}
}
return builder;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return appendTo(builder, builder::append).toString();
}
}