more refactoring IDEMPIERE-1132 foreign key management for ticket IDEMPIERE-2745 - do not create FK if same already exists in DB

This commit is contained in:
Carlos Ruiz 2015-08-17 20:45:40 -05:00
parent 4d933e8287
commit ee4814b6ca
1 changed files with 17 additions and 2 deletions

View File

@ -853,10 +853,13 @@ public class MColumn extends X_AD_Column
{ {
Hashtable<String, DatabaseKey> htForeignKeys = new Hashtable<String, DatabaseKey>(); Hashtable<String, DatabaseKey> htForeignKeys = new Hashtable<String, DatabaseKey>();
if (md.storesUpperCaseIdentifiers()) if (md.storesUpperCaseIdentifiers()) {
referenceTableName = referenceTableName.toUpperCase(); referenceTableName = referenceTableName.toUpperCase();
else if (md.storesLowerCaseIdentifiers()) tableName = tableName.toUpperCase();
} else if (md.storesLowerCaseIdentifiers()) {
referenceTableName = referenceTableName.toLowerCase(); referenceTableName = referenceTableName.toLowerCase();
tableName = tableName.toLowerCase();
}
if (!isNoTable) { if (!isNoTable) {
ResultSet rs = null; ResultSet rs = null;
@ -968,6 +971,18 @@ public class MColumn extends X_AD_Column
column.setFKConstraintName(fkConstraintName); column.setFKConstraintName(fkConstraintName);
column.setFKConstraintType(fkConstraintType); column.setFKConstraintType(fkConstraintType);
column.saveEx(); 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; modified = true;