Forum Stats

  • 3,780,909 Users
  • 2,254,454 Discussions
  • 7,879,490 Comments

Discussions

Design Rule: Check for uniqueness

mmagan-Oracle
mmagan-Oracle Member Posts: 30 Employee

I would like to create a design rule that checks if a Table Abbreviation is unique. All the examples I have seen so far seem to operate on a single object.

Does anyone have a code suggestion how to implement this rule?

Best Answer

  • Dimitar Slavov-Oracle
    Dimitar Slavov-Oracle Member Posts: 345 Employee
    edited Jul 8, 2020 9:18AM Accepted Answer

    Hi,

    Try this, but you'll need to polish it a little

    var ruleMessage;var errType;var table;function checkAbbr(table){result = true;ruleMessage="";abbr = table.getAbbreviation();if(abbr){     tables = table.getRelationalModel().getTableSet().toArray();    for (var t = 0; t<tables.length;t++){        cTable = tables[t];        if (table != cTable) {            cAbbr = cTable.getAbbreviation()            if(cAbbr){                if(cAbbr === abbr){                    result = false;                    errType="Problem:";                    ruleMessage="Duplicate Abbreviation -->" + abbr;                }            }        }    }}return result;}checkAbbr(table);

    And the same as transformation script. It shows message dialog:\

    load("nashorn:mozilla_compat.js");importPackage(javax.swing);var msg = "";var arr = [];tables = model.getTableSet().toArray();for (var t = 0; t<tables.length;t++){ table = tables[t]; abbr = table.getAbbreviation().toLowerCase(); if (abbr){     if (arr.indexOf(abbr) !== -1) {         msg += table.getName() + "  ->  " + abbr + '\n';     }     arr.push(abbr); }    }JOptionPane.showMessageDialog(null, msg);

Answers

  • Dimitar Slavov-Oracle
    Dimitar Slavov-Oracle Member Posts: 345 Employee
    edited Jul 8, 2020 9:18AM Accepted Answer

    Hi,

    Try this, but you'll need to polish it a little

    var ruleMessage;var errType;var table;function checkAbbr(table){result = true;ruleMessage="";abbr = table.getAbbreviation();if(abbr){     tables = table.getRelationalModel().getTableSet().toArray();    for (var t = 0; t<tables.length;t++){        cTable = tables[t];        if (table != cTable) {            cAbbr = cTable.getAbbreviation()            if(cAbbr){                if(cAbbr === abbr){                    result = false;                    errType="Problem:";                    ruleMessage="Duplicate Abbreviation -->" + abbr;                }            }        }    }}return result;}checkAbbr(table);

    And the same as transformation script. It shows message dialog:\

    load("nashorn:mozilla_compat.js");importPackage(javax.swing);var msg = "";var arr = [];tables = model.getTableSet().toArray();for (var t = 0; t<tables.length;t++){ table = tables[t]; abbr = table.getAbbreviation().toLowerCase(); if (abbr){     if (arr.indexOf(abbr) !== -1) {         msg += table.getName() + "  ->  " + abbr + '\n';     }     arr.push(abbr); }    }JOptionPane.showMessageDialog(null, msg);