Announcement

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

    Different datasources per client

    I need to use a different .ds.xml per client, which has a clientId.
    Is it possible to do this? For example, to have the .ds.xml files in different folders, example:
    1/file.ds.xml
    2/file.ds.xml

    where 1 and 2 are the clientIds.
    But:
    What would be the datasource id?
    And what to put in DataSourceLoader?dataSource= ?
    Using smartgwt 5.0p power.

    #2
    I think it will work with server.properties:
    project.datasources: $webRoot/ds,$webRoot/ds/${clientId}

    Where clientId is a property from default.properties loaded in the pom:
    <filters>
    <filter>${basedir}/src/main/resources/classpath/default.properties</filter>
    </filters>

    Comment


      #3
      That works if what you have in mind is running a separate JVM per client. Each JVM uses one .properties file.

      Comment


        #4
        yes, you are correct. I saw this problem today.

        So what can I do if I use the same JVM for all clients? How can I load a different .ds.xml per client ?

        Comment


          #5
          Maybe it is important: I have the clientId in the session after the client logs in:

          So this prints it in a jsp page:
          <% out.print(request.getSession().getAttribute("clientId")); %>

          Comment


            #6
            So this would work in the main jsp page:

            <script src="${gwtDirectory}/sc/DataSourceLoader?dataSource=<% out.print(request.getSession().getAttribute("clientId")); %> /datasourceName

            It would print e.g. DataSourceLoader?dataSource=1/datasourceName
            but why doesn't this work?

            Comment


              #7
              Hi edulid,

              as far as I understood DataSourceLoader is only responsible for getting .ds.xml-data relevant for the js-client to the clientside.
              On the server, the whole ds-dir is checked. So even if this worked, you'd have many .ds.xml with the same ID on the server.

              This also means that you do only need to have the ds in the DataSourceLoader-querystring you are really using clientside. All other ds should not be sent to the client and actually be proteced against client-access.

              What I'm doing here is building different wars for different clients/tenants.
              If this is no option for you, then perhaps subclassing SQLDataSource and doing the per-client modifications here might be an option. I did not try this, though.

              Best regards
              Blama

              Comment


                #8
                Originally posted by Blama View Post
                On the server, the whole ds-dir is checked. So even if this worked, you'd have many .ds.xml with the same ID on the server.
                This is an important point, you are right.

                What I'm doing here is building different wars for different clients/tenants.
                If this is no option for you,
                This is not option for me, indeed.

                then perhaps subclassing SQLDataSource and doing the per-client modifications here might be an option. I did not try this, though.
                The datasources for each client are very different between clients, so I need a completely different datasource for each client.

                Isomorphic? Is there any recommended way to achieve this ?

                Comment


                  #9
                  Use a DynamicDSLoader as described in the QuickStart Guide.

                  DataSources with different definitions need different IDs, so the variations on DataSources used for different clients should incorporate the clientID into the DataSource ID (we would recommend using it as a prefix).

                  Note that DataSource IDs must be valid identifiers, so using a filesystem path, which includes "/", is not allowed.

                  Comment


                    #10
                    Originally posted by Isomorphic View Post
                    Use a DynamicDSLoader as described in the QuickStart Guide.
                    I will take a look at this, thanks

                    DataSources with different definitions need different IDs, so the variations on DataSources used for different clients should incorporate the clientID into the DataSource ID (we would recommend using it as a prefix).
                    They need different IDs even if I load only one of them? Why? I don't know if I understand this correctly.

                    Comment


                      #11
                      Originally posted by Isomorphic View Post
                      Use a DynamicDSLoader as described in the QuickStart Guide.
                      I cannot find anything on "DynamicDSLoader", neither on the quick guide nor in the javadocs. Are you sure the class name is this ?
                      I found DynamicDSGenerator, but I am not generating Datasources..

                      Comment


                        #12
                        Sorry yes, DynamicDSGenerator.

                        Two DataSources with two different definitions cannot have the same ID if they are both used in the same JVM. So yes, you need distinct IDs.

                        Comment


                          #13
                          Ok, and can Datasources generated by a DynamicDSGenerator also be used in the client-side or only on the server-side? How to load them on the client-side ?

                          Comment


                            #14
                            Exactly the same way other DataSources are used: DataSourceLoader, DataSource.load() etc. The whole point of DynamicDSGenerator is that both client and server-side usage is identical - you could take a normal DataSource, make it dynamic, and no other code would need to change.

                            Comment


                              #15
                              Ok, thanks, I am taking a look at this.

                              I am trying to load a generator, but where is the best place to register it?

                              I have tried in different places, but I get:
                              Code:
                              java.io.IOException: Configured for containerIO, but servletContext not available!  You need to install the Init servlet
                              	at com.isomorphic.io.ISCFile.<init>(ISCFile.java:180)
                              	at com.isomorphic.xml.XML.getXMLDocument(XML.java:286)
                              	at com.isomorphic.xml.XML.toDSRecords(XML.java:294)
                              	at com.isomorphic.xml.XML.toDSRecords(XML.java:298)
                              	at com.isomorphic.xml.XML.toDSRecords(XML.java:303)
                              	at com.isomorphic.datasource.DataSource.<clinit>(DataSource.java:990)
                              	at de.mks_infofabrik.kids.server.guice.DispatchServletModule.configureServlets(DispatchServletModule.java:166)
                              	at com.google.inject.servlet.ServletModule.configure(ServletModule.java:53)
                              	at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
                              	at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
                              	at com.google.inject.spi.Elements.getElements(Elements.java:101)
                              	at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
                              	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
                              	at com.google.inject.Guice.createInjector(Guice.java:95)
                              	at com.google.inject.Guice.createInjector(Guice.java:72)
                              	at com.google.inject.Guice.createInjector(Guice.java:62)
                              	at de.mks_infofabrik.kids.server.guice.MyGuiceServletContextListener.getInjector(MyGuiceServletContextListener.java:13)
                              	at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)
                              	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4728)
                              	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166)
                              	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
                              	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
                              	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
                              	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
                              	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)
                              	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1720)
                              	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
                              	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
                              	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                              	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                              	at java.lang.Thread.run(Thread.java:745)
                              Where to register the generator?

                              Comment

                              Working...
                              X