5 Replies Latest reply on Jul 31, 2019 8:06 PM by jflack

    Parameters for a transformation script

    jflack

      Requirement - change the names of all objects found by a search.  For instance, I have objects named "^.*Request.*$" (regular expression) and I want to replace the word "Request" with the word "Application".

       

      I don't think there is a way to do this in the built-in functions of SDDM, but I thought it might be possible to do it in a transformation script.

       

      But the script would need two parameters - an input regular expression like "^(.*)Request(.*)$" and a replace expression like "$1Application$2".

       

      Is there a way for a script to have parameters?

        • 1. Re: Parameters for a transformation script
          Philip Stoyanov-Oracle

          why do you need a parameters in script? We provide access points through variables (like model).

          Then you can do what ever you want in the script - well don't destroy your design on first place .

          You can use the search result (from advanced search) in your transformation script - described in related document (SQLDeveloperDataModelerScripting.docx -  IX.    Usage of result from search functionality).

          Probably there is a replace functionality in the language you are using - at least it exist in Java - so:

          newName = table.getName().replace("Request","Application");

          table.setName(newName);

           

          should work. Of course you can check if the name is changed before setting the new name

          Philip

          • 2. Re: Parameters for a transformation script
            jflack

            The parameters are to generalize the script for reusability. Sure, I COULD write the script with the text to be replaced, and the text to replace it with as hard coded values.  But the next time I need to change names it might be from "Windows" to "Linux", and I'd have to go edit the script and change the hard coded values.

             

            And I ALWAYS save my model before I run a transformation script, and check to make sure it did it right before I save the transformed model.

             

            No problem writing the script - I pretty much know what it needs to do, except for generalizing it.  I did write one that uses User Defined Properties, but those properties don't change very often - I set them and forget them.

            • 3. Re: Parameters for a transformation script
              Gaz in Oz

              Another aproach would be to generate your script then edit it using vim (vi)  or if you are more comfortable with gui, notepad++...

              Both editors have excellent REGEX search and replace capabilities.

              • 4. Re: Parameters for a transformation script
                Dave Schleis

                Hi John,

                You could read the parameters from a file easily enough, but that would require you first writing them to a file.

                 

                If you are using SDDM^Plus you could use the ask() method to prompt for the parameters.

                Screen Shot 2019-07-29 at 7.49.40 AM.png

                 

                If you want to use only the built-in features, to get a dialog box look into JOptionPane.showInputDialog(), which is how ask() works under the covers.

                 

                hope this helps

                 

                --dave

                • 5. Re: Parameters for a transformation script
                  jflack

                  Dave -

                  My code (JavaScript - sorry client doesn't allow Groovy ):

                  JOptionPane = Java.type('javax.swing.JOptionPane');
                  source = JOptionPane.showInputDialog("String to be replaced in selected object names:","");
                  target = JOptionPane.showInputDialog("Replacement string:","");
                  doIt = JOptionPane.showConfirmDialog(null,"Replace "+source+" with "+target+"?");
                  

                  Works great! Prompts for the parameters I need and even a confirmation before it does the actual transformation.

                   

                  Thanks.