From ee4814b6cac2795e0dab730715cbaea5ef46e145 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 17 Aug 2015 20:45:40 -0500 Subject: [PATCH] more refactoring IDEMPIERE-1132 foreign key management for ticket IDEMPIERE-2745 - do not create FK if same already exists in DB --- .../src/org/compiere/model/MColumn.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MColumn.java b/org.adempiere.base/src/org/compiere/model/MColumn.java index 8858d88a5c..2d7ce046d8 100644 --- a/org.adempiere.base/src/org/compiere/model/MColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MColumn.java @@ -853,10 +853,13 @@ public class MColumn extends X_AD_Column { Hashtable htForeignKeys = new Hashtable(); - if (md.storesUpperCaseIdentifiers()) + if (md.storesUpperCaseIdentifiers()) { referenceTableName = referenceTableName.toUpperCase(); - else if (md.storesLowerCaseIdentifiers()) + tableName = tableName.toUpperCase(); + } else if (md.storesLowerCaseIdentifiers()) { referenceTableName = referenceTableName.toLowerCase(); + tableName = tableName.toLowerCase(); + } if (!isNoTable) { ResultSet rs = null; @@ -968,6 +971,18 @@ public class MColumn extends X_AD_Column column.setFKConstraintName(fkConstraintName); column.setFKConstraintType(fkConstraintType); column.saveEx(); + + // if the current db FK is same as what we need to create + if ( dbForeignKey.getKeyName().equalsIgnoreCase(column.getFKConstraintName()) + && ( (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeyCascade && MColumn.FKCONSTRAINTTYPE_Cascade.equals(column.getFKConstraintType())) + || (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeySetNull && MColumn.FKCONSTRAINTTYPE_SetNull.equals(column.getFKConstraintType())) + || (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeyNoAction && MColumn.FKCONSTRAINTTYPE_NoAction.equals(column.getFKConstraintType())) + || (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeyRestrict && MColumn.FKCONSTRAINTTYPE_NoAction.equals(column.getFKConstraintType())) + ) + ) { + // nothing changed + return ""; + } } } modified = true;