Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.sf.jsqlparser.statement.create.table.Index;
import net.sf.jsqlparser.statement.create.table.NamedConstraint;
import net.sf.jsqlparser.statement.create.table.KeyConstraint;
import net.sf.jsqlparser.statement.create.table.TableElement;
import net.sf.jsqlparser.statement.create.table.IndexOptionSource;
import net.sf.jsqlparser.statement.create.table.ConstraintKind;
import net.sf.jsqlparser.statement.create.table.PartitionDefinition;
Expand Down Expand Up @@ -822,8 +823,12 @@ private ConstraintKind getAddedConstraintKind() {
}

private boolean hasColumnOrNamedTarget() {
return oldIndex != null || hasGeneralBodyTarget();
}

private boolean hasGeneralBodyTarget() {
return columnName != null || colDataTypeList != null || constraintName != null
|| oldIndex != null || commentText != null || columnSetNotNullList != null
|| commentText != null || columnSetNotNullList != null
|| columnDropNotNullList != null
|| columnDropDefaultList != null && !columnDropDefaultList.isEmpty();
}
Expand All @@ -835,12 +840,30 @@ private boolean hasColumnOrNamedTarget() {
*/
public boolean hasActiveTableDefinition() {
return operation == AlterOperation.ADD && (constraint != null || index != null)
&& !(constraintType != null && constraintSymbol != null)
&& !isRenameOperation() && commentText == null && columnName == null
&& colDataTypeList == null && columnSetNotNullList == null
&& columnDropNotNullList == null
&& (columnDropDefaultList == null || columnDropDefaultList.isEmpty())
&& constraintName == null;
&& usesGeneralBody() && !hasGeneralBodyTarget();
}

/**
* Returns the original definition contributing to the current body, or null when another
* payload takes precedence. A legacy constraint header renders only its key elements, not every
* option of the returned definition. Stored definitions remain available through
* {@link #getConstraint()} and {@link #getIndex()}.
*/
public TableElement getActiveTableDefinition() {
if (hasActiveConstraintHeader()) {
return operation == AlterOperation.ADD && constraint instanceof KeyConstraint
? constraint
: null;
}
if (!usesGeneralBody() || hasGeneralBodyTarget()) {
return null;
}
return constraint != null ? constraint : index;
}

/** Whether the selected body renders the legacy constraint header. */
public boolean hasActiveConstraintHeader() {
return hasExplicitConstraintHeader();
}

/** Sets an index definition or target; a non-null value replaces any constraint definition. */
Expand Down Expand Up @@ -1166,7 +1189,7 @@ public final String toString() {
protected void appendBody(StringBuilder b) {
if (operation == AlterOperation.UNSPECIFIC) {
b.append(optionalSpecifier);
} else if (hasExplicitConstraintHeader()) {
} else if (hasActiveConstraintHeader()) {
toStringConstraintAlter(b);
} else if (usesColumnActionBody()) {
toStringAlterColumn(b);
Expand Down Expand Up @@ -1197,7 +1220,7 @@ private boolean hasAlterColumnValueActions() {
* overriding {@link #appendBody(StringBuilder)} must reflect their dispatch here as well.
*/
protected boolean usesColumnActionBody() {
return hasAlterColumnValueActions() && !hasExplicitConstraintHeader();
return hasAlterColumnValueActions() && !hasActiveConstraintHeader();
}

/**
Expand All @@ -1206,8 +1229,13 @@ protected boolean usesColumnActionBody() {
* deparsing. Subclasses with their own body dispatch override this method accordingly.
*/
public boolean hasActiveColumnDefinitions() {
return hasColumnDefinitionPayload() && operation != AlterOperation.UNSPECIFIC
&& !hasExplicitConstraintHeader() && !usesColumnActionBody()
return hasColumnDefinitionPayload() && usesGeneralBody();
}

/** Whether this action selects the general body, before choosing its active payload. */
protected boolean usesGeneralBody() {
return operation != AlterOperation.UNSPECIFIC
&& !hasActiveConstraintHeader() && !usesColumnActionBody()
&& !isSimpleKeywordOperation() && !isRenameOperation() && !isDropSpecialOperation()
&& operation != AlterOperation.CONVERT && operation != AlterOperation.COLLATE
&& !isPartitionOperation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
return hasColumnDefinitionPayload() && !isDropSpecialOperation()
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
protected boolean usesGeneralBody() {
return !isDropSpecialOperation()
&& getOperation() != AlterOperation.DROP_PARTITION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

@Override
public KeyConstraint getActiveTableDefinition() {
return getConstraint();
}

@Override
public KeyConstraint getConstraint() {
return (KeyConstraint) super.getConstraint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
return getOperation() == AlterOperation.RENAME && hasColumnDefinitionPayload();
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
protected boolean usesGeneralBody() {
return getOperation() == AlterOperation.RENAME;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ protected boolean usesColumnActionBody() {
}

@Override
public boolean hasActiveColumnDefinitions() {
public boolean hasActiveConstraintHeader() {
return false;
}

@Override
public boolean hasActiveTableDefinition() {
protected boolean usesGeneralBody() {
return false;
}

Expand Down
Loading
Loading