Announcement

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

    Multiple DBs Publich to JNDI

    I have multiple DBs that I'm accessing from the same application. I have them both defined in my server.properties file and they work with the ds.xml just fine. However, I would like to be able to access both data sources from my server. I'm getting the default database from JNDI just fine using:

    Code:
    sql.defaultDatabase.jndi.publish.path:isomorphic/jdbc/defaultDatabase
    Is there a way to publish the second database to JNDI as well?

    #2
    Use the DataSouce.dbName property to have a particular DataSource use a SQL database that is not the default.

    Comment


      #3
      Yeah I got that to work. I'm talking about utilizing the JDBC data source in other server side code. I'm retrieving the default datasource as a Spring bean like this:

      Code:
          @Bean
          public DataSource dataSource() throws NamingException {
              return (DataSource) new JndiTemplate().lookup((String) com.isomorphic.base.Config.getProperty("sql.defaultDatabase.jndi.publish.path"));
          }
      I'm not sure how I can get the other datasource from JNDI. Here's my server.properties:

      Code:
      sql.defaultDatabase.jndi.publish.path:isomorphic/jdbc/defaultDatabase
      sql.defaultDatabase:Mysql
      sql.Mysql.type:mysql
      sql.Mysql.interface.type:dataSource
      sql.Mysql.driver:org.mariadb.jdbc.MariaDbDataSource
      sql.Mysql.driver.serverName:${db.host}
      sql.Mysql.driver.portNumber:3306
      sql.Mysql.driver.databaseName:${db.name}
      sql.Mysql.driver.user:${db.user}
      sql.Mysql.driver.password:${db.password}
      sql.PBDB.type:mysql
      sql.PBDB.interface.type:dataSource
      sql.PBDB.driver:org.mariadb.jdbc.MariaDbDataSource
      sql.PBDB.driver.serverName:${pbdb.db.host}
      sql.PBDB.driver.portNumber:3306
      sql.PBDB.driver.databaseName:${pbdb.db.name}
      sql.PBDB.driver.user:${pbdb.db.user}
      sql.PBDB.driver.password:${pbdb.db.password}
      sql.PBDB.jndi.publish.path:isomorphic/jdbc/PBDB
      I added the property "sql.PBDB.jndi.publish.path", but that doesn't seem to work. Is this possible?

      Comment


        #4
        Hi, it looks like you may have been digging into internal properties files (like framework.properties) and discovering undocumented settings. This setting is used only for some internal projects, and not documented on purpose, and the way it works may be changed without notice.

        You still haven't said why you want the object in question, but:

        1. this sample shows how you can get the Connection object to perform your own operations directly against JDBC, and still be part of the automatically generated transaction

        2. you can just access the property values with the Config server-side class if you want to create an equivalent JDBC DataSource yourself

        Comment


          #5
          No, I'm not talking about framework.properties, this is all in server.properties. I'm taking the info from here:

          https://www.smartclient.com/smartgwt...lSettings.html

          I have 2 DB connections. I've defined both of them in server.properties, and they both work. The default connection, "Mysql" I've made available via JNDI so that I can pick up the connection and use it in Spring or other backend code. The 2 db connections I've made are "Mysql" and "PBDB". Is there a way to publish the second connection to JNDI the same as I'm doing with the first one?

          Comment


            #6
            Again, the property you're trying to use (sql.defaultdatabase.jndi.publish.path) is not documented, nor is the functionality of retrieving JDBC DataSources that are configured in server.properties via JNDI.

            The only mention of JNDI in the above doc is that if *you* set up a JDBC DataSource yourself, then SmartGWT can retrieve it via JNDI.

            That's one possible solution for you, create your JDBC DataSources yourself and make then available to SmartGWT via JNDI. Then obviously they will be available via JNDI to you as well.

            Comment


              #7
              Sorry, you're right, it's not in that link. It is however directly in the server.properties file. Here's the source text:

              # Publish the JDBC endpoint for the defaultDatabase via JNDI at the specified path for use by
              # other frameworks such as Spring, Hibernate, etc.
              # Note that we do not use the java:comp or java:comp/env prefix because that
              # subtree is read-only on Tomcat (and possibly other containers) due to security
              # considerations
              sql.defaultDatabase.jndi.publish.path: isomorphic/jdbc/defaultDatabase
              I've done that for my default database. Can I do that for the second database connection?

              Comment


                #8
                OK, it appears that text got there by some kind of merge error. But the answer is: no, there isn't a way to publish the non-default database to JNDI via built-in framework functionality, but you've already been given multiple alternate solutions.

                Comment


                  #9
                  Thanks, I was just curious if this was an option. I had already used an alternative.

                  Comment

                  Working...
                  X