1414import net .sf .jsqlparser .schema .Table ;
1515import net .sf .jsqlparser .statement .RoutineReference ;
1616import net .sf .jsqlparser .statement .create .table .ColDataType ;
17+ import net .sf .jsqlparser .statement .create .table .ExclusionOperator ;
1718
1819/** A catalog object addressed by COMMENT, rather than a function invocation or a query. */
1920public class CommentTarget implements Serializable {
@@ -24,7 +25,11 @@ public enum Kind {
2425
2526 COLLATION , FOREIGN_TABLE , STATISTICS , DATABASE , ROLE , TABLESPACE , ACCESS_METHOD , EXTENSION ,
2627
27- FOREIGN_DATA_WRAPPER , LANGUAGE , SERVER , EVENT_TRIGGER , PUBLICATION , SUBSCRIPTION ;
28+ FOREIGN_DATA_WRAPPER , LANGUAGE , SERVER , EVENT_TRIGGER , PUBLICATION , SUBSCRIPTION ,
29+
30+ OPERATOR , OPERATOR_CLASS , OPERATOR_FAMILY , LARGE_OBJECT , CONVERSION , TRANSFORM ,
31+
32+ TEXT_SEARCH_CONFIGURATION , TEXT_SEARCH_DICTIONARY , TEXT_SEARCH_PARSER , TEXT_SEARCH_TEMPLATE ;
2833
2934 /**
3035 * Whether the target is a routine signature, exposed by {@link CommentTarget#getRoutine()}.
@@ -40,6 +45,14 @@ public boolean isRoutine() {
4045 public boolean isOwnedByRelation () {
4146 return this == CONSTRAINT || this == TRIGGER || this == POLICY || this == RULE ;
4247 }
48+
49+ /**
50+ * Whether the target is named within the index access method of
51+ * {@link CommentTarget#getAccessMethod()}.
52+ */
53+ public boolean isOwnedByAccessMethod () {
54+ return this == OPERATOR_CLASS || this == OPERATOR_FAMILY ;
55+ }
4356 }
4457
4558 private Kind kind ;
@@ -50,6 +63,13 @@ public boolean isOwnedByRelation() {
5063 private boolean procedural ;
5164 private ColDataType sourceType ;
5265 private ColDataType targetType ;
66+ private ExclusionOperator operator ;
67+ private ColDataType leftOperandType ;
68+ private ColDataType rightOperandType ;
69+ private String accessMethod ;
70+ private Long largeObjectOid ;
71+ private ColDataType transformType ;
72+ private String language ;
5373
5474 public Kind getKind () {
5575 return kind ;
@@ -60,8 +80,8 @@ public void setKind(Kind kind) {
6080 }
6181
6282 /**
63- * The object's identifier; using Table preserves the individual name components. Routine and
64- * cast targets have no name.
83+ * The object's identifier; using Table preserves the individual name components. Routine, cast,
84+ * operator, large object and transform targets have no name.
6585 */
6686 public Table getName () {
6787 return name ;
@@ -126,6 +146,75 @@ public void setTargetType(ColDataType targetType) {
126146 this .targetType = targetType ;
127147 }
128148
149+ /**
150+ * The possibly schema-qualified operator of an {@link Kind#OPERATOR} target, read by the
151+ * operator reference shared with exclusion constraints and ALTER EXTENSION.
152+ */
153+ public ExclusionOperator getOperator () {
154+ return operator ;
155+ }
156+
157+ public void setOperator (ExclusionOperator operator ) {
158+ this .operator = operator ;
159+ }
160+
161+ /** The left operand type of an {@link Kind#OPERATOR} target; null stands for NONE. */
162+ public ColDataType getLeftOperandType () {
163+ return leftOperandType ;
164+ }
165+
166+ public void setLeftOperandType (ColDataType leftOperandType ) {
167+ this .leftOperandType = leftOperandType ;
168+ }
169+
170+ /** The right operand type of an {@link Kind#OPERATOR} target; null stands for NONE. */
171+ public ColDataType getRightOperandType () {
172+ return rightOperandType ;
173+ }
174+
175+ public void setRightOperandType (ColDataType rightOperandType ) {
176+ this .rightOperandType = rightOperandType ;
177+ }
178+
179+ /**
180+ * The index access method of an {@link Kind#OPERATOR_CLASS} or {@link Kind#OPERATOR_FAMILY}
181+ * target.
182+ */
183+ public String getAccessMethod () {
184+ return accessMethod ;
185+ }
186+
187+ public void setAccessMethod (String accessMethod ) {
188+ this .accessMethod = accessMethod ;
189+ }
190+
191+ /** The OID of a {@link Kind#LARGE_OBJECT} target. */
192+ public Long getLargeObjectOid () {
193+ return largeObjectOid ;
194+ }
195+
196+ public void setLargeObjectOid (Long largeObjectOid ) {
197+ this .largeObjectOid = largeObjectOid ;
198+ }
199+
200+ /** The data type of a {@link Kind#TRANSFORM} target. */
201+ public ColDataType getTransformType () {
202+ return transformType ;
203+ }
204+
205+ public void setTransformType (ColDataType transformType ) {
206+ this .transformType = transformType ;
207+ }
208+
209+ /** The procedural language of a {@link Kind#TRANSFORM} target. */
210+ public String getLanguage () {
211+ return language ;
212+ }
213+
214+ public void setLanguage (String language ) {
215+ this .language = language ;
216+ }
217+
129218 /**
130219 * Returns only an explicitly named table, foreign table or view, never an index, type,
131220 * function, statistics object or domain.
@@ -150,6 +239,13 @@ public StringBuilder appendTo(StringBuilder builder, Consumer<Table> relationWri
150239 builder .append (routine );
151240 } else if (kind == Kind .CAST ) {
152241 builder .append ('(' ).append (sourceType ).append (" AS " ).append (targetType ).append (')' );
242+ } else if (kind == Kind .OPERATOR ) {
243+ builder .append (operator ).append (" (" ).append (operandType (leftOperandType ))
244+ .append (", " ).append (operandType (rightOperandType )).append (')' );
245+ } else if (kind == Kind .LARGE_OBJECT ) {
246+ builder .append (largeObjectOid );
247+ } else if (kind == Kind .TRANSFORM ) {
248+ builder .append ("FOR " ).append (transformType ).append (" LANGUAGE " ).append (language );
153249 } else if (namesRelation ()) {
154250 relationWriter .accept (name );
155251 } else {
@@ -161,11 +257,17 @@ public StringBuilder appendTo(StringBuilder builder, Consumer<Table> relationWri
161257 } else {
162258 relationWriter .accept (relation );
163259 }
260+ } else if (kind .isOwnedByAccessMethod ()) {
261+ builder .append (" USING " ).append (accessMethod );
164262 }
165263 }
166264 return builder ;
167265 }
168266
267+ private static Object operandType (ColDataType type ) {
268+ return type == null ? "NONE" : type ;
269+ }
270+
169271 @ Override
170272 public String toString () {
171273 StringBuilder builder = new StringBuilder ();
0 commit comments