DataSource discussion


EJB programming & troubleshooting: DataSource discussion

  1. DataSource discussion (1 messages)

    Hey gurus.
    I have the following questions:

    1. I have developed a javax.sql.DataSource implementation which I want my J2EE application to use. That is, wish to be able to retrieve this DataSource from code by JNDI lookup (and I also want the CMPs to use this DataSource). In the deployment tool, I can define a jdbc driver, dbURL, and a JNDI name, and then reference that JNDI name with username, and password in the deployment settings for a component.
    My question is: Where can I define the DataSource implementation to be used for the application? Is this not at all possible?

    2. I need to get instances of other DataSources in the code. I was planning on initializing the DataSources on startup and store a JNDI reference to them (and in code, I then access the DataSources by JNDI lookup). Isn't this the best way?

    3. Is the DataSource that the container is using for the CMP management in any way special, that is, will I be suffering any performance loss by using another DataSource?

    4. I know that I can define a <resource-ref> to a DataSource in my components, so that they always reference the same JNDI name. But every time that I deploy the application, I need to manually type in the username and password for the database.Isn't there a way to embed this information in a deployment descriptor, so that a default username and password can be provided? You might wonder why this would be a requirement, but the application will create the db user by it self, so the user does not have to know anything about it (unless he wants to).

    Any discussion of the above topics will be greatly appreciated. Thanks for your help.

    Oli Gauti.
  2. DataSource discussion[ Go to top ]

    Hi Oli,

    The answers to what you are asking depend heavily on the J2EE app server you use. I use Weblogic 6.1 so I will answer from that perspective:

    1. It doesn't seem possible to specify a javax.sql.DataSource interface for the app server to use. If you decompile any of the Weblogic JDBC stuff you'll notice that there is a lot of WL specific code embedded into the jdbc classes. Therefore, even if you could replace their DataSource with your own it most likely wouldn't run.

    2. Hmmm ... not quite on your wavelength here. WL provides access to its connection pools via JNDI - so there is no reason to get one and then store it back into JNDI using another name.

    3. Refer to Answer 1. Considering the app servers use their own implementations of the jdbc classes, it is highly likely that your replacements will not access any of the proprietary app server features and would therefore come second in the performance race.

    4. With WL, when you define a connection pool you can provide a username and password for it to use when you grab a connection.

    Hope this helped.