Announcement

Collapse
No announcement yet.

Don't wont to hardcode the database connection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Don't wont to hardcode the database connection

    Hi All

    In the first row of my filter i got this string connection

    var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('org.firebirdsql.jdbc.FBDriver','jdbc:firebirdsql :127.0.0.1:C:\\HDDell\\Data\\MIRTH.FDB','xyxy','xz xzxz');

    Im looking for a way to not hard code the value of the connection

    Is there a way to put the value in a kind of ini file and read the value of thes file ,affect a variable and use this variable in the string connection ?

    What is the best way to do that.

    TIA
    Benzo

  • #2
    Sure. Just use the file reading/writing functions in JavaScript. They should be in the reference list on the right when you're working on a JS step. A preprocessor or a deploy script would be a good idea, read the file when the channel starts then save the params in the channel or global map.
    Jon Bartels

    Zen is hiring!!!!
    http://consultzen.com/careers/
    Talented healthcare IT professionals wanted. Engineers to sales to management.
    Good benefits, great working environment, genuinely interesting work.

    Comment


    • #3
      Right, thats what we are doing (not curently for the DB connections- would be a good idea though) but for replacement tables etc.

      Another way to work with variable parameters is to set up a MASTER-channel that does nothing but setting up global variables, depending on the environment. Thus, our master-channel identifies the environment, based on the servername, and sets some variables accordingly. This could also be used to set database connection data and having appropriate values in any environment.
      JJ Mouris
      FFE Luxembourg
      IT-Department

      Comment


      • #4
        Another advantage to the "master" channel mourisj suggests is that you can simply set these parameters in that channel rather than messing around with an external config file.
        Jon Bartels

        Zen is hiring!!!!
        http://consultzen.com/careers/
        Talented healthcare IT professionals wanted. Engineers to sales to management.
        Good benefits, great working environment, genuinely interesting work.

        Comment


        • #5
          I like this idea of a Master Chanel

          I supposed i have to put the code in the deploy script of it

          But how can i tell to Mirth to strat with the Master Chanel and after run the Update Data Chanel

          Comment


          • #6
            Another way (similar to what was previously posted) is to use the global deploy script that reads a java properties file and places the key/value pairs on the globalMap.
            You can start other channels from within a channel. I had posted a thread with a topic od "Mirth APIs" a week or so ago that shows how to control channels and read java property files pushing values to the map
            http://www.mirthcorp.com/community/f...ead.php?t=4090

            Comment


            • #7
              Hi rts
              I have taken a part of the code of these threrad

              http://www.mirthcorp.com/community/f...ead.php?t=4090

              Code:
              var channelCont = Packages.com.webreach.mirth.server.controllers.Cha.nnelController.getInstance();
              var channelID = channelCont.getChannelId("Update Data");
              var channelStaCont = Packges.com.webreach.mirth.server.controllers.Cha.nnelStatusController.getInstance();
              channelStaCont.stratChanel(channelID);
              I put this code in the deploy scripts of my Master Chanel thinking it will start the Update Data Chanel.

              Is it ok to do it like this ?




              Benzo

              Comment


              • #8
                I have never put that code in a deploy script, not sure if it will run. What I have done is used that code in a transformer. Did you paste that code to the formum because there are errors in it:

                var channelCont = Packages.com.webreach.mirth.server.controllers.Cha nnelController.getInstance();
                var channelID = channelCont.getChannelId("Update Data");
                var channelStaCont = Packges.com.webreach.mirth.server.controllers.Chan nelStatusController.getInstance();
                channelStaCont.startChanel(channelID);

                I see that ChannelController displays as "Cha nnel" There should not be a space there

                Comment


                • #9
                  No i paste the code just to be clear
                  sorry for the "Cha nnel " i have made a error when typing it

                  Comment


                  • #10
                    Originally posted by Benzo View Post
                    I like this idea of a Master Chanel
                    Me too LOL !! Of course, the idea was mine on our site ...

                    I supposed i have to put the code in the deploy script of it
                    Yes, that's the way we do.
                    For the rest, the channel is just a Javascript Reader on the source side and Javascript writer as a destination.

                    The code on both ends is quite complex:

                    Code:
                    return;
                    (As it needs to execute, it executes once a day. We have no performance issues ... )


                    But how can i tell to Mirth to strat with the Master Chanel and after run the Update Data Chanel
                    Last edited by mourisj; 07-14-2010, 11:28 AM.
                    JJ Mouris
                    FFE Luxembourg
                    IT-Department

                    Comment


                    • #11
                      This is what i have done with the help of all of you

                      In the deployed script of the Master Chanel i have write this code
                      Code:
                      globalMap.put("FbDriver",'org.firebirdsql.jdbc.FBDriver');
                      globalMap.put("FbUrl",'jdbc:firebirdsql:127.0.0.1:C:\\xxxx\\yyyy\\MIRTH.FDB');
                      globalMap.put("FbUsername",'XYXYXY');
                      globalMap.put("FbPw",'xyxyxyx');
                      like mourisj wrote

                      For the rest, the channel is just a Javascript Reader on the source side and Javascript writer as a destination.

                      The code on both ends is quite complex:
                      Code:
                      return;
                      and in each place where i need a conenction i have this code
                      Code:
                      var dbConn = DatabaseConnectionFactory.createDatabaseConnection(globalMap.get('FbDriver'),globalMap.get('FbUrl'),globalMap.get('FbUsername'),globalMap.get('FbPw'));
                      If it can help somebody

                      Thank again for your help

                      Comment

                      Working...
                      X