Announcement

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

    Basic SQL Connector / Multiple Schema

    The DataSource in Basic SQL Connector uses the default database defined in server.properties.

    One use case we are looking at is to be able to switch to any number of Database instances, each instance representing a different environment, with the same table definitions but different data.

    For simple prototype / demo, we can use the DB Admin console to switch the default database instance. However, this obviously is not desirable, as it forces all instances of SmartGWT clients to use whatever the default happens to be selected by one of the end users. The desirable behavior is to allow each client instance to use its own database instances.

    Updating the dbName attribute, after the dataSource has already been loaded using DataSource.get(<name>) has no effect - the default database is still been used. Is there anyway to specify the DataSource to point to a different database - other than the default one?


    SmartGWT Version: 3.0
    Last edited by ksusweep; 14 Dec 2011, 08:53.

    #2
    You can use DataSource.addDynamicDSGenerator() to dynamically generate your DataSources so you can use a different dbName according to each user's preference. In this case you would add a suffix or prefix for all DataSources for a given user, so that they still all have unique names.

    Comment


      #3
      I am building a quick demo app that connects to our database by making relatively minor modifications to the smartgwtEE-3.0 sample built-in-ds, customized to our schema.

      It looks like, from your response, that I need to make modificationon the server side (i.e. com.isomorphic.datasource.DataSource)...

      Does there exist a modified sample of built-in-ds showing how dynamic datasource generator can be used to have different client pointing to different (pre-configured) Database instance?

      Thanks.

      Comment


        #4
        You need to add code, typically in a load-on-startup servlet, that calls DataSource.addDynamicDSGenerator(). It should use the .ds.xml files on disk but add a user-specific dbName property to the XML definition.

        There's no sample of this as it would require an authentication system and various other external pieces to be set up in order to wind up demonstrating just a few lines of code.

        Here's one user who succeeded with this API, doing something similar, and did post some code snippets.

        Comment


          #5
          Thanks. I assume this means adding a custom servlet for loading DataSource, replacing com.isomorphic.servlet.DataSourceLoader ?

          Comment


            #6
            No, a servlet that is load-on-startup and simply calls DataSource.addDynamicDSGenerator. It does not replace any existing servlet. Look at the API and docs and related thread, you seem to think this is more complex than it is.

            Comment


              #7
              Okay, I think the picture is getting clear. W/o a working sample, or visibility into the source code (or the time to read through all the appropriate threads / docs), a relatively simple task could appear to be much more complex than it is.

              Based on my understanding now, I simply have to add a custom servlet that supports dynamic generation of DS. The dynamic DS generator loads DS and connect it to different DB, with the dbName parsed out from the 'cusotmized' DS name specified by the client.

              I'll give this a try. Thanks.

              Comment


                #8
                Hmm, I am not able to invoke the DynamicDSGenerator registered through my servlet.

                I see that my servlet was invoked during server startup, with the following code:

                DataSource.addDynamicDSGenerator(new CustomGenerator(), "dynamic:");

                CustomGenerator is the same as what was posted by Michaelnel. The only modification I made was the separator - ":" instead of "_".

                On the client side, I did:

                //
                // where dbName and dsName in my test case are:
                // "Mysql_env1", and "demoData", respectively
                //
                String name = "dynamic:" + dbName + ":" + dsName;
                DataSource.load(name, new MyCallback(name), true)

                In MyCallback's execute() method, I called DataSource.get(name) -- where
                name was passed in earlier, and is the same string as the one used for loading (i.e. "dynamic:Mysql_env1:demoData"). The response from DataSource.get(name) is null.

                The break point I set in my CustomGenerator:getDataSource() never got triggered... so it appears that either (1) my generator did not get registered successfully somehow, or (2) DataSource failed to delegate the request to load the DataSource to my generator.

                Any idea what the problem might be?

                Comment


                  #9
                  DataSource IDs have to be valid identifiers, can't use ":".

                  Comment


                    #10
                    Yes, that was the problem. Thank you.

                    Comment

                    Working...
                    X