8 Replies Latest reply on Apr 7, 2011 8:43 PM by racumin

    Adding properties to Jboss JNDI DataSource

    racumin

      Hi,

       

      I'm using Jboss AS 6 with Spring 2.5.6

       

      In my applicationContext.xml, I have:

       

      <jee:jndi-lookup id="dataSource" jndi-name="java:/MyDataSource"/>

       


      This is the xml of my datasource:

       

      <local-tx-datasource>

              <jndi-name>MyDataSource</jndi-name>

              <connection-url>jdbc:oracle:thin:@<ip>:<port>:<sid></connection-url>

              <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>

              <user-name>username</user-name>

              <password>password</password>

              <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>

              <metadata>

                  <type-mapping>oracle</type-mapping>

              </metadata>

       

       

              <idle-timeout-minutes>5</idle-timeout-minutes>

              <min-pool-size>5</min-pool-size>

              <max-pool-size>20</max-pool-size>

              <query-timeout>300</query-timeout>

              <use-fast-fail>true</use-fast-fail>

          </local-tx-datasource>

       

       

       

      Now, how do I add other properties (like read tiemout) in my datasource?

       

      When I was not using JNDI DataSource, we have something like this:

       

      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

                          <property name="driverClassName">

                                    <value>{driverClassName}</value>

                          </property>

                          <property name="url">

                                    <value>${url}</value>

                          </property>

                          <property name="username">

                                    <value>${username}</value>

                          </property>

                          <property name="password">

                                    <value>${password}</value>

                          </property>

                          <property name="initialSize">

                                    <value>${initialSize}</value>

                          </property>

                          <property name="maxActive">

                                    <value>${maxActive}</value>

                          </property>

                          <property name="maxIdle">

                                    <value>${maxIdle}</value>

                          </property>

                          <property name="minIdle">

                                    <value>${minIdle}</value>

                          </property>

                          <property name="maxWait">

                                    <value>${maxWait}</value>

                          </property>

                          <property name="timeBetweenEvictionRunsMillis">

                                    <value>${timeBetweenEvictionRunsMillis}</value>

                          </property>

                          <property name="numTestsPerEvictionRun">

                                    <value>${numTestsPerEvictionRun}</value>

                          </property>

                          <property name="minEvictableIdleTimeMillis">

                                    <value>${minEvictableIdleTimeMillis}</value>

                          </property>

                          <property name="maxOpenPreparedStatements">

                                    <value>${maxOpenPreparedStatements}</value>

                          </property>

                          <property name="poolPreparedStatements">

                                    <value>${poolPreparedStatements}</value>

                          </property>

                </bean>

       

       

      How do I copy the properties from the previous datasource to the one that was using JNDI?

       

       

      Thanks!

        • 1. Adding properties to Jboss JNDI DataSource
          philani

          easest way to edit your datasource is to do it via the JBOSS web console. Deploy it then launch the web console to see the various properties/fields that you can edit.

          • 2. Adding properties to Jboss JNDI DataSource
            racumin

            Philani Dlamini wrote:

             

            easest way to edit your datasource is to do it via the JBOSS web console. Deploy it then launch the web console to see the various properties/fields that you can edit.

            But I want my configuration to be in the xml file. With the current configuration in my xml, what's happening in my project is that if I specified a wrong URL, my query (SELECT statement) will just hang for some minutes. What do I need to do so that if the URL is not valid (or the database server is down), the query will throw an exception instantly? (say CannotGetJdbcException)

             

            And the various properties/fields that I can edit in the web console is already in my xml file. I read the jboss-ds_1_5.dtd and I have not seen any read timeout property there.

             

            I really need help in configuring the jboss data source.

             

            Thanks!

            • 3. Adding properties to Jboss JNDI DataSource
              genman

              If you are just setting a timeout for a query, then create a separate thread that runs (java.util.Timer e.g.) and have that thread do a Thread.interrupt() on the query thread.

              • 4. Adding properties to Jboss JNDI DataSource
                racumin

                Elias Ross wrote:

                 

                If you are just setting a timeout for a query, then create a separate thread that runs (java.util.Timer e.g.) and have that thread do a Thread.interrupt() on the query thread.

                Thanks for the reply! Your answer is a possible solution but I believe that a simpler solution (involving datasource properties) exist. I just do not know how to configure the Jboss datasource to 'mimic' the org.apache.commons.dbcp.BasicDataSource wherein I just need to set some properties and the read/query timeout will be handled by it.

                • 5. Adding properties to Jboss JNDI DataSource
                  philani

                  when making changes to your datasource using the web console, the changes are propagated to the actual xml file that you have deployed. It should not matter whether you make the changes manually of via the web console, the point is the web console abstarcts away the complexity of XML.

                  • 6. Adding properties to Jboss JNDI DataSource
                    racumin

                    I really cannot find the right property to set in my xml or in the web console. I also noticed that if my database is down, the query will always hang for about 190 seconds. I just want to set it to say 1 second so that JBoss will instantly throw an exception if it cannot connect to the database.

                    • 7. Adding properties to Jboss JNDI DataSource
                      genman

                      Thinking about this harder, what you should be doing is setting the JTA timeout. You can do this at the EJB method level, or by calling the transaction manager... I think this is better than doing it at the database level.

                       

                      http://community.jboss.org/wiki/TransactionTimeout

                      • 8. Adding properties to Jboss JNDI DataSource
                        racumin

                        Elias Ross wrote:

                         

                        Thinking about this harder, what you should be doing is setting the JTA timeout. You can do this at the EJB method level, or by calling the transaction manager... I think this is better than doing it at the database level.

                         

                        http://community.jboss.org/wiki/TransactionTimeout

                        I'm not using EJB.

                         

                        By the way I discovered that my problem has nothing to do with the Datasource. My mistake was that the IP for the database that I used was wrong all along. Silly me

                         

                        When I tried a valid IP (I can ping it), JBoss instantly throws an Exception (this is what I want)

                         

                        Sorry for the trouble and thanks for helping!