@@ -36,6 +36,9 @@ public class AlterExpression implements Serializable {
36
36
private List <ColumnDataType > colDataTypeList ;
37
37
private List <ColumnDropNotNull > columnDropNotNullList ;
38
38
private List <ColumnDropDefault > columnDropDefaultList ;
39
+ private List <ColumnSetDefault > columnSetDefaultList ;
40
+ private List <ColumnSetVisibility > columnSetVisibilityList ;
41
+
39
42
private List <String > pkColumns ;
40
43
private List <String > ukColumns ;
41
44
private String ukName ;
@@ -88,6 +91,10 @@ public class AlterExpression implements Serializable {
88
91
89
92
private int keyBlockSize ;
90
93
94
+ private String constraintSymbol ;
95
+ private boolean enforced ;
96
+ private String constraintType ;
97
+
91
98
public Index getOldIndex () {
92
99
return oldIndex ;
93
100
}
@@ -302,13 +309,39 @@ public void addColDropNotNull(ColumnDropNotNull columnDropNotNull) {
302
309
columnDropNotNullList .add (columnDropNotNull );
303
310
}
304
311
312
+ public List <ColumnDropDefault > getColumnDropDefaultList () {
313
+ return columnDropDefaultList ;
314
+ }
315
+
305
316
public void addColDropDefault (ColumnDropDefault columnDropDefault ) {
306
317
if (columnDropDefaultList == null ) {
307
318
columnDropDefaultList = new ArrayList <>();
308
319
}
309
320
columnDropDefaultList .add (columnDropDefault );
310
321
}
311
322
323
+ public void addColSetDefault (ColumnSetDefault columnSetDefault ) {
324
+ if (columnSetDefaultList == null ) {
325
+ columnSetDefaultList = new ArrayList <>();
326
+ }
327
+ columnSetDefaultList .add (columnSetDefault );
328
+ }
329
+
330
+ public List <ColumnSetDefault > getColumnSetDefaultList () {
331
+ return columnSetDefaultList ;
332
+ }
333
+
334
+ public void addColSetVisibility (ColumnSetVisibility columnSetVisibility ) {
335
+ if (columnSetVisibilityList == null ) {
336
+ columnSetVisibilityList = new ArrayList <>();
337
+ }
338
+ columnSetVisibilityList .add (columnSetVisibility );
339
+ }
340
+
341
+ public List <ColumnSetVisibility > getColumnSetVisibilityList () {
342
+ return columnSetVisibilityList ;
343
+ }
344
+
312
345
public List <String > getFkSourceColumns () {
313
346
return fkSourceColumns ;
314
347
}
@@ -571,6 +604,30 @@ public int getKeyBlockSize() {
571
604
return keyBlockSize ;
572
605
}
573
606
607
+ public String getConstraintSymbol () {
608
+ return constraintSymbol ;
609
+ }
610
+
611
+ public void setConstraintSymbol (String constraintSymbol ) {
612
+ this .constraintSymbol = constraintSymbol ;
613
+ }
614
+
615
+ public boolean isEnforced () {
616
+ return enforced ;
617
+ }
618
+
619
+ public void setEnforced (boolean enforced ) {
620
+ this .enforced = enforced ;
621
+ }
622
+
623
+ public String getConstraintType () {
624
+ return constraintType ;
625
+ }
626
+
627
+ public void setConstraintType (String constraintType ) {
628
+ this .constraintType = constraintType ;
629
+ }
630
+
574
631
@ Override
575
632
@ SuppressWarnings ({"PMD.CyclomaticComplexity" , "PMD.NPathComplexity" ,
576
633
"PMD.ExcessiveMethodLength" , "PMD.SwitchStmtsShouldHaveDefault" })
@@ -580,6 +637,38 @@ public String toString() {
580
637
581
638
if (operation == AlterOperation .UNSPECIFIC ) {
582
639
b .append (optionalSpecifier );
640
+ } else if (operation == AlterOperation .ALTER && constraintType != null ) {
641
+ b .append ("ALTER" );
642
+ b .append (" " ).append (constraintType );
643
+
644
+ if (constraintSymbol != null ) {
645
+ b .append (" " ).append (constraintSymbol );
646
+ }
647
+ if (!isEnforced ()) {
648
+ b .append (" NOT " );
649
+ }
650
+ b .append (" ENFORCED" );
651
+ } else if (operation == AlterOperation .ALTER
652
+ && columnDropDefaultList != null && !columnDropDefaultList .isEmpty ()) {
653
+ b .append ("ALTER " );
654
+ if (hasColumn ) {
655
+ b .append ("COLUMN " );
656
+ }
657
+ b .append (PlainSelect .getStringList (columnDropDefaultList ));
658
+ } else if (operation == AlterOperation .ALTER
659
+ && columnSetDefaultList != null && !columnSetDefaultList .isEmpty ()) {
660
+ b .append ("ALTER " );
661
+ if (hasColumn ) {
662
+ b .append ("COLUMN " );
663
+ }
664
+ b .append (PlainSelect .getStringList (columnSetDefaultList ));
665
+ } else if (operation == AlterOperation .ALTER
666
+ && columnSetVisibilityList != null && !columnSetVisibilityList .isEmpty ()) {
667
+ b .append ("ALTER " );
668
+ if (hasColumn ) {
669
+ b .append ("COLUMN " );
670
+ }
671
+ b .append (PlainSelect .getStringList (columnSetVisibilityList ));
583
672
} else if (operation == AlterOperation .SET_TABLE_OPTION ) {
584
673
b .append (tableOption );
585
674
} else if (operation == AlterOperation .DISCARD_TABLESPACE ) {
@@ -1139,6 +1228,52 @@ public String toString() {
1139
1228
}
1140
1229
}
1141
1230
1231
+ public static final class ColumnSetDefault implements Serializable {
1232
+ private final String columnName ;
1233
+ private final String defaultValue ;
1234
+
1235
+ public ColumnSetDefault (String columnName , String defaultValue ) {
1236
+ this .columnName = columnName ;
1237
+ this .defaultValue = defaultValue ;
1238
+ }
1239
+
1240
+ public String getColumnName () {
1241
+ return columnName ;
1242
+ }
1243
+
1244
+ public String getDefaultValue () {
1245
+ return defaultValue ;
1246
+ }
1247
+
1248
+ @ Override
1249
+ public String toString () {
1250
+ return columnName + " SET DEFAULT " + defaultValue ;
1251
+ }
1252
+ }
1253
+
1254
+ public static final class ColumnSetVisibility implements Serializable {
1255
+ private final String columnName ;
1256
+ private final boolean visible ;
1257
+
1258
+ public ColumnSetVisibility (String columnName , boolean visible ) {
1259
+ this .columnName = columnName ;
1260
+ this .visible = visible ;
1261
+ }
1262
+
1263
+ public String getColumnName () {
1264
+ return columnName ;
1265
+ }
1266
+
1267
+ public boolean isVisible () {
1268
+ return visible ;
1269
+ }
1270
+
1271
+ @ Override
1272
+ public String toString () {
1273
+ return columnName + " SET " + (visible ? " VISIBLE" : " INVISIBLE" );
1274
+ }
1275
+ }
1276
+
1142
1277
public enum ConvertType {
1143
1278
CONVERT_TO , DEFAULT_CHARACTER_SET , CHARACTER_SET
1144
1279
}
0 commit comments