Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Load a list of all SQL datasourcs (*.ds.xml)

    Version: SmartGWT EE 2.3

    Hi all,

    How do I retrieve/load a list of all SQL datasourcs (i.e. *.ds.xml)?

    The strategy I came up with is to retrieve value of the property project.datasources from server.properties, then read in all *.ds.xml files.

    I found in dsGenerator.jsp this was done like

    <%@ page import="com.isomorphic.base.Config" %>
    .........

    <%
    ...
    // Remember the path we're going to store to, so we can put it in the instructions
    String path = Config.getGlobal().getString("project.datasources");
    if (path.indexOf(",") != -1) path = path.substring(0, path.indexOf(","));

    // Replace '\' with '/' to prevent unwanted escaping on Windows servers
    path = path.replace('\\', '/');
    %>

    ...

    But I wasn't able to access the Config class in SmartGWT.

    Can someone give me a pointer?

    Thanks,

    Sam

    #2
    You can create a DMI that returns the list of DataSources as data.

    Comment


      #3
      Hi,

      Thanks for reply. Can you be a bit more specific about how to do that in DMI?

      I managed to load server.properties file but the tricky part is intepreting
      $webRoot from project.datasources (i.e. project.datasources: $webRoot/ds )

      Thanks

      Sam

      Comment


        #4
        Use the Config class you previously mentioned to get the property. If you're having trouble accessing it, explain what the issue is in detail (with logs or error messages, etc).

        Comment


          #5
          Thanks for reply.

          I added the following code in entry class.

          ...
          import com.isomorphic.base.Config;
          ...
          private IButton debugButton() {

          IButton vbButton = new IButton("Debug");

          vbButton.addClickHandler(new ClickHandler() {
          public void onClick(ClickEvent event) {
          String path = com.isomorphic.base.Config.getGlobal().getString("project.datasources" );
          if (path.indexOf(",") != -1) path = path.substring(0, path.indexOf(","));

          // Replace '\' with '/' to prevent unwanted escaping on Windows servers
          path = path.replace('\\', '/');

          System.out.println("Path: " + path );
          }
          });
          vbButton.draw();
          return vbButton;

          }


          When I try to compile, I will get the following error

          ...
          javac:
          [mkdir] Created dir: C:\progs\smartgwt\smartgwtee-2.3\samples\built-in-ds\war\WEB-INF\classes
          [javac] Compiling 5 source files to C:\progs\smartgwt\smartgwtee-2.3\samples\built-in-ds\war\WEB-INF\classes
          [copy] Copying 4 files to C:\progs\smartgwt\smartgwtee-2.3\samples\built-in-ds\war\WEB-INF\classes
          gwtc:
          [java] Compiling module com.smartgwt.sample.BuiltInDS
          [java] Validating newly compiled units
          [java] [ERROR] Errors in 'file:/C:/progs/smartgwt/smartgwtee-2.3/samples/built-in-ds/src/com/smartgwt/sample/client/BuiltInDS.java'
          [java] [ERROR] Line 267: No source code is available for type com.isomorphic.base.Config; did you forget to inherit a required module?
          [java] Finding entry point classes
          [java] [ERROR] Unable to find type 'com.smartgwt.sample.client.BuiltInDS'
          [java] [ERROR] Hint: Previous compiler errors may have made this type unavailable
          [java] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

          BUILD FAILED
          C:\progs\smartgwt\smartgwtee-2.3\samples\built-in-ds\build.xml:51: Java returned: 1

          The Config class is found in isomorphic_core_rpc.jar, which is in my classpath
          (i.e. in ..\war\WEB-INF\lib)

          I suspect I need to add something to inherit Config class in BuiltInDS.gwt.xml but I don't what.

          Thanks

          Sam

          Comment


            #6
            Config is a server-side class. It's not in the browser. Write server-side Java code (a DMI) to access it.

            Comment


              #7
              Hi,

              Could you outline the approach you would take to do that?
              I just can't get it to work.

              My objective is to populate a ListGrid with all datasources available like in sample app BuldInDS rather than adding datasource to ListGrid manually.

              Thanks

              Sam

              Comment


                #8
                There's not much to outline?

                Define a DataSource with one field "dataSourceId" and add a DMI (see QuickStart) declaration. In the target method, use Config to get the directory where DataSources are stored. Then get the list of .ds.xml files in that directory (you see to already know how to do that part). Return it as a List of Maps where each Map has the DataSource id (first part of the filename) as one entry under the key "dataSourceId".

                Comment


                  #9
                  Cool. Thanks. I finally got it working.

                  It looks like I have to use DMI to access server-side classes,
                  which raises another important question
                  like exactly what classes/packages from smartgwtee are server-side?

                  I am assuming it's any package under

                  com.isomorphic.*

                  Correct me if wrong.

                  Thanks

                  Sam

                  Comment


                    #10
                    That's correct, but we deliver the JavaDoc in two separate directories so there's no ambiguity. See the QuickStart Guide.

                    Comment


                      #11
                      Thanks for clarification.

                      It looks like there are some server side classes that have no JavaDoc
                      for smartgwtee-2.3

                      E.g. com.isomorphic.base.Config

                      I think others have asked this question for other classes.

                      Is there any plan to publish JavaDoc for these internal server side classes in future?

                      Thanks

                      Sam

                      Comment


                        #12
                        Config now has some public APIs if you get the latest.

                        For the rest, if they are internal, you aren't meant to use them and their APIs are not supported, so no, they won't be documented.

                        Comment

                        Working...
                        X