Permalink
Browse files

0003537: initial load create: Cascade Delete rule is not syncing as part

of the create DDL
  • Loading branch information...
philipmarzullo64 committed Feb 4, 2019
1 parent 167beb0 commit 886645a93deb145cf9ab4c4798a7bcb4a2ddc223
@@ -572,8 +572,7 @@ public static void write(Table table, Writer output) {
public static String writeForeignKeyOnUpdateClause(ForeignKey fk) {
// No need to output action for RESTRICT and NO ACTION since that is the default in every database that supports foreign keys
StringBuilder sb = new StringBuilder();
if(! (fk.getOnUpdateAction().equals(ForeignKeyAction.UNDEFINED) ||
fk.getOnUpdateAction().equals(ForeignKeyAction.RESTRICT) ||
if(! (fk.getOnUpdateAction().equals(ForeignKeyAction.RESTRICT) ||
fk.getOnUpdateAction().equals(ForeignKeyAction.NOACTION)
))
{
@@ -586,8 +585,7 @@ public static String writeForeignKeyOnUpdateClause(ForeignKey fk) {
public static String writeForeignKeyOnDeleteClause(ForeignKey fk) {
// No need to output action for RESTRICT and NO ACTION since that is the default in every database that supports foreign keys
StringBuilder sb = new StringBuilder();
if(! (fk.getOnDeleteAction().equals(ForeignKeyAction.UNDEFINED) ||
fk.getOnDeleteAction().equals(ForeignKeyAction.RESTRICT) ||
if(! (fk.getOnDeleteAction().equals(ForeignKeyAction.RESTRICT) ||
fk.getOnDeleteAction().equals(ForeignKeyAction.NOACTION)
))
{
@@ -37,7 +37,6 @@
public class ForeignKey implements Cloneable, Serializable {

public enum ForeignKeyAction {
UNDEFINED("UNDEFINED"),
CASCADE("CASCADE"),
NOACTION("NO ACTION"),
SETNULL("SET NULL"),
@@ -77,9 +76,9 @@ public String getForeignKeyActionName() {

private String foreignTableSchema;

private ForeignKeyAction onDeleteAction = ForeignKeyAction.UNDEFINED;
private ForeignKeyAction onDeleteAction = ForeignKeyAction.NOACTION;

private ForeignKeyAction onUpdateAction = ForeignKeyAction.UNDEFINED;
private ForeignKeyAction onUpdateAction = ForeignKeyAction.NOACTION;

/**
* Creates a new foreign key object that has no name.
@@ -352,8 +351,28 @@ public boolean equals(Object obj) {
builder.append(name, otherFk.name);
}
builder.append(foreignTableName, otherFk.foreignTableName);
builder.append(getOnDeleteAction(), otherFk.getOnDeleteAction());
builder.append(getOnUpdateAction(), otherFk.getOnUpdateAction());

// RESTRICT and NOACTION mean the same functionally, so change RESTRICT to NOACTION
ForeignKeyAction otherForeignKeyDeleteAction = otherFk.getOnDeleteAction();
if(otherForeignKeyDeleteAction.equals(ForeignKeyAction.RESTRICT)) {
otherForeignKeyDeleteAction = ForeignKeyAction.NOACTION;
}
ForeignKeyAction myForeignKeyDeleteAction = getOnDeleteAction();
if(myForeignKeyDeleteAction.equals(ForeignKeyAction.RESTRICT)) {
myForeignKeyDeleteAction = ForeignKeyAction.NOACTION;
}

ForeignKeyAction otherForeignKeyUpdateAction = otherFk.getOnUpdateAction();
if(otherForeignKeyUpdateAction.equals(ForeignKeyAction.RESTRICT)) {
otherForeignKeyUpdateAction = ForeignKeyAction.NOACTION;
}
ForeignKeyAction myForeignKeyUpdateAction = getOnUpdateAction();
if(myForeignKeyUpdateAction.equals(ForeignKeyAction.RESTRICT)) {
myForeignKeyUpdateAction = ForeignKeyAction.NOACTION;
}

builder.append(myForeignKeyDeleteAction, otherForeignKeyDeleteAction);
builder.append(myForeignKeyUpdateAction, otherForeignKeyUpdateAction);

builder.append(references.size(), otherFk.references.size());
for (int i = 0; i < references.size() && i < otherFk.references.size(); i++) {
@@ -382,10 +401,27 @@ public boolean equalsIgnoreCase(ForeignKey otherFk) {

if ((!checkName || name.equalsIgnoreCase(otherFk.name))
&& foreignTableName.equalsIgnoreCase(otherFk.foreignTableName)) {
if(! otherFk.getOnDeleteAction().equals(getOnDeleteAction())) {
// RESTRICT and NOACTION mean the same functionally, so change RESTRICT to NOACTION
ForeignKeyAction otherForeignKeyDeleteAction = otherFk.getOnDeleteAction();
if(otherForeignKeyDeleteAction.equals(ForeignKeyAction.RESTRICT)) {
otherForeignKeyDeleteAction = ForeignKeyAction.NOACTION;
}
ForeignKeyAction myForeignKeyDeleteAction = getOnDeleteAction();
if(myForeignKeyDeleteAction.equals(ForeignKeyAction.RESTRICT)) {
myForeignKeyDeleteAction = ForeignKeyAction.NOACTION;
}
if(! otherForeignKeyDeleteAction.equals(myForeignKeyDeleteAction)) {
return false;
}
if(! otherFk.getOnUpdateAction().equals(getOnUpdateAction())) {
ForeignKeyAction otherForeignKeyUpdateAction = otherFk.getOnUpdateAction();
if(otherForeignKeyUpdateAction.equals(ForeignKeyAction.RESTRICT)) {
otherForeignKeyUpdateAction = ForeignKeyAction.NOACTION;
}
ForeignKeyAction myForeignKeyUpdateAction = getOnUpdateAction();
if(myForeignKeyUpdateAction.equals(ForeignKeyAction.RESTRICT)) {
myForeignKeyUpdateAction = ForeignKeyAction.NOACTION;
}
if(! otherForeignKeyUpdateAction.equals(myForeignKeyUpdateAction)) {
return false;
}
HashSet<Reference> otherRefs = new HashSet<Reference>();
@@ -428,8 +464,18 @@ public int hashCode() {
if (isNotBlank(name)) {
builder.append(name);
}
builder.append(getOnDeleteAction());
builder.append(getOnUpdateAction());
// RESTRICT and NOACTION mean the same functionally, so change RESTRICT to NOACTION
ForeignKeyAction myForeignKeyDeleteAction = getOnDeleteAction();
if(myForeignKeyDeleteAction.equals(ForeignKeyAction.RESTRICT)) {
myForeignKeyDeleteAction = ForeignKeyAction.NOACTION;
}

ForeignKeyAction myForeignKeyUpdateAction = getOnUpdateAction();
if(myForeignKeyUpdateAction.equals(ForeignKeyAction.RESTRICT)) {
myForeignKeyUpdateAction = ForeignKeyAction.NOACTION;
}
builder.append(myForeignKeyDeleteAction);
builder.append(myForeignKeyUpdateAction);
return builder.toHashCode();
}

@@ -448,10 +494,10 @@ public String toString() {
result.append("foreign table=");
result.append(getForeignTableName());
result.append("; ");
if(! getOnDeleteAction().equals(ForeignKeyAction.UNDEFINED)) {
if(! (getOnDeleteAction().equals(ForeignKeyAction.RESTRICT) || getOnDeleteAction().equals(ForeignKeyAction.NOACTION))) {
result.append("ON DELETE " + getOnDeleteAction().getForeignKeyActionName()).append("; ");
}
if(! getOnUpdateAction().equals(ForeignKeyAction.UNDEFINED)) {
if(! (getOnUpdateAction().equals(ForeignKeyAction.RESTRICT) || getOnUpdateAction().equals(ForeignKeyAction.NOACTION))) {
result.append("ON UPDATE " + getOnUpdateAction().getForeignKeyActionName()).append(";");
}
result.append(getReferenceCount());
@@ -477,10 +523,10 @@ public String toVerboseString() {
result.append("foreign table=");
result.append(getForeignTableName());
result.append(";");
if(! getOnDeleteAction().equals(ForeignKeyAction.UNDEFINED)) {
if(! (getOnDeleteAction().equals(ForeignKeyAction.RESTRICT) || getOnDeleteAction().equals(ForeignKeyAction.NOACTION))) {
result.append(" ON DELETE " + getOnDeleteAction().getForeignKeyActionName());
}
if(! getOnUpdateAction().equals(ForeignKeyAction.UNDEFINED)) {
if(! (getOnUpdateAction().equals(ForeignKeyAction.RESTRICT) || getOnUpdateAction().equals(ForeignKeyAction.NOACTION))) {
result.append(" ON UPDATE " + getOnUpdateAction().getForeignKeyActionName());
}
result.append("] references:");
@@ -537,7 +583,7 @@ public static ForeignKeyAction getForeignKeyAction(short importedKeyAction) {
case DatabaseMetaData.importedKeySetNull:
return ForeignKeyAction.SETNULL;
default:
return ForeignKeyAction.UNDEFINED;
return ForeignKeyAction.NOACTION;
}
}

@@ -2464,7 +2464,6 @@ protected void writeCascadeAttributesForForeignKey(ForeignKey key, StringBuilder
protected void writeCascadeAttributesForForeignKeyDelete(ForeignKey key, StringBuilder ddl) {
// No need to output action for RESTRICT and NO ACTION since that is the default in every database that supports foreign keys
if(! (
key.getOnDeleteAction().equals(ForeignKeyAction.UNDEFINED) ||
key.getOnDeleteAction().equals(ForeignKeyAction.RESTRICT) ||
key.getOnDeleteAction().equals(ForeignKeyAction.NOACTION)
)
@@ -2477,7 +2476,6 @@ protected void writeCascadeAttributesForForeignKeyDelete(ForeignKey key, StringB
protected void writeCascadeAttributesForForeignKeyUpdate(ForeignKey key, StringBuilder ddl) {
// No need to output action for RESTRICT and NO ACTION since that is the default in every database that supports foreign keys
if(! (
key.getOnUpdateAction().equals(ForeignKeyAction.UNDEFINED) ||
key.getOnUpdateAction().equals(ForeignKeyAction.RESTRICT) ||
key.getOnUpdateAction().equals(ForeignKeyAction.NOACTION)
)
@@ -1113,15 +1113,15 @@ protected void readForeignKeyUpdateRule(Map<String, Object> values, ForeignKey f
if(values.get(getName("UPDATE_RULE")) != null && values.get(getName("UPDATE_RULE")) instanceof Short) {
fk.setOnUpdateAction(ForeignKey.getForeignKeyAction((Short) values.get(getName("UPDATE_RULE"))));
} else {
fk.setOnUpdateAction(ForeignKeyAction.UNDEFINED);
fk.setOnUpdateAction(ForeignKeyAction.NOACTION);
}
}

protected void readForeignKeyDeleteRule(Map<String, Object> values, ForeignKey fk) {
if(values.get(getName("DELETE_RULE")) != null && values.get(getName("DELETE_RULE")) instanceof Short) {
fk.setOnDeleteAction(ForeignKey.getForeignKeyAction((Short) values.get(getName("DELETE_RULE"))));
} else {
fk.setOnDeleteAction(ForeignKeyAction.UNDEFINED);
fk.setOnDeleteAction(ForeignKeyAction.NOACTION);
}
}

0 comments on commit 886645a

Please sign in to comment.