99 */
1010package net .sf .jsqlparser .util .deparser ;
1111
12- import java .util .Iterator ;
1312import net .sf .jsqlparser .expression .ExpressionVisitor ;
14- import net .sf .jsqlparser .statement .create .table .CheckConstraint ;
1513import net .sf .jsqlparser .statement .create .table .ColumnDefinition ;
1614import net .sf .jsqlparser .statement .create .table .ColumnOption ;
17- import net .sf .jsqlparser .statement .create .table .DefaultConstraint ;
18- import net .sf .jsqlparser .statement .create .table .ExcludeConstraint ;
1915import net .sf .jsqlparser .statement .create .table .Index ;
2016import net .sf .jsqlparser .statement .create .table .TableElement ;
2117
@@ -31,13 +27,9 @@ public TableElementDeParser(StringBuilder builder,
3127
3228 @ Override
3329 public void deParse (TableElement element ) {
34- if (element instanceof DefaultConstraint ) {
35- ((DefaultConstraint ) element ).appendTo (builder ,
30+ if (element instanceof Index ) {
31+ ((Index ) element ).appendTo (builder ,
3632 expression -> expression .accept (expressionVisitor , null ));
37- } else if (element instanceof ExcludeConstraint ) {
38- deParseExclude ((ExcludeConstraint ) element );
39- } else if (element instanceof CheckConstraint ) {
40- deParseCheck ((CheckConstraint ) element );
4133 } else if (element instanceof ColumnDefinition
4234 && ((ColumnDefinition ) element ).getColumnOptions () != null ) {
4335 deParseColumn ((ColumnDefinition ) element );
@@ -64,48 +56,4 @@ private void deParseColumn(ColumnDefinition column) {
6456 }
6557 }
6658
67- private void deParseExclude (ExcludeConstraint constraint ) {
68- if (constraint .getName () != null ) {
69- builder .append ("CONSTRAINT " ).append (constraint .getName ()).append (' ' );
70- }
71- builder .append ("EXCLUDE" );
72- if (constraint .getUsing () != null ) {
73- builder .append (" USING " ).append (constraint .getUsing ());
74- }
75- if (constraint .getColumns () != null ) {
76- builder .append (" (" );
77- for (Iterator <Index .ColumnParams > iterator =
78- constraint .getColumns ().iterator (); iterator .hasNext ();) {
79- iterator .next ().appendTo (builder ,
80- expression -> expression .accept (expressionVisitor , null ));
81- if (iterator .hasNext ()) {
82- builder .append (", " );
83- }
84- }
85- builder .append (')' );
86- }
87- constraint .appendConstraintOptionsTo (builder );
88- if (constraint .getExpression () != null ) {
89- builder .append (" WHERE (" );
90- constraint .getExpression ().accept (expressionVisitor , null );
91- builder .append (')' );
92- }
93- constraint .appendConstraintAttributesTo (builder );
94- }
95-
96- private void deParseCheck (CheckConstraint constraint ) {
97- constraint .appendConstraintPrefixTo (builder );
98- builder .append ("CHECK (" );
99- if (constraint .getExpression () != null ) {
100- constraint .getExpression ().accept (expressionVisitor , null );
101- } else {
102- builder .append ("null" );
103- }
104- builder .append (')' );
105- if (constraint .getEnforced () != null ) {
106- builder .append (constraint .getEnforced () ? " ENFORCED" : " NOT ENFORCED" );
107- }
108- constraint .appendConstraintSuffixTo (builder );
109- constraint .appendConstraintAttributesTo (builder );
110- }
11159}
0 commit comments